mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-15 14:03:36 +08:00
perf: 优化路由 rank,当rank 不存在时,根据顺序自动创建,首页路由永远在第一位
This commit is contained in:
@@ -6,6 +6,7 @@ export default {
|
||||
redirect: "/error/403",
|
||||
meta: {
|
||||
icon: "informationLine",
|
||||
// showLink: false,
|
||||
title: $t("menus.hsabnormal"),
|
||||
rank: error
|
||||
},
|
||||
|
||||
@@ -13,6 +13,7 @@ import { useTimeoutFn } from "@vueuse/core";
|
||||
import { RouteConfigs } from "@/layout/types";
|
||||
import {
|
||||
isString,
|
||||
isAllEmpty,
|
||||
storageSession,
|
||||
isIncludeAllChildren
|
||||
} from "@pureadmin/utils";
|
||||
@@ -28,19 +29,21 @@ const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
|
||||
// 动态路由
|
||||
import { getAsyncRoutes } from "@/api/routes";
|
||||
|
||||
function handRank(ramk: number, name: string, path: string) {
|
||||
return isAllEmpty(ramk) || (ramk === 0 && name !== "Home" && path !== "/")
|
||||
? true
|
||||
: false;
|
||||
}
|
||||
|
||||
/** 按照路由中meta下的rank等级升序来排序路由 */
|
||||
function ascending(arr: any[]) {
|
||||
arr.forEach(v => {
|
||||
if (v?.meta?.rank === null) v.meta.rank = undefined;
|
||||
if (v?.meta?.rank === 0) {
|
||||
if (v.name !== "Home" && v.path !== "/") {
|
||||
console.warn("rank only the home page can be 0");
|
||||
}
|
||||
}
|
||||
arr.forEach((v, index) => {
|
||||
// 当rank不存在时,根据顺序自动创建,首页路由永远在第一位
|
||||
if (handRank(v?.meta?.rank, v.name, v.path)) v.meta.rank = index + 2;
|
||||
});
|
||||
return arr.sort(
|
||||
(a: { meta: { rank: number } }, b: { meta: { rank: number } }) => {
|
||||
return a?.meta?.rank - b?.meta?.rank;
|
||||
return a?.meta.rank - b?.meta.rank;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -252,7 +255,7 @@ function formatTwoStageRoutes(routesList: RouteRecordRaw[]) {
|
||||
children: []
|
||||
});
|
||||
} else {
|
||||
newRoutesList[0].children.push({ ...v });
|
||||
newRoutesList[0]?.children.push({ ...v });
|
||||
}
|
||||
});
|
||||
return newRoutesList;
|
||||
|
||||
@@ -7,8 +7,12 @@ defineOptions({
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="back" title="返回上一页" @click="$router.go(-1)">
|
||||
<back class="w-[80px] h-[80px]" />
|
||||
<div class="w-full h-full text-center">
|
||||
<h1>业务内容模块</h1>
|
||||
<p>使用场景:需要外嵌平台某个页面,不需要展示菜单导航以及额外模块</p>
|
||||
<div class="back" title="返回上一页" @click="$router.go(-1)">
|
||||
<back class="w-[80px] h-[80px]" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user