login.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div class="login">
  3. <div class="color-model"></div>
  4. <div class="background-border"></div>
  5. <img class="login-text" src="../assets/images/login-text.svg" alt="">
  6. <img class="login-logo" src="../assets/images/login-logo.svg" alt="">
  7. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" label-width="80px">
  8. <el-form-item prop="username" label="">
  9. <h3 class="mini-title">欢迎登录</h3>
  10. <h3 class="title">安全保卫管理平台</h3>
  11. </el-form-item>
  12. <el-form-item prop="username" label="用户名">
  13. <el-input
  14. v-model="loginForm.username"
  15. type="text"
  16. auto-complete="off"
  17. placeholder="账号">
  18. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  19. </el-input>
  20. </el-form-item>
  21. <el-form-item prop="password" label="密码">
  22. <el-input
  23. v-model="loginForm.password"
  24. type="password"
  25. auto-complete="off"
  26. placeholder="密码"
  27. @keyup.enter.native="handleLogin">
  28. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  29. </el-input>
  30. </el-form-item>
  31. <el-form-item prop="code" v-if="captchaEnabled">
  32. <el-input
  33. v-model="loginForm.code"
  34. auto-complete="off"
  35. placeholder="验证码"
  36. style="width: 63%"
  37. @keyup.enter.native="handleLogin"
  38. >
  39. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  40. </el-input>
  41. <div class="login-code">
  42. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  43. </div>
  44. </el-form-item>
  45. <el-form-item style="margin-bottom:1px !important;">
  46. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  47. </el-form-item>
  48. <!-- <div style="width:80%;margin: 0 auto;">
  49. <el-button
  50. :loading="loading"
  51. size="medium"
  52. style="width:100%;background-color: #00afff;color:#fff;"
  53. @click.native.prevent="handleLogin">
  54. <span v-if="!loading">登 录</span>
  55. <span v-else>登 录 中...</span>
  56. </el-button>
  57. <div style="float: right;" v-if="register">
  58. <router-link class="link-type" :to="'/register'">立即注册</router-link>
  59. </div>
  60. </div>-->
  61. <el-form-item prop="password" label="">
  62. <el-button
  63. :loading="loading"
  64. size="medium"
  65. style="width:100%;background-color: #00afff;color:#fff;"
  66. @click.native.prevent="handleLogin">
  67. <span v-if="!loading">登 录</span>
  68. <span v-else>登 录 中...</span>
  69. </el-button>
  70. </el-form-item>
  71. </el-form>
  72. <!-- 底部 -->
  73. <div class="el-login-footer">
  74. <!-- <span>Copyright © 2018-2023 ruoyi.vip All Rights Reserved.</span>-->
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. import { getCodeImg } from "@/api/login";
  80. import { encrypt, decrypt } from '@/utils/jsencrypt'
  81. import { setLocal, getLocal, removeLocal } from '../utils/auth'
  82. export default {
  83. name: "Login",
  84. data() {
  85. return {
  86. codeUrl: "",
  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: [{ required: true, trigger: "change", message: "请输入验证码" }]
  102. },
  103. loading: false,
  104. // 验证码开关
  105. captchaEnabled: false,
  106. // 注册开关
  107. register: false,
  108. redirect: undefined
  109. };
  110. },
  111. watch: {
  112. $route: {
  113. handler: function(route) {
  114. //this.redirect = route.query && route.query.redirect;
  115. console.log(this.redirect,'重定向')
  116. },
  117. immediate: true
  118. }
  119. },
  120. created() {
  121. //this.getCode();
  122. this.getUserInfo();
  123. },
  124. methods: {
  125. getCode() {
  126. getCodeImg().then(res => {
  127. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  128. if (this.captchaEnabled) {
  129. this.codeUrl = "data:image/gif;base64," + res.img;
  130. this.loginForm.uuid = res.uuid;
  131. }
  132. });
  133. },
  134. getUserInfo() {
  135. const username = getLocal("username");
  136. const password = getLocal("password");
  137. const rememberMe = getLocal('rememberMe')
  138. this.loginForm = {
  139. username: !username? this.loginForm.username : username,
  140. password: !password? this.loginForm.password : decrypt(password),
  141. rememberMe: !rememberMe ? false : Boolean(rememberMe)
  142. };
  143. },
  144. handleLogin(key, value) {
  145. this.$refs.loginForm.validate(valid => {
  146. if (valid) {
  147. this.loading = true;
  148. //判断是否保存登录信息,没有则登陆时删除
  149. if (this.loginForm.rememberMe) {
  150. setLocal("username", this.loginForm.username);
  151. setLocal("password", encrypt(this.loginForm.password));
  152. setLocal('rememberMe', this.loginForm.rememberMe);
  153. } else {
  154. removeLocal("username");
  155. removeLocal("password");
  156. removeLocal('rememberMe');
  157. }
  158. //登录请求
  159. this.$store.dispatch("Login", this.loginForm).then(() => {
  160. this.loading = false;
  161. console.log(this.redirect,'this.redirect')
  162. this.$router.push({ path:"/home" }).catch(()=>{});
  163. }).catch(() => {
  164. this.loading = false;
  165. if (this.captchaEnabled) {
  166. this.getCode();
  167. }
  168. });
  169. }
  170. });
  171. }
  172. }
  173. };
  174. </script>
  175. <style lang="scss">
  176. .login {
  177. display: flex;
  178. justify-content: right;
  179. align-items: center;
  180. height: 100%;
  181. background: rgba(0, 140, 214, 1) url("../assets/images/login-background.png") no-repeat;
  182. background-size: cover;
  183. position: relative;
  184. .el-checkbox__inner::after{
  185. height: 9px;
  186. left:5px;
  187. }
  188. }
  189. .color-model{
  190. width: 100%;
  191. height: 100%;
  192. position: fixed;
  193. background-color: rgba(0, 140, 214, .5);
  194. }
  195. .background-border{
  196. position: absolute;
  197. width: 100%;
  198. height: 342px;
  199. background-color: #fff;
  200. opacity: .2;
  201. z-index:0;
  202. display: flex;
  203. }
  204. .login-logo{
  205. position: absolute;
  206. left: 118px;
  207. top: 77px;
  208. width: 245px;
  209. height: 69px;
  210. }
  211. .login-text{
  212. position: absolute;
  213. left:23%;
  214. align-items: center;
  215. width: 510px;
  216. height: 190px;
  217. }
  218. .mini-title{
  219. font-size: 16px;
  220. text-align: center;
  221. color: #999;
  222. }
  223. .title {
  224. font-size: 32px;
  225. margin: 0 auto 50px auto;
  226. text-align: center;
  227. color: #333;
  228. }
  229. .login-form {
  230. border-radius: 6px;
  231. background: #ffffff;
  232. width: 544px;
  233. height: 488px;
  234. padding: 25px 60px 50px 60px;
  235. z-index:2;
  236. position: absolute;
  237. right: 12%;
  238. .el-input {
  239. height: 38px;
  240. input {
  241. height: 38px;
  242. }
  243. }
  244. .input-icon {
  245. height: 39px;
  246. width: 14px;
  247. margin-left: 2px;
  248. }
  249. }
  250. .login-tip {
  251. font-size: 13px;
  252. text-align: center;
  253. color: #bfbfbf;
  254. }
  255. .login-code {
  256. width: 33%;
  257. height: 38px;
  258. float: right;
  259. img {
  260. cursor: pointer;
  261. vertical-align: middle;
  262. }
  263. }
  264. .el-login-footer {
  265. height: 40px;
  266. line-height: 40px;
  267. position: fixed;
  268. bottom: 0;
  269. width: 100%;
  270. text-align: center;
  271. color: #fff;
  272. font-family: Arial;
  273. font-size: 12px;
  274. letter-spacing: 1px;
  275. }
  276. .login-code-img {
  277. height: 38px;
  278. }
  279. </style>