login.vue 9.1 KB

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