调解系统PC端服务

login.vue 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. <div>Copyright © 2023 乙巢(上海)企业管理服务有限公司.</div>
  71. <div>Version:1.1.0</div>
  72. </div>
  73. </div>
  74. </template>
  75. <script>
  76. import { getCodeImg } from "@/api/login";
  77. import Cookies from "js-cookie";
  78. import { encrypt, decrypt } from '@/utils/jsencrypt'
  79. export default {
  80. name: "Login",
  81. data() {
  82. return {
  83. codeUrl: "",
  84. loginForm: {
  85. username: "admin",
  86. password: "admin123",
  87. rememberMe: false,
  88. code: "",
  89. uuid: ""
  90. },
  91. loginRules: {
  92. username: [
  93. { required: true, trigger: "blur", message: "请输入您的账号" }
  94. ],
  95. password: [
  96. { required: true, trigger: "blur", message: "请输入您的密码" }
  97. ],
  98. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  99. },
  100. loading: false,
  101. // 验证码开关
  102. captchaEnabled: true,
  103. // 注册开关
  104. register: true,
  105. redirect: undefined
  106. };
  107. },
  108. watch: {
  109. $route: {
  110. handler: function(route) {
  111. this.redirect = route.query && route.query.redirect;
  112. },
  113. immediate: true
  114. }
  115. },
  116. created() {
  117. this.getCode();
  118. this.getCookie();
  119. },
  120. methods: {
  121. getCode() {
  122. getCodeImg().then(res => {
  123. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  124. if (this.captchaEnabled) {
  125. this.codeUrl = "data:image/gif;base64," + res.img;
  126. this.loginForm.uuid = res.uuid;
  127. }
  128. });
  129. },
  130. getCookie() {
  131. const username = Cookies.get("username");
  132. const password = Cookies.get("password");
  133. const rememberMe = Cookies.get('rememberMe')
  134. this.loginForm = {
  135. username: username === undefined ? this.loginForm.username : username,
  136. password: password === undefined ? this.loginForm.password : decrypt(password),
  137. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  138. };
  139. },
  140. handleLogin() {
  141. this.$refs.loginForm.validate(valid => {
  142. if (valid) {
  143. this.loading = true;
  144. if (this.loginForm.rememberMe) {
  145. Cookies.set("username", this.loginForm.username, { expires: 30 });
  146. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  147. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  148. } else {
  149. Cookies.remove("username");
  150. Cookies.remove("password");
  151. Cookies.remove('rememberMe');
  152. }
  153. this.$store.dispatch("Login", this.loginForm).then(() => {
  154. this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
  155. }).catch(() => {
  156. this.loading = false;
  157. if (this.captchaEnabled) {
  158. this.getCode();
  159. }
  160. });
  161. }
  162. });
  163. }
  164. }
  165. };
  166. </script>
  167. <style rel="stylesheet/scss" lang="scss">
  168. .login {
  169. display: flex;
  170. justify-content: center;
  171. align-items: center;
  172. height: 100%;
  173. .leftBox {
  174. width: 50%;
  175. height: 90%;
  176. .leftIcon {
  177. height: 20%;
  178. width: 100%;
  179. margin: 0% 10% 1% 15%;
  180. .Icon {
  181. width: 100px;
  182. height: 105px;
  183. background-image: url("../assets/images/logos.png");
  184. background-size: cover;
  185. }
  186. div {
  187. font-size: 18px;
  188. }
  189. }
  190. .leftImage {
  191. width: 100%;
  192. height: 90%;
  193. margin-left: 10%;
  194. margin-top: -15%;
  195. background-image: url("../assets/images/login.svg");
  196. background-size: cover;
  197. }
  198. }
  199. .rightBox {
  200. width: 50%;
  201. height: 90%;
  202. display: flex;
  203. justify-content: center;
  204. align-items: center;
  205. }
  206. }
  207. .title {
  208. margin: 0px auto 30px auto;
  209. text-align: center;
  210. color: #1296db;
  211. font-weight: 600;
  212. }
  213. .login-form {
  214. border-radius: 6px;
  215. background: #ffffff;
  216. width: 400px;
  217. padding: 25px 25px 5px 25px;
  218. .el-input {
  219. height: 38px;
  220. input {
  221. height: 38px;
  222. }
  223. }
  224. .input-icon {
  225. height: 39px;
  226. width: 14px;
  227. margin-left: 2px;
  228. }
  229. }
  230. .login-tip {
  231. font-size: 13px;
  232. text-align: center;
  233. color: #bfbfbf;
  234. }
  235. .login-code {
  236. width: 33%;
  237. height: 38px;
  238. float: right;
  239. img {
  240. cursor: pointer;
  241. vertical-align: middle;
  242. }
  243. }
  244. .el-login-footer {
  245. background-color: rgb(126, 131, 135);
  246. height: 55px;
  247. line-height: 55px;
  248. position: fixed;
  249. bottom: 0;
  250. width: 100%;
  251. text-align: center;
  252. color: #fff;
  253. font-family: Arial;
  254. font-size: 12px;
  255. letter-spacing: 1px;
  256. div {
  257. height: 30%;
  258. }
  259. }
  260. .login-code-img {
  261. height: 38px;
  262. }
  263. </style>