index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="login-container">
  3. <div class="login-from-box">
  4. <el-form
  5. class="login-form"
  6. ref="loginForm"
  7. autocomplete="on"
  8. :model="loginForm"
  9. :rules="loginRules"
  10. label-position="left"
  11. >
  12. <h3 class="title">{{ systemName }}</h3>
  13. <el-form-item prop="username">
  14. <span class="svg-container svg-container_login">
  15. <svg-icon icon-class="user" />
  16. </span>
  17. <el-input
  18. name="username"
  19. type="text"
  20. clearable
  21. v-model="loginForm.username"
  22. autocomplete="on"
  23. placeholder="用户名"
  24. />
  25. </el-form-item>
  26. <el-form-item prop="password">
  27. <span class="svg-container svg-container_login">
  28. <svg-icon icon-class="password"></svg-icon>
  29. </span>
  30. <el-input
  31. name="password"
  32. :type="pwdType"
  33. clearable
  34. @keyup.enter.native="handleLogin()"
  35. v-model="loginForm.password"
  36. autocomplete="on"
  37. placeholder="密码"
  38. ></el-input>
  39. <span class="show-pwd" @click="showPwd()">
  40. <svg-icon :icon-class="pwdType === 'password' ? 'eye' : 'eye-open'" />
  41. </span>
  42. </el-form-item>
  43. <el-form-item prop="captchaCode">
  44. <span class="svg-container svg-container_login">
  45. <svg-icon icon-class="eye"></svg-icon>
  46. </span>
  47. <el-input
  48. v-model="loginForm.captchaCode"
  49. auto-complete="off"
  50. placeholder="请输入验证码"
  51. style="width: 63%"
  52. clearable
  53. @keyup.enter.native="handleLogin"
  54. ></el-input>
  55. <div class="login-code">
  56. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  57. </div>
  58. </el-form-item>
  59. <div class="login-btn">
  60. <button type="button" class="btn" @click="handleLogin()">立即登录</button>
  61. </div>
  62. <div class="tips">
  63. <!-- <span>Copyright © 2020-2024 <a target="_blank" href="https://www.fuint.cn">fuint.cn</a> 延禾技术 All Rights Reserved.</span> -->
  64. </div>
  65. </el-form>
  66. </div>
  67. </div>
  68. </template>
  69. <script>
  70. import { useUserStore } from '@/store/user'
  71. import { useRouter } from '@/hooks/use-router'
  72. import { getCodeImg } from '@/api/login'
  73. const { login } = useUserStore()
  74. const router = useRouter()
  75. export default {
  76. data() {
  77. return {
  78. systemName: this.$t('app.title'),
  79. loading: false,
  80. loginForm: { uuid: '', username: '', password: '', captchaCode: '' },
  81. codeUrl: '',
  82. pwdType: 'password',
  83. loginRules: {
  84. username: [{ required: true, trigger: 'blur', message: '请输入您的账号' }],
  85. password: [{ required: true, trigger: 'blur', message: '请输入您的密码' }],
  86. captchaCode: [
  87. { required: true, trigger: 'change', message: '请输入验证码' },
  88. { min: 4, max: 6, message: '请输入正确验证码', trigger: 'blur' },
  89. ],
  90. },
  91. }
  92. },
  93. created() {
  94. console.log(this.$t)
  95. this.getCode()
  96. },
  97. methods: {
  98. getCode() {
  99. const app = this
  100. getCodeImg().then((res) => {
  101. app.codeUrl = res.data.captcha
  102. app.loginForm.uuid = res.data.uuid
  103. })
  104. },
  105. showPwd() {
  106. if (this.pwdType === 'password') {
  107. this.pwdType = ''
  108. } else {
  109. this.pwdType = 'password'
  110. }
  111. },
  112. handleLogin() {
  113. const app = this
  114. app.$refs.loginForm.validate((valid) => {
  115. if (valid) {
  116. app.loading = true
  117. login(app.loginForm)
  118. .then(() => {
  119. app.loading = false
  120. console.log('登录成功了!')
  121. app.$router.push({ path: '/cashier' }).catch(() => {})
  122. router.push({ path: '/' }).catch((err) => {
  123. console.log('跳转失败...', err)
  124. })
  125. console.log('登录成功了...')
  126. })
  127. .catch(() => {
  128. app.loading = false
  129. })
  130. } else {
  131. console.log('error submit!!')
  132. return false
  133. }
  134. })
  135. },
  136. },
  137. }
  138. </script>
  139. <style rel="stylesheet/scss" lang="scss" scoped>
  140. // 定义新的配色变量
  141. $primary-color: #a9b1b8; // 主色调,蓝色
  142. $secondary-color: #eabc48; // 次色调,深蓝色
  143. $light-gray: #f5f5f5; // 浅灰色
  144. $dark-gray: #9f8787; // 深灰色
  145. $background-color: #161212; // 背景色,灰色
  146. /* reset element-ui css */
  147. .login-container {
  148. position: fixed;
  149. height: 100%;
  150. width: 100%;
  151. top: 0;
  152. left: 0;
  153. background: linear-gradient(to bottom right, $primary-color, $secondary-color);
  154. background-position: center;
  155. color: #ffffff;
  156. ::v-deep .el-input {
  157. display: inline-block;
  158. height: 47px;
  159. width: 85%;
  160. input {
  161. background: transparent;
  162. border: 0px;
  163. -webkit-appearance: none;
  164. border-radius: 0px;
  165. padding: 12px 5px 12px 15px;
  166. color: $light-gray;
  167. height: 47px;
  168. &:-webkit-autofill {
  169. -webkit-box-shadow: 0 0 0px 1000px $background-color inset !important;
  170. -webkit-text-fill-color: $light-gray !important;
  171. }
  172. }
  173. }
  174. ::v-deep .el-form-item {
  175. border: 1px solid rgba(255, 255, 255, 0.3);
  176. background: rgba(0, 0, 0, 0.1);
  177. border-radius: 5px;
  178. color: #454545;
  179. }
  180. .login-from-box {
  181. position: relative;
  182. .login-form {
  183. position: absolute;
  184. left: 0;
  185. right: 0;
  186. width: 520px;
  187. padding: 35px 35px 15px 35px;
  188. margin: 150px auto;
  189. align-items: center;
  190. color: white;
  191. background-color: rgba(63, 63, 63, 0.373);
  192. border-radius: 10px;
  193. .login-btn {
  194. .btn {
  195. position: relative;
  196. width: 100%;
  197. padding: 6px 0;
  198. margin: 10px 0 36px 0;
  199. font-size: 1.2em;
  200. color: white;
  201. background: linear-gradient(to right, $primary-color, $secondary-color);
  202. border: none;
  203. outline: none;
  204. cursor: pointer;
  205. overflow: hidden;
  206. transition: 0.5s;
  207. &::before {
  208. position: absolute;
  209. content: '';
  210. top: 0;
  211. left: 0;
  212. width: 100%;
  213. height: 100%;
  214. background: linear-gradient(120deg, transparent, hsla(207, 90%, 72%, 0.5), transparent);
  215. transform: translateX(-100%);
  216. transition: 0.5s;
  217. }
  218. &:hover::before {
  219. transform: translateX(100%);
  220. }
  221. }
  222. }
  223. .login-code {
  224. // width: 100px;
  225. height: 100%;
  226. float: right;
  227. img {
  228. cursor: pointer;
  229. vertical-align: middle;
  230. height: 48px;
  231. height: 100%;
  232. border-radius: 1px;
  233. }
  234. }
  235. }
  236. .tips {
  237. font-size: 14px;
  238. color: $light-gray;
  239. margin-bottom: 10px;
  240. text-align: center;
  241. }
  242. .svg-container {
  243. padding: 6px 5px 6px 15px;
  244. color: $dark-gray;
  245. vertical-align: middle;
  246. width: 30px;
  247. display: inline-block;
  248. &_login {
  249. font-size: 20px;
  250. }
  251. }
  252. .title {
  253. font-size: 26px;
  254. font-weight: 400;
  255. color: $light-gray;
  256. margin: 0px auto 20px auto;
  257. text-align: center;
  258. font-weight: bold;
  259. }
  260. .show-pwd {
  261. position: absolute;
  262. right: 10px;
  263. top: 7px;
  264. font-size: 16px;
  265. color: $dark-gray;
  266. cursor: pointer;
  267. user-select: none;
  268. }
  269. }
  270. }
  271. </style>