fix: 静态路由角色拦截限制
This commit is contained in:
@@ -31,13 +31,6 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
||||
}
|
||||
);
|
||||
|
||||
/** is super role in static route */
|
||||
const isStaticSuper = computed(() => {
|
||||
const { VITE_AUTH_ROUTE_MODE, VITE_STATIC_SUPER_ROLE } = import.meta.env;
|
||||
|
||||
return VITE_AUTH_ROUTE_MODE === 'static' && userInfo.roles?.includes(VITE_STATIC_SUPER_ROLE);
|
||||
});
|
||||
|
||||
/** Is login */
|
||||
const isLogin = computed(() => Boolean(token.value));
|
||||
|
||||
@@ -160,7 +153,6 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
||||
return {
|
||||
token,
|
||||
userInfo,
|
||||
isStaticSuper,
|
||||
isLogin,
|
||||
loginLoading,
|
||||
resetStore,
|
||||
|
||||
@@ -165,21 +165,37 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
|
||||
/** Init auth route */
|
||||
async function initAuthRoute() {
|
||||
await initStaticAuthRoute();
|
||||
await initDynamicAuthRoute();
|
||||
// await initStaticAuthRoute();
|
||||
// await initDynamicAuthRoute();
|
||||
|
||||
|
||||
const { data: routes, error } = await doGetUserRoutes();
|
||||
if (!error) {
|
||||
const { authRoutes: staticAuthRoutes } = createStaticRoutes();
|
||||
const filteredAuthRoutes = filterAuthRoutesByRoles(staticAuthRoutes, authStore.userInfo.roles ?? []);
|
||||
console.log(authStore.userInfo.roles,filteredAuthRoutes)
|
||||
console.log(authStore.userInfo.roles,[ ...filteredAuthRoutes,...routes])
|
||||
addAuthRoutes([ ...filteredAuthRoutes,...routes]);
|
||||
|
||||
handleAuthRoutes();
|
||||
|
||||
setRouteHome('home');
|
||||
|
||||
handleUpdateRootRouteRedirect('home');
|
||||
|
||||
setIsInitAuthRoute(true);
|
||||
} else {
|
||||
await authStore.resetStore();
|
||||
}
|
||||
tabStore.initHomeTab();
|
||||
}
|
||||
|
||||
/** Init static auth route */
|
||||
async function initStaticAuthRoute() {
|
||||
const { authRoutes: staticAuthRoutes } = createStaticRoutes();
|
||||
if (authStore.isStaticSuper) {
|
||||
addAuthRoutes(staticAuthRoutes);
|
||||
} else {
|
||||
const filteredAuthRoutes = filterAuthRoutesByRoles(staticAuthRoutes, authStore.userInfo.roles ?? []);
|
||||
const filteredAuthRoutes = filterAuthRoutesByRoles(staticAuthRoutes, authStore.userInfo.roles ?? []);
|
||||
|
||||
addAuthRoutes(filteredAuthRoutes);
|
||||
}
|
||||
addAuthRoutes(filteredAuthRoutes);
|
||||
|
||||
handleAuthRoutes();
|
||||
|
||||
@@ -196,7 +212,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
|
||||
setRouteHome('home');
|
||||
|
||||
handleUpdateRootRouteRedirect('manage_role');
|
||||
handleUpdateRootRouteRedirect('home');
|
||||
|
||||
setIsInitAuthRoute(true);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user