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