LoginView.vue 7.9 KB

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