调解系统PC端服务

login.vue 6.7KB

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