login.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="login-container">
  3. <div class="login-form">
  4. <div class="login-logo">
  5. <i class="el-icon-lock"></i>
  6. </div>
  7. <h2 class="login-title">系统登录</h2>
  8. <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-position="top">
  9. <el-form-item prop="username">
  10. <el-input v-model="loginForm.username" placeholder="请输入账号" prefix-icon="el-icon-user"
  11. :class="{ 'is-focused': usernameFocus }" @focus="usernameFocus = true"
  12. @blur="usernameFocus = false"></el-input>
  13. </el-form-item>
  14. <el-form-item prop="password">
  15. <el-input v-model="loginForm.password" placeholder="请输入密码" prefix-icon="el-icon-lock" show-password
  16. :class="{ 'is-focused': passwordFocus }" @focus="passwordFocus = true"
  17. @blur="passwordFocus = false"></el-input>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" @click="handleLogin" class="login-btn" :loading="loginLoading">
  21. 登录
  22. </el-button>
  23. </el-form-item>
  24. </el-form>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import { dualFactorLogin } from '@/api/sigon'
  30. import { encrypt, decrypt } from '@/utils/jsencrypt'
  31. export default {
  32. data() {
  33. return {
  34. loginForm: {
  35. username: '',
  36. password: ''
  37. },
  38. loginRules: {
  39. username: [
  40. { required: true, message: '请输入账号', trigger: 'blur' }
  41. ],
  42. password: [
  43. { required: true, message: '请输入密码', trigger: 'blur' }
  44. ]
  45. },
  46. usernameFocus: false,
  47. passwordFocus: false,
  48. loginLoading: false
  49. }
  50. },
  51. methods: {
  52. handleLogin() {
  53. this.$refs.loginForm.validate((valid) => {
  54. if (valid) {
  55. this.loginLoading = true;
  56. // 加密账号
  57. this.loginForm.username = encrypt(this.loginForm.username)
  58. // 加密密码
  59. this.loginForm.password = encrypt(this.loginForm.password)
  60. // 调用登录接口
  61. dualFactorLogin(this.loginForm).then(res => {
  62. if (res.code === 200) {
  63. sessionStorage.setItem("getInfoName", this.loginForm.username);
  64. this.$router.push('/SignOn');
  65. this.loginLoading = false;
  66. } else {
  67. this.$message.error(res.message);
  68. this.loginLoading = false;
  69. }
  70. }).catch(() => {
  71. this.$message.error(res.message);
  72. this.loginLoading = false;
  73. });
  74. // 模拟登录请求
  75. // setTimeout(() => {
  76. // sessionStorage.setItem("getInfoName", this.loginForm.username);
  77. // this.$router.push('/SignOn');
  78. // this.loginLoading = false;
  79. // }, 500);
  80. }
  81. });
  82. }
  83. }
  84. }
  85. </script>
  86. <style scoped>
  87. .login-container {
  88. display: flex;
  89. justify-content: center;
  90. align-items: center;
  91. height: 100vh;
  92. background: url("../assets/singleSignOn/bj.png");
  93. background-size: cover;
  94. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  95. }
  96. .login-form {
  97. width: 100%;
  98. max-width: 400px;
  99. padding: 40px;
  100. background-color: rgba(255, 255, 255, 0.98);
  101. border-radius: 16px;
  102. box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  103. backdrop-filter: blur(10px);
  104. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  105. }
  106. .login-logo {
  107. display: flex;
  108. justify-content: center;
  109. margin-bottom: 24px;
  110. }
  111. .login-logo i {
  112. font-size: 48px;
  113. color: #326eff;
  114. background: #326eff;
  115. -webkit-background-clip: text;
  116. -webkit-text-fill-color: transparent;
  117. background-clip: text;
  118. }
  119. .login-title {
  120. text-align: center;
  121. margin-bottom: 32px;
  122. color: #2d3748;
  123. font-size: 24px;
  124. font-weight: 600;
  125. letter-spacing: -0.3px;
  126. }
  127. .login-btn {
  128. width: 100%;
  129. height: 48px;
  130. font-size: 16px;
  131. font-weight: 500;
  132. border-radius: 8px;
  133. background-color: #326eff;
  134. border: none;
  135. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  136. box-shadow: 0 4px 12px rgba(50, 110, 255, 0.3);
  137. }
  138. .login-btn:hover {
  139. transform: translateY(-2px);
  140. box-shadow: 0 8px 20px rgba(50, 110, 255, 0.4);
  141. background-color: #2558d1;
  142. }
  143. .login-btn:active {
  144. transform: translateY(0);
  145. }
  146. .login-btn:focus {
  147. box-shadow: 0 0 0 3px rgba(50, 110, 255, 0.2);
  148. }
  149. /* 输入框样式优化 */
  150. .el-form-item {
  151. margin-bottom: 20px;
  152. }
  153. .el-input__inner {
  154. height: 48px;
  155. border-radius: 8px;
  156. border: 2px solid #e2e8f0;
  157. font-size: 15px;
  158. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  159. background-color: #fafbfc;
  160. }
  161. .el-input__inner:focus {
  162. border-color: #326eff;
  163. box-shadow: 0 0 0 3px rgba(50, 110, 255, 0.1);
  164. background-color: #ffffff;
  165. }
  166. .el-input__prefix {
  167. color: #a0aec0;
  168. font-size: 18px;
  169. }
  170. .el-input.is-focused .el-input__prefix {
  171. color: #326eff;
  172. }
  173. /* 响应式设计 */
  174. @media (max-width: 768px) {
  175. .login-form {
  176. margin: 0 20px;
  177. padding: 32px 24px;
  178. }
  179. .login-title {
  180. font-size: 20px;
  181. margin-bottom: 24px;
  182. }
  183. .login-logo i {
  184. font-size: 40px;
  185. }
  186. .el-input__inner {
  187. height: 44px;
  188. font-size: 14px;
  189. }
  190. .login-btn {
  191. height: 44px;
  192. font-size: 15px;
  193. }
  194. .el-form-item {
  195. margin-bottom: 16px;
  196. }
  197. }
  198. @media (max-width: 480px) {
  199. .login-form {
  200. margin: 0 16px;
  201. padding: 24px 20px;
  202. }
  203. }
  204. </style>