LoginNow.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div>
  3. <div class="bigBox">
  4. <div class="winBox">
  5. <button class="winBtn" @click="WinMin">-</button>
  6. <button class="winBtn" @click="WinClose">×</button>
  7. </div>
  8. <!-- 信息 -->
  9. <div class="imgBox">
  10. <img src="../../assets/image/loginImg.png" alt="">
  11. <!-- <p>登录</p> -->
  12. </div>
  13. <!-- 登录信息 -->
  14. <div class="formBox">
  15. <el-form :model="loginForm" label-width="45px" style="padding-top: 24px;">
  16. <el-form-item label="账号">
  17. <el-input class="loginInp" v-model="loginForm.username" placeholder="你的账号..." maxlength="32" />
  18. </el-form-item>
  19. <el-form-item label="密码">
  20. <el-input class="loginInp" type="password" v-model="loginForm.userpass" show-password
  21. placeholder="你的密码..." maxlength="32" />
  22. </el-form-item>
  23. </el-form>
  24. <div @keyup.enter="sureLog">
  25. <el-button class="loginBtn" type="primary" @click="sureLog">登录</el-button>
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import { ref, onMounted, onBeforeUnmount } from "vue"
  33. import { useRouter } from 'vue-router'
  34. import { ElMessage } from "element-plus"
  35. import login from "@/api/login"
  36. import { useDataStore } from '@/store/modules/golbal-data';
  37. const userStoreCode = useDataStore();
  38. export default {
  39. setup() {
  40. let less = ref("")
  41. let loginForm = ref({
  42. username: "",
  43. userpass: ""
  44. })
  45. let isLogin = ref(false)
  46. let router = useRouter()
  47. function encryptPassword(password) {
  48. if (typeof SmCrypto == 'undefined') {
  49. window.location.reload()
  50. } else {
  51. let val = SmCrypto.doSm3AndSm2Encrypt(password) + '0000'
  52. let ascCode = 0
  53. for (var i = 0; i < password.length; i++) {
  54. ascCode = password.charCodeAt(i).toString(16);
  55. // console.log(ascCode,'asc');
  56. if (ascCode.length == 1) {
  57. val += '00' + ascCode
  58. } else if (ascCode.length == 2) {
  59. val += '0' + ascCode
  60. } else {
  61. val += ascCode
  62. }
  63. }
  64. return val
  65. }
  66. }
  67. function sureLog() {
  68. let kis = encryptPassword(loginForm.value.userpass)
  69. login.LoginNow({
  70. login_account: loginForm.value.username,
  71. pwd: kis
  72. }).then(res => {
  73. if (res.returncode === 200) {
  74. isLogin.value = true
  75. sessionStorage.setItem("loginStatus", isLogin.value)
  76. sessionStorage.setItem("userInfo", JSON.stringify(res.data))
  77. if (typeof (window.windowEx) != "undefined") {
  78. windowEx.Size(0, 0) //全屏
  79. windowEx.Position('center')
  80. }
  81. router.push('/home/mission')
  82. userStoreCode.GlobalCodes();
  83. ElMessage({
  84. message: '登陆成功!',
  85. type: "success"
  86. })
  87. } else {
  88. ElMessage({
  89. message: res.msg,
  90. type: "error"
  91. })
  92. }
  93. })
  94. }
  95. // 添加键盘事件监听器
  96. function handleKeyUp(event) {
  97. if (event.key === 'Enter') {
  98. sureLog();
  99. }
  100. };
  101. function WinClose() {
  102. windowEx.Exit()
  103. }
  104. function WinMin() {
  105. windowEx.Min()
  106. }
  107. onMounted(() => {
  108. window.addEventListener('keyup', handleKeyUp);
  109. // window.onload = function () {
  110. // // 设置定时器,在 5000 毫秒(即 5 秒)后执行刷新操作
  111. // setTimeout(function () {
  112. // location.reload(); // 执行页面刷新
  113. // }, 100); // 5000 毫秒 = 5 秒
  114. // };
  115. })
  116. onBeforeUnmount(() => {
  117. window.removeEventListener('keyup', handleKeyUp);
  118. })
  119. return {
  120. encryptPassword,
  121. less,
  122. sureLog,
  123. loginForm,
  124. isLogin,
  125. WinMin,
  126. WinClose,
  127. handleKeyUp,
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. .bigBox {
  134. width: 31.8rem;
  135. height: 35.5rem;
  136. margin: 0;
  137. background: #FFFFFF;
  138. box-shadow: 0px 1px 1.25rem 2px rgba(61, 128, 177, 0.13);
  139. position: absolute;
  140. border: 1px solid #ededed;
  141. border-radius: 3px;
  142. left: 50%;
  143. top: 50%;
  144. margin-top: -17.25rem;
  145. margin-left: -15.9rem
  146. }
  147. .formBox {
  148. width: 320px;
  149. height: 244px;
  150. text-align: center;
  151. background: #FFFFFF;
  152. box-shadow: 0px 1px 1.67rem 3px rgba(52, 123, 231, 0.12);
  153. border-radius: 4px 4px 4px 4px;
  154. opacity: 1;
  155. margin: 0 auto;
  156. }
  157. .imgBox {
  158. width: 22.67rem;
  159. height: 8.33rem;
  160. margin: 0 auto;
  161. margin-left: 90px;
  162. padding-top: 40px;
  163. }
  164. .loginInp {
  165. width: 22.5rem;
  166. height: 3.33rem;
  167. margin-top: 5px;
  168. border: 1px solid #A3ADE0;
  169. }
  170. .loginBtn {
  171. width: 22.67rem;
  172. height: 3.33rem;
  173. margin-top: 10px;
  174. background-color: #255CE7;
  175. }
  176. .winBox {
  177. width: 5.67rem;
  178. height: 5.67rem;
  179. position: absolute;
  180. top: 0px;
  181. right: 0px;
  182. color: #676767;
  183. }
  184. .winBtn {
  185. width: 2.83rem;
  186. height: 2.83rem;
  187. background-color: transparent;
  188. border: none;
  189. font-size: 2.5rem;
  190. text-align: center;
  191. line-height: 2.83rem;
  192. color: #676767;
  193. }
  194. .winBtn:nth-child(1):hover {
  195. border: 1px black solid;
  196. }
  197. .winBtn:nth-child(2):hover {
  198. background-color: red;
  199. }
  200. </style>