login.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div>
  3. <div class="login">
  4. <el-form
  5. ref="loginForm"
  6. :model="loginForm"
  7. :rules="loginRules"
  8. class="login-form"
  9. >
  10. <h3 class="title">投资管理系统</h3>
  11. <el-form-item prop="username">
  12. <el-input
  13. v-model="loginForm.username"
  14. type="text"
  15. auto-complete="off"
  16. placeholder="账号"
  17. >
  18. <svg-icon
  19. slot="prefix"
  20. icon-class="user"
  21. class="el-input__icon input-icon"
  22. />
  23. </el-input>
  24. </el-form-item>
  25. <el-form-item prop="password">
  26. <el-input
  27. v-model="loginForm.password"
  28. type="password"
  29. auto-complete="off"
  30. placeholder="密码"
  31. @keyup.enter.native="handleLogin"
  32. >
  33. <svg-icon
  34. slot="prefix"
  35. icon-class="password"
  36. class="el-input__icon input-icon"
  37. />
  38. </el-input>
  39. </el-form-item>
  40. <el-form-item prop="code" v-if="captchaEnabled">
  41. <el-input
  42. v-model="loginForm.code"
  43. auto-complete="off"
  44. placeholder="验证码"
  45. style="width: 63%"
  46. @keyup.enter.native="handleLogin"
  47. >
  48. <svg-icon
  49. slot="prefix"
  50. icon-class="validCode"
  51. class="el-input__icon input-icon"
  52. />
  53. </el-input>
  54. <div class="login-code">
  55. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  56. </div>
  57. </el-form-item>
  58. <el-checkbox
  59. v-model="loginForm.rememberMe"
  60. style="margin: 0px 0px 25px 0px"
  61. >记住密码</el-checkbox
  62. >
  63. <el-form-item style="width: 100%">
  64. <el-button
  65. :loading="loading"
  66. size="medium"
  67. type="primary"
  68. style="width: 100%"
  69. @click.native.prevent="handleLogin"
  70. >
  71. <span v-if="!loading">登 录</span>
  72. <span v-else>登 录 中...</span>
  73. </el-button>
  74. <div style="float: right" v-if="register">
  75. <router-link class="link-type" :to="'/register'"
  76. >立即注册</router-link
  77. >
  78. </div>
  79. </el-form-item>
  80. </el-form>
  81. <!-- <div class="el-login-footer">
  82. <span>投资管理系统</span>
  83. </div> -->
  84. </div>
  85. </div>
  86. </template>
  87. <script>
  88. import router from "../router";
  89. import store from "../store";
  90. import { getCodeImg, avoidLogin, authToken } from "@/api/login";
  91. import Cookies from "js-cookie";
  92. import { encrypt, decrypt } from "@/utils/jsencrypt";
  93. import { openAuth } from "dingtalk-design-libs/biz/openAuth";
  94. import { setToken } from "@/utils/auth";
  95. export default {
  96. name: "Login",
  97. data() {
  98. return {
  99. codeUrl: "",
  100. loginForm: {
  101. // username: "admin",
  102. // password: "admin123",
  103. username: "",
  104. password: "",
  105. rememberMe: false,
  106. code: "",
  107. uuid: "",
  108. },
  109. loginRules: {
  110. username: [
  111. { required: true, trigger: "blur", message: "请输入您的账号" },
  112. ],
  113. password: [
  114. { required: true, trigger: "blur", message: "请输入您的密码" },
  115. ],
  116. code: [{ required: true, trigger: "change", message: "请输入验证码" }],
  117. },
  118. loading: false,
  119. // 验证码开关
  120. captchaEnabled: true,
  121. // 注册开关
  122. register: false,
  123. redirect: undefined,
  124. };
  125. },
  126. watch: {
  127. $route: {
  128. handler: function (route) {
  129. this.redirect = route.query && route.query.redirect;
  130. },
  131. immediate: true,
  132. },
  133. },
  134. created() {
  135. this.getCode();
  136. this.getCookie();
  137. },
  138. methods: {
  139. getCode() {
  140. getCodeImg().then((res) => {
  141. this.captchaEnabled =
  142. res.captchaEnabled === undefined ? true : res.captchaEnabled;
  143. if (this.captchaEnabled) {
  144. this.codeUrl = "data:image/gif;base64," + res.img;
  145. this.loginForm.uuid = res.uuid;
  146. }
  147. });
  148. },
  149. getCookie() {
  150. const username = Cookies.get("username");
  151. const password = Cookies.get("password");
  152. const rememberMe = Cookies.get("rememberMe");
  153. this.loginForm = {
  154. username: username === undefined ? this.loginForm.username : username,
  155. password:
  156. password === undefined ? this.loginForm.password : decrypt(password),
  157. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  158. };
  159. },
  160. handleLogin() {
  161. this.$refs.loginForm.validate((valid) => {
  162. if (valid) {
  163. this.loading = true;
  164. if (this.loginForm.rememberMe) {
  165. Cookies.set("username", this.loginForm.username, { expires: 30 });
  166. Cookies.set("password", encrypt(this.loginForm.password), {
  167. expires: 30,
  168. });
  169. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  170. expires: 30,
  171. });
  172. } else {
  173. Cookies.remove("username");
  174. Cookies.remove("password");
  175. Cookies.remove("rememberMe");
  176. }
  177. this.$store
  178. .dispatch("Login", this.loginForm)
  179. .then(() => {
  180. this.$router.push({
  181. path: this.redirect || "/",
  182. query: { type: "admin", title: "投资系统" },
  183. });
  184. })
  185. .then(() => {
  186. let inspectNum = 0, //评估考察
  187. projectLXNum = 0, //项目立项
  188. dueNum = 0, //尽职背调
  189. projectTJNum = 0,//项目投决
  190. //我的任务下的菜单
  191. investOppNum=0,//项目机会
  192. approvalNum = 0, //项目立项
  193. investigateNum = 0, //项目背调
  194. decisionNum = 0, //项目投决
  195. terminationNum = 0; //项目终止
  196. // 获取代办任务数量
  197. this.$store.commit("SET_INSPECTNUM", inspectNum);
  198. this.$store.commit("SET_PROJECTLXNUM", projectLXNum);
  199. this.$store.commit("SET_DUENUM", dueNum);
  200. this.$store.commit("SET_PROJECTTJNUM", projectTJNum);
  201. //我的任务下的代办任务数量
  202. this.$store.commit("SET_INVESTOPPNUM", investOppNum);
  203. this.$store.commit("SET_APPROVALNUM", approvalNum);
  204. this.$store.commit("SET_INVESTIGATENUM", investigateNum);
  205. this.$store.commit("SET_DECISIONNUM", decisionNum);
  206. this.$store.commit("SET_TERMINATIONNUM", terminationNum);
  207. })
  208. .catch(() => {
  209. this.loading = false;
  210. if (this.captchaEnabled) {
  211. this.getCode();
  212. }
  213. });
  214. }
  215. });
  216. },
  217. },
  218. };
  219. </script>
  220. <style rel="stylesheet/scss" lang="scss">
  221. .login {
  222. display: flex;
  223. justify-content: center;
  224. align-items: center;
  225. height: 100vh;
  226. background-image: url("../assets/images/bg03.jpg");
  227. background-size: cover;
  228. }
  229. .title {
  230. margin: 0px auto 30px auto;
  231. text-align: center;
  232. color: #707070;
  233. }
  234. .login-form {
  235. border-radius: 6px;
  236. background: #ffffff;
  237. width: 400px;
  238. padding: 25px 25px 5px 25px;
  239. .el-input {
  240. height: 38px;
  241. input {
  242. height: 38px;
  243. }
  244. }
  245. .input-icon {
  246. height: 39px;
  247. width: 14px;
  248. margin-left: 2px;
  249. }
  250. }
  251. .login-tip {
  252. font-size: 13px;
  253. text-align: center;
  254. color: #bfbfbf;
  255. }
  256. .login-code {
  257. width: 33%;
  258. height: 38px;
  259. float: right;
  260. img {
  261. cursor: pointer;
  262. vertical-align: middle;
  263. }
  264. }
  265. .el-login-footer {
  266. height: 40px;
  267. line-height: 40px;
  268. position: fixed;
  269. bottom: 0;
  270. width: 100%;
  271. text-align: center;
  272. color: #fff;
  273. font-family: Arial;
  274. font-size: 12px;
  275. letter-spacing: 1px;
  276. }
  277. .login-code-img {
  278. height: 38px;
  279. }
  280. </style>