docs: 补充前端 Vben/Ant 组件选用规则供 Agent 参考

This commit is contained in:
2026-09-22 22:06:01 +08:00
parent ff3c8bbe4c
commit 5b15c01606
3 changed files with 199 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
---
description: 前端 UI 组件选用优先级(Vben → Ant Design → 封装 → 自研)
globs: apps/web/**/*.{vue,ts,tsx}
alwaysApply: false
---
# 前端 UI 组件选用(Vben 5.7 / web-antd)
写 `apps/web` 业务页时按下面顺序选型,**禁止**一上来自研通用控件。
## 优先级
1. **Vben 应用层组件 / hooks**(`@vben/common-ui`、`#/adapter/*`、`@vben/plugins`)
2. **Ant Design Vue**(`ant-design-vue`)——原子控件、反馈、布局碎片
3. **可复用则封装**——抽到 `components/` 或 adapter,不要复制粘贴
4. **最后才自研**——仅当以上都无法满足,且注释说明原因
> web-antd 是 Ant Design 皮肤。业务页优先 `Button`/`Input`/`Select` 等 antd,不要用 shadcn 的 `VbenButton` 等(那些偏框架内部 / 文档演示)。
## 常用 Vben(优先用)
| 能力 | 用法 | 来源 |
|------|------|------|
| 页面壳 | `Page` | `@vben/common-ui` |
| 左右分栏 | `ColPage` | `@vben/common-ui` |
| 弹窗 | `useVbenModal` | `@vben/common-ui` |
| 抽屉 | `useVbenDrawer` | `@vben/common-ui` |
| 确认/提示/输入 | `alert` / `confirm` / `prompt` | `@vben/common-ui` |
| 搜索/编辑表单 | `useVbenForm` + `z` | `#/adapter/form` |
| 表格 | `useVbenVxeGrid` | `#/adapter/vxe-table` |
| 远程选项 | `ApiComponent` / 表单里 `ApiSelect` `ApiTreeSelect` | `@vben/common-ui` / adapter |
| 图标选择 | `IconPicker` | `@vben/common-ui` |
| 省略文案 | `EllipsisText` | `@vben/common-ui` |
| 数字滚动 | `CountTo` | `@vben/common-ui` |
| JSON 展示 | `JsonViewer` | `@vben/common-ui` |
| 加载 | `Loading` / `Spinner` | `@vben/common-ui` |
| 裁剪 | `VCropper` | `@vben/common-ui` |
| 可调宽 | `VResize` | `@vben/common-ui` |
| Tippy | `Tippy` / 指令 | `@vben/common-ui` |
| 树 | `Tree` | `@vben/common-ui` |
| 验证码 | `SliderCaptcha` 等 | `@vben/common-ui` |
| 图表 | `EchartsUI` / `useEcharts` | `@vben/plugins/echarts` |
| 富文本 | `VbenTiptap` | `@vben/plugins/tiptap` |
| 兜底页 | `Fallback` | `@vben/common-ui` |
列表页典型组合:`Page` + `useVbenVxeGrid`(可带 `useVbenForm` 搜索)+ `useVbenModal` 表单。
## 表单 schema 可用组件类型(adapter 已注册)
`Input` `InputNumber` `InputPassword` `Textarea` `Mentions` `Select` `ApiSelect` `TreeSelect` `ApiTreeSelect` `AutoComplete` `Checkbox` `CheckboxGroup` `Radio` `RadioGroup` `Switch` `DatePicker` `RangePicker` `TimePicker` `Rate` `Upload` `Divider` `Space` `IconPicker` `DefaultButton` `PrimaryButton`
## Ant Design(Vben 没有对应能力时用)
常用:`Button` `Input` `Select` `Table`(轻量表) `Tabs` `Tag` `Card` `Space` `Flex` `Row/Col` `Form`(简单场景) `Modal`(临时/极简) `Drawer` `Dropdown` `Menu` `Tooltip` `Popover` `Popconfirm` `message` `notification` `Spin` `Empty` `Pagination` `Cascader` `Transfer` `Tree` `Upload` `DatePicker` `Progress` `Badge` `Avatar` `Descriptions` `Statistic` `Skeleton` `Alert` `Result` `Image` …
注意:可滚动列表**不要**用 `<Spin :spinning>` 整块包裹(见 `antd-spin-scrollable-layout`)。
## 导入约定
```ts
import { Page, useVbenModal } from '@vben/common-ui';
import { useVbenForm, z } from '#/adapter/form';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { Button, message } from 'ant-design-vue';
```
更完整清单见 `apps/web/docs/agent-ui-components.md`。
+2
View File
@@ -32,8 +32,10 @@ deploy/ # 部署 TUI(原 ecom-deploy),流程见 deploy/MANU
- 开发 `pnpm dev:antd`,构建 `pnpm build:antd`;类型检查 `pnpm -F @vben/web-antd typecheck`
- lefthook 钩子会对暂存文件跑 `pnpm lint`(oxfmt/oxlint 等)与 `check:type`,commitlint 强制 conventional commit,不要绕过
- 代码内 `#/` 别名 = `src/`
- **UI 选型**:Vben 应用层 → Ant Design Vue → 可复用封装 → 自研;清单见 `apps/web/docs/agent-ui-components.md`(规则 `.cursor/rules/frontend-ui-priority.mdc`)
- **web-antd 视图里不要用 `<Spin :spinning>` 整块包住可滚动列表**(ant-spin-container 破坏滚动链);滚动依赖 `flex-1 min-h-0 overflow-y-auto`,加载态拆细(详见 `.cursor/rules/antd-spin-scrollable-layout.mdc`)
- 智能助手页:`views/agent/chat`;开发代理 `/api/agent` → `localhost:8200`(见 `vite.config.mts`)
- 当前应用版本:`@vben/web-antd` **5.7.0**
## Agent(apps/agent)
+130
View File
@@ -0,0 +1,130 @@
# Agent 前端 UI 组件清单(Vben 5.7 / web-antd)
写 `apps/web/apps/web-antd` 时按:**Vben → Ant Design Vue → 可复用就封装 → 最后自研**。
业务页是 **Ant Design 皮肤**:原子控件用 antd,不要用 shadcn 系 `VbenButton` 等(偏框架内部)。
---
## 1. 选用顺序
| 顺序 | 用什么 | 何时 |
|------|--------|------|
| ① | Vben 应用层(下表) | 页面壳、弹窗抽屉、表单、表格、远程下拉 |
| ② | `ant-design-vue` | 按钮/输入/标签/反馈等原子控件 |
| ③ | 项目内封装 | 多处重复(放 `components/` 或补 adapter) |
| ④ | 自研 | 仅 ①②③ 都不够,并注明原因 |
典型列表页:`Page` + `useVbenVxeGrid` +(可选搜索 `useVbenForm`)+ `useVbenModal`。
---
## 2. Vben 可用组件(简表)
### 布局 / 页面
| 导出 | 用途 |
|------|------|
| `Page` | 标准内容页壳(标题区 + 内容区) |
| `ColPage` | 左右可拖拽分栏(侧栏 + 主区) |
| `Fallback` | 403/404/500/离线等兜底 |
来自 `@vben/common-ui`。
### 弹层 / 反馈
| 导出 | 用途 |
|------|------|
| `useVbenModal` / `VbenModal` | 业务弹窗(优先于 antd Modal) |
| `useVbenDrawer` / `VbenDrawer` | 业务抽屉 |
| `alert` / `confirm` / `prompt` | 命令式确认、提示、输入 |
来自 `@vben/common-ui`(popup-ui)。
### 表单
| 导出 | 用途 |
|------|------|
| `useVbenForm` | 配置式表单(搜索栏 / 弹窗表单) |
| `z` | Zod 校验 |
| `ApiComponent` | 远程数据驱动的选择器底座 |
业务代码用 `#/adapter/form` 的 `useVbenForm`(已接 antd 组件)。
**表单 schema `component` 已注册类型:**
`Input` `InputNumber` `InputPassword` `Textarea` `Mentions` `Select` `ApiSelect` `TreeSelect` `ApiTreeSelect` `AutoComplete` `Checkbox` `CheckboxGroup` `Radio` `RadioGroup` `Switch` `DatePicker` `RangePicker` `TimePicker` `Rate` `Upload` `Divider` `Space` `IconPicker` `DefaultButton` `PrimaryButton`
### 表格
| 导出 | 用途 |
|------|------|
| `useVbenVxeGrid` / `VbenVxeGrid` | 列表/工具栏/分页(优先于手写 antd Table) |
来自 `#/adapter/vxe-table`(底层 `@vben/plugins/vxe-table`)。
### 其它 common-ui
| 导出 | 用途 |
|------|------|
| `EllipsisText` | 超长省略 + tooltip |
| `CountTo` | 数字滚动动画 |
| `JsonViewer` | JSON 树查看 |
| `IconPicker` | 图标选择 |
| `Loading` / `Spinner` | 加载指示 |
| `Tree` | 树(Vben 版) |
| `VCropper` | 图片裁剪 |
| `VResize` | 拖拽调宽 |
| `Tippy` | Tippy 浮层 |
| `SliderCaptcha` / `SliderRotateCaptcha` / `SliderTranslateCaptcha` / `PointSelectionCaptcha` | 验证码 |
### 插件 `@vben/plugins`
| 导出 | 用途 |
|------|------|
| `EchartsUI` / `useEcharts` | 图表 |
| `VbenTiptap` / `VbenTiptapPreview` | 富文本 |
| `useVbenVxeGrid` | 见上(经 adapter) |
### 认证 / 工作台 UI(少改业务页)
`AuthenticationLogin` `AuthenticationRegister` `AuthenticationCodeLogin` `AuthenticationQrCodeLogin` `AuthenticationForgetPassword` `AuthenticationLoginExpiredModal`;`Workbench*` / `Analysis*`;`Profile*`;`About`。
### shadcn 封装(一般不直接用于业务页)
`VbenAvatar` `VbenButton` `VbenButtonGroup` `VbenCheckbox` `VbenCheckButtonGroup` `VbenCollapsibleParams` `VbenContextMenu` `VbenCountToAnimator` `VbenFullScreen` `VbenIconButton` `VbenInputPassword` `VbenLoading` `VbenLogo` `VbenPinInput` `VbenSelect` `VbenSpinner` 等——框架/布局内部用;**业务交互控件继续用 antd**。
---
## 3. Ant Design Vue(②)
Vben 没有对等封装时用 antd,例如:
- 操作:`Button` `Dropdown` `Popconfirm`
- 输入:`Input` `InputNumber` `Select` `Cascader` `TreeSelect` `DatePicker` `Upload` …
- 展示:`Tag` `Card` `Descriptions` `Empty` `Image` `Badge` `Avatar` `Statistic` `Progress` `Skeleton` `Alert` `Result`
- 布局:`Space` `Flex` `Row` `Col` `Divider` `Tabs`
- 反馈:`message` `notification` `Modal`(极简临时) `Spin`(注意滚动规则)
- 轻量表:少量静态数据可用 antd `Table`;正式列表仍用 `useVbenVxeGrid`
图标:`@ant-design/icons-vue`。
---
## 4. 导入示例
```ts
import { Page, useVbenModal } from '@vben/common-ui';
import { useVbenForm, z } from '#/adapter/form';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { Button, Space, message } from 'ant-design-vue';
```
---
## 5. 源码位置(需查 props 时)
- `@vben/common-ui` → `packages/effects/common-ui`
- Form / Modal / Drawer → `packages/@core/ui-kit/form-ui`、`popup-ui`
- VXE / ECharts / Tiptap → `packages/effects/plugins`
- antd 表单适配 → `apps/web-antd/src/adapter/`