mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-01-24 04:10:20 +08:00
fix: add loss action for userStore
This commit is contained in:
parent
628e820684
commit
a36825a6d4
@ -94,29 +94,33 @@ export const useUserStore = defineStore({
|
|||||||
|
|
||||||
// save token
|
// save token
|
||||||
this.setToken(token);
|
this.setToken(token);
|
||||||
// get user info
|
return this.afterLoginAction(goHome);
|
||||||
const userInfo = await this.getUserInfoAction();
|
|
||||||
|
|
||||||
const sessionTimeout = this.sessionTimeout;
|
|
||||||
if (sessionTimeout) {
|
|
||||||
this.setSessionTimeout(false);
|
|
||||||
} else if (goHome) {
|
|
||||||
const permissionStore = usePermissionStore();
|
|
||||||
if (!permissionStore.isDynamicAddedRoute) {
|
|
||||||
const routes = await permissionStore.buildRoutesAction();
|
|
||||||
routes.forEach((route) => {
|
|
||||||
router.addRoute(route as unknown as RouteRecordRaw);
|
|
||||||
});
|
|
||||||
router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw);
|
|
||||||
permissionStore.setDynamicAddedRoute(true);
|
|
||||||
}
|
|
||||||
await router.replace(userInfo.homePath || PageEnum.BASE_HOME);
|
|
||||||
}
|
|
||||||
return userInfo;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async afterLoginAction(goHome?: boolean): Promise<GetUserInfoModel | null> {
|
||||||
|
if (!this.getToken) return null;
|
||||||
|
// get user info
|
||||||
|
const userInfo = await this.getUserInfoAction();
|
||||||
|
|
||||||
|
const sessionTimeout = this.sessionTimeout;
|
||||||
|
if (sessionTimeout) {
|
||||||
|
this.setSessionTimeout(false);
|
||||||
|
} else {
|
||||||
|
const permissionStore = usePermissionStore();
|
||||||
|
if (!permissionStore.isDynamicAddedRoute) {
|
||||||
|
const routes = await permissionStore.buildRoutesAction();
|
||||||
|
routes.forEach((route) => {
|
||||||
|
router.addRoute(route as unknown as RouteRecordRaw);
|
||||||
|
});
|
||||||
|
router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw);
|
||||||
|
permissionStore.setDynamicAddedRoute(true);
|
||||||
|
}
|
||||||
|
goHome && (await router.replace(userInfo.homePath || PageEnum.BASE_HOME));
|
||||||
|
}
|
||||||
|
return userInfo;
|
||||||
|
},
|
||||||
async getUserInfoAction(): Promise<UserInfo> {
|
async getUserInfoAction(): Promise<UserInfo> {
|
||||||
const userInfo = await getUserInfo();
|
const userInfo = await getUserInfo();
|
||||||
const { roles = [] } = userInfo;
|
const { roles = [] } = userInfo;
|
||||||
|
Loading…
Reference in New Issue
Block a user