diff --git a/src/router/modules/demo.ts b/src/router/modules/demo.ts index cd5cafb..3bc2bd3 100644 --- a/src/router/modules/demo.ts +++ b/src/router/modules/demo.ts @@ -121,12 +121,13 @@ 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', ''); + cptPath = route.mergeDuplicatePathSegments(cptPath); return { path: cptPath, name: route.convertPathToName(cptPath), component: components[path], meta: { - title: route.getTitleFromPathStr(titleArr, cptPath), + title: route.getTitleFromPathStr(titleArr, cptPath, '/demo/'), }, }; }); diff --git a/src/utils/tools.ts b/src/utils/tools.ts index 3c8b689..b90dfc5 100644 --- a/src/utils/tools.ts +++ b/src/utils/tools.ts @@ -39,9 +39,24 @@ export const route = { .map((part) => part.charAt(0).toUpperCase() + part.slice(1)) // 首字母大写 .join(''); // 连接成字符串 }, - getTitleFromPathStr: (arr: any, path: string): string => { + getTitleFromPathStr: (arr: any, path: string, ignoreFields: string = ''): string => { const item = arr.find(({ key }) => path.includes(key)); - return item ? item.title : path; // 如果找到,返回 title;否则返回 null + return item ? item.title : path.replace(ignoreFields, ''); // 如果找到,返回 title;否则返回 null + }, + mergeDuplicatePathSegments(path: string) { + // 移除开头和结尾的斜杠,然后按斜杠分割 + const segments = path.replace(/^\/|\/$/g, '').split('/'); + + // 如果最后两个段相同且至少有2个段 + if (segments.length >= 2 && segments[segments.length - 1] === segments[segments.length - 2]) { + // 移除最后一个段 + segments.pop(); + // 重新组合路径 + return '/' + segments.join('/'); + } + + // 不需要处理的情况,返回原路径 + return path; }, }; diff --git a/src/views/demo/buildCli/buildCli.md b/src/views/demo/buildCli/buildCli.md new file mode 100644 index 0000000..e4c5a82 --- /dev/null +++ b/src/views/demo/buildCli/buildCli.md @@ -0,0 +1 @@ +## 请参考demoBuildCli目录演示 \ No newline at end of file diff --git a/src/views/demo/buildCli/buildCli.vue b/src/views/demo/buildCli/buildCli.vue new file mode 100644 index 0000000..7cf3c34 --- /dev/null +++ b/src/views/demo/buildCli/buildCli.vue @@ -0,0 +1,18 @@ + + +