login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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="mar_stys textStys">手机号码</div>
  61. <el-form-item prop="phonenumber">
  62. <el-input
  63. v-model="loginForm.phonenumber"
  64. type="text"
  65. placeholder="请输入手机号码"
  66. >
  67. </el-input>
  68. </el-form-item>
  69. <div class="mar_stys textStys">手机验证码</div>
  70. <el-form-item prop="smsCode">
  71. <el-input placeholder="获取验证码" v-model="loginForm.smsCode">
  72. <span class="btn" slot="suffix" @click="getRegisterSms">
  73. {{
  74. registerCountDown == 0
  75. ? "获取验证码"
  76. : `${registerCountDown}秒重新获取`
  77. }}
  78. </span>
  79. </el-input>
  80. </el-form-item>
  81. <div class="rightStsyt">
  82. <el-checkbox v-model="loginForm.rememberMe" class="checkStyles"
  83. >记住密码</el-checkbox
  84. >
  85. </div>
  86. <el-form-item style="width: 100%">
  87. <el-button
  88. :loading="loading"
  89. size="medium"
  90. type="primary"
  91. class="btnFootsty"
  92. @click.native.prevent="handleLogin"
  93. >
  94. <span v-if="!loading">登 录</span>
  95. <span v-else>登 录 中...</span>
  96. </el-button>
  97. <div style="float: right" v-if="register">
  98. <router-link class="link-type" :to="'/register'"
  99. >立即注册</router-link
  100. >
  101. </div>
  102. </el-form-item>
  103. </el-form>
  104. </div>
  105. </div>
  106. </template>
  107. <script>
  108. import { getCodeImg, commondual_auth, commonsms_login } from "@/api/login";
  109. import Cookies from "js-cookie";
  110. import { encrypt, decrypt } from "@/utils/jsencrypt";
  111. export default {
  112. name: "Login",
  113. data() {
  114. return {
  115. registerCountDown: 0,
  116. codeUrl: "",
  117. cookiePassword: "",
  118. loginForm: {
  119. username: "",
  120. password: "",
  121. rememberMe: false,
  122. code: "",
  123. uuid: "",
  124. phonenumber: "",
  125. smsCode: "",
  126. },
  127. loginRules: {
  128. username: [
  129. { required: true, trigger: "blur", message: "请输入您的账号" },
  130. ],
  131. password: [
  132. { required: true, trigger: "blur", message: "请输入您的密码" },
  133. ],
  134. code: [{ required: true, trigger: "change", message: "请输入验证码" }],
  135. phonenumber: [
  136. { required: true, trigger: "blur", message: "请输入手机号码" },
  137. ],
  138. smsCode: [
  139. { required: true, trigger: "blur", message: "请输入手机验证码" },
  140. ],
  141. },
  142. loading: false,
  143. // 验证码开关
  144. captchaOnOff: true,
  145. // 注册开关
  146. register: false,
  147. redirect: undefined,
  148. commondual: false,
  149. getRegisterCodeLock: false,
  150. };
  151. },
  152. watch: {
  153. $route: {
  154. handler: function (route) {
  155. this.redirect = route.query && route.query.redirect;
  156. },
  157. immediate: true,
  158. },
  159. },
  160. created() {
  161. commondual_auth().then((res) => {
  162. if (res.data === "1") {
  163. this.commondual = true;
  164. } else {
  165. this.commondual = false;
  166. }
  167. });
  168. this.getCode();
  169. this.getCookie();
  170. },
  171. methods: {
  172. /**
  173. * 获取注册验证码
  174. */
  175. getRegisterSms() {
  176. var self = this;
  177. this.$refs.loginForm.validateField("phonenumber", (valid) => {
  178. if (!valid) {
  179. if (this.registerCountDown == 0) {
  180. if (this.getRegisterCodeLock) {
  181. return;
  182. }
  183. this.getRegisterCodeLock = true;
  184. commonsms_login({ tel: this.loginForm.phonenumber })
  185. .then((res) => {
  186. this.getRegisterCodeLock = false;
  187. this.$message({
  188. message: `验证码已发送`,
  189. type: "success",
  190. });
  191. this.registerCountDown = 60;
  192. this.registerCountDownTimer = setInterval(() => {
  193. self.registerCountDown--;
  194. if (self.registerCountDown == 0) {
  195. clearInterval(self.registerCountDownTimer);
  196. }
  197. }, 1000);
  198. })
  199. .catch((err) => {
  200. this.$message({
  201. message: err.msg,
  202. type: "error",
  203. });
  204. this.getRegisterCodeLock = false;
  205. });
  206. }
  207. }
  208. });
  209. },
  210. getCode() {
  211. getCodeImg().then((res) => {
  212. // this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff;
  213. // if (this.captchaOnOff) {
  214. this.codeUrl = "data:image/gif;base64," + res.data.img;
  215. this.loginForm.uuid = res.data.uuid;
  216. // }
  217. });
  218. },
  219. getCookie() {
  220. const username = Cookies.get("username");
  221. const password = Cookies.get("password");
  222. const rememberMe = Cookies.get("rememberMe");
  223. this.loginForm = {
  224. username: username === undefined ? this.loginForm.username : username,
  225. password:
  226. password === undefined ? this.loginForm.password : decrypt(password),
  227. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  228. };
  229. },
  230. handleLogin() {
  231. this.$refs.loginForm.validate((valid) => {
  232. if (valid) {
  233. this.loading = true;
  234. if (this.loginForm.rememberMe) {
  235. Cookies.set("username", this.loginForm.username, { expires: 30 });
  236. Cookies.set("password", encrypt(this.loginForm.password), {
  237. expires: 30,
  238. });
  239. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  240. expires: 30,
  241. });
  242. } else {
  243. Cookies.remove("username");
  244. Cookies.remove("password");
  245. Cookies.remove("rememberMe");
  246. }
  247. this.$store
  248. .dispatch("Login", this.loginForm)
  249. .then(() => {
  250. this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  251. })
  252. .catch(() => {
  253. this.loading = false;
  254. if (this.captchaOnOff) {
  255. this.getCode();
  256. }
  257. });
  258. }
  259. });
  260. },
  261. },
  262. };
  263. </script>
  264. <style lang="less" scoped>
  265. .login {
  266. display: flex;
  267. height: 100%;
  268. overflow: hidden;
  269. .login_Left {
  270. width: 100%;
  271. min-width: 1920px;
  272. background: url("../assets/images/left@2x.png") no-repeat center;
  273. background-size: contain;
  274. overflow: hidden;
  275. .anima1 {
  276. position: fixed;
  277. top: 343px;
  278. left: 182px;
  279. width: 48px;
  280. height: 136px;
  281. background: url("../assets/images/mZ/1@2x.png");
  282. background-size: 48px 136px;
  283. animation: animal1 4s linear infinite;
  284. opacity: 0;
  285. }
  286. .anima2 {
  287. position: fixed;
  288. top: 580px;
  289. left: -20px;
  290. width: 62px;
  291. height: 170px;
  292. background: url("../assets/images/mZ/2@2x.png");
  293. background-size: 62px 170px;
  294. animation: animal1 4s linear infinite;
  295. opacity: 0;
  296. }
  297. .anima3 {
  298. position: fixed;
  299. bottom: -258px;
  300. left: 183px;
  301. width: 151px;
  302. height: 415px;
  303. background: url("../assets/images/mZ/3@2x.png");
  304. background-size: 151px 415px;
  305. animation: animal1 4s linear infinite;
  306. opacity: 0;
  307. }
  308. .anima4 {
  309. position: fixed;
  310. bottom: -350px;
  311. left: 987px;
  312. width: 199px;
  313. height: 551px;
  314. background: url("../assets/images/mZ/4@2x.png");
  315. background-size: 199px 551px;
  316. animation: animal1 4s linear infinite;
  317. opacity: 0;
  318. }
  319. .anima5 {
  320. position: fixed;
  321. top: 200px;
  322. left: 1289px;
  323. width: 85px;
  324. height: 236px;
  325. background: url("../assets/images/mZ/5@2x.png");
  326. background-size: 85px 236px;
  327. animation: animal1 4s linear infinite;
  328. opacity: 0;
  329. }
  330. @keyframes animal1 {
  331. 50% {
  332. transform: translateY(-50px);
  333. opacity: 1;
  334. }
  335. }
  336. }
  337. .login_divs {
  338. position: fixed;
  339. right: 0;
  340. top: 0;
  341. min-width: 500px;
  342. width: 574px;
  343. height: 100%;
  344. background-color: #4174ff;
  345. z-index: 1000;
  346. display: flex;
  347. align-items: center;
  348. justify-content: center;
  349. box-shadow: -4px 0px 9px 1px rgba(17, 33, 77, 0.1);
  350. .login_Right {
  351. width: 420px;
  352. }
  353. }
  354. }
  355. .textStys {
  356. margin-left: 13px;
  357. color: #fff;
  358. font-weight: 400;
  359. font-family: Microsoft YaHei;
  360. font-size: 24px;
  361. }
  362. .weComeSty {
  363. margin-bottom: 70px;
  364. }
  365. .mar_stys {
  366. margin-bottom: 16px;
  367. }
  368. /deep/.el-input--medium .el-input__inner {
  369. height: 48px;
  370. font-size: 20px;
  371. border-radius: 24px;
  372. }
  373. /deep/.el-form-item--medium .el-form-item__content {
  374. display: flex;
  375. align-items: center;
  376. }
  377. .login-code {
  378. height: 40px;
  379. margin-left: 18px;
  380. .login-code-img {
  381. height: 40px;
  382. }
  383. }
  384. .rightStsyt {
  385. display: flex;
  386. align-items: center;
  387. justify-content: flex-end;
  388. }
  389. /deep/.checkStyles {
  390. margin: 0px 0px 25px 0px;
  391. color: #fff;
  392. }
  393. /deep/.el-checkbox__input.is-checked + .el-checkbox__label {
  394. color: #fff;
  395. }
  396. .btnFootsty {
  397. width: 100%;
  398. height: 48px;
  399. border-radius: 24px;
  400. background-color: #fff;
  401. color: #4174ff;
  402. font-size: 20px;
  403. font-weight: bold;
  404. font-family: Microsoft YaHei;
  405. }
  406. /deep/ .fle_x > .el-form-item__content {
  407. display: flex;
  408. align-items: center;
  409. }
  410. .btn {
  411. font-size: 14px;
  412. font-family: Microsoft YaHei;
  413. font-weight: 400;
  414. color: #3f8dfd;
  415. white-space: nowrap;
  416. cursor: pointer;
  417. }
  418. </style>