login.vue 9.4 KB

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