Rap 原分销系统代码Web
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

1ec2404c5ac703385baa58deeb14b9b0e87850f7.svn-base 6.5KB

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