/** * 组件元数据清单。 * * 这是文档站的唯一数据源,三处消费它: * - `config.ts` 生成侧边栏导航 * - `plugins/docgen.ts` 按 `entry` 定位源码并交给 vue-docgen-api 解析 * - 页面内的 `` 按 `name` 查询解析结果 * * 新增组件时只需在此追加一项,导航、API 表、文档路由会同步生效。 */ /** 分类展示顺序即数组顺序。 */ export const CATEGORY_LIST = [ "布局组件", "编辑器组件", "用户组件" ] as const; export type ComponentCategory = (typeof CATEGORY_LIST)[number]; export interface ComponentMeta { /** 组件名,必须与组件内 `defineOptions` 的 name 一致,同时是 api-table 的查询键。 */ name: string; /** 文档与侧边栏展示的中文标题。 */ title: string; /** 一句话功能描述。 */ description: string; /** 所属分类。 */ category: ComponentCategory; /** 组件入口源码,相对仓库根目录。 */ entry: string; } export const COMPONENT_LIST: ComponentMeta[] = [ // ---------- 布局组件 ---------- { name: "RootLayout", title: "RootLayout 根布局", description: "提供页面级骨架与统一留白,承载顶部区域与主内容。", category: "布局组件", entry: "src/components/root-layout/index.vue" }, { name: "AdminLayout", title: "AdminLayout 管理台布局", description: "侧边菜单、顶部栏与内容区三区合一的后台骨架,支持菜单折叠。", category: "布局组件", entry: "src/components/admin-layout/index.vue" }, // ---------- 编辑器组件 ---------- { name: "CodeEditor", title: "CodeEditor 代码编辑器", description: "带行号、语法高亮与查找替换的代码输入框。", category: "编辑器组件", entry: "src/components/code-editor/index.vue" }, { name: "TiptapEditor", title: "TiptapEditor 富文本编辑器", description: "基于 Tiptap 的富文本编辑器,内置媒体、表格、链接与代码块等工具栏能力。", category: "编辑器组件", entry: "src/components/tiptap-editor/index.vue" }, { name: "TiptapView", title: "TiptapView 富文本视图", description: "Tiptap 内容的只读渲染视图,与编辑器共用同一套样式。", category: "编辑器组件", entry: "src/components/tiptap-view/index.vue" }, { name: "ArticleEditor", title: "ArticleEditor 文章编辑器", description: "以 Article 为数据模型,按正文类型切换纯文本、Markdown 与富文本编辑。", category: "编辑器组件", entry: "src/components/article-editor/index.vue" }, { name: "ArticleView", title: "ArticleView 文章视图", description: "按 Article 的正文类型渲染标题、正文与附件列表。", category: "编辑器组件", entry: "src/components/article-view/index.vue" }, { name: "NotifyEditor", title: "NotifyEditor 通知编辑器", description: "以 NotifyDetail 为数据模型的通知编辑表单,复用文章编辑器能力。", category: "编辑器组件", entry: "src/components/notify-editor/index.vue" }, { name: "NotifyView", title: "NotifyView 通知视图", description: "渲染通知主题、状态与正文内容。", category: "编辑器组件", entry: "src/components/notify-view/index.vue" }, // ---------- 用户组件 ---------- { name: "AuthorizeForm", title: "AuthorizeForm 授权表单", description: "登录与注册合一的授权表单,验证码、请求与回调全部由外部注入。", category: "用户组件", entry: "src/components/authorize-form/index.vue" }, { name: "UserProfile", title: "UserProfile 用户资料", description: "展示用户头像、昵称与等级信息,支持点击展开资料弹窗。", category: "用户组件", entry: "src/components/user-profile/index.vue" }, { name: "UserProfilePopup", title: "UserProfilePopup 用户资料弹窗", description: "用户资料卡弹窗,由 UserProfile 唤起,也可独立使用。", category: "用户组件", entry: "src/components/user-profile/popup/index.vue" }, { name: "UserLevel", title: "UserLevel 用户等级", description: "按等级值渲染等级图标与文案,等级规则可外部覆盖。", category: "用户组件", entry: "src/components/user-level/index.vue" } ]; /** PascalCase 转 kebab-case,用于推导文档路径与路由。 */ export function toKebabCase(name: string): string { return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(); } /** 组件文档页的站内绝对路径。 */ export function toDocLink(meta: ComponentMeta): string { return `/components/${toKebabCase(meta.name)}`; } /** 按分类分组,保持 CATEGORY_LIST 的声明顺序。 */ export function groupByCategory(): Array<{ category: ComponentCategory; items: ComponentMeta[] }> { return CATEGORY_LIST.map(category => ({ category, items: COMPONENT_LIST.filter(item => item.category === category) })).filter(group => group.items.length > 0); }