From 75560e0c4b7ec4c4eb533c7d678c8cff1dcc0970 Mon Sep 17 00:00:00 2001 From: Leo <98382335+gaoziman@users.noreply.github.com> Date: Sat, 27 Sep 2025 01:21:23 +0800 Subject: [PATCH] =?UTF-8?q?docs(dict):=20=E6=B7=BB=E5=8A=A0=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E4=BD=BF=E7=94=A8=E6=8C=87=E5=8D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CLAUDE.md | 92 +++++++++++-------------------------------------------- 1 file changed, 18 insertions(+), 74 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 3c12a38..c48fca4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,6 +59,14 @@ pnpm sizecheck - **UnoCSS 66.2.0** 原子化CSS - **Alova 3.3.2** HTTP客户端 +## 开发规范补充 + +### 字典数据使用约定 +- **严禁写死常量**:凡是来源于数据库的枚举/状态类数据(启用/停用、成功/失败、性别、角色/菜单/文件服务等),必须通过后端字典接口 `listDataByType` 获取,不得在前端硬编码。 +- **统一入口**:所有页面应使用 `useDict`/`useDictStore`、`DictTag` 与 `getSelectOptions` 等工具消费字典,确保新增字典值时页面自动生效。 +- **缓存刷新**:对字典类型或字典数据进行增删改操作后,务必调用 `dictStore.invalidate` 失效前端缓存,确保其它模块能够获取最新字典信息。 +- **新增字典类型**:若发现现有字典无法覆盖业务,需要先在后端补充字典类型及数据,再在前端按照上述方式接入,不得继续使用手工数组。 + ### 目录结构要点 ``` src/ @@ -167,7 +175,7 @@ src/ ## ⚠️ 严格禁止事项 **1. 消息提示** -```typescript +```text // ❌ 严禁使用Element Plus原生消息 // ✅ 必须使用项目封装的消息函数 import { coiMsgError, coiMsgSuccess } from '@/utils/coi.ts' @@ -179,7 +187,7 @@ coiMsgError('操作失败') ``` **2. 类型定义** -```typescript +```text // ❌ 严禁使用any类型 const response: any = await getList() @@ -188,7 +196,7 @@ const response: Result = await getList() ``` **3. 数据访问** -```typescript +```text // ❌ 错误的数据访问 const data = response @@ -1229,74 +1237,10 @@ import { coiMsgError, coiMsgSuccess, coiMsgWarning } from '@/utils/coi' ### 标准按钮实现规范 **✅ 正确的表格操作列按钮实现方式**: -```typescript -// 表格列定义 - 操作列 -{ - title: '操作', - 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) - }, -} -``` +- 编辑按钮:`type: 'primary'`、`size: 'small'`、`class: 'action-btn-primary'`,图标固定为 `IconParkOutlineEdit`。 +- 删除按钮:使用 `NPopconfirm` 包裹 `type: 'error'`、`secondary: true`、`size: 'small'` 的按钮,图标用 `IconParkOutlineDelete`,确认文案统一为“确定删除此记录吗?”。 +- 其它功能按钮:根据语义选择 `type: 'warning'`、`'info'` 等,并附加 `secondary: true` 与对应语义图标(如 `IconParkOutlineSetting`)。 +- 操作列返回 `div.flex.items-center.justify-center.gap-2` 布局,按钮顺序遵循“编辑→删除→其他”。 ### 按钮样式核心标准 @@ -1381,7 +1325,7 @@ const buttons = [] buttons.push(h(NButton, { type: 'primary', size: 'small', - class: 'action-btn-primary' + class: 'action-btn-primary', // ... 其他属性 })) @@ -1392,7 +1336,7 @@ buttons.push(h(NPopconfirm, { type: 'error', secondary: true, 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', secondary: true, size: 'small', - class: 'action-btn-secondary action-btn-info' + class: 'action-btn-secondary action-btn-info', // ... 其他属性 })) ```