login.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <template>
  2. <div class="login-container">
  3. <div class="login-left">
  4. <div class="login-texts">
  5. <p>
  6. <span
  7. >{{ configInfor ? `${configInfor.title}-` : "" }}教材管理系统</span
  8. >
  9. </p>
  10. </div>
  11. <el-form
  12. :model="loginForm"
  13. :rules="loginRules"
  14. auto-complete="on"
  15. class="login-form"
  16. label-position="left"
  17. ref="loginForm"
  18. size="mini"
  19. >
  20. <div class="title-container">
  21. <h3 class="title">登录</h3>
  22. </div>
  23. <div class="login-input" v-show="loginCheck == 'login'">
  24. <p class="input-title">用户名</p>
  25. <el-form-item prop="username">
  26. <el-input
  27. autocomplete="off"
  28. name="username"
  29. ref="username"
  30. tabindex="1"
  31. type="text"
  32. v-model="loginForm.username"
  33. />
  34. </el-form-item>
  35. <p class="input-title">密码</p>
  36. <el-form-item prop="password">
  37. <el-input
  38. :key="passwordType"
  39. :type="passwordType"
  40. @keyup.enter.native="handleLogin"
  41. autocomplete="off"
  42. name="password"
  43. ref="password"
  44. tabindex="2"
  45. v-model="loginForm.password"
  46. />
  47. <!-- <span @click="showPwd" class="show-pwd">
  48. <svg-icon
  49. :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
  50. />
  51. </span>-->
  52. </el-form-item>
  53. <p class="input-title">验证码</p>
  54. <div class="verificationCode-box">
  55. <el-form-item prop="verificationCode">
  56. <el-input
  57. autocomplete="off"
  58. name="verificationCode"
  59. ref="verificationCode"
  60. tabindex="3"
  61. type="text"
  62. v-model="loginForm.verificationCode"
  63. />
  64. </el-form-item>
  65. <div class="verificationCode-img">
  66. <img
  67. v-if="verificationCodeimg && verificationCodeLoading"
  68. :src="verificationCodeimg"
  69. alt="图形验证码"
  70. @click="getVerificationCodeimg"
  71. />
  72. </div>
  73. </div>
  74. <!-- <p class="input-title">邮箱验证码</p>
  75. <div class="verificationCode-box">
  76. <el-form-item prop="emailCode">
  77. <el-input
  78. autocomplete="off"
  79. name="emailCode"
  80. ref="emailCode"
  81. tabindex="3"
  82. type="text"
  83. v-model="loginForm.emailCode"
  84. />
  85. </el-form-item>
  86. <div class="verificationCode-btn" @click="getVerificationCode"
  87. :class="VerificationCodeShow ? 'waitTime' : 'getVerification'">
  88. {{ VerificationCodeShow ? time+'s' : '获取' }}
  89. </div>
  90. </div> -->
  91. <p class="input-title">用户类型</p>
  92. <el-form-item class="el-form-item-type" prop="type">
  93. <el-radio label="TEACHER" v-model="loginForm.type">教师</el-radio>
  94. <el-radio label="STUDENT" v-model="loginForm.type">学员</el-radio>
  95. <el-radio label="ADMIN" v-model="loginForm.type"
  96. >系统管理员</el-radio
  97. >
  98. <!-- <span @click="showPwd" class="show-pwd">
  99. <svg-icon
  100. :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
  101. />
  102. </span>-->
  103. </el-form-item>
  104. <el-button
  105. :loading="loading"
  106. @click.native.prevent="handleLogin"
  107. size="small"
  108. style="width: 100%; margin-bottom: 30px"
  109. type="primary"
  110. >登录</el-button
  111. >
  112. </div>
  113. </el-form>
  114. </div>
  115. <div class="login-right">
  116. <!-- <img alt src="@/assets/login/index.png"> -->
  117. </div>
  118. </div>
  119. </template>
  120. <script>
  121. import { validUsername } from "@/utils/validate";
  122. import { getStaticContent, getLogin, postapi } from "@/api/api";
  123. import { getObjArr } from "@/utils/role";
  124. import { setToken } from "@/utils/auth";
  125. import { removeSession } from "@/utils/role";
  126. import { getConfigInfor } from "@/utils/index";
  127. import md5 from "js-md5";
  128. import Cookies from "js-cookie";
  129. export default {
  130. name: "Login",
  131. data() {
  132. const validateUsername = (rule, value, callback) => {
  133. if (!validUsername(value)) {
  134. callback(new Error("请输入用户名"));
  135. } else {
  136. callback();
  137. }
  138. };
  139. const validatePassword = (rule, value, callback) => {
  140. if (!value) {
  141. callback(new Error("请输入密码"));
  142. } else {
  143. callback();
  144. }
  145. };
  146. const validateVerificationCode = (rule, value, callback) => {
  147. if (!value) {
  148. callback(new Error("请输入验证码"));
  149. } else {
  150. callback();
  151. }
  152. };
  153. return {
  154. options: [],
  155. select: "1",
  156. codeText: "获取验证码",
  157. codeSend: false,
  158. //登录
  159. loginForm: {
  160. username: getObjArr("userName") || "",
  161. password: "",
  162. type: "TEACHER",
  163. verificationCode: "",
  164. emailCode: ""
  165. },
  166. //input 规则
  167. loginRules: {
  168. username: [
  169. { required: true, trigger: "blur", validator: validateUsername },
  170. ],
  171. password: [
  172. { required: true, trigger: "blur", validator: validatePassword },
  173. ],
  174. verificationCode: [
  175. {
  176. required: true,
  177. trigger: "blur",
  178. validator: validateVerificationCode,
  179. },
  180. ],
  181. },
  182. loading: false,
  183. passwordType: "password",
  184. redirect: undefined,
  185. loginCheck: "login",
  186. configInfor: null,
  187. verificationCodeimg: "", // 图形验证码
  188. verificationCodeimgID: "", // 图形验证码ID
  189. verificationCodeLoading: true, // 图形验证码的flag
  190. time: 60, //获取验证码的时间
  191. VerificationCodeShow: false, //是否已经获取了验证码
  192. };
  193. },
  194. watch: {
  195. $route: {
  196. handler: function (route) {
  197. this.redirect = route.query && route.query.redirect;
  198. },
  199. immediate: true,
  200. },
  201. },
  202. methods: {
  203. showPwd() {
  204. if (this.passwordType === "password") {
  205. this.passwordType = "";
  206. } else {
  207. this.passwordType = "password";
  208. }
  209. this.$nextTick(() => {
  210. this.$refs.password.focus();
  211. });
  212. },
  213. //登录
  214. handleLogin() {
  215. removeSession("SysList");
  216. this.$refs.loginForm.validate((valid) => {
  217. if (valid) {
  218. this.loading = true;
  219. let MethodName = "login_control-Login";
  220. let data = {
  221. user_type: this.loginForm.type,
  222. user_name: this.loginForm.username,
  223. is_password_md5: "true",
  224. password: md5(this.loginForm.password).toUpperCase(),
  225. verification_code_image_text: this.loginForm.verificationCode,
  226. verification_code_image_id: this.verificationCodeimgID,
  227. // dynamic_verification_type:'EMAIL',
  228. // phone_or_email: this.loginForm.username,
  229. // dynamic_verification_code: this.loginForm.emailCode
  230. };
  231. getLogin(MethodName, data)
  232. .then((res) => {
  233. let tokenData = res;
  234. postapi({
  235. url: "/GCLSTCServer/login",
  236. data: {
  237. userCode: res.user_code,
  238. userType: res.user_type,
  239. sessionId: res.session_id,
  240. },
  241. })
  242. .then((res) => {
  243. Cookies.set("JSESSIONID", res.data.JSESSIONID);
  244. setToken(tokenData);
  245. this.$router.push({ path: "/EnterSys" });
  246. })
  247. .catch((res) => {});
  248. })
  249. .catch(() => {
  250. this.loading = false;
  251. this.getVerificationCodeimg();
  252. });
  253. } else {
  254. this.loading = false;
  255. return false;
  256. }
  257. });
  258. },
  259. async _getConfig() {
  260. this.configInfor = await getConfigInfor();
  261. },
  262. // 图形验证码
  263. getVerificationCodeimg() {
  264. if (!this.verificationCodeLoading) return;
  265. this.verificationCodeLoading = false;
  266. let MethodName = "login_control-GetVerificationCodeImage";
  267. let data = {};
  268. getStaticContent(MethodName, data)
  269. .then((res) => {
  270. if (res) {
  271. this.verificationCodeLoading = true;
  272. this.verificationCodeimgID = res.image_id;
  273. this.verificationCodeimg =
  274. "data:image/jpeg;base64," + res.image_content_base64;
  275. } else {
  276. this.verificationCodeLoading = true;
  277. }
  278. })
  279. .catch(() => {
  280. this.verificationCodeLoading = true;
  281. });
  282. },
  283. // 获取验证码
  284. getVerificationCode() {
  285. let this_ = this;
  286. if(this_.time != 60){
  287. return
  288. }
  289. let timer;
  290. if (this_.loginForm.username) {
  291. this_.VerificationCodeShow = true;
  292. timer = setInterval(() => {
  293. this_.time--;
  294. if (this_.time == 0) {
  295. this_.VerificationCodeShow = false;
  296. clearInterval(timer);
  297. timer = null;
  298. this_.time = 60;
  299. }
  300. }, 1000);
  301. let MethodName = "user_manager-SendVerificationCode";
  302. let data = {
  303. verification_type: 'EMAIL',
  304. phone_or_email: this_.loginForm.username,
  305. };
  306. getLogin(MethodName, data).then((res) => {
  307. }).catch(()=>{
  308. this_.VerificationCodeShow = false;
  309. clearInterval(timer);
  310. timer = null;
  311. this_.time = 60;
  312. });
  313. } else {
  314. this_.$message.warning('请先输入邮箱或手机号码');
  315. }
  316. },
  317. },
  318. mounted() {
  319. removeSession("SysList");
  320. this._getConfig();
  321. this.getVerificationCodeimg();
  322. },
  323. };
  324. </script>
  325. <style lang="scss">
  326. /* 修复input 背景不协调 和光标变色 */
  327. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  328. $bg: #283443;
  329. $light_gray: #fff;
  330. $cursor: #000;
  331. $fc: rgb(24, 144, 255);
  332. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  333. .login-container .el-input input {
  334. color: $cursor !important;
  335. }
  336. .el-form-item.is-success .el-input__inner {
  337. border-color: $fc !important;
  338. }
  339. }
  340. /* reset element-ui css */
  341. .login-input {
  342. font-size: 0;
  343. .el-input {
  344. display: inline-block;
  345. height: 32px;
  346. width: 85%;
  347. input {
  348. background: transparent;
  349. border: 0px;
  350. -webkit-appearance: none;
  351. border-radius: 0px;
  352. padding: 5px 5px 5px 15px;
  353. color: rgb(117, 117, 117);
  354. height: 32px;
  355. caret-color: #000;
  356. &:-webkit-autofill {
  357. box-shadow: 0 0 0px 1000px $light_gray inset !important;
  358. -webkit-text-fill-color: $cursor !important;
  359. }
  360. }
  361. }
  362. .el-form-item {
  363. border: 1px solid #ccc;
  364. // background: rgba(0, 0, 0, 0.1);
  365. border-radius: 5px;
  366. color: #454545;
  367. }
  368. .el-form-item-type {
  369. border-color: #fff;
  370. }
  371. }
  372. .sign-input {
  373. .school.el-select {
  374. width: 100%;
  375. margin-bottom: 14px;
  376. }
  377. .el-input {
  378. height: 32px;
  379. .el-input__inner {
  380. height: 32px;
  381. line-height: 32px;
  382. }
  383. }
  384. .area-code {
  385. margin-bottom: 14px;
  386. .el-input-group__prepend {
  387. background: #fff;
  388. width: 80px;
  389. }
  390. }
  391. }
  392. .code {
  393. display: flex;
  394. justify-content: space-around;
  395. align-items: center;
  396. .code-number {
  397. flex-basis: 80%;
  398. margin-right: 10px;
  399. .el-input--mini .el-input__inner {
  400. height: 32px;
  401. line-height: 32px;
  402. }
  403. }
  404. .code-btn {
  405. margin-top: -2px;
  406. .el-button--mini {
  407. padding: 8px 15px;
  408. width: 120px;
  409. }
  410. }
  411. .sends {
  412. .el-button--mini {
  413. background: #ccc;
  414. border-color: #ccc;
  415. }
  416. }
  417. }
  418. </style>
  419. <style lang="scss" scoped>
  420. $bg: #fff;
  421. $dark_gray: #889aa4;
  422. $light_gray: #eee;
  423. $fc: rgb(24, 144, 255);
  424. .login-container {
  425. min-height: 100%;
  426. height: 100%;
  427. width: 100%;
  428. background: url("../assets/login/bg-login.jpg") center no-repeat;
  429. background-size: cover;
  430. overflow: hidden;
  431. position: relative;
  432. display: flex;
  433. justify-content: space-between;
  434. align-items: center;
  435. .login-form {
  436. position: relative;
  437. width: 350px;
  438. background: #fff;
  439. border-radius: 5px;
  440. padding: 42px;
  441. box-sizing: border-box;
  442. max-width: 100%;
  443. overflow: hidden;
  444. }
  445. .tips {
  446. font-size: 14px;
  447. color: #fff;
  448. margin-bottom: 10px;
  449. span {
  450. &:first-of-type {
  451. margin-right: 16px;
  452. }
  453. }
  454. }
  455. .svg-container {
  456. padding: 0px 5px 0px 15px;
  457. color: $dark_gray;
  458. vertical-align: middle;
  459. width: 30px;
  460. display: inline-block;
  461. }
  462. .colors {
  463. color: blue;
  464. }
  465. .title-container {
  466. position: relative;
  467. .title {
  468. font-size: 24px;
  469. color: rgb(73, 73, 73);
  470. margin: 0px auto 30px auto;
  471. text-align: left;
  472. font-weight: normal;
  473. }
  474. }
  475. .show-pwd {
  476. position: absolute;
  477. right: 10px;
  478. top: 3px;
  479. font-size: 16px;
  480. color: $dark_gray;
  481. cursor: pointer;
  482. user-select: none;
  483. }
  484. }
  485. .input-title {
  486. font-size: 12px;
  487. font-weight: 500;
  488. color: rgba(19, 20, 21, 1);
  489. line-height: 20px;
  490. margin-bottom: 10px;
  491. }
  492. /*login tab切换*/
  493. .login-table {
  494. display: flex;
  495. justify-content: center;
  496. align-items: center;
  497. height: 40px;
  498. margin-bottom: 20px;
  499. font-size: 16px;
  500. p {
  501. flex: 1;
  502. text-align: center;
  503. color: #000;
  504. }
  505. span {
  506. display: inline-block;
  507. padding: 0 20px;
  508. height: 46px;
  509. line-height: 46px;
  510. cursor: pointer;
  511. }
  512. span.hover {
  513. color: $fc;
  514. border-bottom: 3px solid $fc;
  515. }
  516. }
  517. /*text*/
  518. .login-texts {
  519. font-size: 16px;
  520. font-weight: 500;
  521. color: #1c1c1c;
  522. line-height: 30px;
  523. margin-bottom: 20px;
  524. text-align: center;
  525. > p:nth-child(1) {
  526. line-height: 50px;
  527. > span:nth-child(1) {
  528. font-size: 32px;
  529. margin-right: 10px;
  530. }
  531. }
  532. }
  533. .login-left {
  534. // flex: 1;
  535. margin: 0 auto;
  536. }
  537. .login-right {
  538. // flex: 1;
  539. text-align: right;
  540. height: 100%;
  541. display: flex;
  542. align-items: flex-end;
  543. justify-content: flex-end;
  544. img {
  545. width: 100%;
  546. vertical-align: bottom;
  547. }
  548. }
  549. .verificationCode-box {
  550. display: flex;
  551. > div {
  552. flex: 1;
  553. max-width: 171px;
  554. &.verificationCode-img {
  555. min-width: 90px;
  556. height: 34px;
  557. margin-left: 5px;
  558. flex: initial;
  559. background: #c5c5c5;
  560. border-radius: 4px;
  561. overflow: hidden;
  562. > img {
  563. height: 34px;
  564. cursor: pointer;
  565. }
  566. }
  567. &.verificationCode-btn{
  568. max-width: 90px;
  569. height: 34px;
  570. margin-left: 5px;
  571. background: #FF9900;
  572. border-radius: 4px;
  573. color: #fff;
  574. font-weight: 700;
  575. font-size: 14px;
  576. display: flex;
  577. align-items: center;
  578. justify-content: center;
  579. cursor: pointer;
  580. &.waitTime{
  581. background: #F0F0F0;
  582. color: #6C6C6C;
  583. }
  584. }
  585. }
  586. }
  587. </style>