mirror of
https://gitee.com/h_mo/uniapp-vue3-vite-ts-template
synced 2025-04-05 19:41:44 +08:00
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { assign } from 'lodash-es';
|
|
import pagesJson from '@/pages.json';
|
|
import { Route } from '@/types/router/route';
|
|
|
|
const { pages, subPackages, tabBar } = pagesJson;
|
|
|
|
// 将pages.json转换成Map对象,path为key
|
|
const pagesMap = new Map<string, Route>();
|
|
|
|
pages.forEach((page) => {
|
|
pagesMap.set(page.path, page as Route);
|
|
});
|
|
|
|
if (Array.isArray(subPackages) && subPackages.length) {
|
|
subPackages.forEach((el) => {
|
|
const rootPath = el.root;
|
|
el.pages.forEach((page) => {
|
|
page.path = `${rootPath}/${page.path}`;
|
|
pagesMap.set(page.path, page as Route);
|
|
});
|
|
});
|
|
}
|
|
|
|
if (tabBar) {
|
|
const tabBarList = tabBar.list;
|
|
if (Array.isArray(tabBarList)) {
|
|
tabBarList.forEach((el) => {
|
|
if (pagesMap.has(el.pagePath)) {
|
|
const page = pagesMap.get(el.pagePath);
|
|
const meta = page?.meta || {};
|
|
// @ts-ignore
|
|
meta.tabBar = true;
|
|
// @ts-ignore
|
|
page.meta = assign({}, meta);
|
|
pagesMap.set(el.pagePath, page as Route);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
export { pagesMap };
|