import { route } from '@/utils/tools'; const titleArr = [ { key: 'jsx', title: '使用jsx', }, { key: 'tools', title: '工具方法', }, { key: 'importOrExportExcel', title: '导入导出excel', }, { key: 'clickOutSide', title: '点击空白处关闭弹窗或者下拉菜单', }, { key: 'nestedFormVaild', title: '动态增减嵌套表单验证问题', }, { key: 'stepStyle', title: '步骤条结构样式', }, { key: 'textAlign', title: 'css文本两端对齐方式', }, { key: 'webWorker', title: '创建webWorker时如何不指定特定的文件', }, { key: 'borderArrow', title: 'div边框箭头和阴影问题', }, { key: 'pullLoadData', title: '首页高度不够,手写移动端下拉加载历史数据', }, { key: 'autoLoadData', title: '首页高度足够,自动触发下拉加载数据', }, { key: 'dynamicNodeEvent', title: '动态html加载的事件监听', }, { key: 'iframeEvent', title: 'iframe页面的事件监听', }, { key: 'cookie', title: '相同顶级域名不同子域名共享cookie', }, { key: 'module', title: 'CommonJS AMD CMD ESM总结', }, { key: 'viteProxy', title: 'vite中设置代理转发', }, { key: 'virtualList', title: 'item固定高度的虚拟列表实现', }, ]; // @/views/demo/**/*.vue /** * (使用 ** 表示递归查找) * 递归匹配views/demo目录下所有.vue文件 * 也包含/demo/jsx/components/index.vue 这种某个页面的子组件 */ // @/views/demo/*.vue 第一层目录 // @/views/demo/*/*.vue 第二层目录 /** * 第一层目录 => 匹配views/demo目录下所有.vue文件(第一层) * 例如 /views/demo/index.vue * * 第二层目录 => 匹配views/demo目录下所有文件夹下的.vue文件(第二层) * 例如 /views/demo/jsx/index.vue * * 不会匹配/views/demo/jsx/components/index.vue 这种某个页面的子组件 */ const firstLevelComponents = import.meta.glob('@/views/demo/*.vue'); const secondLevelComponents = import.meta.glob('@/views/demo/*/*.vue'); const components = { ...firstLevelComponents, ...secondLevelComponents }; const demoRoutes = Object.keys(components).map((path) => { const isHasIndex = path.includes('/index.vue'); let cptPath = path.replace(route.FILE_NAME_PREFIX, ''); cptPath = isHasIndex ? cptPath.replace('/index.vue', '') : cptPath.replace('.vue', ''); return { path: cptPath, name: route.convertPathToName(cptPath), component: components[path], meta: { title: route.getTitleFromPathStr(titleArr, cptPath), }, }; }); export default { path: '/demo', redirect: '/demo/jsx', meta: { icon: 'ep:data-analysis', title: '示例', rank: 1, }, children: [...demoRoutes], } satisfies RouteConfigsTable;