login.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div class="login" id="loginBox">
  3. <div class="login-con">
  4. <div class="title">芳华佳选客户服务管理系统</div>
  5. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  6. <el-form-item prop="username">
  7. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  8. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  9. </el-input>
  10. </el-form-item>
  11. <el-form-item prop="password">
  12. <el-input
  13. v-model="loginForm.password"
  14. type="password"
  15. auto-complete="off"
  16. placeholder="密码"
  17. @keyup.enter.native="handleLogin"
  18. >
  19. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  20. </el-input>
  21. </el-form-item>
  22. <el-form-item prop="code">
  23. <el-input
  24. v-model="loginForm.code"
  25. auto-complete="off"
  26. placeholder="验证码"
  27. style="width: 63%"
  28. @keyup.enter.native="handleLogin"
  29. >
  30. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  31. </el-input>
  32. <div class="login-code">
  33. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  34. </div>
  35. </el-form-item>
  36. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  37. <el-form-item style="width:100%;">
  38. <el-button
  39. :loading="loading"
  40. size="medium"
  41. type="primary"
  42. style="width:100%;"
  43. @click.native.prevent="handleLogin"
  44. >
  45. <span v-if="!loading">登 录</span>
  46. <span v-else>登 录 中...</span>
  47. </el-button>
  48. </el-form-item>
  49. </el-form>
  50. </div>
  51. <!-- 底部 -->
  52. <div class="el-login-footer">
  53. <span>Copyright © 2023 <a href="https://beian.miit.gov.cn/" target="_blank">渝ICP备19014022号-7</a></span>
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. import { getCodeImg } from "@/api/login";
  59. import Cookies from "js-cookie";
  60. import { encrypt, decrypt } from '@/utils/jsencrypt'
  61. export default {
  62. name: "Login",
  63. data() {
  64. return {
  65. codeUrl: "",
  66. cookiePassword: "",
  67. loginForm: {
  68. username: "",
  69. password: "",
  70. rememberMe: false,
  71. code: "",
  72. uuid: ""
  73. },
  74. loginRules: {
  75. username: [
  76. { required: true, trigger: "blur", message: "用户名不能为空" }
  77. ],
  78. password: [
  79. { required: true, trigger: "blur", message: "密码不能为空" }
  80. ],
  81. code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
  82. },
  83. loading: false,
  84. redirect: undefined
  85. };
  86. },
  87. watch: {
  88. $route: {
  89. handler: function(route) {
  90. this.redirect = route.query && route.query.redirect;
  91. },
  92. immediate: true
  93. }
  94. },
  95. mounted () {
  96. },
  97. created() {
  98. this.getCode();
  99. this.getCookie();
  100. },
  101. methods: {
  102. getCode() {
  103. getCodeImg().then(res => {
  104. this.codeUrl = "data:image/gif;base64," + res.img;
  105. this.loginForm.uuid = res.uuid;
  106. });
  107. },
  108. getCookie() {
  109. const username = Cookies.get("username");
  110. const password = Cookies.get("password");
  111. const rememberMe = Cookies.get('rememberMe')
  112. this.loginForm = {
  113. username: username === undefined ? this.loginForm.username : username,
  114. password: password === undefined ? this.loginForm.password : decrypt(password),
  115. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  116. };
  117. },
  118. handleLogin() {
  119. this.$refs.loginForm.validate(valid => {
  120. if (valid) {
  121. this.loading = true;
  122. if (this.loginForm.rememberMe) {
  123. Cookies.set("username", this.loginForm.username, { expires: 30 });
  124. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  125. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  126. } else {
  127. Cookies.remove("username");
  128. Cookies.remove("password");
  129. Cookies.remove('rememberMe');
  130. }
  131. this.$store
  132. .dispatch("Login", this.loginForm)
  133. .then(() => {
  134. this.$router.push({ path: this.redirect || "/" });
  135. })
  136. .catch(() => {
  137. this.loading = false;
  138. this.getCode();
  139. });
  140. }
  141. });
  142. }
  143. }
  144. };
  145. </script>
  146. <style rel="stylesheet/scss" lang="scss">
  147. .login {
  148. display: flex;
  149. justify-content: center;
  150. align-items: center;
  151. height: 100%;
  152. width: 100%;
  153. background: linear-gradient(-90deg, #1CBAAC 0%, rgba(19, 164, 180, 0.8) 45%, rgba(54, 161, 194, 0.57) 100%);
  154. background-image: url(../assets/image/login-background.jpg);
  155. background-size: cover;
  156. background-repeat: no-repeat;
  157. .login-con{
  158. width: 435px;
  159. display: flex;
  160. flex-direction: column;
  161. align-items: center;
  162. justify-content: center;
  163. .title{
  164. font-size: 30px;
  165. font-family: Microsoft YaHei;
  166. font-weight: bold;
  167. color: #FFFFFF;
  168. }
  169. .login-form{
  170. border-radius: 8px;
  171. overflow: hidden;
  172. background: #ffffff;
  173. }
  174. .img-box{
  175. width: 420px;
  176. height: 420px;
  177. img{
  178. width: 100%;
  179. height: 100%;
  180. object-fit: cover;
  181. }
  182. }
  183. }
  184. }
  185. .title {
  186. margin: 0px auto 30px auto;
  187. text-align: center;
  188. color: #707070;
  189. }
  190. .login-form {
  191. box-sizing: border-box;
  192. background: #ffffff;
  193. width: 330px;
  194. padding: 25px 25px 5px 25px;
  195. .el-input {
  196. height: 38px;
  197. input {
  198. height: 38px;
  199. }
  200. }
  201. .input-icon {
  202. height: 39px;
  203. width: 14px;
  204. margin-left: 2px;
  205. }
  206. }
  207. .login-tip {
  208. font-size: 13px;
  209. text-align: center;
  210. color: #bfbfbf;
  211. }
  212. .login-code {
  213. width: 33%;
  214. height: 38px;
  215. float: right;
  216. img {
  217. cursor: pointer;
  218. vertical-align: middle;
  219. }
  220. }
  221. .el-login-footer {
  222. height: 40px;
  223. line-height: 40px;
  224. position: fixed;
  225. bottom: 0;
  226. width: 100%;
  227. text-align: center;
  228. color: #fff;
  229. font-family: Arial;
  230. font-size: 12px;
  231. letter-spacing: 1px;
  232. }
  233. .login-code-img {
  234. height: 38px;
  235. }
  236. </style>