LoginView.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <!-- 界面整体背景图 -->
  3. <div class="container">
  4. <!-- 界面左边背景图 -->
  5. <div class="left"></div>
  6. <!-- 界面右边背景图 -->
  7. <div class="right">
  8. <!-- 分为上下两部分,上面是标题,使用背景图片 -->
  9. <div class="right_top"></div>
  10. <!-- 登录界面 -->
  11. <div class="login">
  12. <el-form
  13. ref="loginForm"
  14. :model="loginForm"
  15. :rules="loginRules"
  16. class="login-form"
  17. >
  18. <h3 class="title">登&nbsp;录</h3>
  19. <el-form-item prop="username">
  20. <el-input
  21. v-model="loginForm.username"
  22. type="text"
  23. auto-complete="off"
  24. placeholder="请输入手机号/邮箱"
  25. >
  26. <svg-icon
  27. slot="prefix"
  28. icon-class="user"
  29. class="el-input__icon input-icon"
  30. />
  31. </el-input>
  32. </el-form-item>
  33. <el-form-item prop="password">
  34. <el-input
  35. v-model="loginForm.password"
  36. type="password"
  37. auto-complete="off"
  38. placeholder="请输入密码"
  39. @keyup.enter.native="handleLogin"
  40. >
  41. <svg-icon
  42. slot="prefix"
  43. icon-class="password"
  44. class="el-input__icon input-icon"
  45. />
  46. </el-input>
  47. </el-form-item>
  48. <el-form-item prop="code" v-if="captchaEnabled">
  49. <el-input
  50. v-model="loginForm.code"
  51. auto-complete="off"
  52. placeholder="验证码"
  53. style="width: 63%"
  54. @keyup.enter.native="handleLogin"
  55. >
  56. <svg-icon
  57. slot="prefix"
  58. icon-class="validCode"
  59. class="el-input__icon input-icon"
  60. />
  61. </el-input>
  62. <div class="login-code">
  63. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  64. </div>
  65. </el-form-item>
  66. <el-checkbox
  67. v-model="loginForm.rememberMe"
  68. style="margin: 0px 0px 25px 50px"
  69. >记住密码</el-checkbox
  70. >
  71. <el-form-item style="width: 100%">
  72. <el-button
  73. :loading="loading"
  74. size="medium"
  75. type="primary"
  76. style="width: 100%"
  77. @click.native.prevent="handleLogin"
  78. >
  79. <span v-if="!loading">登 录</span>
  80. <span v-else>登 录 中...</span>
  81. </el-button>
  82. <div style="float: right" v-if="register">
  83. <router-link class="link-type" :to="'/register'"
  84. >立即注册</router-link
  85. >
  86. </div>
  87. </el-form-item>
  88. </el-form>
  89. </div>
  90. </div>
  91. </div>
  92. </template>
  93. <script>
  94. import { getCodeImg } from "@/api/login1";
  95. import Cookies from "js-cookie";
  96. import { encrypt, decrypt } from "@/utils/jsencrypt";
  97. export default {
  98. name: "Login",
  99. data() {
  100. return {
  101. codeUrl: "",
  102. loginForm: {
  103. username: "admin",
  104. password: "admin123",
  105. rememberMe: false,
  106. code: "",
  107. uuid: "",
  108. },
  109. loginRules: {
  110. username: [
  111. { required: true, trigger: "blur", message: "请输入您的账号" },
  112. ],
  113. password: [
  114. { required: true, trigger: "blur", message: "请输入您的密码" },
  115. ],
  116. code: [{ required: true, trigger: "change", message: "请输入验证码" }],
  117. },
  118. loading: false,
  119. // 验证码开关
  120. captchaEnabled: false,
  121. // 注册开关
  122. register: false,
  123. redirect: undefined,
  124. };
  125. },
  126. watch: {
  127. $route: {
  128. handler: function (route) {
  129. this.redirect = route.query && route.query.redirect;
  130. },
  131. immediate: true,
  132. },
  133. },
  134. created() {
  135. this.getCode();
  136. this.getCookie();
  137. },
  138. methods: {
  139. getCode() {
  140. getCodeImg().then((res) => {
  141. this.captchaEnabled =
  142. res.captchaEnabled === undefined ? true : res.captchaEnabled;
  143. if (this.captchaEnabled) {
  144. this.codeUrl = "data:image/gif;base64," + res.img;
  145. this.loginForm.uuid = res.uuid;
  146. }
  147. });
  148. },
  149. getCookie() {
  150. const username = Cookies.get("username");
  151. const password = Cookies.get("password");
  152. const rememberMe = Cookies.get("rememberMe");
  153. this.loginForm = {
  154. username: username === undefined ? this.loginForm.username : username,
  155. password:
  156. password === undefined ? this.loginForm.password : decrypt(password),
  157. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  158. };
  159. },
  160. handleLogin() {
  161. this.$refs.loginForm.validate((valid) => {
  162. if (valid) {
  163. this.loading = true;
  164. if (this.loginForm.rememberMe) {
  165. Cookies.set("username", this.loginForm.username, { expires: 30 });
  166. Cookies.set("password", encrypt(this.loginForm.password), {
  167. expires: 30,
  168. });
  169. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  170. expires: 30,
  171. });
  172. } else {
  173. Cookies.remove("username");
  174. Cookies.remove("password");
  175. Cookies.remove("rememberMe");
  176. }
  177. this.$store
  178. .dispatch("Login", this.loginForm)
  179. .then(() => {
  180. this.$router.push({ path: this.redirect || "/home/page" }).catch(() => {});
  181. })
  182. .catch(() => {
  183. this.loading = false;
  184. if (this.captchaEnabled) {
  185. this.getCode();
  186. }
  187. });
  188. }
  189. });
  190. },
  191. },
  192. };
  193. </script>
  194. <style scoped lang='scss'>
  195. .container {
  196. background: url(../assets/img/dl_background.png);
  197. background-size: cover;
  198. height: 100%;
  199. width: 100%;
  200. display: flex;
  201. .left {
  202. background: url(../assets/img/dl_logo.png);
  203. background-size: calc(100vw * (820 / 1920)) calc(100vh * (894 / 1080));
  204. height: calc(100vh * (894 / 1080));
  205. width: calc(100vw * (820 / 1920));
  206. margin-top: 93px;
  207. margin-left: 189px;
  208. }
  209. .right {
  210. height: calc(100vh * (780 / 1080));
  211. width: calc(100vw * (516 / 1920));
  212. margin-top: 140px;
  213. margin-left: 193px;
  214. .right_top {
  215. background: url(../assets/img/dl_title.png);
  216. background-size: calc(100vw * (497 / 1920)) calc(100vh * (70 / 1080));
  217. height: calc(100vh * (70 / 1080));
  218. width: calc(100vw * (497 / 1920));
  219. font-family: YouSheBiaoTiHei-Regular;
  220. }
  221. .login {
  222. background: url(../assets/img/dl_login.png);
  223. background-size: calc(100vw * (482 / 1920)) calc(100vh * (630 / 1080));
  224. height: calc(100vh * (630 / 1080));
  225. width: calc(100vw * (482 / 1920));
  226. box-sizing: border-box;
  227. border: 1px solid rgba(0, 116, 223, 0.2);
  228. margin-top: 30px;
  229. .title {
  230. width: 60px;
  231. height: 42px;
  232. font-size: 25px;
  233. font-family: PingFang SC-Medium, PingFang SC;
  234. font-weight: 500;
  235. color: #ffffff;
  236. line-height: 30px;
  237. margin-left: 45%;
  238. margin-top: 15%;
  239. }
  240. }
  241. }
  242. ::v-deep .el-input--medium .el-input__inner {
  243. background:transparent;
  244. border: 1px solid #03486F;
  245. }
  246. ::v-deep .el-form-item__content {
  247. margin-left: 50px !important;
  248. width: calc(100vw * (360 / 1920));
  249. }
  250. }
  251. </style>