【前端】智能库房综合管理系统前端项目
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.

307 lines
7.7 KiB

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