fix(projects): fix router when the dynamic routes api was failed [修复当动态路由接口失败后路由异常问题]
This commit is contained in:
parent
3bd8858121
commit
f2b580fc06
@ -52,6 +52,7 @@ export const useAuthStore = defineStore('auth-store', {
|
||||
* @param backendToken - 返回的token
|
||||
*/
|
||||
async handleActionAfterLogin(backendToken: ApiAuth.Token) {
|
||||
const route = useRouteStore();
|
||||
const { toLoginRedirect } = useRouterPush(false);
|
||||
|
||||
const loginSuccess = await this.loginByToken(backendToken);
|
||||
@ -61,11 +62,13 @@ export const useAuthStore = defineStore('auth-store', {
|
||||
toLoginRedirect();
|
||||
|
||||
// 登录成功弹出欢迎提示
|
||||
window.$notification?.success({
|
||||
title: '登录成功!',
|
||||
content: `欢迎回来,${this.userInfo.userName}!`,
|
||||
duration: 3000
|
||||
});
|
||||
if (route.isInitAuthRoute) {
|
||||
window.$notification?.success({
|
||||
title: '登录成功!',
|
||||
content: `欢迎回来,${this.userInfo.userName}!`,
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ interface RouteState {
|
||||
authRouteMode: ImportMetaEnv['VITE_AUTH_ROUTE_MODE'];
|
||||
/** 是否初始化了权限路由 */
|
||||
isInitAuthRoute: boolean;
|
||||
/** 动态路由是否初始化失败 */
|
||||
failedInitDynamicRoute: boolean;
|
||||
/** 路由首页name(前端静态路由时生效,后端动态路由该值会被后端返回的值覆盖) */
|
||||
routeHomeName: AuthRoute.AllRouteKey;
|
||||
/** 菜单 */
|
||||
@ -39,6 +41,7 @@ export const useRouteStore = defineStore('route-store', {
|
||||
state: (): RouteState => ({
|
||||
authRouteMode: import.meta.env.VITE_AUTH_ROUTE_MODE,
|
||||
isInitAuthRoute: false,
|
||||
failedInitDynamicRoute: false,
|
||||
routeHomeName: transformRoutePathToRouteName(import.meta.env.VITE_ROUTE_HOME_PATH),
|
||||
menus: [],
|
||||
searchMenus: [],
|
||||
@ -112,11 +115,14 @@ export const useRouteStore = defineStore('route-store', {
|
||||
throw new Error('userId 不能为空!');
|
||||
}
|
||||
|
||||
const { data } = await fetchUserRoutes(userId);
|
||||
if (data) {
|
||||
const { error, data } = await fetchUserRoutes(userId);
|
||||
|
||||
if (!error) {
|
||||
this.routeHomeName = data.home;
|
||||
this.handleUpdateRootRedirect(data.home);
|
||||
this.handleAuthRoute(data.routes);
|
||||
} else {
|
||||
this.failedInitDynamicRoute = true;
|
||||
}
|
||||
},
|
||||
/** 初始化静态路由 */
|
||||
@ -138,7 +144,7 @@ export const useRouteStore = defineStore('route-store', {
|
||||
|
||||
initHomeTab(this.routeHomeName, router);
|
||||
|
||||
this.isInitAuthRoute = true;
|
||||
this.isInitAuthRoute = !this.failedInitDynamicRoute;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user