Login.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <div class="login-page">
  3. <div class="login-bg">
  4. <div class="login-particles"></div>
  5. </div>
  6. <div class="login-container">
  7. <div class="login-header">
  8. <h1>实验室安全智慧化管控中心</h1>
  9. <p>中国安全生产科学研究院</p>
  10. </div>
  11. <div class="login-form-wrapper">
  12. <h2>用户登录</h2>
  13. <el-form ref="loginForm" :model="form" :rules="rules" class="login-form">
  14. <el-form-item prop="username">
  15. <el-input
  16. v-model="form.username"
  17. prefix-icon="el-icon-user"
  18. placeholder="请输入用户名/手机号"
  19. clearable
  20. />
  21. </el-form-item>
  22. <el-form-item prop="password">
  23. <el-input
  24. v-model="form.password"
  25. prefix-icon="el-icon-lock"
  26. type="password"
  27. placeholder="请输入密码"
  28. show-password
  29. @keyup.enter.native="handleLogin"
  30. />
  31. </el-form-item>
  32. <el-form-item prop="captcha">
  33. <div class="captcha-row">
  34. <el-input
  35. v-model="form.captcha"
  36. prefix-icon="el-icon-key"
  37. placeholder="请输入验证码"
  38. clearable
  39. />
  40. <div class="captcha-img" @click="refreshCaptcha">{{ captchaText }}</div>
  41. </div>
  42. </el-form-item>
  43. <el-form-item>
  44. <el-button
  45. type="primary"
  46. :loading="loading"
  47. class="login-btn"
  48. @click="handleLogin"
  49. >
  50. 登 录
  51. </el-button>
  52. </el-form-item>
  53. </el-form>
  54. </div>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import md5 from 'js-md5'
  60. import { loginApi } from '@/api'
  61. export default {
  62. name: 'Login',
  63. data() {
  64. return {
  65. form: {
  66. username: '',
  67. password: '',
  68. captcha: ''
  69. },
  70. rules: {
  71. username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  72. password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
  73. captcha: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
  74. },
  75. loading: false,
  76. captchaText: '0000'
  77. }
  78. },
  79. methods: {
  80. refreshCaptcha() {
  81. // 模拟验证码,固定为0000
  82. this.captchaText = '0000'
  83. },
  84. handleLogin() {
  85. this.$refs.loginForm.validate(async (valid) => {
  86. if (!valid) return
  87. // 验证码校验
  88. if (this.form.captcha !== '0000') {
  89. this.$message.error('验证码错误')
  90. return
  91. }
  92. this.loading = true
  93. try {
  94. const params = {
  95. account: this.form.username,
  96. password: md5(this.form.password)
  97. }
  98. const res = await loginApi(params)
  99. this.$store.dispatch('login', { token: res.data.token, userInfo: {} })
  100. this.$message.success('登录成功')
  101. this.$router.push('/lab-status')
  102. } catch (err) {
  103. this.$message.error('登录失败,请重试')
  104. } finally {
  105. this.loading = false
  106. }
  107. })
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .login-page {
  114. width: 1920px;
  115. height: 1080px;
  116. display: flex;
  117. align-items: center;
  118. justify-content: center;
  119. position: relative;
  120. background: linear-gradient(135deg, #0a1628 0%, #0d2247 50%, #0a1a3a 100%);
  121. overflow: hidden;
  122. }
  123. .login-bg {
  124. position: absolute;
  125. top: 0;
  126. left: 0;
  127. width: 100%;
  128. height: 100%;
  129. background: radial-gradient(ellipse at 50% 50%, rgba(30, 144, 255, 0.08) 0%, transparent 60%);
  130. }
  131. .login-container {
  132. position: relative;
  133. z-index: 1;
  134. text-align: center;
  135. }
  136. .login-header {
  137. margin-bottom: 50px;
  138. h1 {
  139. font-size: 36px;
  140. color: #fff;
  141. letter-spacing: 6px;
  142. text-shadow: 0 0 20px rgba(30, 144, 255, 0.5);
  143. }
  144. p {
  145. font-size: 16px;
  146. color: $text-secondary;
  147. margin-top: 12px;
  148. letter-spacing: 4px;
  149. }
  150. }
  151. .login-form-wrapper {
  152. width: 420px;
  153. padding: 40px;
  154. margin:40px;
  155. background: rgba(13, 34, 71, 0.85);
  156. border: 1px solid rgba(30, 144, 255, 0.3);
  157. border-radius: 8px;
  158. backdrop-filter: blur(10px);
  159. box-shadow: 0 0 40px rgba(30, 144, 255, 0.1);
  160. h2 {
  161. font-size: 22px;
  162. color: #fff;
  163. margin-bottom: 30px;
  164. letter-spacing: 2px;
  165. }
  166. }
  167. .login-form {
  168. .el-input__inner {
  169. background: rgba(255, 255, 255, 0.05);
  170. border: 1px solid rgba(255, 255, 255, 0.1);
  171. color: #fff;
  172. height: 44px;
  173. &::placeholder {
  174. color: rgba(255, 255, 255, 0.3);
  175. }
  176. &:focus {
  177. border-color: $accent-blue;
  178. }
  179. }
  180. .el-input__prefix {
  181. color: $text-secondary;
  182. }
  183. }
  184. .captcha-row {
  185. display: flex;
  186. gap: 12px;
  187. .el-input {
  188. flex: 1;
  189. }
  190. .captcha-img {
  191. width: 120px;
  192. height: 44px;
  193. line-height: 44px;
  194. text-align: center;
  195. background: rgba(30, 144, 255, 0.15);
  196. border: 1px solid rgba(30, 144, 255, 0.3);
  197. border-radius: 4px;
  198. color: $accent-cyan;
  199. font-size: 20px;
  200. letter-spacing: 8px;
  201. cursor: pointer;
  202. user-select: none;
  203. &:hover {
  204. background: rgba(30, 144, 255, 0.25);
  205. }
  206. }
  207. }
  208. .login-btn {
  209. width: 100%;
  210. height: 44px;
  211. font-size: 16px;
  212. letter-spacing: 6px;
  213. background: linear-gradient(90deg, #1565c0, #1e88e5);
  214. border: none;
  215. &:hover {
  216. background: linear-gradient(90deg, #1e88e5, #42a5f5);
  217. }
  218. }
  219. </style>