Files
ai-crm/.cursor/rules/frontend-ui-priority.mdc
2026-10-21 23:23:48 +08:00

68 lines
3.3 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
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`。