login.vue 15 KB

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