|
@@ -67,7 +67,8 @@ import Cookies from "js-cookie";
|
|
|
import { encrypt } from '@/utils/jsencrypt'
|
|
|
import errorCode from '@/utils/errorCode'
|
|
|
import { login, getCode, getPublicKey } from '@/api/user';
|
|
|
-import {Message} from "element-ui";
|
|
|
+import { Message } from "element-ui";
|
|
|
+import { setUserInfo } from "@/utils/auth";
|
|
|
|
|
|
export default {
|
|
|
name: "Login",
|
|
@@ -148,37 +149,17 @@ export default {
|
|
|
this.$refs.loginForm.validate(valid => {
|
|
|
if (valid) {
|
|
|
this.loading = true;
|
|
|
- // if (this.loginForm.rememberMe) {
|
|
|
- // Cookies.set("username", this.loginForm.username, {expires: 30});
|
|
|
- // Cookies.set("password", encrypt(this.loginForm.password), {expires: 30});
|
|
|
- // Cookies.set('rememberMe', this.loginForm.rememberMe, {expires: 30});
|
|
|
- // } else {
|
|
|
- // Cookies.remove("username");
|
|
|
- // Cookies.remove("password");
|
|
|
- // Cookies.remove('rememberMe');
|
|
|
- // }
|
|
|
- // this.$store.dispatch("Login", this.loginForm).then(() => {
|
|
|
- // this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
|
|
- // }).catch(() => {
|
|
|
- // this.loading = false;
|
|
|
- // if (this.captchaEnabled) {
|
|
|
- // this.getCode();
|
|
|
- // }
|
|
|
- // });
|
|
|
-
|
|
|
const pwd = encrypt(this.loginForm.password, this.publicKey)
|
|
|
-
|
|
|
- login(this.loginForm.username.trim(), pwd, this.loginForm.code, this.loginForm.uid).then(result => {
|
|
|
- console.log(result);
|
|
|
- // this.$router.push({ path: this.redirect || "/index" });
|
|
|
- // this.$router.push("/index");
|
|
|
+ login(this.loginForm.username.trim(), pwd, this.loginForm.code, this.loginForm.uid).then(res => {
|
|
|
+ console.log(res);
|
|
|
+ setUserInfo(res.data.user, res.data.token)
|
|
|
+ this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
|
|
}).catch((e) => {
|
|
|
this.loading = false;
|
|
|
if (this.captchaEnabled) {
|
|
|
this.getCode();
|
|
|
}
|
|
|
})
|
|
|
- // this.$router.push({ path: this.redirect || "/index" }).catch(()=>{});
|
|
|
}
|
|
|
});
|
|
|
}
|