refactor: ♻️ userStore 代码重构优化

Former-commit-id: ef31b8420a48a91dd2449d62fb615941d528bf24
This commit is contained in:
郝先瑞
2023-09-11 18:20:03 +08:00
parent 7fcf66c8d0
commit 18daf33f9d
8 changed files with 32 additions and 44 deletions

View File

@@ -22,7 +22,7 @@ router.beforeEach(async (to, from, next) => {
NProgress.done();
} else {
const userStore = useUserStoreHook();
const hasRoles = userStore.roles && userStore.roles.length > 0;
const hasRoles = userStore.user.roles && userStore.user.roles.length > 0;
if (hasRoles) {
// 未匹配到任何路由跳转404
if (to.matched.length === 0) {
@@ -40,7 +40,7 @@ router.beforeEach(async (to, from, next) => {
next({ ...to, replace: true });
} catch (error) {
// 移除 token 并跳转登录页
await userStore.resetToken();
await userStore.resetStore();
next(`/login?redirect=${to.path}`);
NProgress.done();
}