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

340 lines
9.0 KiB

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: 'admin',
  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({
  189. message: res.message,
  190. type: 'warning',
  191. duration: 5000
  192. })
  193. this.getCode()
  194. } else {
  195. this.$router.push({ path: this.redirect || '/' })
  196. }
  197. }).catch(res => {
  198. this.loading = false
  199. this.getCode()
  200. })
  201. } else {
  202. console.log('error submit!!')
  203. return false
  204. }
  205. })
  206. },
  207. point() {
  208. const point = Cookies.get('point') !== undefined
  209. if (point) {
  210. this.$message({
  211. message: '当前登录状态已过期,请重新登录!',
  212. type: 'warning',
  213. duration: 5000
  214. })
  215. Cookies.remove('point')
  216. }
  217. }
  218. }
  219. }
  220. </script>
  221. <style rel="stylesheet/scss" lang="scss">
  222. .login {
  223. display: flex;
  224. justify-content: center;
  225. align-items: center;
  226. width: 100%;
  227. height: 100vh;
  228. position: relative;
  229. background-size: cover;
  230. }
  231. // 登录界面左边bg
  232. .login-left-img{
  233. position: absolute;
  234. top: 19.16%;
  235. left: 10.625%;
  236. width: 48%;
  237. height: 67.8%;
  238. background: url('~@/assets/images/login/dl-bgt.png') no-repeat;
  239. background-size: contain;
  240. }
  241. // 登录框内标题
  242. .login-title {
  243. width: 272px;
  244. height: 49px;
  245. margin: 0 auto 43px auto;
  246. background: url('~@/assets/images/login/dl-logo.png') no-repeat;
  247. background-size: contain;
  248. }
  249. // 登录表单
  250. .login-form {
  251. width: 26%;
  252. padding: 5% 2% 5.8% 2%;
  253. position: absolute;
  254. left: calc(100vw - 44%);
  255. top: 50%;
  256. transform: translateY(-50%);
  257. background: #fff;
  258. box-shadow: 0px 10px 25px -4px rgba(14,44,119,0.1);
  259. border-radius: 10px;
  260. .el-form-item {
  261. width: 100% !important;
  262. height: 48px;
  263. margin-bottom: 24px;
  264. .el-form-item__content{
  265. height: 100%;
  266. .el-input{
  267. font-size: 14px;
  268. height: 100%;
  269. input{
  270. height: 100%;
  271. padding: 0 20px 0 45px;
  272. border-radius: 3px;
  273. border-color: #E6E8ED;
  274. }
  275. }
  276. }
  277. }
  278. .login-icon{
  279. margin-left: 10px;
  280. line-height: 48px;
  281. color: #545B65;
  282. }
  283. // 图形验证码
  284. .login-code {
  285. .el-form-item__content{
  286. display: flex;
  287. justify-content: space-between;
  288. .el-input{
  289. width: 60%;
  290. }
  291. .code-img{
  292. flex: 1;
  293. height: 43px;
  294. margin-left: 20px;
  295. display: inline-block;
  296. img {
  297. width: 100%;
  298. height: 100% !important;
  299. cursor: pointer;
  300. }
  301. }
  302. }
  303. }
  304. // 登录btn
  305. .el-button {
  306. width: 100% !important;
  307. height: 52px;
  308. margin-top: 36px;
  309. font-size: 20px;
  310. background: #0348F3;
  311. border-radius: 5px;
  312. color: #ffffff;
  313. border: none;
  314. }
  315. }
  316. // 底部-备案
  317. #el-login-footer{
  318. position: absolute;
  319. left: 50%;
  320. bottom: 3%;
  321. transform: translateX(-50%);
  322. font-size: 12px;
  323. color: #A6ADB6;
  324. text-align: center;
  325. .login-footer-link{
  326. margin-bottom: 10px;
  327. span{
  328. display: inline-block;
  329. margin: 0 6px;
  330. color: #CBD5E6;
  331. }
  332. }
  333. }
  334. </style>