feat: 完成ruoyi、pure菜单兼容

This commit is contained in:
橙子
2024-09-07 02:17:07 +08:00
parent 9fc5b521e5
commit 978a7fab4c
16 changed files with 1052 additions and 437 deletions

View File

@@ -27,7 +27,8 @@ const IFrame = () => import("@/layout/frame.vue");
const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
// 动态路由
import { getAsyncRoutes } from "@/api/routes";
// getAsyncRoutes
import { getRoutes,getAsyncRoutes } from "@/api/routes";
function handRank(routeInfo: any) {
const { name, path, parentId, meta } = routeInfo;
@@ -202,7 +203,7 @@ function initRouter() {
});
} else {
return new Promise(resolve => {
getAsyncRoutes().then(({ data }) => {
getRoutes().then(({ data }) => {
handleAsyncRoutes(cloneDeep(data));
storageLocal().setItem(key, data);
resolve(router);
@@ -211,7 +212,7 @@ function initRouter() {
}
} else {
return new Promise(resolve => {
getAsyncRoutes().then(({ data }) => {
getRoutes().then(({ data }) => {
handleAsyncRoutes(cloneDeep(data));
resolve(router);
});
@@ -303,6 +304,9 @@ function addAsyncRoutes(arrRoutes: Array<RouteRecordRaw>) {
if (!arrRoutes || !arrRoutes.length) return;
const modulesRoutesKeys = Object.keys(modulesRoutes);
arrRoutes.forEach((v: RouteRecordRaw) => {
if (v.children == null) {
v.children = undefined;
}
// 将backstage属性加入meta标识此路由为后端返回路由
v.meta.backstage = true;
// 父级的redirect属性取值如果子级存在且父级的redirect属性不存在默认取第一个子级的path如果子级存在且父级的redirect属性存在取存在的redirect属性会覆盖默认值