login.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="login">
  3. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  4. <h3 class="title">
  5. <!-- <svg-icon icon-class="logo" /> -->
  6. {{ loginTitle }}</h3>
  7. <el-form-item prop="username">
  8. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  9. <i slot="prefix" class="el-icon-user-solid input-icon"></i>
  10. <!-- <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> -->
  11. </el-input>
  12. </el-form-item>
  13. <el-form-item prop="password">
  14. <el-input
  15. v-model="loginForm.password"
  16. type="password"
  17. auto-complete="off"
  18. placeholder="密码"
  19. @keyup.enter.native="handleLogin"
  20. >
  21. <i slot="prefix" class="el-icon-lock input-icon"></i>
  22. <!-- <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />0 -->
  23. </el-input>
  24. </el-form-item>
  25. <el-form-item prop="code">
  26. <el-input
  27. v-model="loginForm.code"
  28. auto-complete="off"
  29. placeholder="验证码"
  30. style="width: 63%;"
  31. @keyup.enter.native="handleLogin"
  32. >
  33. <i slot="prefix" class="el-icon-mobile input-icon"></i>
  34. <!-- <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> -->
  35. </el-input>
  36. <div class="login-code">
  37. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  38. </div>
  39. </el-form-item>
  40. <!-- <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> -->
  41. <el-form-item style="width:100%;">
  42. <el-button
  43. :loading="loading"
  44. size="medium"
  45. style="width:100%;background:#3d5d4c;color:#fff"
  46. class="login-form-loginbtn"
  47. @click.native.prevent="handleLogin"
  48. >
  49. <span v-if="!loading" >登 录</span>
  50. <span v-else>登 录 中...</span>
  51. </el-button>
  52. </el-form-item>
  53. </el-form>
  54. <!-- 底部 -->
  55. <!-- <div class="el-login-footer">
  56. <span>Copyright © 2018-2021 ****** All Rights Reserved.</span>
  57. </div>-->
  58. </div>
  59. </template>
  60. <script>
  61. // import { getCodeImg } from "@/api/login";
  62. import { getCaptcha, login } from "@/utils/api.js";
  63. // // import Cookies from "js-cookie";
  64. // import { encrypt, decrypt } from '@/utils/jsencrypt';
  65. // const loginAppProjectKey = process.env.VUE_APP_PROJECT_KEY + '-';
  66. export default {
  67. name: "Login",
  68. inject: ["reload"],
  69. directives: {
  70. focus: {
  71. inserted(el) {
  72. el.querySelector("input").focus();
  73. },
  74. },
  75. },
  76. data() {
  77. return {
  78. loginTitle: '',
  79. codeUrl: "",
  80. cookiePassword: "",
  81. loginForm: {
  82. username: "",
  83. password: "",
  84. rememberMe: false,
  85. code: "",
  86. uuid: ""
  87. },
  88. loginRules: {
  89. username: [
  90. { required: true, trigger: "blur", message: "用户名不能为空" }
  91. ],
  92. password: [
  93. { required: true, trigger: "blur", message: "密码不能为空" }
  94. ],
  95. code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
  96. },
  97. loading: false,
  98. redirect: undefined
  99. };
  100. },
  101. watch: {
  102. $route: {
  103. handler: function(route) {
  104. this.redirect = localStorage.getItem("fromUrl");
  105. },
  106. immediate: true
  107. }
  108. },
  109. created() {
  110. this.loginTitle = this.webTitle;
  111. if (process.env.NODE_ENV === 'development') {
  112. this.loginForm.username = 'ry123456';
  113. this.loginForm.password = 'asd123fsadf@$!~';
  114. }
  115. this.getCode();
  116. },
  117. methods: {
  118. getCode() {
  119. getCaptcha().then(res => {
  120. this.codeUrl = res.data.image;
  121. this.loginForm.uuid = res.data.key;
  122. });
  123. },
  124. handleLogin() {
  125. let that = this;
  126. let backUrl = "/";
  127. this.$refs.loginForm.validate((valid) => {
  128. if (valid) {
  129. this.loading = true;
  130. console.log("this.loginForm", this.loginForm);
  131. login(this.loginForm)
  132. .then((res) => {
  133. this.$mc.vuex("vuex_token", res.data.access_token);
  134. this.$message(res.msg);
  135. const routerPath =
  136. that.redirect === "/404" || that.redirect === "/401"
  137. ? "/"
  138. : that.redirect;
  139. if (that.redirect) {
  140. backUrl = that.redirect.split()[0];
  141. }
  142. // console.log("that.redirect", that.redirect);
  143. localStorage.removeItem("fromUrl");
  144. this.reload();
  145. location.href = backUrl;
  146. // that.$router.replace("/jobdetails").catch(() => {});
  147. that.loading = false;
  148. console.log("login", res);
  149. })
  150. .catch((err) => {
  151. this.loading = false;
  152. console.log("login err", err);
  153. });
  154. } else {
  155. return false;
  156. }
  157. });
  158. }
  159. }
  160. };
  161. </script>
  162. <style rel="stylesheet/scss" lang="scss">
  163. #app{
  164. min-height: 100vh;
  165. }
  166. .login {
  167. display: flex;
  168. justify-content: center;
  169. align-items: center;
  170. height: 100%;
  171. min-height: 100vh;
  172. background-image: url("../../static/images/background.png");
  173. background-size: cover;
  174. }
  175. .title {
  176. margin: 0px auto 30px auto;
  177. text-align: center;
  178. color: #707070;
  179. }
  180. .login-form {
  181. border-radius: 6px;
  182. background: #ffffff;
  183. width: 400px;
  184. padding: 25px 25px 5px 25px;
  185. .el-input {
  186. height: 38px;
  187. input {
  188. height: 38px;
  189. }
  190. }
  191. .input-icon {
  192. height: 39px;
  193. width: 14px;
  194. margin-left: 2px;
  195. }
  196. }
  197. .login-tip {
  198. font-size: 13px;
  199. text-align: center;
  200. color: #bfbfbf;
  201. }
  202. .login-code {
  203. width: 33%;
  204. height: 38px;
  205. float: right;
  206. img {
  207. cursor: pointer;
  208. vertical-align: middle;
  209. }
  210. }
  211. .el-login-footer {
  212. height: 40px;
  213. line-height: 40px;
  214. position: fixed;
  215. bottom: 0;
  216. width: 100%;
  217. text-align: center;
  218. color: #fff;
  219. font-family: Arial;
  220. font-size: 12px;
  221. letter-spacing: 1px;
  222. }
  223. .login-code-img {
  224. height: 38px;
  225. }
  226. </style>