组件修改

This commit is contained in:
2025-12-08 17:36:20 +08:00
parent bc1ee71fc1
commit 19ff3e2a93
23 changed files with 4036 additions and 82 deletions

View File

@@ -15,8 +15,8 @@ interface RouteItem {
}
// 布局组件
const DefaultLayout = defineAsyncComponent(
() => import('../layouts/DefaultLayout.vue')
const SharedLayout = defineAsyncComponent(
() => import('../layouts/SharedLayout.vue')
)
// 首页组件
@@ -46,7 +46,7 @@ const Home = {
const routes: RouteRecordRaw[] = [
{
path: '/',
component: DefaultLayout,
component: SharedLayout,
children: [
{
path: '',
@@ -59,29 +59,33 @@ const routes: RouteRecordRaw[] = [
}
]
// 自动导入所有以 Test.vue 结尾的组件
const testComponents = import.meta.glob('../components/**/*Test.vue')
// 自动导入所有以 Example.vue 结尾的组件
const testComponents = import.meta.glob('../components/**/*Example.vue')
// 为每个测试组件创建路由
Object.entries(testComponents).forEach(([path, component]) => {
// 从路径中提取路由路径
// 例如: ../components/fileupload/FileUploadTest.vue -> /fileupload
const routePath = path
.replace('../components/', '/') // 移除相对路径
.replace(/\/\w+Test\.vue$/, '') // 移除 Test.vue 部分
.toLowerCase() // 统一小写
const routeName = routePath.slice(1) || 'home'
// 保持完整的路径结构
// ../components/base/button/ButtonExample.vue -> /base/button
// ../components/fileupload/FileUploadExample.vue -> /fileupload
const pathSegments = path
.replace('../components/', '')
.replace(/Test\.vue$/, '')
.split('/')
.filter(Boolean)
const routePath = `/${pathSegments.join('/').toLowerCase()}`
const componentName = pathSegments[pathSegments.length - 1].toLowerCase()
const routeConfig: RouteRecordRaw = {
path: routePath,
name: routeName,
component: DefaultLayout,
name: componentName,
component: SharedLayout,
children: [
{
path: '',
name: `${routeName}-content`,
name: `${componentName}-content`,
component: defineAsyncComponent(component as any),
meta: { title: `${routeName} Demo` }
meta: { title: `${componentName.charAt(0).toUpperCase() + componentName.slice(1)} Demo` }
}
]
}
@@ -103,7 +107,7 @@ Object.entries(testComponents).forEach(([path, component]) => {
const props = homeRoute.props as { routes: RouteItem[] }
props.routes.push({
path: routePath,
name: routeName
name: componentName
})
}
})