阅行客电子档案
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.

332 lines
8.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="login" :style="'background-image:url(' + Background + ');'">
  3. <div class="login-left-img" />
  4. <el-form
  5. ref="loginForm"
  6. :model="loginForm"
  7. :rules="loginRules"
  8. label-position="left"
  9. label-width="0px"
  10. class="login-form"
  11. >
  12. <h3 class="login-title" />
  13. <el-form-item prop="username">
  14. <el-input
  15. v-model="loginForm.username"
  16. type="text"
  17. auto-complete="off"
  18. placeholder="登录账号"
  19. >
  20. <i slot="prefix" class="iconfont icon-zhanghao login-icon" />
  21. </el-input>
  22. </el-form-item>
  23. <el-form-item prop="password">
  24. <el-input
  25. v-model="loginForm.password"
  26. type="password"
  27. auto-complete="off"
  28. placeholder="密码"
  29. @keyup.enter.native="handleLogin"
  30. >
  31. <i slot="prefix" class="iconfont icon-mima login-icon" />
  32. </el-input>
  33. </el-form-item>
  34. <el-form-item class="login-code" prop="code">
  35. <el-input
  36. v-model="loginForm.code"
  37. auto-complete="off"
  38. placeholder="验证码"
  39. @keyup.enter.native="handleLogin"
  40. >
  41. <i slot="prefix" class="iconfont icon-yanzhengma login-icon" />
  42. </el-input>
  43. <div class="code-img">
  44. <img :src="codeUrl" @click="getCode">
  45. </div>
  46. </el-form-item>
  47. <el-button
  48. :loading="loading"
  49. size="medium"
  50. @click.native.prevent="handleLogin"
  51. >
  52. <span v-if="!loading"> </span>
  53. <span v-else> 中...</span>
  54. </el-button>
  55. </el-form>
  56. <!-- 底部 -->
  57. <div v-if="$store.state.settings.showFooter" id="el-login-footer">
  58. <div class="login-footer-link">
  59. <a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">帮助</a>
  60. <span> | </span>
  61. <a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">隐私</a>
  62. <span> | </span>
  63. <a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">条款</a>
  64. </div>
  65. <span v-html="$store.state.settings.footerTxt" />
  66. <!-- <span> </span>
  67. <a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">{{
  68. $store.state.settings.caseNumber
  69. }}</a> -->
  70. </div>
  71. </div>
  72. </template>
  73. <script>
  74. import { encrypt } from '@/utils/rsaEncrypt'
  75. import Config from '@/settings'
  76. import { getCodeImg } from '@/api/login'
  77. import Cookies from 'js-cookie'
  78. import qs from 'qs'
  79. import Background from '@/assets/images/login/dl-bg.png'
  80. export default {
  81. name: 'Login',
  82. data() {
  83. return {
  84. Background: Background,
  85. codeUrl: '',
  86. cookiePass: '',
  87. loginForm: {
  88. username: '',
  89. password: '',
  90. rememberMe: false,
  91. code: '',
  92. uuid: ''
  93. },
  94. loginRules: {
  95. username: [
  96. { required: true, trigger: 'blur', message: '登录账号不能为空' }
  97. ],
  98. password: [
  99. { required: true, trigger: 'blur', message: '密码不能为空' }
  100. ],
  101. code: [
  102. { required: true, trigger: 'change', message: '验证码不能为空' }
  103. ]
  104. },
  105. loading: false,
  106. redirect: undefined
  107. }
  108. },
  109. watch: {
  110. $route: {
  111. handler: function(route) {
  112. const data = route.query
  113. if (data && data.redirect) {
  114. this.redirect = data.redirect
  115. delete data.redirect
  116. if (JSON.stringify(data) !== '{}') {
  117. this.redirect =
  118. this.redirect + '&' + qs.stringify(data, { indices: false })
  119. }
  120. }
  121. },
  122. immediate: true
  123. }
  124. },
  125. created() {
  126. // 获取验证码
  127. this.getCode()
  128. // 获取用户名密码等Cookie
  129. this.getCookie()
  130. // token 过期提示
  131. this.point()
  132. },
  133. methods: {
  134. getCode() {
  135. getCodeImg().then((res) => {
  136. this.codeUrl = res.img
  137. this.loginForm.uuid = res.uuid
  138. })
  139. },
  140. getCookie() {
  141. const username = Cookies.get('username')
  142. let password = Cookies.get('password')
  143. const rememberMe = Cookies.get('rememberMe')
  144. // 保存cookie里面的加密后的密码
  145. this.cookiePass = password === undefined ? '' : password
  146. password = password === undefined ? this.loginForm.password : password
  147. this.loginForm = {
  148. username: username === undefined ? this.loginForm.username : username,
  149. password: password,
  150. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  151. code: ''
  152. }
  153. },
  154. handleLogin() {
  155. this.$refs.loginForm.validate((valid) => {
  156. const user = {
  157. username: this.loginForm.username,
  158. password: this.loginForm.password,
  159. rememberMe: this.loginForm.rememberMe,
  160. code: this.loginForm.code,
  161. uuid: this.loginForm.uuid
  162. }
  163. if (user.password !== this.cookiePass) {
  164. user.password = encrypt(user.password)
  165. }
  166. if (valid) {
  167. this.loading = true
  168. if (user.rememberMe) {
  169. Cookies.set('username', user.username, {
  170. expires: Config.passCookieExpires
  171. })
  172. Cookies.set('password', user.password, {
  173. expires: Config.passCookieExpires
  174. })
  175. Cookies.set('rememberMe', user.rememberMe, {
  176. expires: Config.passCookieExpires
  177. })
  178. } else {
  179. Cookies.remove('username')
  180. Cookies.remove('password')
  181. Cookies.remove('rememberMe')
  182. }
  183. this.$store
  184. .dispatch('Login', user)
  185. .then((res) => {
  186. this.loading = false
  187. if (res.code === 500) {
  188. this.$message({ message: res.message, type: 'warning', duration: 5000, offset: 8 })
  189. this.getCode()
  190. } else {
  191. this.$router.push({ path: this.redirect || '/' })
  192. }
  193. }).catch(res => {
  194. this.loading = false
  195. this.getCode()
  196. })
  197. } else {
  198. console.log('error submit!!')
  199. return false
  200. }
  201. })
  202. },
  203. point() {
  204. const point = Cookies.get('point') !== undefined
  205. if (point) {
  206. this.$message({ message: '当前登录状态已过期,请重新登录!', type: 'warning', duration: 5000, offset: 8 })
  207. Cookies.remove('point')
  208. }
  209. }
  210. }
  211. }
  212. </script>
  213. <style rel="stylesheet/scss" lang="scss">
  214. .login {
  215. display: flex;
  216. justify-content: center;
  217. align-items: center;
  218. width: 100%;
  219. height: 100vh;
  220. position: relative;
  221. background-size: cover;
  222. }
  223. // 登录界面左边bg
  224. .login-left-img{
  225. position: absolute;
  226. top: 19.16%;
  227. left: 10.625%;
  228. width: 48%;
  229. height: 67.8%;
  230. background: url('~@/assets/images/login/dl-bgt.png') no-repeat;
  231. background-size: contain;
  232. }
  233. // 登录框内标题
  234. .login-title {
  235. width: 272px;
  236. height: 49px;
  237. margin: 0 auto 43px auto;
  238. background: url('~@/assets/images/login/dl-logo.png') no-repeat;
  239. background-size: contain;
  240. }
  241. // 登录表单
  242. .login-form {
  243. width: 26%;
  244. padding: 5% 2% 5.8% 2%;
  245. position: absolute;
  246. left: calc(100vw - 44%);
  247. top: 50%;
  248. transform: translateY(-50%);
  249. background: #fff;
  250. box-shadow: 0px 10px 25px -4px rgba(14,44,119,0.1);
  251. border-radius: 10px;
  252. .el-form-item {
  253. width: 100% !important;
  254. height: 48px;
  255. margin-bottom: 24px;
  256. .el-form-item__content{
  257. height: 100%;
  258. .el-input{
  259. font-size: 14px;
  260. height: 100%;
  261. input{
  262. height: 100%;
  263. padding: 0 20px 0 45px;
  264. border-radius: 3px;
  265. border-color: #E6E8ED;
  266. }
  267. }
  268. }
  269. }
  270. .login-icon{
  271. margin-left: 10px;
  272. line-height: 48px;
  273. color: #545B65;
  274. }
  275. // 图形验证码
  276. .login-code {
  277. .el-form-item__content{
  278. display: flex;
  279. justify-content: space-between;
  280. .el-input{
  281. width: 60%;
  282. }
  283. .code-img{
  284. flex: 1;
  285. height: 43px;
  286. margin-left: 20px;
  287. display: inline-block;
  288. img {
  289. width: 100%;
  290. height: 100% !important;
  291. cursor: pointer;
  292. }
  293. }
  294. }
  295. }
  296. // 登录btn
  297. .el-button {
  298. width: 100% !important;
  299. height: 52px;
  300. margin-top: 36px;
  301. font-size: 20px;
  302. background: #0348F3;
  303. border-radius: 5px;
  304. color: #ffffff;
  305. border: none;
  306. }
  307. }
  308. // 底部-备案
  309. #el-login-footer{
  310. position: absolute;
  311. left: 50%;
  312. bottom: 3%;
  313. transform: translateX(-50%);
  314. font-size: 12px;
  315. color: #A6ADB6;
  316. text-align: center;
  317. .login-footer-link{
  318. margin-bottom: 10px;
  319. span{
  320. display: inline-block;
  321. margin: 0 6px;
  322. color: #CBD5E6;
  323. }
  324. }
  325. }
  326. </style>