chore(permisssion): optimize logout

This commit is contained in:
pengYYY 2022-03-07 17:45:38 +08:00
parent ae3e021587
commit 732eb1b289
2 changed files with 2 additions and 8 deletions

View File

@ -18,12 +18,8 @@ router.beforeEach(async (to, from, next) => {
const { token } = userStore; const { token } = userStore;
if (token) { if (token) {
if (to.path === '/login') { if (to.path === '/login') {
setTimeout(() => { userStore.logout();
if (userStore.token) { permissionStore.restore();
userStore.logout();
permissionStore.restore();
}
});
next(); next();
return; return;
} }

View File

@ -61,7 +61,6 @@ export const usePermissionStore = defineStore('permission', {
async initRoutes(roles: Array<unknown>) { async initRoutes(roles: Array<unknown>) {
let accessedRouters = []; let accessedRouters = [];
// 路由做减法,优化登陆后的跳转时间
let removeRoutes = []; let removeRoutes = [];
// special token // special token
if (roles.includes('all')) { if (roles.includes('all')) {
@ -82,7 +81,6 @@ export const usePermissionStore = defineStore('permission', {
}); });
}, },
async restore() { async restore() {
// 复原route,保证在登陆状态时路由全量
this.removeRoutes.forEach((item: RouteRecordRaw) => { this.removeRoutes.forEach((item: RouteRecordRaw) => {
router.addRoute(item); router.addRoute(item);
}); });