login.vue 9.5 KB

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