fix: 🐛 修复注销登录location.reload导致接口无响应数据
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
import type { RouteRecordRaw } from "vue-router";
|
||||
import { constantRoutes } from "@/router";
|
||||
import { store } from "@/store";
|
||||
import MenuAPI, { type RouteVO } from "@/api/menu";
|
||||
import MenuAPI, { type RouteVO } from "@/api/system/menu";
|
||||
|
||||
const modules = import.meta.glob("../../views/**/**.vue");
|
||||
const Layout = () => import("@/layout/index.vue");
|
||||
|
||||
import router from "@/router";
|
||||
|
||||
export const usePermissionStore = defineStore("permission", () => {
|
||||
/** 所有路由,包括静态和动态路由 */
|
||||
const routes = ref<RouteRecordRaw[]>([]);
|
||||
/** 混合模式左侧菜单 */
|
||||
const mixLeftMenus = ref<RouteRecordRaw[]>([]);
|
||||
|
||||
const isRoutesLoaded = ref(false);
|
||||
|
||||
/**
|
||||
* 生成动态路由
|
||||
*/
|
||||
@@ -21,6 +25,7 @@ export const usePermissionStore = defineStore("permission", () => {
|
||||
.then((data) => {
|
||||
const dynamicRoutes = transformRoutes(data);
|
||||
routes.value = constantRoutes.concat(dynamicRoutes);
|
||||
isRoutesLoaded.value = true;
|
||||
resolve(dynamicRoutes);
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -41,11 +46,29 @@ export const usePermissionStore = defineStore("permission", () => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置路由
|
||||
*/
|
||||
const resetRouter = () => {
|
||||
// 删除动态路由,保留静态路由
|
||||
routes.value.forEach((route) => {
|
||||
if (route.name && !constantRoutes.find((r) => r.name === route.name)) {
|
||||
router.removeRoute(route.name); // 从 router 实例中移除动态路由
|
||||
}
|
||||
});
|
||||
|
||||
routes.value = [];
|
||||
mixLeftMenus.value = [];
|
||||
isRoutesLoaded.value = false;
|
||||
};
|
||||
|
||||
return {
|
||||
routes,
|
||||
generateRoutes,
|
||||
mixLeftMenus,
|
||||
setMixLeftMenus,
|
||||
isRoutesLoaded,
|
||||
resetRouter,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user