refactor: ♻️ userStore 代码重构优化
Former-commit-id: ef31b8420a48a91dd2449d62fb615941d528bf24
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user