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

219 lines
6.3 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  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 { getCodeImg } from '@/api/login'
  47. import Cookies from 'js-cookie'
  48. import Background from '@/assets/images/background.jpg'
  49. export default {
  50. name: 'Login',
  51. data() {
  52. return {
  53. Background: Background,
  54. codeUrl: '',
  55. cookiePass: '',
  56. loginForm: {
  57. username: 'admin',
  58. password: '123456',
  59. rememberMe: false,
  60. code: '',
  61. uuid: ''
  62. },
  63. loginRules: {
  64. username: [
  65. { required: true, trigger: 'blur', message: '用户名不能为空' }
  66. ],
  67. password: [
  68. { required: true, trigger: 'blur', message: '密码不能为空' }
  69. ],
  70. code: [{ required: true, trigger: 'change', message: '验证码不能为空' }]
  71. },
  72. loading: false,
  73. redirect: undefined
  74. }
  75. },
  76. watch: {
  77. $route: {
  78. handler: function(route) {
  79. this.redirect = route.query && route.query.redirect
  80. },
  81. immediate: true
  82. }
  83. },
  84. created() {
  85. // 获取验证码
  86. this.getCode()
  87. // 获取用户名密码等Cookie
  88. this.getCookie()
  89. // token 过期提示
  90. this.point()
  91. },
  92. methods: {
  93. getCode() {
  94. getCodeImg().then(res => {
  95. this.codeUrl = res.img
  96. this.loginForm.uuid = res.uuid
  97. })
  98. },
  99. getCookie() {
  100. const username = Cookies.get('username')
  101. let password = Cookies.get('password')
  102. const rememberMe = Cookies.get('rememberMe')
  103. // 保存cookie里面的加密后的密码
  104. this.cookiePass = password === undefined ? '' : password
  105. password = password === undefined ? this.loginForm.password : password
  106. this.loginForm = {
  107. username: username === undefined ? this.loginForm.username : username,
  108. password: password,
  109. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  110. code: ''
  111. }
  112. },
  113. handleLogin() {
  114. this.$refs.loginForm.validate(valid => {
  115. const user = {
  116. username: this.loginForm.username,
  117. password: this.loginForm.password,
  118. rememberMe: this.loginForm.rememberMe,
  119. code: this.loginForm.code,
  120. uuid: this.loginForm.uuid
  121. }
  122. if (user.password !== this.cookiePass) {
  123. user.password = encrypt(user.password)
  124. }
  125. if (valid) {
  126. this.loading = true
  127. if (user.rememberMe) {
  128. Cookies.set('username', user.username, {
  129. expires: Config.passCookieExpires
  130. })
  131. Cookies.set('password', user.password, {
  132. expires: Config.passCookieExpires
  133. })
  134. Cookies.set('rememberMe', user.rememberMe, {
  135. expires: Config.passCookieExpires
  136. })
  137. } else {
  138. Cookies.remove('username')
  139. Cookies.remove('password')
  140. Cookies.remove('rememberMe')
  141. }
  142. this.$store.dispatch('Login', user).then(() => {
  143. this.loading = false
  144. this.$router.push({ path: this.redirect || '/layout/TopMenus' })
  145. }).catch(() => {
  146. this.loading = false
  147. this.getCode()
  148. })
  149. } else {
  150. console.log('error submit!!')
  151. return false
  152. }
  153. })
  154. },
  155. point() {
  156. const point = Cookies.get('point') !== undefined
  157. if (point) {
  158. this.$notify({
  159. title: '提示',
  160. message: '当前登录状态已过期,请重新登录!',
  161. type: 'warning',
  162. duration: 5000
  163. })
  164. Cookies.remove('point')
  165. }
  166. }
  167. }
  168. }
  169. </script>
  170. <style rel="stylesheet/scss" lang="scss">
  171. .login {
  172. display: flex;
  173. justify-content: center;
  174. align-items: center;
  175. height: 100%;
  176. background-size: cover;
  177. }
  178. .title {
  179. margin: 0 auto 30px auto;
  180. text-align: center;
  181. color: #707070;
  182. }
  183. .login-form {
  184. border-radius: 6px;
  185. background: #ffffff;
  186. width: 385px;
  187. padding: 25px 25px 5px 25px;
  188. .el-input {
  189. height: 38px;
  190. input {
  191. height: 38px;
  192. }
  193. }
  194. .input-icon {
  195. height: 39px;
  196. width: 14px;
  197. margin-left: 2px;
  198. }
  199. }
  200. .login-tip {
  201. font-size: 13px;
  202. text-align: center;
  203. color: #bfbfbf;
  204. }
  205. .login-code {
  206. width: 33%;
  207. display: inline-block;
  208. height: 38px;
  209. float: right;
  210. img {
  211. cursor: pointer;
  212. vertical-align: middle;
  213. }
  214. }
  215. </style>