login.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <div class="login">
  3. <div class="login_Left">
  4. <div class="anima1"></div>
  5. <div class="anima2"></div>
  6. <div class="anima3"></div>
  7. <div class="anima4"></div>
  8. <div class="anima5"></div>
  9. </div>
  10. <div class="login_divs">
  11. <el-form
  12. class="login_Right"
  13. ref="loginForm"
  14. :model="loginForm"
  15. :rules="loginRules"
  16. >
  17. <div class="weComeSty">
  18. <img
  19. style="width: 30px; height: 24px; vertical-align: sub"
  20. src="@/assets/images/smile@2x.png"
  21. alt=""
  22. /><span class="textStys">欢迎登录</span>
  23. </div>
  24. <div class="mar_stys textStys">用户名</div>
  25. <el-form-item prop="username">
  26. <el-input
  27. v-model="loginForm.username"
  28. type="text"
  29. auto-complete="off"
  30. placeholder="请输入用户名"
  31. >
  32. </el-input>
  33. </el-form-item>
  34. <div class="mar_stys textStys">密码</div>
  35. <el-form-item prop="password">
  36. <el-input
  37. class="el_inputSty"
  38. v-model="loginForm.password"
  39. type="password"
  40. auto-complete="off"
  41. placeholder="密码"
  42. @keyup.enter.native="handleLogin"
  43. >
  44. </el-input>
  45. </el-form-item>
  46. <div class="mar_stys textStys">验证码</div>
  47. <el-form-item prop="code" v-if="captchaOnOff" class="fle_x">
  48. <el-input
  49. class="el_inputSty"
  50. v-model="loginForm.code"
  51. auto-complete="off"
  52. placeholder="验证码"
  53. @keyup.enter.native="handleLogin"
  54. >
  55. </el-input>
  56. <div class="login-code">
  57. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  58. </div>
  59. </el-form-item>
  60. <div class="rightStsyt">
  61. <el-checkbox v-model="loginForm.rememberMe" class="checkStyles"
  62. >记住密码</el-checkbox
  63. >
  64. </div>
  65. <el-form-item style="width: 100%">
  66. <el-button
  67. :loading="loading"
  68. size="medium"
  69. type="primary"
  70. class="btnFootsty"
  71. @click.native.prevent="handleLogin"
  72. >
  73. <span v-if="!loading">登 录</span>
  74. <span v-else>登 录 中...</span>
  75. </el-button>
  76. <div style="float: right" v-if="register">
  77. <router-link class="link-type" :to="'/register'"
  78. >立即注册</router-link
  79. >
  80. </div>
  81. </el-form-item>
  82. </el-form>
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import { getCodeImg } from "@/api/login";
  88. import Cookies from "js-cookie";
  89. import { encrypt, decrypt } from "@/utils/jsencrypt";
  90. export default {
  91. name: "Login",
  92. data() {
  93. return {
  94. codeUrl: "",
  95. cookiePassword: "",
  96. loginForm: {
  97. username: "",
  98. password: "",
  99. rememberMe: false,
  100. code: "",
  101. uuid: "",
  102. },
  103. loginRules: {
  104. username: [
  105. { required: true, trigger: "blur", message: "请输入您的账号" },
  106. ],
  107. password: [
  108. { required: true, trigger: "blur", message: "请输入您的密码" },
  109. ],
  110. code: [{ required: true, trigger: "change", message: "请输入验证码" }],
  111. },
  112. loading: false,
  113. // 验证码开关
  114. captchaOnOff: true,
  115. // 注册开关
  116. register: false,
  117. redirect: undefined,
  118. };
  119. },
  120. watch: {
  121. $route: {
  122. handler: function (route) {
  123. this.redirect = route.query && route.query.redirect;
  124. },
  125. immediate: true,
  126. },
  127. },
  128. created() {
  129. console.log("---Systems:中正科技")
  130. this.getCode();
  131. this.getCookie();
  132. },
  133. methods: {
  134. getCode() {
  135. getCodeImg().then((res) => {
  136. // this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff;
  137. // if (this.captchaOnOff) {
  138. this.codeUrl = "data:image/gif;base64," + res.data.img;
  139. this.loginForm.uuid = res.data.uuid;
  140. // }
  141. });
  142. },
  143. getCookie() {
  144. const username = Cookies.get("username");
  145. const password = Cookies.get("password");
  146. const rememberMe = Cookies.get("rememberMe");
  147. this.loginForm = {
  148. username: username === undefined ? this.loginForm.username : username,
  149. password:
  150. password === undefined ? this.loginForm.password : decrypt(password),
  151. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  152. };
  153. },
  154. handleLogin() {
  155. this.$refs.loginForm.validate((valid) => {
  156. if (valid) {
  157. this.loading = true;
  158. if (this.loginForm.rememberMe) {
  159. Cookies.set("username", this.loginForm.username, { expires: 30 });
  160. Cookies.set("password", encrypt(this.loginForm.password), {
  161. expires: 30,
  162. });
  163. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  164. expires: 30,
  165. });
  166. } else {
  167. Cookies.remove("username");
  168. Cookies.remove("password");
  169. Cookies.remove("rememberMe");
  170. }
  171. this.$store
  172. .dispatch("Login", this.loginForm)
  173. .then(() => {
  174. this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  175. })
  176. .catch(() => {
  177. this.loading = false;
  178. if (this.captchaOnOff) {
  179. this.getCode();
  180. }
  181. });
  182. }
  183. });
  184. },
  185. },
  186. };
  187. </script>
  188. <style lang="less" scoped>
  189. .login {
  190. display: flex;
  191. height: 100%;
  192. overflow: hidden;
  193. .login_Left {
  194. width: 100%;
  195. min-width: 1920px;
  196. background: url("../assets/images/left@2x.png") no-repeat center;
  197. background-size: contain;
  198. overflow: hidden;
  199. .anima1 {
  200. position: fixed;
  201. top: 343px;
  202. left: 182px;
  203. width: 48px;
  204. height: 136px;
  205. background: url("../assets/images/mZ/1@2x.png");
  206. background-size: 48px 136px;
  207. animation: animal1 4s linear infinite;
  208. opacity: 0;
  209. }
  210. .anima2 {
  211. position: fixed;
  212. top: 580px;
  213. left: -20px;
  214. width: 62px;
  215. height: 170px;
  216. background: url("../assets/images/mZ/2@2x.png");
  217. background-size: 62px 170px;
  218. animation: animal1 4s linear infinite;
  219. opacity: 0;
  220. }
  221. .anima3 {
  222. position: fixed;
  223. bottom: -258px;
  224. left: 183px;
  225. width: 151px;
  226. height: 415px;
  227. background: url("../assets/images/mZ/3@2x.png");
  228. background-size: 151px 415px;
  229. animation: animal1 4s linear infinite;
  230. opacity: 0;
  231. }
  232. .anima4 {
  233. position: fixed;
  234. bottom: -350px;
  235. left: 987px;
  236. width: 199px;
  237. height: 551px;
  238. background: url("../assets/images/mZ/4@2x.png");
  239. background-size: 199px 551px;
  240. animation: animal1 4s linear infinite;
  241. opacity: 0;
  242. }
  243. .anima5 {
  244. position: fixed;
  245. top: 200px;
  246. left: 1289px;
  247. width: 85px;
  248. height: 236px;
  249. background: url("../assets/images/mZ/5@2x.png");
  250. background-size: 85px 236px;
  251. animation: animal1 4s linear infinite;
  252. opacity: 0;
  253. }
  254. @keyframes animal1 {
  255. 50% {
  256. transform: translateY(-50px);
  257. opacity: 1;
  258. }
  259. }
  260. }
  261. .login_divs {
  262. position: fixed;
  263. right: 0;
  264. top: 0;
  265. min-width: 500px;
  266. width: 574px;
  267. height: 100%;
  268. background-color: #4174ff;
  269. z-index: 1000;
  270. display: flex;
  271. align-items: center;
  272. justify-content: center;
  273. box-shadow: -4px 0px 9px 1px rgba(17, 33, 77, 0.1);
  274. .login_Right {
  275. width: 420px;
  276. }
  277. }
  278. }
  279. .textStys {
  280. margin-left: 13px;
  281. color: #fff;
  282. font-weight: 400;
  283. font-family: Microsoft YaHei;
  284. font-size: 24px;
  285. }
  286. .weComeSty {
  287. margin-bottom: 70px;
  288. }
  289. .mar_stys {
  290. margin-bottom: 16px;
  291. }
  292. /deep/.el-input--medium .el-input__inner {
  293. height: 48px;
  294. font-size: 20px;
  295. border-radius: 24px;
  296. }
  297. /deep/.el-form-item--medium .el-form-item__content {
  298. display: flex;
  299. align-items: center;
  300. }
  301. .login-code {
  302. height: 40px;
  303. margin-left: 18px;
  304. .login-code-img {
  305. height: 40px;
  306. }
  307. }
  308. .rightStsyt {
  309. display: flex;
  310. align-items: center;
  311. justify-content: flex-end;
  312. }
  313. /deep/.checkStyles {
  314. margin: 0px 0px 25px 0px;
  315. color: #fff;
  316. }
  317. /deep/.el-checkbox__input.is-checked + .el-checkbox__label {
  318. color: #fff;
  319. }
  320. .btnFootsty {
  321. width: 100%;
  322. height: 48px;
  323. border-radius: 24px;
  324. background-color: #fff;
  325. color: #4174ff;
  326. font-size: 20px;
  327. font-weight: bold;
  328. font-family: Microsoft YaHei;
  329. }
  330. /deep/ .fle_x > .el-form-item__content {
  331. display: flex;
  332. align-items: center;
  333. }
  334. </style>