login.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div class="login-container">
  3. <el-row>
  4. <el-col :xs="24" :sm="24" :md="12" :lg="16" :xl="16">
  5. <div style="color: transparent">占位符</div>
  6. </el-col>
  7. <el-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  8. <el-form
  9. ref="form"
  10. :model="form"
  11. :rules="rules"
  12. class="login-form"
  13. label-position="left"
  14. >
  15. <div class="title">hello !</div>
  16. <div class="title-tips">欢迎来到{{ title }}!</div>
  17. <el-form-item style="margin-top: 40px" prop="username">
  18. <span class="svg-container svg-container-admin">
  19. <i class="el-icon-user-solid"></i>
  20. </span>
  21. <el-input
  22. v-model.trim="form.username"
  23. v-focus
  24. placeholder="请输入用户名"
  25. tabindex="1"
  26. type="text"
  27. />
  28. </el-form-item>
  29. <el-form-item prop="password">
  30. <span class="svg-container">
  31. <i class="el-icon-more"></i>
  32. </span>
  33. <el-input
  34. :key="passwordType"
  35. ref="password"
  36. v-model.trim="form.password"
  37. :type="passwordType"
  38. tabindex="2"
  39. placeholder="请输入密码"
  40. maxlength="16"
  41. @keyup.enter.native="handleLogin"
  42. />
  43. <span
  44. v-if="passwordType === 'password'"
  45. class="show-password"
  46. @click="handlePassword"
  47. >
  48. <i class="el-icon-view"></i>
  49. </span>
  50. <span v-else class="show-password" @click="handlePassword">
  51. <i class="el-icon-edit"></i>
  52. </span>
  53. </el-form-item>
  54. <el-form-item style="display: flex;flex-wrap: nowrap;flex-direction:column;flejustify-content: space-between" prop="code">
  55. <span class="svg-container svg-container-admin">
  56. <i class="el-icon-s-help"></i>
  57. </span>
  58. <el-input
  59. style="width: 60%"
  60. v-model.trim="form.code"
  61. v-focus
  62. placeholder="请输入验证码"
  63. tabindex="1"
  64. type="text"
  65. />
  66. <img
  67. class="code-img middle-img"
  68. :src="codeImg"
  69. alt=""
  70. @click="handelGetCaptcha"
  71. />
  72. </el-form-item>
  73. <el-button
  74. :loading="loading"
  75. class="login-btn"
  76. type="primary"
  77. @click="handleLogin"
  78. >
  79. 登录
  80. </el-button>
  81. <router-link to="/register">
  82. <div style="margin-top: 20px">注册</div>
  83. </router-link>
  84. </el-form>
  85. </el-col>
  86. </el-row>
  87. </div>
  88. </template>
  89. <script>
  90. import { getCaptcha, login } from "@/utils/api.js";
  91. export default {
  92. name: "Login",
  93. directives: {
  94. focus: {
  95. inserted(el) {
  96. el.querySelector("input").focus();
  97. },
  98. },
  99. },
  100. data() {
  101. return {
  102. nodeEnv: process.env.NODE_ENV,
  103. title: "",
  104. form: {
  105. username: "ry123456",
  106. password: "asd123fsadf@$!~",
  107. code: "",
  108. uuid: "",
  109. },
  110. rules: {
  111. username: [
  112. {
  113. required: true,
  114. pattern: /^[a-zA-Z][0-9a-zA-Z]{6,20}$/,
  115. message: "请输入规则的用户名",
  116. trigger: "blur",
  117. },
  118. ],
  119. password: [
  120. {
  121. required: true,
  122. pattern:
  123. /((^(?=.*[a-z])(?=.*[A-Z])(?=.*\W)[\da-zA-Z\W]{8,16}$)|(^(?=.*\d)(?=.*[A-Z])(?=.*\W)[\da-zA-Z\W]{8,16}$)|(^(?=.*\d)(?=.*[a-z])(?=.*\W)[\da-zA-Z\W]{8,16}$)|(^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[\da-zA-Z\W]{8,16}$))/,
  124. message:
  125. "请输入8-16位字符、大小写字母、数字、特殊字符,任意三种组合密码",
  126. trigger: "blur",
  127. },
  128. ],
  129. code: [
  130. {
  131. required: true,
  132. message: "请输入验证码",
  133. trigger: "blur",
  134. },
  135. ],
  136. },
  137. loading: false,
  138. passwordType: "password",
  139. redirect: undefined,
  140. codeImg: "",
  141. };
  142. },
  143. watch: {
  144. $route: {
  145. handler(route) {
  146. // console.log("fromUrl", localStorage.getItem("fromUrl"));
  147. this.redirect = localStorage.getItem("fromUrl");
  148. // this.redirect = (route.query && route.query.redirect) || "/";
  149. },
  150. immediate: true,
  151. },
  152. },
  153. created() {
  154. this.title = this.webTitle;
  155. this.handelGetCaptcha();
  156. document.body.style.overflow = "hidden";
  157. },
  158. beforeDestroy() {
  159. document.body.style.overflow = "auto";
  160. },
  161. mounted() {},
  162. methods: {
  163. handelGetCaptcha() {
  164. getCaptcha()
  165. .then((res) => {
  166. this.codeImg = res.data.image;
  167. this.form.uuid = res.data.key;
  168. console.log("getCaptcha", res);
  169. })
  170. .catch((err) => {
  171. console.log("getCaptcha err", err);
  172. });
  173. },
  174. handlePassword() {
  175. this.passwordType === "password"
  176. ? (this.passwordType = "")
  177. : (this.passwordType = "password");
  178. this.$nextTick(() => {
  179. this.$refs.password.focus();
  180. });
  181. },
  182. handleLogin() {
  183. let that = this;
  184. let backUrl = "";
  185. this.$refs.form.validate((valid) => {
  186. if (valid) {
  187. this.loading = true;
  188. console.log("this.form", this.form);
  189. login(this.form)
  190. .then((res) => {
  191. this.$mc.vuex("vuex_token", res.data.access_token);
  192. this.$message(res.msg);
  193. const routerPath =
  194. that.redirect === "/404" || that.redirect === "/401"
  195. ? "/"
  196. : that.redirect;
  197. if (that.redirect) {
  198. backUrl = that.redirect.split()[0];
  199. }
  200. // console.log("that.redirect", that.redirect);
  201. localStorage.removeItem("fromUrl");
  202. location.href = backUrl;
  203. // that.$router.replace("/jobdetails").catch(() => {});
  204. that.loading = false;
  205. console.log("login", res);
  206. })
  207. .catch((err) => {
  208. this.loading = false;
  209. console.log("login err", err);
  210. });
  211. } else {
  212. return false;
  213. }
  214. });
  215. },
  216. },
  217. };
  218. </script>
  219. <style lang="scss" scoped>
  220. $base-input-height: 32px;
  221. $base-font-size-small: 12px;
  222. $base-color-red: #f34d37;
  223. $base-font-color: #606266;
  224. .login-container {
  225. height: 100vh;
  226. background: url("../../static/images/background.jpg") center center fixed
  227. no-repeat;
  228. background-size: cover;
  229. .title {
  230. font-size: 54px;
  231. font-weight: 500;
  232. color: rgba(14, 18, 26, 1);
  233. }
  234. .title-tips {
  235. margin-top: 29px;
  236. font-size: 26px;
  237. font-weight: 400;
  238. color: rgba(14, 18, 26, 1);
  239. text-overflow: ellipsis;
  240. white-space: nowrap;
  241. }
  242. .login-btn {
  243. display: inherit;
  244. width: 220px;
  245. height: 60px;
  246. margin-top: 5px;
  247. border: 0;
  248. &:hover {
  249. opacity: 0.9;
  250. }
  251. }
  252. .login-form {
  253. position: relative;
  254. max-width: 100%;
  255. margin: calc((100vh - 425px) / 2) 10% 10%;
  256. overflow: hidden;
  257. .forget-password {
  258. width: 100%;
  259. margin-top: 40px;
  260. text-align: left;
  261. .forget-pass {
  262. width: 129px;
  263. height: 19px;
  264. font-size: 20px;
  265. font-weight: 400;
  266. color: rgba(92, 102, 240, 1);
  267. }
  268. }
  269. }
  270. .tips {
  271. margin-bottom: 10px;
  272. font-size: 14px;
  273. color: #ddd;
  274. span {
  275. &:first-of-type {
  276. margin-right: 16px;
  277. }
  278. }
  279. }
  280. .title-container {
  281. position: relative;
  282. .title {
  283. margin: 0 auto 40px auto;
  284. font-size: 34px;
  285. font-weight: bold;
  286. color: blue;
  287. text-align: center;
  288. }
  289. }
  290. .svg-container {
  291. position: absolute;
  292. top: 14px;
  293. left: 15px;
  294. z-index: 999;
  295. font-size: 16px;
  296. color: #d7dee3;
  297. cursor: pointer;
  298. user-select: none;
  299. }
  300. .show-password {
  301. position: absolute;
  302. top: 14px;
  303. right: 25px;
  304. font-size: 16px;
  305. color: #d7dee3;
  306. cursor: pointer;
  307. user-select: none;
  308. }
  309. ::v-deep {
  310. .el-form-item {
  311. padding-right: 0;
  312. margin: 20px 0;
  313. color: #454545;
  314. background: transparent;
  315. border: 1px solid transparent;
  316. border-radius: 2px;
  317. &__content {
  318. min-height: $base-input-height;
  319. line-height: $base-input-height;
  320. }
  321. &__error {
  322. position: absolute;
  323. top: 100%;
  324. left: 18px;
  325. font-size: $base-font-size-small;
  326. line-height: 18px;
  327. color: $base-color-red;
  328. }
  329. }
  330. .el-input {
  331. box-sizing: border-box;
  332. input {
  333. height: 58px;
  334. padding-left: 45px;
  335. font-size: 14px;
  336. line-height: 58px;
  337. color: $base-font-color;
  338. background: #f6f4fc;
  339. border: 0;
  340. caret-color: $base-font-color;
  341. }
  342. }
  343. }
  344. }
  345. .code-img {
  346. margin-left: 10px;
  347. cursor: pointer;
  348. }
  349. </style>