集成后台重构版本
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.

240 lines
6.8 KiB

  1. <template>
  2. <div class="login" :style="'background-image:url('+ Background +');'">
  3. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" label-position="left" label-width="0px" class="login-form">
  4. <h3 class="title">
  5. 阅行集成后台管理
  6. </h3>
  7. <el-form-item prop="username">
  8. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  9. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  10. </el-input>
  11. </el-form-item>
  12. <el-form-item prop="password">
  13. <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码" @keyup.enter.native="handleLogin">
  14. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  15. </el-input>
  16. </el-form-item>
  17. <el-form-item prop="code">
  18. <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter.native="handleLogin">
  19. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  20. </el-input>
  21. <div class="login-code">
  22. <img :src="codeUrl" @click="getCode">
  23. </div>
  24. </el-form-item>
  25. <el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;">
  26. 记住我
  27. </el-checkbox>
  28. <el-form-item style="width:100%;">
  29. <el-button :loading="loading" size="medium" type="primary" style="width:100%;" @click.native.prevent="handleLogin">
  30. <span v-if="!loading"> </span>
  31. <span v-else> 中...</span>
  32. </el-button>
  33. </el-form-item>
  34. </el-form>
  35. <!-- 底部 -->
  36. <!-- <div v-if="$store.state.settings.showFooter" id="el-login-footer">
  37. <span v-html="$store.state.settings.footerTxt" />
  38. <span> </span>
  39. <a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">{{ $store.state.settings.caseNumber }}</a>
  40. </div> -->
  41. </div>
  42. </template>
  43. <script>
  44. import { encrypt } from "@/utils/rsaEncrypt";
  45. import Config from "@/settings";
  46. import Cookies from "js-cookie";
  47. import Background from "@/assets/images/background.jpg";
  48. import { getCodeImg } from '@/api/login'
  49. export default {
  50. //输出模块名称
  51. name: 'Login',
  52. data() {
  53. return {
  54. //背景图
  55. Background: Background,
  56. //登录验证码
  57. codeUrl: '',
  58. //通行证
  59. cookiePass: '',
  60. //默认登录信息--测试用
  61. loginForm: {
  62. username: 'admin',
  63. password: '123456',
  64. rememberMe: false,
  65. code: '',
  66. uuid: '',
  67. },
  68. //登录规则
  69. loginRules: {
  70. username: [
  71. { required: true, trigger: 'blur', message: '用户名不能为空' },
  72. ],
  73. password: [
  74. { required: true, trigger: 'blur', message: '密码不能为空' },
  75. ],
  76. code: [
  77. { required: true, trigger: 'change', message: '验证码不能为空' },
  78. ],
  79. },
  80. //加载状态是否显示
  81. loading: false,
  82. //跳转定向
  83. redirect: undefined
  84. };
  85. },
  86. watch: {
  87. //监听路由变化
  88. $route: {
  89. handler: function (route) {
  90. this.redirect = route.query && route.query.redirect;
  91. },
  92. //立即执行handler
  93. immediate: true,
  94. },
  95. },
  96. // 使用钩子初始化获取信息
  97. created() {
  98. //获取验证码
  99. this.getCode();
  100. //获取用户名密码等 Cookie
  101. this.getCookie();
  102. // token过期提示
  103. this.point();
  104. },
  105. methods: {
  106. //获取验证码方法
  107. getCode() {
  108. getCodeImg().then((res) => {
  109. this.codeUrl = res.img;
  110. this.loginForm.uuid = res.uuid;
  111. });
  112. },
  113. //获取Cookie
  114. getCookie() {
  115. const username = Cookies.get('username');
  116. let password = Cookies.get('password');
  117. const rememberMe = Cookies.get('rememberMe');
  118. // 保存cookie里面的加密后的密码
  119. this.cookiePass = password === undefined ? '' : password;
  120. password = password === undefined ? this.loginForm.password : password;
  121. this.loginForm = {
  122. username: username === undefined ? this.loginForm.username : username,
  123. password: password,
  124. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  125. code: '',
  126. };
  127. },
  128. handleLogin() {
  129. this.$refs.loginForm.validate((valid) => {
  130. // 获取登录信息
  131. const user = {
  132. username: this.loginForm.username,
  133. password: this.loginForm.password,
  134. rememberMe: this.loginForm.rememberMe,
  135. code: this.loginForm.code,
  136. uuid: this.loginForm.uuid,
  137. };
  138. //如果cookie通行证不匹配
  139. if (user.password !== this.cookiePass) {
  140. //把密码进行加密处理
  141. user.password = encrypt(user.password);
  142. }
  143. if (valid) {
  144. this.loading = true;
  145. if (user.rememberMe) {
  146. Cookies.set('username', user.username, {
  147. expires: Config.passCookieExpires,
  148. });
  149. Cookies.set('password', user.password, {
  150. expires: Config.passCookieExpires,
  151. });
  152. Cookies.set('rememberMe', user.rememberMe, {
  153. expires: Config.passCookieExpires,
  154. });
  155. } else {
  156. Cookies.remove('username');
  157. Cookies.remove('password');
  158. Cookies.remove('rememberMe');
  159. }
  160. this.$store
  161. .dispatch('Login', user)
  162. .then(() => {
  163. this.loading = false;
  164. this.$router.push({ path: this.redirect || '/' });
  165. })
  166. .catch(() => {
  167. this.loading = false;
  168. this.getCode();
  169. });
  170. } else {
  171. console.log("提交错误!!");
  172. return false;
  173. }
  174. });
  175. },
  176. point() {
  177. const point = Cookies.get('point') !== undefined;
  178. if (point) {
  179. this.$notify({
  180. title: "提示",
  181. message: "当前登录状态已过期,请重新登录!",
  182. type: "warning",
  183. duration: 5000,
  184. });
  185. Cookies.remove("point");
  186. }
  187. },
  188. },
  189. };
  190. </script>
  191. <style rel="stylesheet/scss" lang="scss">
  192. .login {
  193. display: flex;
  194. justify-content: center;
  195. align-items: center;
  196. height: 100%;
  197. background-size: cover;
  198. }
  199. .title {
  200. margin: 0 auto 30px auto;
  201. text-align: center;
  202. color: #707070;
  203. }
  204. .login-form {
  205. border-radius: 6px;
  206. background: #ffffff;
  207. width: 385px;
  208. padding: 25px 25px 5px 25px;
  209. .el-input {
  210. height: 38px;
  211. input {
  212. height: 38px;
  213. }
  214. }
  215. .input-icon {
  216. height: 39px;
  217. width: 14px;
  218. margin-left: 2px;
  219. }
  220. }
  221. .login-tip {
  222. font-size: 13px;
  223. text-align: center;
  224. color: #bfbfbf;
  225. }
  226. .login-code {
  227. width: 33%;
  228. display: inline-block;
  229. height: 38px;
  230. float: right;
  231. img {
  232. cursor: pointer;
  233. vertical-align: middle;
  234. }
  235. }
  236. </style>