mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-09 13:53:38 +08:00
perf: 使用/** */替换//注释,对编辑器的智能提示更友好
This commit is contained in:
@@ -43,7 +43,7 @@ import remainingRouter from "./modules/remaining";
|
||||
import componentsRouter from "./modules/components";
|
||||
import formDesignRouter from "./modules/formdesign";
|
||||
|
||||
// 原始静态路由(未做任何处理)
|
||||
/** 原始静态路由(未做任何处理) */
|
||||
const routes = [
|
||||
pptRouter,
|
||||
homeRouter,
|
||||
@@ -60,22 +60,22 @@ const routes = [
|
||||
formDesignRouter
|
||||
];
|
||||
|
||||
// 导出处理后的静态路由(三级及以上的路由全部拍成二级)
|
||||
/** 导出处理后的静态路由(三级及以上的路由全部拍成二级) */
|
||||
export const constantRoutes: Array<RouteRecordRaw> = formatTwoStageRoutes(
|
||||
formatFlatteningRoutes(buildHierarchyTree(ascending(routes)))
|
||||
);
|
||||
|
||||
// 用于渲染菜单,保持原始层级
|
||||
/** 用于渲染菜单,保持原始层级 */
|
||||
export const constantMenus: Array<RouteComponent> = ascending(routes).concat(
|
||||
...remainingRouter
|
||||
);
|
||||
|
||||
// 不参与菜单的路由
|
||||
/** 不参与菜单的路由 */
|
||||
export const remainingPaths = Object.keys(remainingRouter).map(v => {
|
||||
return remainingRouter[v].path;
|
||||
});
|
||||
|
||||
// 创建路由实例
|
||||
/** 创建路由实例 */
|
||||
export const router: Router = createRouter({
|
||||
history: getHistoryMode(),
|
||||
routes: constantRoutes.concat(...(remainingRouter as any)),
|
||||
@@ -95,7 +95,7 @@ export const router: Router = createRouter({
|
||||
}
|
||||
});
|
||||
|
||||
// 重置路由
|
||||
/** 重置路由 */
|
||||
export function resetRouter() {
|
||||
router.getRoutes().forEach(route => {
|
||||
const { name, meta } = route;
|
||||
@@ -109,7 +109,7 @@ export function resetRouter() {
|
||||
usePermissionStoreHook().clearAllCachePage();
|
||||
}
|
||||
|
||||
// 路由白名单
|
||||
/** 路由白名单 */
|
||||
const whiteList = ["/login"];
|
||||
|
||||
router.beforeEach((to: toRouteType, _from, next) => {
|
||||
|
||||
@@ -21,7 +21,7 @@ const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
|
||||
// 动态路由
|
||||
import { getAsyncRoutes } from "/@/api/routes";
|
||||
|
||||
// 按照路由中meta下的rank等级升序来排序路由
|
||||
/** 按照路由中meta下的rank等级升序来排序路由 */
|
||||
function ascending(arr: any[]) {
|
||||
arr.forEach(v => {
|
||||
if (v?.meta?.rank === null) v.meta.rank = undefined;
|
||||
@@ -38,7 +38,7 @@ function ascending(arr: any[]) {
|
||||
);
|
||||
}
|
||||
|
||||
// 过滤meta中showLink为false的路由
|
||||
/** 过滤meta中showLink为false的路由 */
|
||||
function filterTree(data: RouteComponent[]) {
|
||||
const newTree = cloneDeep(data).filter(
|
||||
(v: { meta: { showLink: boolean } }) => v.meta?.showLink !== false
|
||||
@@ -49,7 +49,7 @@ function filterTree(data: RouteComponent[]) {
|
||||
return newTree;
|
||||
}
|
||||
|
||||
// 批量删除缓存路由(keepalive)
|
||||
/** 批量删除缓存路由(keepalive) */
|
||||
function delAliveRoutes(delAliveRouteList: Array<RouteConfigs>) {
|
||||
delAliveRouteList.forEach(route => {
|
||||
usePermissionStoreHook().cacheOperate({
|
||||
@@ -59,7 +59,7 @@ function delAliveRoutes(delAliveRouteList: Array<RouteConfigs>) {
|
||||
});
|
||||
}
|
||||
|
||||
// 通过path获取父级路径
|
||||
/** 通过path获取父级路径 */
|
||||
function getParentPaths(path: string, routes: RouteRecordRaw[]) {
|
||||
// 深度遍历查找
|
||||
function dfs(routes: RouteRecordRaw[], path: string, parents: string[]) {
|
||||
@@ -83,7 +83,7 @@ function getParentPaths(path: string, routes: RouteRecordRaw[]) {
|
||||
return dfs(routes, path, []);
|
||||
}
|
||||
|
||||
// 查找对应path的路由信息
|
||||
/** 查找对应path的路由信息 */
|
||||
function findRouteByPath(path: string, routes: RouteRecordRaw[]) {
|
||||
let res = routes.find((item: { path: string }) => item.path == path);
|
||||
if (res) {
|
||||
@@ -114,7 +114,7 @@ function addPathMatch() {
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化路由
|
||||
/** 初始化路由 */
|
||||
function initRouter(name: string) {
|
||||
return new Promise(resolve => {
|
||||
getAsyncRoutes({ name }).then(({ info }) => {
|
||||
@@ -195,7 +195,7 @@ function formatTwoStageRoutes(routesList: RouteRecordRaw[]) {
|
||||
return newRoutesList;
|
||||
}
|
||||
|
||||
// 处理缓存路由(添加、删除、刷新)
|
||||
/** 处理缓存路由(添加、删除、刷新) */
|
||||
function handleAliveRoute(matched: RouteRecordNormalized[], mode?: string) {
|
||||
switch (mode) {
|
||||
case "add":
|
||||
@@ -222,7 +222,7 @@ function handleAliveRoute(matched: RouteRecordNormalized[], mode?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// 过滤后端传来的动态路由 重新生成规范路由
|
||||
/** 过滤后端传来的动态路由 重新生成规范路由 */
|
||||
function addAsyncRoutes(arrRoutes: Array<RouteRecordRaw>) {
|
||||
if (!arrRoutes || !arrRoutes.length) return;
|
||||
const modulesRoutesKeys = Object.keys(modulesRoutes);
|
||||
@@ -251,7 +251,7 @@ function addAsyncRoutes(arrRoutes: Array<RouteRecordRaw>) {
|
||||
return arrRoutes;
|
||||
}
|
||||
|
||||
// 获取路由历史模式 https://next.router.vuejs.org/zh/guide/essentials/history-mode.html
|
||||
/** 获取路由历史模式 https://next.router.vuejs.org/zh/guide/essentials/history-mode.html */
|
||||
function getHistoryMode(): RouterHistory {
|
||||
const routerHistory = loadEnv().VITE_ROUTER_HISTORY;
|
||||
// len为1 代表只有历史模式 为2 代表历史模式中存在base参数 https://next.router.vuejs.org/zh/api/#%E5%8F%82%E6%95%B0-1
|
||||
@@ -275,7 +275,7 @@ function getHistoryMode(): RouterHistory {
|
||||
}
|
||||
}
|
||||
|
||||
// 是否有权限
|
||||
/** 是否有权限 */
|
||||
function hasPermissions(value: Array<string>): boolean {
|
||||
if (value && value instanceof Array && value.length > 0) {
|
||||
const roles = usePermissionStoreHook().buttonAuth;
|
||||
|
||||
Reference in New Issue
Block a user