|
@@ -128,29 +128,51 @@ export default {
|
|
|
};
|
|
|
},
|
|
|
handleLogin() {
|
|
|
- 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 });
|
|
|
+ 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((error) => {
|
|
|
+ // 提取具体错误信息
|
|
|
+ let errorMsg;
|
|
|
+ if (error && error.msg) {
|
|
|
+ errorMsg = error.msg;
|
|
|
+ } else if (error && error.message) {
|
|
|
+ errorMsg = error.message;
|
|
|
} else {
|
|
|
- Cookies.remove("username");
|
|
|
- Cookies.remove("password");
|
|
|
- Cookies.remove('rememberMe');
|
|
|
+ errorMsg = '登录失败';
|
|
|
}
|
|
|
- this.$store.dispatch("Login", this.loginForm).then(() => {
|
|
|
- this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
|
|
- }).catch(() => {
|
|
|
- this.loading = false;
|
|
|
- if (this.captchaEnabled) {
|
|
|
+ this.$message.error(errorMsg);
|
|
|
+ // 刷新验证码
|
|
|
+ if (this.captchaEnabled) {
|
|
|
+ try {
|
|
|
this.getCode();
|
|
|
+ } catch (e) {
|
|
|
+ console.error('刷新验证码失败:', e);
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
}
|
|
|
+ });
|
|
|
+}
|
|
|
}
|
|
|
};
|
|
|
</script>
|