You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
5.9 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. <template>
  2. <div class="login">
  3. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  4. <h3 class="title">琛海科技AI智能管理</h3>
  5. <el-form-item prop="username">
  6. <el-input
  7. v-model="loginForm.username"
  8. type="text"
  9. auto-complete="off"
  10. placeholder="账号"
  11. >
  12. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item prop="password">
  16. <el-input
  17. v-model="loginForm.password"
  18. type="password"
  19. auto-complete="off"
  20. placeholder="密码"
  21. @keyup.enter.native="handleLogin"
  22. >
  23. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  24. </el-input>
  25. </el-form-item>
  26. <el-form-item prop="code" v-if="captchaEnabled">
  27. <el-input
  28. v-model="loginForm.code"
  29. auto-complete="off"
  30. placeholder="验证码"
  31. style="width: 63%"
  32. @keyup.enter.native="handleLogin"
  33. >
  34. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  35. </el-input>
  36. <div class="login-code">
  37. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  38. </div>
  39. </el-form-item>
  40. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  41. <el-form-item style="width:100%;">
  42. <el-button
  43. :loading="loading"
  44. size="medium"
  45. type="primary"
  46. style="width:100%; font-family: '思源宋体 Light' !important;"
  47. @click.native.prevent="handleLogin"
  48. >
  49. <span v-if="!loading"> </span>
  50. <span v-else> 中...</span>
  51. </el-button>
  52. <div style="float: right;" v-if="register">
  53. <router-link class="link-type" :to="'/register'">立即注册</router-link>
  54. </div>
  55. </el-form-item>
  56. </el-form>
  57. <!-- 底部 -->
  58. <div class="el-login-footer">
  59. <span>琛海科技有限公司.</span>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import { getCodeImg } from "@/api/login";
  65. import Cookies from "js-cookie";
  66. import { encrypt, decrypt } from '@/utils/jsencrypt'
  67. export default {
  68. name: "Login",
  69. data() {
  70. return {
  71. codeUrl: "",
  72. loginForm: {
  73. username: "admin",
  74. password: "admin123",
  75. rememberMe: false,
  76. code: "",
  77. uuid: ""
  78. },
  79. loginRules: {
  80. username: [
  81. { required: true, trigger: "blur", message: "请输入您的账号" }
  82. ],
  83. password: [
  84. { required: true, trigger: "blur", message: "请输入您的密码" }
  85. ],
  86. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  87. },
  88. loading: false,
  89. // 验证码开关
  90. captchaEnabled: true,
  91. // 注册开关
  92. register: false,
  93. redirect: undefined
  94. };
  95. },
  96. watch: {
  97. $route: {
  98. handler: function(route) {
  99. this.redirect = route.query && route.query.redirect;
  100. },
  101. immediate: true
  102. }
  103. },
  104. created() {
  105. this.getCode();
  106. this.getCookie();
  107. },
  108. methods: {
  109. getCode() {
  110. getCodeImg().then(res => {
  111. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  112. if (this.captchaEnabled) {
  113. this.codeUrl = "data:image/gif;base64," + res.img;
  114. this.loginForm.uuid = res.uuid;
  115. }
  116. });
  117. },
  118. getCookie() {
  119. const username = Cookies.get("username");
  120. const password = Cookies.get("password");
  121. const rememberMe = Cookies.get('rememberMe')
  122. this.loginForm = {
  123. username: username === undefined ? this.loginForm.username : username,
  124. password: password === undefined ? this.loginForm.password : decrypt(password),
  125. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  126. };
  127. },
  128. handleLogin() {
  129. this.$refs.loginForm.validate(valid => {
  130. if (valid) {
  131. this.loading = true;
  132. if (this.loginForm.rememberMe) {
  133. Cookies.set("username", this.loginForm.username, { expires: 30 });
  134. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  135. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  136. } else {
  137. Cookies.remove("username");
  138. Cookies.remove("password");
  139. Cookies.remove('rememberMe');
  140. }
  141. this.$store.dispatch("Login", this.loginForm).then(() => {
  142. // this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
  143. this.$router.push({ path: "/home" }).catch(() => { });
  144. }).catch(() => {
  145. this.loading = false;
  146. if (this.captchaEnabled) {
  147. this.getCode();
  148. }
  149. });
  150. }
  151. });
  152. }
  153. }
  154. };
  155. </script>
  156. <style rel="stylesheet/scss" lang="scss">
  157. .login {
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. height: 100%;
  162. background-image: url("../assets/images/logo.png");
  163. // background-size: 100% 100%;
  164. background-size: cover;
  165. }
  166. .title {
  167. margin: 0px auto 30px auto;
  168. text-align: center;
  169. color: #707070;
  170. }
  171. .login-form {
  172. border-radius: 6px;
  173. background: #ffffff;
  174. width: 400px;
  175. padding: 25px 25px 5px 25px;
  176. .el-input {
  177. height: 38px;
  178. input {
  179. height: 38px;
  180. }
  181. }
  182. .input-icon {
  183. height: 39px;
  184. width: 14px;
  185. margin-left: 2px;
  186. }
  187. }
  188. .login-tip {
  189. font-size: 13px;
  190. text-align: center;
  191. color: #bfbfbf;
  192. }
  193. .login-code {
  194. width: 33%;
  195. height: 38px;
  196. float: right;
  197. img {
  198. cursor: pointer;
  199. vertical-align: middle;
  200. }
  201. }
  202. .el-login-footer {
  203. height: 40px;
  204. line-height: 40px;
  205. position: fixed;
  206. bottom: 0;
  207. width: 100%;
  208. text-align: center;
  209. color: #fff;
  210. font-family: Arial;
  211. font-size: 12px;
  212. letter-spacing: 1px;
  213. }
  214. .login-code-img {
  215. height: 38px;
  216. }
  217. </style>