/** * 组件元数据清单。 * * 这是文档站的唯一数据源,三处消费它: * - `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; /** * 文档路径覆盖。 * * 默认取 `entry` 所在目录名,只有目录名与对外组件名不一致时才需要显式指定 * (如 `v-popup` 目录导出的是 `HoverPopup`)。 */ slug?: string; } export const COMPONENT_LIST: ComponentMeta[] = [ // ---------- 基础组件 ---------- { name: "Icon", title: "Icon 图标", description: "内置 149 个 SVG 图标,支持缩放、着色与禁用态。", category: "基础组件", entry: "src/components/icon/index.vue" }, { name: "Loading", title: "Loading 加载中", description: "四段线动画的加载指示器,可延迟显示并支持内联或铺满两种形态。", category: "基础组件", entry: "src/components/loading/index.vue" }, { name: "CenterTips", title: "CenterTips 居中提示", description: "列表或容器无数据时的居中占位文案。", category: "基础组件", entry: "src/components/center-tips/index.vue" }, { name: "Copyright", title: "Copyright 版权信息", description: "统一页脚:版权声明、备案号与自定义文案。", category: "基础组件", entry: "src/components/copyright/index.vue" }, // ---------- 数据展示 ---------- { name: "AnimatedNumber", title: "AnimatedNumber 数字动画", description: "数值变化时按缓动函数滚动过渡,支持小数位与千分位。", category: "数据展示", entry: "src/components/animated-number/index.vue" }, { name: "DescriptionGrid", title: "DescriptionGrid 描述栅格", description: "键值对描述列表,可指定列数、对齐方式与逐项具名插槽。", category: "数据展示", entry: "src/components/description-grid/index.vue" }, { name: "TimeLabel", title: "TimeLabel 时间标签", description: "把时间戳显示为过去或未来的相对时间,点击可切换为完整日期时间。", category: "数据展示", entry: "src/components/time-label/index.vue" }, { name: "ContactNumber", title: "ContactNumber 联系电话", description: "按号段分组的电话号码展示,可点击拨号并支持前置图标。", category: "数据展示", entry: "src/components/contact-number/index.vue" }, // ---------- 内容与浮层 ---------- { name: "MarkdownView", title: "MarkdownView 渲染视图", description: "把 Markdown 或代码片段渲染为带语法高亮的富文本。", category: "内容与浮层", entry: "src/components/markdown-view/index.vue" }, { name: "MarkdownEditor", title: "MarkdownEditor 编辑器", description: "左侧编辑右侧预览的 Markdown 编辑器,窄屏自动折叠预览区。", category: "内容与浮层", entry: "src/components/markdown-editor/index.vue" }, { name: "Popup", title: "Popup 浮层容器", description: "全局唯一的浮层挂载点,配合 v-popup 指令或 HoverPopup 使用。", category: "内容与浮层", entry: "src/components/popup/index.vue" }, { name: "HoverPopup", title: "HoverPopup 悬停浮层", description: "鼠标悬停时在浮层容器里展示文本、图片或自定义节点。", category: "内容与浮层", entry: "src/components/v-popup/index.vue", // 目录名是历史遗留的 v-popup,对外组件名是 HoverPopup,文档按后者取路径。 slug: "hover-popup" }, // ---------- 安全与特效 ---------- { name: "Captcha", title: "Captcha 验证码", description: "点击刷新的图形验证码,图片由外部 request 回调提供。", category: "安全与特效", entry: "src/components/captcha/index.vue" }, { name: "BEFlowerFall", title: "BEFlowerFall 落花背景", description: "飘落花瓣的页面背景特效,随窗口尺寸自适应。", category: "安全与特效", entry: "src/components/background-effect/flower-fall/index.vue" } ]; /** * 文档路径与路由片段。 * * 默认取组件源码所在目录名,而不是把组件名转 kebab-case: * 目录名天然就是合适的短横线形式(如 `flower-fall`), * 而 `BEFlowerFall` 这类连续大写用正则会得到 `beflower-fall` 这种不理想的路径。 * 目录名与对外组件名不一致时,用 `slug` 显式覆盖。 */ export function toSlug(meta: ComponentMeta): string { if (meta.slug) { return meta.slug; } const segments = meta.entry.split("/"); return segments[segments.length - 2]; } /** 组件文档页的站内绝对路径。 */ export function toDocLink(meta: ComponentMeta): string { return `/components/${toSlug(meta)}`; } /** 按分类分组,保持 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); }