login.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div class="allConDiv">
  3. <div class="headerDiv">
  4. <img src="../assets/logo/logo.png"/>
  5. <span class="line"></span>
  6. <span class="text">管理系统</span>
  7. </div>
  8. <div class="login">
  9. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  10. <h3 class="title"><span class="orangeLine"></span>用户登录</h3>
  11. <el-form-item prop="username">
  12. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  13. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  14. </el-input>
  15. </el-form-item>
  16. <el-form-item prop="password">
  17. <el-input
  18. v-model="loginForm.password"
  19. type="password"
  20. auto-complete="off"
  21. placeholder="密码"
  22. @keyup.enter.native="handleLogin"
  23. >
  24. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  25. </el-input>
  26. </el-form-item>
  27. <el-form-item prop="code">
  28. <el-input
  29. v-model="loginForm.code"
  30. auto-complete="off"
  31. placeholder="验证码"
  32. style="width: 63%"
  33. @keyup.enter.native="handleLogin"
  34. >
  35. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  36. </el-input>
  37. <div class="login-code">
  38. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  39. </div>
  40. </el-form-item>
  41. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  42. <el-form-item style="width:100%;">
  43. <el-button
  44. :loading="loading"
  45. size="medium"
  46. type="primary"
  47. style="width:100%;background: #F39800;border-color: #F39800;"
  48. @click.native.prevent="handleLogin"
  49. >
  50. <span v-if="!loading">登 录</span>
  51. <span v-else>登 录 中...</span>
  52. </el-button>
  53. </el-form-item>
  54. </el-form>
  55. <!-- 底部 -->
  56. <!--<div class="el-login-footer">-->
  57. <!--<span>Copyright © 2018-2019 ruoyi.vip All Rights Reserved.</span>-->
  58. <!--</div>-->
  59. </div>
  60. <div class="footerDiv"> © 2020上海人寿保险股份有限公司</div>
  61. </div>
  62. </template>
  63. <script>
  64. import { getCodeImg } from "@/api/login";
  65. import Cookies from "js-cookie";
  66. import { encrypt, decrypt } from '@/utils/jsencrypt'
  67. export default {
  68. name: "Login",
  69. data() {
  70. return {
  71. codeUrl: "",
  72. cookiePassword: "",
  73. // 用户名密码 admin admin123
  74. loginForm: {
  75. username: "",
  76. password: "",
  77. rememberMe: false,
  78. code: "",
  79. uuid: ""
  80. },
  81. loginRules: {
  82. username: [
  83. { required: true, trigger: "blur", message: "用户名不能为空" }
  84. ],
  85. password: [
  86. { required: true, trigger: "blur", message: "密码不能为空" }
  87. ],
  88. code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
  89. },
  90. loading: false,
  91. redirect: undefined
  92. };
  93. },
  94. watch: {
  95. $route: {
  96. handler: function(route) {
  97. this.redirect = route.query && route.query.redirect;
  98. },
  99. immediate: true
  100. }
  101. },
  102. created() {
  103. this.getCode();
  104. this.getCookie();
  105. },
  106. methods: {
  107. getCode() {
  108. getCodeImg().then(res => {
  109. this.codeUrl = "data:image/gif;base64," + res.img;
  110. this.loginForm.uuid = res.uuid;
  111. });
  112. },
  113. getCookie() {
  114. const username = Cookies.get("username");
  115. const password = Cookies.get("password");
  116. const rememberMe = Cookies.get('rememberMe')
  117. this.loginForm = {
  118. username: username === undefined ? this.loginForm.username : username,
  119. password: password === undefined ? this.loginForm.password : decrypt(password),
  120. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  121. };
  122. },
  123. handleLogin() {
  124. this.$refs.loginForm.validate(valid => {
  125. if (valid) {
  126. this.loading = true;
  127. if (this.loginForm.rememberMe) {
  128. Cookies.set("username", this.loginForm.username, { expires: 30 });
  129. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  130. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  131. } else {
  132. Cookies.remove("username");
  133. Cookies.remove("password");
  134. Cookies.remove('rememberMe');
  135. }
  136. this.$store
  137. .dispatch("Login", this.loginForm)
  138. .then(() => {
  139. this.$router.push({ path: this.redirect || "/" });
  140. })
  141. .catch(() => {
  142. this.loading = false;
  143. this.getCode();
  144. });
  145. }
  146. });
  147. }
  148. }
  149. };
  150. </script>
  151. <style rel="stylesheet/scss" lang="scss">
  152. .login {
  153. display: flex;
  154. justify-content: flex-end;
  155. align-items: center;
  156. height: 83%;
  157. background-image: url("../assets/image/login-background.png");
  158. background-size: cover;
  159. padding: 0 80px;
  160. box-sizing: border-box;
  161. }
  162. .title {
  163. margin: 0px auto 30px auto;
  164. /*text-align: center;*/
  165. color: #707070;
  166. position: relative;
  167. }
  168. .orangeLine{
  169. height: 18px;
  170. width: 4px;
  171. background: #F39800;
  172. display: inline-block;
  173. position: absolute;
  174. left: -25px;
  175. top: 0;
  176. }
  177. .login-form {
  178. border-radius: 6px;
  179. background: #ffffff;
  180. width: 400px;
  181. padding: 25px 25px 5px 25px;
  182. .el-input {
  183. height: 38px;
  184. input {
  185. height: 38px;
  186. }
  187. }
  188. .input-icon {
  189. height: 39px;
  190. width: 14px;
  191. margin-left: 2px;
  192. }
  193. }
  194. .login-tip {
  195. font-size: 13px;
  196. text-align: center;
  197. color: #bfbfbf;
  198. }
  199. .login-code {
  200. width: 33%;
  201. height: 38px;
  202. float: right;
  203. img {
  204. cursor: pointer;
  205. vertical-align: middle;
  206. }
  207. }
  208. .el-login-footer {
  209. height: 40px;
  210. line-height: 40px;
  211. position: fixed;
  212. bottom: 0;
  213. width: 100%;
  214. text-align: center;
  215. color: #fff;
  216. font-family: Arial;
  217. font-size: 12px;
  218. letter-spacing: 1px;
  219. }
  220. .login-code-img {
  221. height: 38px;
  222. }
  223. .allConDiv{
  224. height: 100%;
  225. .headerDiv{
  226. height: 10%;
  227. display: flex;
  228. align-items: center;
  229. background:#FFF;
  230. padding: 0 50px;
  231. box-sizing:border-box;
  232. img{
  233. height: 40%;
  234. }
  235. .line{
  236. display: inline-block;
  237. height: 30%;
  238. width: 2px;
  239. background: #333;
  240. margin: 0 6px;
  241. }
  242. .text{
  243. font-size: 20px;
  244. color: #333;
  245. font-weight: bold;
  246. }
  247. }
  248. .footerDiv{
  249. height: 7%;
  250. display: flex;
  251. align-items: center;
  252. justify-content: center;
  253. background:#FFF;
  254. font-size: 14px;
  255. color: #333;
  256. }
  257. }
  258. </style>