mirror of
https://github.com/certd/certd.git
synced 2026-05-16 13:17:29 +08:00
ad360e81cb
perf: 优化antdv4 示例授权页面tree的样式 build: publish success chore: 1 chore: 1 chore: 1 fix: getFileName支持item参数 https://github.com/fast-crud/fast-crud/issues/385 fix: fs-form独立使用支持插槽 https://github.com/fast-crud/fast-crud/issues/389 fix: 修复三级以上路由页面无法缓存的问题 https://github.com/fast-crud/fast-crud/issues/394 perf: form.wrapper.buttons支持compute动态计算 feat: 表单支持变更关闭前提醒保存,form.wrapper支持beforeClose事件 fix: 修复图片裁剪按钮上下和左右相反的bug https://github.com/fast-crud/fast-crud/issues/402 perf: alioss getAuthorization接口支持后台返回key https://github.com/fast-crud/fast-crud/issues/405 perf: alioss getAuthorization接口支持后台返回key https://github.com/fast-crud/fast-crud/issues/405 perf: fs-dict-tree支持插槽 https://github.com/fast-crud/fast-crud/issues/407 perf: 单选、多选、select、tree-select、table-select 都提供selected-change事件,可以获取选中的dict选项 feat: table-select 支持查看模式 https://github.com/fast-crud/fast-crud/issues/413 perf: 优化fs-admin可以在手机上操作 chore: pnpm workspace问题优化 docs: 1 chore: antdv4 支持主题色选择 ...
156 lines
4.0 KiB
TypeScript
156 lines
4.0 KiB
TypeScript
import LayoutPass from "/src/layout/layout-pass.vue";
|
|
import _ from "lodash-es";
|
|
import { outsideResource } from "./source/outside";
|
|
import { headerResource } from "./source/header";
|
|
import { frameworkResource } from "./source/framework";
|
|
const modules = import.meta.glob("/src/views/**/*.vue");
|
|
|
|
let index = 0;
|
|
function transformOneResource(resource: any, parent: any) {
|
|
let menu: any = null;
|
|
if (resource.meta == null) {
|
|
resource.meta = {};
|
|
}
|
|
const meta = resource.meta;
|
|
meta.title = meta.title ?? resource.title ?? "未命名";
|
|
if (resource.title == null) {
|
|
resource.title = meta.title;
|
|
}
|
|
if (meta.isMenu === false) {
|
|
menu = null;
|
|
} else {
|
|
menu = _.cloneDeep(resource);
|
|
delete menu.component;
|
|
if (menu.path?.startsWith("/")) {
|
|
menu.fullPath = menu.path;
|
|
} else {
|
|
menu.fullPath = (parent?.fullPath || "") + "/" + menu.path;
|
|
}
|
|
}
|
|
let route;
|
|
if (meta.isRoute === false || resource.path == null || resource.path.startsWith("https://") || resource.path.startsWith("http://")) {
|
|
//没有route
|
|
route = null;
|
|
} else {
|
|
route = _.cloneDeep(resource);
|
|
if (route.component && typeof route.component === "string") {
|
|
const path = "/src/views" + route.component;
|
|
route.component = modules[path];
|
|
}
|
|
if (route.component == null) {
|
|
route.component = LayoutPass;
|
|
}
|
|
if (route?.meta?.cache !== false) {
|
|
if (route.meta == null) {
|
|
route.meta = {};
|
|
}
|
|
route.meta.cache = true;
|
|
}
|
|
}
|
|
if (resource.children) {
|
|
const { menus, routes } = buildMenusAndRouters(resource.children, resource);
|
|
if (menu) {
|
|
menu.children = menus;
|
|
}
|
|
if (route) {
|
|
route.children = routes;
|
|
}
|
|
}
|
|
return {
|
|
menu,
|
|
route
|
|
};
|
|
}
|
|
|
|
export const buildMenusAndRouters = (resources: any, parent: any = null) => {
|
|
const routes: Array<any> = [];
|
|
const menus: Array<any> = [];
|
|
for (const item of resources) {
|
|
const { menu, route } = transformOneResource(item, parent);
|
|
|
|
if (menu) {
|
|
menus.push(menu);
|
|
}
|
|
if (route) {
|
|
routes.push(route);
|
|
}
|
|
}
|
|
|
|
setIndex(menus);
|
|
return {
|
|
routes,
|
|
menus
|
|
};
|
|
};
|
|
|
|
function setIndex(menus: any) {
|
|
for (const menu of menus) {
|
|
menu.index = "index_" + index;
|
|
index++;
|
|
if (menu.children && menu.children.length > 0) {
|
|
setIndex(menu.children);
|
|
}
|
|
}
|
|
}
|
|
|
|
function findMenus(menus: any, condition: any) {
|
|
const list: any = [];
|
|
for (const menu of menus) {
|
|
if (condition(menu)) {
|
|
list.push(menu);
|
|
}
|
|
if (menu.children && menu.children.length > 0) {
|
|
const subList = findMenus(menu.children, condition);
|
|
for (const item of subList) {
|
|
list.push(item);
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
function filterMenus(menus: any, condition: any) {
|
|
const list = menus.filter((item: any) => {
|
|
return condition(item);
|
|
});
|
|
|
|
for (const item of list) {
|
|
if (item.children && item.children.length > 0) {
|
|
item.children = filterMenus(item.children, condition);
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
function flatChildren(list: any, children: any) {
|
|
for (const child of children) {
|
|
list.push(child);
|
|
if (child.children && child.children.length > 0) {
|
|
flatChildren(list, child.children);
|
|
}
|
|
child.children = null;
|
|
}
|
|
}
|
|
function flatSubRouters(routers: any) {
|
|
for (const router of routers) {
|
|
const children: Array<any> = [];
|
|
if (router.children && router.children.length > 0) {
|
|
flatChildren(children, router.children);
|
|
}
|
|
router.children = children;
|
|
}
|
|
return routers;
|
|
}
|
|
|
|
const frameworkRet = buildMenusAndRouters(frameworkResource);
|
|
const outsideRet = buildMenusAndRouters(outsideResource);
|
|
const headerRet = buildMenusAndRouters(headerResource);
|
|
|
|
const outsideRoutes = outsideRet.routes;
|
|
const frameworkRoutes = frameworkRet.routes;
|
|
const routes = [...outsideRoutes, ...frameworkRoutes];
|
|
const frameworkMenus = frameworkRet.menus;
|
|
const headerMenus = headerRet.menus;
|
|
export { routes, outsideRoutes, frameworkRoutes, frameworkMenus, headerMenus, findMenus, filterMenus };
|
|
|