@agile-team/wl-skills-kit 2.3.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -57
- package/README.md +23 -148
- package/bin/wl-skills.js +2 -100
- package/files/.github/guides/README.md +13 -13
- package/files/.github/guides/architecture.md +555 -576
- package/files/.github/guides/usage.md +176 -176
- package/files/.github/reports/README.md +65 -65
- package/files/.github/reports/SYS_DICT_INFO.md +50 -50
- package/files/.github/reports/SYS_MENU_INFO.md +247 -247
- package/files/.github/reports/SYS_PERMISSION_INFO.md +20 -20
- package/files/.github/reports//347/273/204/344/273/266/346/217/220/345/217/226/345/273/272/350/256/256.md +33 -33
- package/files/.github/reports//350/247/204/350/214/203/345/256/241/346/237/245/346/212/245/345/221/212.md +44 -44
- package/files/.github/skills/_compat/README.md +108 -108
- package/files/.github/skills/_compat/headers/agents.txt +8 -8
- package/files/.github/skills/_compat/headers/claude-code.txt +7 -7
- package/files/.github/skills/_compat/headers/cline.txt +7 -7
- package/files/.github/skills/_compat/headers/cursor-mdc.txt +16 -16
- package/files/.github/skills/_compat/headers/cursor-rules.txt +7 -7
- package/files/.github/skills/_compat/headers/github-copilot.txt +1 -1
- package/files/.github/skills/_compat/headers/kiro.txt +10 -10
- package/files/.github/skills/_compat/headers/trae.txt +11 -11
- package/files/.github/skills/_compat/headers/windsurf.txt +7 -7
- package/files/.github/skills/_registry.md +81 -81
- package/files/.github/skills/core/api-contract/SKILL.md +344 -344
- package/files/.github/skills/core/api-contract/USAGE.md +110 -110
- package/files/.github/skills/core/convention-audit/SKILL.md +189 -189
- package/files/.github/skills/core/convention-audit/USAGE.md +99 -99
- package/files/.github/skills/core/page-codegen/SKILL.md +973 -973
- package/files/.github/skills/core/page-codegen/USAGE.md +102 -102
- package/files/.github/skills/core/page-codegen/templates/_index.md +46 -46
- package/files/.github/skills/core/page-codegen/templates/domains/_CONTRIBUTING.md +107 -107
- package/files/.github/skills/core/page-codegen/templates/domains/produce/TPL-OPERATION-STATION.md +442 -442
- package/files/.github/skills/core/page-codegen/templates/domains/sale/README.md +26 -26
- package/files/.github/skills/core/page-codegen/templates/universal/TPL-CHANGE-HISTORY.md +276 -276
- package/files/.github/skills/core/page-codegen/templates/universal/TPL-DETAIL-TABS.md +1145 -1145
- package/files/.github/skills/core/page-codegen/templates/universal/TPL-DRIVEN.md +309 -124
- package/files/.github/skills/core/page-codegen/templates/universal/TPL-FORM-ROUTE.md +436 -436
- package/files/.github/skills/core/page-codegen/templates/universal/TPL-LIST.md +191 -191
- package/files/.github/skills/core/page-codegen/templates/universal/TPL-MASTER-DETAIL.md +148 -148
- package/files/.github/skills/core/page-codegen/templates/universal/TPL-RECORD-FORM.md +376 -376
- package/files/.github/skills/core/page-codegen/templates/universal/TPL-TREE-LIST.md +186 -186
- package/files/.github/skills/core/prototype-scan/SKILL.md +498 -498
- package/files/.github/skills/core/prototype-scan/USAGE.md +95 -95
- package/files/.github/skills/core/template-extract/SKILL.md +139 -139
- package/files/.github/skills/core/template-extract/USAGE.md +93 -93
- package/files/.github/skills/domain/README.md +51 -51
- package/files/.github/skills/sync/menu-sync/SKILL.md +263 -263
- package/files/.github/skills/sync/menu-sync/USAGE.md +104 -104
- package/files/.github/skills/sync/menu-sync/env/env.local.json +7 -7
- package/files/.github/skills/sync/menu-sync/env/guide.md +99 -99
- package/files/.github/skills/sync/permission-sync/SKILL.draft.md +91 -91
- package/files/.github/standards/01-toolchain.md +57 -57
- package/files/.github/standards/02-code-structure.md +111 -111
- package/files/.github/standards/03-comments.md +53 -53
- package/files/.github/standards/04-coding-basics.md +33 -33
- package/files/.github/standards/05-logging.md +38 -38
- package/files/.github/standards/06-security.md +44 -44
- package/files/.github/standards/07-config.md +52 -52
- package/files/.github/standards/08-git.md +60 -60
- package/files/.github/standards/09-typescript.md +71 -71
- package/files/.github/standards/10-pinia.md +57 -57
- package/files/.github/standards/11-form-validation.md +81 -81
- package/files/.github/standards/12-base-table.md +153 -153
- package/files/.github/standards/13-platform-components.md +123 -123
- package/files/.github/standards/index.md +89 -89
- package/files/demo/produce/aiflow/mmwr-customer-apply-add/api.md +1 -1
- package/files/demo/produce/aiflow/mmwr-customer-apply-change-history/data.ts +196 -196
- package/files/demo/produce/aiflow/mmwr-customer-apply-change-history/index.scss +150 -150
- package/files/demo/produce/aiflow/mmwr-customer-apply-change-history/index.vue +79 -79
- package/files/docs/jh-date-range.md +257 -257
- package/files/docs/jh-date.md +222 -222
- package/files/docs/jh-dept-picker.md +190 -190
- package/files/docs/jh-drag-row.md +590 -590
- package/files/docs/jh-file-upload.md +216 -216
- package/files/docs/jh-picker.md +218 -218
- package/files/docs/jh-select.md +148 -148
- package/files/docs/jh-text.md +248 -248
- package/files/docs/jh-user-picker.md +197 -197
- package/files/docs/request.md +24 -9
- package/files/src/components/global/C_RightToolbar/data.ts +228 -0
- package/files/src/components/global/C_RightToolbar/index.scss +44 -0
- package/files/src/components/global/C_RightToolbar/index.vue +34 -336
- package/files/src/components/global/C_Splitter/index.scss +61 -0
- package/files/src/components/global/C_Splitter/index.vue +2 -64
- package/files/src/components/global/C_SvgIcon/index.scss +15 -0
- package/files/src/components/global/C_SvgIcon/index.vue +20 -50
- package/files/src/components/global/C_TagStatus/index.scss +20 -0
- package/files/src/components/global/C_TagStatus/index.vue +1 -22
- package/files/src/components/global/C_Tree/data.ts +61 -0
- package/files/src/components/global/C_Tree/index.vue +12 -53
- package/files/src/components/local/c_listModal/index.scss +4 -0
- package/files/src/components/local/c_listModal/index.vue +1 -1
- package/package.json +5 -9
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
# 06 — 安全规范
|
|
2
|
-
|
|
3
|
-
> **强制度**:🔴 必遵。
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## v-html 使用约束
|
|
8
|
-
|
|
9
|
-
- ❌ 默认禁止 `v-html`
|
|
10
|
-
- ✅ 仅当内容来源受控(如后端返回已消毒的富文本),且必须在使用处加注释说明来源:
|
|
11
|
-
|
|
12
|
-
```vue
|
|
13
|
-
<!-- v-html 安全声明:内容来自 /api/notice/detail,后端已做 XSS 过滤 -->
|
|
14
|
-
<div v-html="notice.content" />
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Token 存储
|
|
18
|
-
|
|
19
|
-
- ✅ 仅存 `sessionStorage` / `localStorage`
|
|
20
|
-
- ❌ 禁止放在 URL 参数(被日志记录)
|
|
21
|
-
- ❌ 禁止放在 `<meta>` 标签(HTML 静态可见)
|
|
22
|
-
|
|
23
|
-
## 接口请求
|
|
24
|
-
|
|
25
|
-
- ✅ 统一通过 `getAction / postAction / putAction / deleteAction` 走拦截器
|
|
26
|
-
- ✅ 拦截器自动注入 token、统一处理 401 跳转
|
|
27
|
-
- ❌ 禁止 `import axios from 'axios'` 直接使用
|
|
28
|
-
|
|
29
|
-
## 用户输入
|
|
30
|
-
|
|
31
|
-
- ✅ 通过接口参数对象传递
|
|
32
|
-
- ❌ 禁止拼接到 URL 字符串
|
|
33
|
-
- ❌ 禁止直接传给 SQL 语句生成函数(防 SQL 注入)
|
|
34
|
-
|
|
35
|
-
## 对象遍历
|
|
36
|
-
|
|
37
|
-
- ❌ 禁止 `for...in`(可能枚举原型链属性,存在安全隐患)
|
|
38
|
-
- ✅ 使用 `Object.keys(obj).forEach()` / `Object.entries(obj)`
|
|
39
|
-
|
|
40
|
-
## 危险 API
|
|
41
|
-
|
|
42
|
-
- ❌ **禁止 `eval()`** —— 任何场景均不允许
|
|
43
|
-
- ❌ 禁止 `new Function(string)` 动态执行字符串代码
|
|
44
|
-
- ❌ 禁止 `setTimeout(string)` 字符串形式调用
|
|
1
|
+
# 06 — 安全规范
|
|
2
|
+
|
|
3
|
+
> **强制度**:🔴 必遵。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## v-html 使用约束
|
|
8
|
+
|
|
9
|
+
- ❌ 默认禁止 `v-html`
|
|
10
|
+
- ✅ 仅当内容来源受控(如后端返回已消毒的富文本),且必须在使用处加注释说明来源:
|
|
11
|
+
|
|
12
|
+
```vue
|
|
13
|
+
<!-- v-html 安全声明:内容来自 /api/notice/detail,后端已做 XSS 过滤 -->
|
|
14
|
+
<div v-html="notice.content" />
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Token 存储
|
|
18
|
+
|
|
19
|
+
- ✅ 仅存 `sessionStorage` / `localStorage`
|
|
20
|
+
- ❌ 禁止放在 URL 参数(被日志记录)
|
|
21
|
+
- ❌ 禁止放在 `<meta>` 标签(HTML 静态可见)
|
|
22
|
+
|
|
23
|
+
## 接口请求
|
|
24
|
+
|
|
25
|
+
- ✅ 统一通过 `getAction / postAction / putAction / deleteAction` 走拦截器
|
|
26
|
+
- ✅ 拦截器自动注入 token、统一处理 401 跳转
|
|
27
|
+
- ❌ 禁止 `import axios from 'axios'` 直接使用
|
|
28
|
+
|
|
29
|
+
## 用户输入
|
|
30
|
+
|
|
31
|
+
- ✅ 通过接口参数对象传递
|
|
32
|
+
- ❌ 禁止拼接到 URL 字符串
|
|
33
|
+
- ❌ 禁止直接传给 SQL 语句生成函数(防 SQL 注入)
|
|
34
|
+
|
|
35
|
+
## 对象遍历
|
|
36
|
+
|
|
37
|
+
- ❌ 禁止 `for...in`(可能枚举原型链属性,存在安全隐患)
|
|
38
|
+
- ✅ 使用 `Object.keys(obj).forEach()` / `Object.entries(obj)`
|
|
39
|
+
|
|
40
|
+
## 危险 API
|
|
41
|
+
|
|
42
|
+
- ❌ **禁止 `eval()`** —— 任何场景均不允许
|
|
43
|
+
- ❌ 禁止 `new Function(string)` 动态执行字符串代码
|
|
44
|
+
- ❌ 禁止 `setTimeout(string)` 字符串形式调用
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
# 07 — 配置管理规范
|
|
2
|
-
|
|
3
|
-
> **强制度**:🔴 必遵。
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 环境变量
|
|
8
|
-
|
|
9
|
-
- 统一存放 `envs/.env.{mode}` 文件
|
|
10
|
-
- 命名以 `VITE_` 开头(Vite 暴露给客户端的前缀)
|
|
11
|
-
- 通过 `import.meta.env.VITE_XXX` 读取
|
|
12
|
-
- ❌ 不硬编码环境相关值
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
// ✅ 正确
|
|
16
|
-
const apiBase = import.meta.env.VITE_API_URL;
|
|
17
|
-
|
|
18
|
-
// ❌ 错误
|
|
19
|
-
const apiBase = "http://10.0.0.5:8080/api";
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## API 地址
|
|
23
|
-
|
|
24
|
-
- ✅ 通过 `import.meta.env.VITE_API_URL` 等环境变量获取
|
|
25
|
-
- ❌ 不在代码中硬编码 `http://` / `https://` 地址
|
|
26
|
-
|
|
27
|
-
## 接口路径
|
|
28
|
-
|
|
29
|
-
- ✅ 集中在 `data.ts` 的 `API_CONFIG` 对象中声明(`as const`)
|
|
30
|
-
- ❌ 不散落在模板字符串、方法内部
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
export const API_CONFIG = {
|
|
34
|
-
list: "/mmwr/customer/list",
|
|
35
|
-
save: "/mmwr/customer/save",
|
|
36
|
-
remove: "/mmwr/customer/remove",
|
|
37
|
-
} as const;
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## 敏感信息
|
|
41
|
-
|
|
42
|
-
- ❌ 不提交到仓库(已纳入 `.gitignore`)
|
|
43
|
-
- ✅ 团队共享走内部文档或专用密钥服务
|
|
44
|
-
|
|
45
|
-
## AI 检查清单
|
|
46
|
-
|
|
47
|
-
生成代码前,AI 必须确认:
|
|
48
|
-
|
|
49
|
-
- [ ] 没有硬编码的 IP / 域名 / 端口
|
|
50
|
-
- [ ] 所有 API 路径在 `API_CONFIG` 中声明
|
|
51
|
-
- [ ] 环境变量都加了 `VITE_` 前缀
|
|
52
|
-
- [ ] 没有把 token / secret / 密码以明文形式写入代码
|
|
1
|
+
# 07 — 配置管理规范
|
|
2
|
+
|
|
3
|
+
> **强制度**:🔴 必遵。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 环境变量
|
|
8
|
+
|
|
9
|
+
- 统一存放 `envs/.env.{mode}` 文件
|
|
10
|
+
- 命名以 `VITE_` 开头(Vite 暴露给客户端的前缀)
|
|
11
|
+
- 通过 `import.meta.env.VITE_XXX` 读取
|
|
12
|
+
- ❌ 不硬编码环境相关值
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
// ✅ 正确
|
|
16
|
+
const apiBase = import.meta.env.VITE_API_URL;
|
|
17
|
+
|
|
18
|
+
// ❌ 错误
|
|
19
|
+
const apiBase = "http://10.0.0.5:8080/api";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## API 地址
|
|
23
|
+
|
|
24
|
+
- ✅ 通过 `import.meta.env.VITE_API_URL` 等环境变量获取
|
|
25
|
+
- ❌ 不在代码中硬编码 `http://` / `https://` 地址
|
|
26
|
+
|
|
27
|
+
## 接口路径
|
|
28
|
+
|
|
29
|
+
- ✅ 集中在 `data.ts` 的 `API_CONFIG` 对象中声明(`as const`)
|
|
30
|
+
- ❌ 不散落在模板字符串、方法内部
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
export const API_CONFIG = {
|
|
34
|
+
list: "/mmwr/customer/list",
|
|
35
|
+
save: "/mmwr/customer/save",
|
|
36
|
+
remove: "/mmwr/customer/remove",
|
|
37
|
+
} as const;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 敏感信息
|
|
41
|
+
|
|
42
|
+
- ❌ 不提交到仓库(已纳入 `.gitignore`)
|
|
43
|
+
- ✅ 团队共享走内部文档或专用密钥服务
|
|
44
|
+
|
|
45
|
+
## AI 检查清单
|
|
46
|
+
|
|
47
|
+
生成代码前,AI 必须确认:
|
|
48
|
+
|
|
49
|
+
- [ ] 没有硬编码的 IP / 域名 / 端口
|
|
50
|
+
- [ ] 所有 API 路径在 `API_CONFIG` 中声明
|
|
51
|
+
- [ ] 环境变量都加了 `VITE_` 前缀
|
|
52
|
+
- [ ] 没有把 token / secret / 密码以明文形式写入代码
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
# 08 — Git 分支 & 提交规范
|
|
2
|
-
|
|
3
|
-
> **强制度**:🔴 必遵。
|
|
4
|
-
> 本项目强制使用 `@robot-admin/git-standards`(commitlint + cz-customizable + husky)。
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## 分支命名
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
feat/xxx 新功能
|
|
12
|
-
fix/xxx Bug 修复
|
|
13
|
-
refactor/xxx 重构
|
|
14
|
-
docs/xxx 文档更新
|
|
15
|
-
chore/xxx 构建/工具变更
|
|
16
|
-
perf/xxx 性能优化
|
|
17
|
-
test/xxx 测试相关
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## 提交方式(强制)
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
git add .
|
|
24
|
-
git cz # 交互式选择 type + scope + 描述
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
❌ **禁止**:`git commit -m "xxx"` 直接提交(绕过规范校验)
|
|
28
|
-
|
|
29
|
-
## 提交类型(type)枚举
|
|
30
|
-
|
|
31
|
-
`feat` / `fix` / `perf` / `docs` / `style` / `refactor` / `test` / `chore` / `revert` / `build` / `deps` / `wip`
|
|
32
|
-
|
|
33
|
-
## scope 强制要求
|
|
34
|
-
|
|
35
|
-
提交时必须填写影响范围,格式:`type(scope): 中文描述`
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
feat(mmwr-customer): 新增客户档案页面
|
|
39
|
-
fix(domestic-trade): 修复订单状态切换闪烁
|
|
40
|
-
refactor(c_formModal): 重构表单回填逻辑
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## husky 钩子未生效时
|
|
44
|
-
|
|
45
|
-
1. 检查 `@robot-admin/git-standards` 是否已执行 `init`
|
|
46
|
-
2. 检查 `.husky/` 目录及 `pre-commit`、`commit-msg` 钩子文件
|
|
47
|
-
3. 联系 CHENY(工号 409322)
|
|
48
|
-
|
|
49
|
-
## AI 生成 commit message 参考
|
|
50
|
-
|
|
51
|
-
AI 在协助提交时,按以下格式输出建议:
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
feat(模块名): 中文描述
|
|
55
|
-
|
|
56
|
-
- 变更点 1
|
|
57
|
-
- 变更点 2
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
不主动执行 `git commit`,由开发者通过 `git cz` 交互式确认。
|
|
1
|
+
# 08 — Git 分支 & 提交规范
|
|
2
|
+
|
|
3
|
+
> **强制度**:🔴 必遵。
|
|
4
|
+
> 本项目强制使用 `@robot-admin/git-standards`(commitlint + cz-customizable + husky)。
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 分支命名
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
feat/xxx 新功能
|
|
12
|
+
fix/xxx Bug 修复
|
|
13
|
+
refactor/xxx 重构
|
|
14
|
+
docs/xxx 文档更新
|
|
15
|
+
chore/xxx 构建/工具变更
|
|
16
|
+
perf/xxx 性能优化
|
|
17
|
+
test/xxx 测试相关
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 提交方式(强制)
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
git add .
|
|
24
|
+
git cz # 交互式选择 type + scope + 描述
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
❌ **禁止**:`git commit -m "xxx"` 直接提交(绕过规范校验)
|
|
28
|
+
|
|
29
|
+
## 提交类型(type)枚举
|
|
30
|
+
|
|
31
|
+
`feat` / `fix` / `perf` / `docs` / `style` / `refactor` / `test` / `chore` / `revert` / `build` / `deps` / `wip`
|
|
32
|
+
|
|
33
|
+
## scope 强制要求
|
|
34
|
+
|
|
35
|
+
提交时必须填写影响范围,格式:`type(scope): 中文描述`
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
feat(mmwr-customer): 新增客户档案页面
|
|
39
|
+
fix(domestic-trade): 修复订单状态切换闪烁
|
|
40
|
+
refactor(c_formModal): 重构表单回填逻辑
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## husky 钩子未生效时
|
|
44
|
+
|
|
45
|
+
1. 检查 `@robot-admin/git-standards` 是否已执行 `init`
|
|
46
|
+
2. 检查 `.husky/` 目录及 `pre-commit`、`commit-msg` 钩子文件
|
|
47
|
+
3. 联系 CHENY(工号 409322)
|
|
48
|
+
|
|
49
|
+
## AI 生成 commit message 参考
|
|
50
|
+
|
|
51
|
+
AI 在协助提交时,按以下格式输出建议:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
feat(模块名): 中文描述
|
|
55
|
+
|
|
56
|
+
- 变更点 1
|
|
57
|
+
- 变更点 2
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
不主动执行 `git commit`,由开发者通过 `git cz` 交互式确认。
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
# 09 — TypeScript 类型规范
|
|
2
|
-
|
|
3
|
-
> **强制度**:🟡 建议。
|
|
4
|
-
> 项目使用 `strict: false` 宽松模式起步。
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## 类型定义优先级
|
|
9
|
-
|
|
10
|
-
- **`interface`**:可扩展的对象类型
|
|
11
|
-
- **`type`**:联合类型 / 工具类型 / 字面量类型
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
// ✅ interface 用于对象
|
|
15
|
-
interface User {
|
|
16
|
-
id: string;
|
|
17
|
-
name: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// ✅ type 用于联合 / 工具类型
|
|
21
|
-
type Status = "pending" | "active" | "closed";
|
|
22
|
-
type PartialUser = Partial<User>;
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## any 使用约束
|
|
26
|
-
|
|
27
|
-
❌ 禁止滥用 `any`。`as any` 仅允许出现在以下场景:
|
|
28
|
-
|
|
29
|
-
1. 对接外部 SDK 返回值的边界处
|
|
30
|
-
2. `AbstractPageQueryHook.create()` 的返回值接收(框架限制)
|
|
31
|
-
3. 确实无法确定类型时,加注释 `// TODO: 待补充类型`
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
// ✅ 允许(框架限制)
|
|
35
|
-
return Page.create() as any
|
|
36
|
-
|
|
37
|
-
// ✅ 允许(外部边界,加注释)
|
|
38
|
-
const sdkResult = thirdPartySdk.call() as any // TODO(cheny): SDK 1.5 后补充类型
|
|
39
|
-
|
|
40
|
-
// ❌ 禁止(懒省事)
|
|
41
|
-
function handleClick(row: any) { ... }
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## 类型导入
|
|
45
|
-
|
|
46
|
-
- 业务类型统一从 `@/types/page` 桶文件引入
|
|
47
|
-
- ❌ 不重复定义同名类型
|
|
48
|
-
- ✅ 复杂类型在 `@/types/` 下分文件管理
|
|
49
|
-
|
|
50
|
-
## 字段类型
|
|
51
|
-
|
|
52
|
-
- 业务字段优先用 `string` / `number` / `boolean`
|
|
53
|
-
- ❌ 不默认用 `any`
|
|
54
|
-
- ⚠️ 可选字段用 `?`,可空字段用 `| null`
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
interface Customer {
|
|
58
|
-
id: string;
|
|
59
|
-
name: string;
|
|
60
|
-
remark?: string; // 可选
|
|
61
|
-
closedAt: string | null; // 可空(后端明确返回 null)
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## 与 @robot-admin/git-standards 兼容
|
|
66
|
-
|
|
67
|
-
| 项目状态 | 处理 |
|
|
68
|
-
| -------------------- | ------------------------------------------ |
|
|
69
|
-
| 已有 `tsconfig.json` | ✅ 直接安装 git-standards,零冲突 |
|
|
70
|
-
| 无 TS 环境 | 先 `tsc --init` 初始化,再装 git-standards |
|
|
71
|
-
| ESLint TS 规则 | `warn` 级别,不阻断提交,仅作质量提示 |
|
|
1
|
+
# 09 — TypeScript 类型规范
|
|
2
|
+
|
|
3
|
+
> **强制度**:🟡 建议。
|
|
4
|
+
> 项目使用 `strict: false` 宽松模式起步。
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 类型定义优先级
|
|
9
|
+
|
|
10
|
+
- **`interface`**:可扩展的对象类型
|
|
11
|
+
- **`type`**:联合类型 / 工具类型 / 字面量类型
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// ✅ interface 用于对象
|
|
15
|
+
interface User {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ✅ type 用于联合 / 工具类型
|
|
21
|
+
type Status = "pending" | "active" | "closed";
|
|
22
|
+
type PartialUser = Partial<User>;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## any 使用约束
|
|
26
|
+
|
|
27
|
+
❌ 禁止滥用 `any`。`as any` 仅允许出现在以下场景:
|
|
28
|
+
|
|
29
|
+
1. 对接外部 SDK 返回值的边界处
|
|
30
|
+
2. `AbstractPageQueryHook.create()` 的返回值接收(框架限制)
|
|
31
|
+
3. 确实无法确定类型时,加注释 `// TODO: 待补充类型`
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// ✅ 允许(框架限制)
|
|
35
|
+
return Page.create() as any
|
|
36
|
+
|
|
37
|
+
// ✅ 允许(外部边界,加注释)
|
|
38
|
+
const sdkResult = thirdPartySdk.call() as any // TODO(cheny): SDK 1.5 后补充类型
|
|
39
|
+
|
|
40
|
+
// ❌ 禁止(懒省事)
|
|
41
|
+
function handleClick(row: any) { ... }
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 类型导入
|
|
45
|
+
|
|
46
|
+
- 业务类型统一从 `@/types/page` 桶文件引入
|
|
47
|
+
- ❌ 不重复定义同名类型
|
|
48
|
+
- ✅ 复杂类型在 `@/types/` 下分文件管理
|
|
49
|
+
|
|
50
|
+
## 字段类型
|
|
51
|
+
|
|
52
|
+
- 业务字段优先用 `string` / `number` / `boolean`
|
|
53
|
+
- ❌ 不默认用 `any`
|
|
54
|
+
- ⚠️ 可选字段用 `?`,可空字段用 `| null`
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
interface Customer {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
remark?: string; // 可选
|
|
61
|
+
closedAt: string | null; // 可空(后端明确返回 null)
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 与 @robot-admin/git-standards 兼容
|
|
66
|
+
|
|
67
|
+
| 项目状态 | 处理 |
|
|
68
|
+
| -------------------- | ------------------------------------------ |
|
|
69
|
+
| 已有 `tsconfig.json` | ✅ 直接安装 git-standards,零冲突 |
|
|
70
|
+
| 无 TS 环境 | 先 `tsc --init` 初始化,再装 git-standards |
|
|
71
|
+
| ESLint TS 规则 | `warn` 级别,不阻断提交,仅作质量提示 |
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
# 10 — Pinia 状态管理规范
|
|
2
|
-
|
|
3
|
-
> **强制度**:🔴 必遵。
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 何时用 Store
|
|
8
|
-
|
|
9
|
-
- ✅ 跨页面共享:用户信息、权限、全局配置、主题
|
|
10
|
-
- ✅ 需要持久化到 `localStorage` 的状态
|
|
11
|
-
- ✅ 多个不相邻组件共享的会话级状态
|
|
12
|
-
|
|
13
|
-
## 何时不用 Store(保留页面级 ref)
|
|
14
|
-
|
|
15
|
-
- ❌ 当前页的查询参数、列表数据、分页、弹窗状态
|
|
16
|
-
- ❌ data.ts 内部的所有状态(默认页面级,不提升到 Store)
|
|
17
|
-
|
|
18
|
-
## 强制约束
|
|
19
|
-
|
|
20
|
-
❌ **禁止**:在 `data.ts` 里 `import` Store
|
|
21
|
-
|
|
22
|
-
> 理由:data.ts 是**页面数据契约**,应保持职责单一,不依赖全局状态。
|
|
23
|
-
> 跨页面共享数据通过 props / 路由参数 / 组件层包装传入,不直接耦合 Store。
|
|
24
|
-
|
|
25
|
-
## Store 文件结构
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
src/stores/
|
|
29
|
-
└── {domain}/
|
|
30
|
-
└── index.ts 每个领域独立目录,避免单文件膨胀
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Store 命名
|
|
34
|
-
|
|
35
|
-
- `useXxxStore` 标准命名
|
|
36
|
-
- 若项目已统一 `s_` 前缀(如 `s_userStore`),全项目保持一致
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
// src/stores/user/index.ts
|
|
40
|
-
export const useUserStore = defineStore("user", () => {
|
|
41
|
-
const userInfo = ref<User | null>(null);
|
|
42
|
-
function setUser(u: User) {
|
|
43
|
-
userInfo.value = u;
|
|
44
|
-
}
|
|
45
|
-
return { userInfo, setUser };
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## 持久化
|
|
50
|
-
|
|
51
|
-
如需持久化,推荐 `pinia-plugin-persistedstate`:
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
defineStore('user', () => { ... }, {
|
|
55
|
-
persist: { storage: localStorage, paths: ['userInfo'] }
|
|
56
|
-
})
|
|
57
|
-
```
|
|
1
|
+
# 10 — Pinia 状态管理规范
|
|
2
|
+
|
|
3
|
+
> **强制度**:🔴 必遵。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 何时用 Store
|
|
8
|
+
|
|
9
|
+
- ✅ 跨页面共享:用户信息、权限、全局配置、主题
|
|
10
|
+
- ✅ 需要持久化到 `localStorage` 的状态
|
|
11
|
+
- ✅ 多个不相邻组件共享的会话级状态
|
|
12
|
+
|
|
13
|
+
## 何时不用 Store(保留页面级 ref)
|
|
14
|
+
|
|
15
|
+
- ❌ 当前页的查询参数、列表数据、分页、弹窗状态
|
|
16
|
+
- ❌ data.ts 内部的所有状态(默认页面级,不提升到 Store)
|
|
17
|
+
|
|
18
|
+
## 强制约束
|
|
19
|
+
|
|
20
|
+
❌ **禁止**:在 `data.ts` 里 `import` Store
|
|
21
|
+
|
|
22
|
+
> 理由:data.ts 是**页面数据契约**,应保持职责单一,不依赖全局状态。
|
|
23
|
+
> 跨页面共享数据通过 props / 路由参数 / 组件层包装传入,不直接耦合 Store。
|
|
24
|
+
|
|
25
|
+
## Store 文件结构
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
src/stores/
|
|
29
|
+
└── {domain}/
|
|
30
|
+
└── index.ts 每个领域独立目录,避免单文件膨胀
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Store 命名
|
|
34
|
+
|
|
35
|
+
- `useXxxStore` 标准命名
|
|
36
|
+
- 若项目已统一 `s_` 前缀(如 `s_userStore`),全项目保持一致
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
// src/stores/user/index.ts
|
|
40
|
+
export const useUserStore = defineStore("user", () => {
|
|
41
|
+
const userInfo = ref<User | null>(null);
|
|
42
|
+
function setUser(u: User) {
|
|
43
|
+
userInfo.value = u;
|
|
44
|
+
}
|
|
45
|
+
return { userInfo, setUser };
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 持久化
|
|
50
|
+
|
|
51
|
+
如需持久化,推荐 `pinia-plugin-persistedstate`:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
defineStore('user', () => { ... }, {
|
|
55
|
+
persist: { storage: localStorage, paths: ['userInfo'] }
|
|
56
|
+
})
|
|
57
|
+
```
|