login.vue 12 KB

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