docs(dict): 添加字典使用指南

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Leo 2025-09-27 01:21:23 +08:00
parent 5355993a2a
commit 75560e0c4b

View File

@ -59,6 +59,14 @@ pnpm sizecheck
- **UnoCSS 66.2.0** 原子化CSS - **UnoCSS 66.2.0** 原子化CSS
- **Alova 3.3.2** HTTP客户端 - **Alova 3.3.2** HTTP客户端
## 开发规范补充
### 字典数据使用约定
- **严禁写死常量**:凡是来源于数据库的枚举/状态类数据(启用/停用、成功/失败、性别、角色/菜单/文件服务等),必须通过后端字典接口 `listDataByType` 获取,不得在前端硬编码。
- **统一入口**:所有页面应使用 `useDict`/`useDictStore`、`DictTag` 与 `getSelectOptions` 等工具消费字典,确保新增字典值时页面自动生效。
- **缓存刷新**:对字典类型或字典数据进行增删改操作后,务必调用 `dictStore.invalidate` 失效前端缓存,确保其它模块能够获取最新字典信息。
- **新增字典类型**:若发现现有字典无法覆盖业务,需要先在后端补充字典类型及数据,再在前端按照上述方式接入,不得继续使用手工数组。
### 目录结构要点 ### 目录结构要点
``` ```
src/ src/
@ -167,7 +175,7 @@ src/
## ⚠️ 严格禁止事项 ## ⚠️ 严格禁止事项
**1. 消息提示** **1. 消息提示**
```typescript ```text
// ❌ 严禁使用Element Plus原生消息 // ❌ 严禁使用Element Plus原生消息
// ✅ 必须使用项目封装的消息函数 // ✅ 必须使用项目封装的消息函数
import { coiMsgError, coiMsgSuccess } from '@/utils/coi.ts' import { coiMsgError, coiMsgSuccess } from '@/utils/coi.ts'
@ -179,7 +187,7 @@ coiMsgError('操作失败')
``` ```
**2. 类型定义** **2. 类型定义**
```typescript ```text
// ❌ 严禁使用any类型 // ❌ 严禁使用any类型
const response: any = await getList() const response: any = await getList()
@ -188,7 +196,7 @@ const response: Result<ResponseVo[]> = await getList()
``` ```
**3. 数据访问** **3. 数据访问**
```typescript ```text
// ❌ 错误的数据访问 // ❌ 错误的数据访问
const data = response const data = response
@ -1229,74 +1237,10 @@ import { coiMsgError, coiMsgSuccess, coiMsgWarning } from '@/utils/coi'
### 标准按钮实现规范 ### 标准按钮实现规范
**✅ 正确的表格操作列按钮实现方式** **✅ 正确的表格操作列按钮实现方式**
```typescript - 编辑按钮:`type: 'primary'`、`size: 'small'`、`class: 'action-btn-primary'`,图标固定为 `IconParkOutlineEdit`
// 表格列定义 - 操作列 - 删除按钮:使用 `NPopconfirm` 包裹 `type: 'error'`、`secondary: true`、`size: 'small'` 的按钮,图标用 `IconParkOutlineDelete`,确认文案统一为“确定删除此记录吗?”。
{ - 其它功能按钮:根据语义选择 `type: 'warning'`、`'info'` 等,并附加 `secondary: true` 与对应语义图标(如 `IconParkOutlineSetting`)。
title: '操作', - 操作列返回 `div.flex.items-center.justify-center.gap-2` 布局,按钮顺序遵循“编辑→删除→其他”。
key: 'actions',
width: 280,
align: 'center',
fixed: 'right',
render: (row) => {
const buttons = []
// 编辑按钮 - 主要操作按钮
if (hasPermission('edit')) {
buttons.push(h(NButton, {
type: 'primary',
size: 'small',
class: 'action-btn-primary',
onClick: () => handleEdit(row),
}, {
icon: () => h(NIcon, { size: 14, style: 'transform: translateY(-1px)' }, {
default: () => h(IconParkOutlineEdit)
}),
default: () => '编辑',
}))
}
// 删除按钮 - 危险操作按钮
if (hasPermission('delete')) {
buttons.push(h(NPopconfirm, {
onPositiveClick: () => handleDelete(row.id),
negativeText: '取消',
positiveText: '确定',
}, {
default: () => '确定删除此记录吗?',
trigger: () => h(NButton, {
type: 'error',
secondary: true,
size: 'small',
class: 'action-btn-secondary action-btn-danger',
}, {
icon: () => h(NIcon, { size: 14, style: 'transform: translateY(-1px)' }, {
default: () => h(IconParkOutlineDelete),
}),
default: () => '删除',
}),
}))
}
// 其他功能按钮 - 辅助操作按钮
if (hasPermission('other')) {
buttons.push(h(NButton, {
type: 'warning',
secondary: true,
size: 'small',
class: 'action-btn-secondary action-btn-warning',
onClick: () => handleOtherAction(row),
}, {
icon: () => h(NIcon, { size: 14, style: 'transform: translateY(-1px)' }, {
default: () => h(IconParkOutlineSetting),
}),
default: () => '设置',
}))
}
return h('div', { class: 'flex items-center justify-center gap-2' }, buttons)
},
}
```
### 按钮样式核心标准 ### 按钮样式核心标准
@ -1381,7 +1325,7 @@ const buttons = []
buttons.push(h(NButton, { buttons.push(h(NButton, {
type: 'primary', type: 'primary',
size: 'small', size: 'small',
class: 'action-btn-primary' class: 'action-btn-primary',
// ... 其他属性 // ... 其他属性
})) }))
@ -1392,7 +1336,7 @@ buttons.push(h(NPopconfirm, {
type: 'error', type: 'error',
secondary: true, secondary: true,
size: 'small', size: 'small',
class: 'action-btn-secondary action-btn-danger' class: 'action-btn-secondary action-btn-danger',
// ... 其他属性 // ... 其他属性
}) })
})) }))
@ -1402,7 +1346,7 @@ buttons.push(h(NButton, {
type: 'info', type: 'info',
secondary: true, secondary: true,
size: 'small', size: 'small',
class: 'action-btn-secondary action-btn-info' class: 'action-btn-secondary action-btn-info',
// ... 其他属性 // ... 其他属性
})) }))
``` ```