import type { RouteRecordRaw } from 'vue-router'; /** 路由 meta 类型 */ export type AppMeta = { title: string; icon?: string; hideInMenu?: boolean; activeMenu?: string; }; /** * 快速创建路由记录 * 根据路径自动生成 PascalCase 路由 name * * @example * createRoute('list', () => import('@/pages/home'), { title: '赛事列表' }) * // => { path: 'list', name: 'List', meta: {...}, component: ... } */ export function createRoute( path: string, component: RouteRecordRaw['component'], meta: AppMeta, children: RouteRecordRaw[] = [], ): RouteRecordRaw { const cleanPath = path.replace(/[:/]/g, '-'); const name = cleanPath .split('-') .filter(Boolean) .map((p) => p.charAt(0).toUpperCase() + p.slice(1)) .join(''); return { path, name: name || undefined, meta, component, children, }; }