fix(projects): fix routes data when role is change. fixed #391
This commit is contained in:
parent
79d9c5143a
commit
cb83d6d90d
@ -52,6 +52,19 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
|||||||
routeHome.value = routeKey;
|
routeHome.value = routeKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** constant routes */
|
||||||
|
const constantRoutes = shallowRef<ElegantConstRoute[]>([]);
|
||||||
|
|
||||||
|
function addConstantRoutes(routes: ElegantConstRoute[]) {
|
||||||
|
const constantRoutesMap = new Map(constantRoutes.value.map(route => [route.name, route]));
|
||||||
|
|
||||||
|
routes.forEach(route => {
|
||||||
|
constantRoutesMap.set(route.name, route);
|
||||||
|
});
|
||||||
|
|
||||||
|
constantRoutes.value = Array.from(constantRoutesMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
/** auth routes */
|
/** auth routes */
|
||||||
const authRoutes = shallowRef<ElegantConstRoute[]>([]);
|
const authRoutes = shallowRef<ElegantConstRoute[]>([]);
|
||||||
|
|
||||||
@ -167,18 +180,18 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
|||||||
if (isInitConstantRoute.value) return;
|
if (isInitConstantRoute.value) return;
|
||||||
|
|
||||||
if (authRouteMode.value === 'static') {
|
if (authRouteMode.value === 'static') {
|
||||||
const { constantRoutes } = createStaticRoutes();
|
const staticRoute = createStaticRoutes();
|
||||||
|
|
||||||
addAuthRoutes(constantRoutes);
|
addConstantRoutes(staticRoute.constantRoutes);
|
||||||
} else {
|
} else {
|
||||||
const { data, error } = await fetchGetConstantRoutes();
|
const { data, error } = await fetchGetConstantRoutes();
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
addAuthRoutes(data);
|
addConstantRoutes(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleAuthRoutes();
|
handleConstantAndAuthRoutes();
|
||||||
|
|
||||||
setIsInitConstantRoute(true);
|
setIsInitConstantRoute(true);
|
||||||
}
|
}
|
||||||
@ -206,7 +219,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
|||||||
addAuthRoutes(filteredAuthRoutes);
|
addAuthRoutes(filteredAuthRoutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleAuthRoutes();
|
handleConstantAndAuthRoutes();
|
||||||
|
|
||||||
setIsInitAuthRoute(true);
|
setIsInitAuthRoute(true);
|
||||||
}
|
}
|
||||||
@ -220,7 +233,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
|||||||
|
|
||||||
addAuthRoutes(routes);
|
addAuthRoutes(routes);
|
||||||
|
|
||||||
handleAuthRoutes();
|
handleConstantAndAuthRoutes();
|
||||||
|
|
||||||
setRouteHome(home);
|
setRouteHome(home);
|
||||||
|
|
||||||
@ -230,9 +243,11 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** handle auth routes */
|
/** handle constant and auth routes */
|
||||||
function handleAuthRoutes() {
|
function handleConstantAndAuthRoutes() {
|
||||||
const sortRoutes = sortRoutesByOrder(authRoutes.value);
|
const allRoutes = [...constantRoutes.value, ...authRoutes.value];
|
||||||
|
|
||||||
|
const sortRoutes = sortRoutesByOrder(allRoutes);
|
||||||
|
|
||||||
const vueRoutes = getAuthVueRoutes(sortRoutes);
|
const vueRoutes = getAuthVueRoutes(sortRoutes);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user