@xfe-repo/web-components 1.6.2 → 1.7.0
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/package.json +4 -3
- package/skills/GUIDE.md +78 -0
- package/skills/SKILL.md +78 -0
- package/skills/TEMPLATE.md +170 -0
- package/skills/references/ApiService.md +136 -0
- package/skills/references/CInput.md +196 -0
- package/skills/references/CTable.md +274 -0
- package/skills/references/CVideo.md +94 -0
- package/skills/references/Clock.md +53 -0
- package/skills/references/ConfigProvider.md +198 -0
- package/skills/references/Countdown.md +109 -0
- package/skills/references/Counter.md +75 -0
- package/skills/references/Currency.md +112 -0
- package/skills/references/EffectAddressCascade.md +110 -0
- package/skills/references/EffectBrandSelect.md +231 -0
- package/skills/references/EffectBrandTransfer.md +143 -0
- package/skills/references/EffectCategoryCascade.md +228 -0
- package/skills/references/EffectFileUpload.md +349 -0
- package/skills/references/EffectLabelSelect.md +222 -0
- package/skills/references/EffectMerchantSelect.md +183 -0
- package/skills/references/EffectReservoirSelect.md +178 -0
- package/skills/references/EffectScopeSelect.md +220 -0
- package/skills/references/EffectSeriesSelect.md +205 -0
- package/skills/references/EffectSeriesSelectV2.md +154 -0
- package/skills/references/EffectSkuRecognize.md +149 -0
- package/skills/references/EffectSkuSelect.md +251 -0
- package/skills/references/EffectSkuTable.md +184 -0
- package/skills/references/EffectSpuSelect.md +189 -0
- package/skills/references/EffectStaffSelect.md +150 -0
- package/skills/references/EffectWarehouseSelect.md +183 -0
- package/skills/references/EffectWithFilePanel.md +205 -0
- package/skills/references/FileUpload.md +126 -0
- package/skills/references/Iconfont.md +31 -0
- package/skills/references/Loading.md +68 -0
- package/skills/references/MultiWindow.md +145 -0
- package/skills/references/OSSImage.md +230 -0
- package/skills/references/PrivacyField.md +90 -0
- package/skills/references/QRCode.md +148 -0
- package/skills/references/RichTextEditor.md +119 -0
- package/skills/references/SearchForm.md +270 -0
- package/skills/references/SearchList.md +128 -0
- package/skills/references/WithModal.md +328 -0
- package/skills/references/WithPanel.md +307 -0
- package/skills/references/commonFn.md +254 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/web-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"module": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"sideEffects": [
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"./dist/index.css": "./dist/index.css"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"skills"
|
|
24
25
|
],
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@dnd-kit/core": "^6.3.1",
|
|
@@ -61,8 +62,8 @@
|
|
|
61
62
|
"react-dom": "18.2.0",
|
|
62
63
|
"react-use": "^17.5.1",
|
|
63
64
|
"swr": "^2.2.5",
|
|
64
|
-
"@xfe-repo/web-router": "1.6.0",
|
|
65
65
|
"@xfe-repo/web-micro": "1.6.0",
|
|
66
|
+
"@xfe-repo/web-router": "1.6.0",
|
|
66
67
|
"@xfe-repo/web-utils": "1.6.0",
|
|
67
68
|
"@xfe-repo/web-service": "1.6.0"
|
|
68
69
|
},
|
package/skills/GUIDE.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# 组件 Skill Reference 编写指南
|
|
2
|
+
|
|
3
|
+
> 配合 TEMPLATE.md 使用。本文件标注每个组件需要包含模板中的哪些**条件章节**。
|
|
4
|
+
> 所有组件都需要:导入、基本用法、Props。以下仅标注额外需要的章节。
|
|
5
|
+
|
|
6
|
+
## 条件章节速查矩阵
|
|
7
|
+
|
|
8
|
+
| 组件 | 进阶用法 | 导出类型 | API数据源 | 依赖Props | Ref方法 | 子组件 | 常见陷阱 | 相关组件 |
|
|
9
|
+
| ------------------------ | ----------------------- | --------------------------------------- | ------------------------- | ---------------------- | ----------------- | ---------------------------- | ----------- | ------------------- |
|
|
10
|
+
| **Effect 副作用选择器** | | | | | | | | |
|
|
11
|
+
| EffectAddressCascade | | ✅ SelectItem | ✅ commonAddressList | | | | ✅ | |
|
|
12
|
+
| EffectBrandSelect | ✅ 多选/分类过滤 | ✅ BrandValueType, BrandOptions | ✅ useBrandOptions | ✅ categoryId | | | ✅ | ✅ ScopeSelect |
|
|
13
|
+
| EffectBrandTransfer | | ✅ TransferValueType | ✅ useBrandOptions | ✅ categoryId | | | ✅ | |
|
|
14
|
+
| EffectCategoryCascade | ✅ 多选/获取原始数据 | ✅ TreeValueType 等6个 | ✅ useCategoryTree | | | | ✅ | ✅ 级联起点 |
|
|
15
|
+
| EffectFileUpload | ✅ 自动上传/手动上传 | ✅ SimpleFileData, UploadResult | ✅ uploadUploadFile | | ✅ handleUpload等 | ✅ Group | ✅ | ✅ WithFilePanel |
|
|
16
|
+
| EffectLabelSelect | ✅ 自定义数据源 | ✅ SelectOptionItem, LabelDic | ✅ 可自定义 | | | | ✅ | |
|
|
17
|
+
| EffectMerchantSelect | ✅ 搜索源切换 | ✅ MerchantOptions | ✅ useMerchantOptions | | | | ✅ | |
|
|
18
|
+
| EffectReservoirSelect | | | ✅ reservoirList | ✅ warehouseId | | | ✅ | ✅ WarehouseSelect |
|
|
19
|
+
| EffectScopeSelect | ✅ scopeLevel控制 | ✅ ScopeSelectValueType, ScopeLevelEnum | | | | ✅ 内含5个Effect | ✅ | |
|
|
20
|
+
| EffectSeriesSelect | | | ✅ useSeriesOptions | ✅ categoryId, brandId | | | ✅ | ✅ 级联链 |
|
|
21
|
+
| EffectSeriesSelectV2 | | | ✅ seriesList | ✅ categoryId, brandId | | | ✅ | ✅ 级联链 |
|
|
22
|
+
| EffectSkuRecognize | | ✅ EffectSkuRecognizeProps | ✅ productImageSpuSkuList | ✅ image(必填) | | | ✅ | |
|
|
23
|
+
| EffectSkuSelect | | ✅ ValueType, ItemOption | ✅ useSkuOptions | ✅ categoryId~spuId | | | ✅ | ✅ 级联链 |
|
|
24
|
+
| EffectSkuTable | | ✅ EffectSkuTableProps | | | | ✅ 联动表格 | ✅ | |
|
|
25
|
+
| EffectSpuSelect | | | ✅ useSpuOptions | ✅ categoryId~seriesId | | | ✅ | ✅ 级联链 |
|
|
26
|
+
| EffectStaffSelect | | | ✅ businessList | ✅ deptId(可选) | | | | |
|
|
27
|
+
| EffectWarehouseSelect | | ✅ WarehouseOption | ✅ useStoreOptions | | | | ✅ | ✅ ReservoirSelect |
|
|
28
|
+
| EffectWithFilePanel | | | | | | ✅ 包装FileUpload | ✅ | ✅ FileUpload |
|
|
29
|
+
| **容器/高阶组件** | | | | | | | | |
|
|
30
|
+
| WithModal | ✅ 异步保存/外控visible | ✅ WithModalProps | | | | | ✅ | |
|
|
31
|
+
| WithPanel | ✅ 异步保存/外控visible | ✅ WithPanelProps | | | | | ✅ | |
|
|
32
|
+
| MultiWindow | ✅ 缓存控制 | ✅ PagePathType等4个 | | | ✅ contentRef | ✅ Contents | ✅ | |
|
|
33
|
+
| **增强 Ant Design 组件** | | | | | | | | |
|
|
34
|
+
| CInput | | ✅ CInputProps等3个 | | | ✅ InputRef | ✅ .TextArea/.Search/.Group | ✅ autoTrim | |
|
|
35
|
+
| CTable | ✅ 拖拽排序 | ✅ CTableProps, TableDragEndEvent | | | | ✅ .Column/.DragHandle | ✅ | |
|
|
36
|
+
| OSSImage | ✅ 预览组 | ✅ OSSImageProps | | | | ✅ .PreviewGroup/.ModalGroup | ✅ | |
|
|
37
|
+
| **展示/功能组件** | | | | | | | | |
|
|
38
|
+
| Clock | | ✅ ClockProps + formatClock | | | | | | |
|
|
39
|
+
| Countdown | ✅ date/second模式 | ✅ CountdownProps + formatDate | | | | | | |
|
|
40
|
+
| Counter | | ✅ CounterProps | | | | | | |
|
|
41
|
+
| Currency | | ✅ CurrencyUnit, CurrencyProps | | | | | ✅ unit换算 | |
|
|
42
|
+
| FileUpload | ✅ 多文件 | ✅ ModifyFileData | | | | | | ✅ EffectFileUpload |
|
|
43
|
+
| Iconfont | | | | | | | | |
|
|
44
|
+
| Loading | | | | | | | | |
|
|
45
|
+
| PrivacyField | | | | | | | ✅ | |
|
|
46
|
+
| QRCode | ✅ SSE轮询 | ✅ QRCodeStatus + useSseQrcode | | | | | | |
|
|
47
|
+
| RichTextEditor | ✅ 图片插入 | ✅ RichTextEditorProps | | | | | ✅ | ✅ ConfigProvider |
|
|
48
|
+
| SearchForm | | ✅ SearchFormProps | | | | ✅ Content | | |
|
|
49
|
+
| SearchList | | ✅ SearchListProps | | | | | | |
|
|
50
|
+
| **配置/上下文** | | | | | | | | |
|
|
51
|
+
| ConfigProvider | ✅ API覆盖/主题 | ✅ IApiPayload, IConfigContext | | | | | ✅ | ✅ 全局依赖 |
|
|
52
|
+
| **工具模块** | | | | | | | | |
|
|
53
|
+
| ApiService | ✅ 各方法签名 | ✅ IApiService(全量) | | | | | | ✅ ConfigProvider |
|
|
54
|
+
| commonFn | ✅ 各函数用法 | ✅ 函数签名+常量 | | | | | | |
|
|
55
|
+
|
|
56
|
+
## 维护优先级
|
|
57
|
+
|
|
58
|
+
> 全部 40 个组件文档已完成编写,并经过 platform + dashboard + erp 三项目业务用法审计。
|
|
59
|
+
> 以下优先级适用于后续组件新增或文档维护场景。
|
|
60
|
+
|
|
61
|
+
### 高优先级维护(业务使用频率最高、Agent 出错影响最大)
|
|
62
|
+
|
|
63
|
+
1. **CInput** (253 次) — 最高频组件,搜索栏 + Form.Item 是核心模式
|
|
64
|
+
2. **OSSImage** (93 次) — Table 列渲染 + 空值防御是关键
|
|
65
|
+
3. **WithModal** (82 次) — Form 三件套 + With{Action}Modal 封装范式
|
|
66
|
+
4. **SearchList** (69 次) — dashboard 核心,noStyle + div 结构约定
|
|
67
|
+
5. **CTable** (52 次) — TypeTable 别名 + rowSelection + getCTable 反模式
|
|
68
|
+
6. **EffectCategoryCascade** (40 次) — 级联链起点,changeOnSelect 几乎必传
|
|
69
|
+
7. **EffectBrandSelect** (39 次) — key={categoryId} 强制刷新是关键陷阱
|
|
70
|
+
8. **EffectFileUpload** (33 次) — Form.Item 集成 + handleUpload Ref + Promise.all
|
|
71
|
+
|
|
72
|
+
### 中优先级维护
|
|
73
|
+
|
|
74
|
+
9-22. 其余使用频率 3-25 次的组件,详见审计报告
|
|
75
|
+
|
|
76
|
+
### 低优先级
|
|
77
|
+
|
|
78
|
+
未在业务中使用的组件:Clock、Counter、FileUpload、Iconfont、QRCode 等
|
package/skills/SKILL.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: xfe-web-components
|
|
3
|
+
description: >-
|
|
4
|
+
@xfe-repo/web-components 组件库的完整使用指南。包含 40 个 React 组件的 Props 类型定义、
|
|
5
|
+
代码示例、常见陷阱和组件间联动关系。当使用 EffectBrandSelect、EffectCategoryCascade、
|
|
6
|
+
WithModal、EffectFileUpload、EffectScopeSelect、CTable、SearchForm、OSSImage、
|
|
7
|
+
CInput、SearchList、Currency、Loading 等组件时自动激活。
|
|
8
|
+
触发关键词:xfe-repo、web-components、Effect 组件、品牌选择、分类级联、文件上传、弹窗、
|
|
9
|
+
侧边栏、SKU 选择、商户选择、Form.Item、搜索表单、表格。
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# @xfe-repo/web-components 使用指南
|
|
13
|
+
|
|
14
|
+
本 Skill 提供 `@xfe-repo/web-components` 组件库的完整 API 参考文档。
|
|
15
|
+
|
|
16
|
+
## 通用规范
|
|
17
|
+
|
|
18
|
+
- 所有组件从 `@xfe-repo/web-components` 统一导入
|
|
19
|
+
- 类型从同一包导入:`import type { XxxProps } from '@xfe-repo/web-components'`
|
|
20
|
+
- 所有 Effect 组件(`Effect` 前缀)内部会发起 API 请求,依赖 `ConfigProvider` 提供的 `apiService`
|
|
21
|
+
- 业务项目通常已在入口处配置了 `ConfigProvider`,无需重复包裹
|
|
22
|
+
- **Form.Item 集成是绝对主流**:几乎所有组件在业务中都通过 `<Form.Item name="xxx">` 使用,value/onChange 由 Form 自动注入,无需手动管理
|
|
23
|
+
- Effect 选择器级联依赖变化时,使用 `key={依赖值}` 强制重新挂载刷新数据
|
|
24
|
+
|
|
25
|
+
## 组件索引
|
|
26
|
+
|
|
27
|
+
按需查阅 `references/` 中的组件文档:
|
|
28
|
+
|
|
29
|
+
| 组件 | 文档 | 说明 |
|
|
30
|
+
| --------------------- | ------------------------------------- | -------------------------------- |
|
|
31
|
+
| ConfigProvider | `references/ConfigProvider.md` | 全局配置,所有 Effect 组件的依赖 |
|
|
32
|
+
| EffectBrandSelect | `references/EffectBrandSelect.md` | 品牌下拉选择器 |
|
|
33
|
+
| EffectCategoryCascade | `references/EffectCategoryCascade.md` | 分类级联选择器 |
|
|
34
|
+
| EffectFileUpload | `references/EffectFileUpload.md` | 文件上传(支持 Ref) |
|
|
35
|
+
| WithModal | `references/WithModal.md` | 高阶弹窗组件 |
|
|
36
|
+
| EffectScopeSelect | `references/EffectScopeSelect.md` | 商品范围选择(复合组件) |
|
|
37
|
+
| EffectAddressCascade | `references/EffectAddressCascade.md` | 地址级联选择 |
|
|
38
|
+
| EffectBrandTransfer | `references/EffectBrandTransfer.md` | 品牌穿梭框 |
|
|
39
|
+
| EffectLabelSelect | `references/EffectLabelSelect.md` | 标签维度双选择器 |
|
|
40
|
+
| EffectMerchantSelect | `references/EffectMerchantSelect.md` | 商户选择器 |
|
|
41
|
+
| EffectReservoirSelect | `references/EffectReservoirSelect.md` | 库区选择器 |
|
|
42
|
+
| EffectSeriesSelect | `references/EffectSeriesSelect.md` | 系列选择器 |
|
|
43
|
+
| EffectSeriesSelectV2 | `references/EffectSeriesSelectV2.md` | 系列多选器 V2 |
|
|
44
|
+
| EffectSkuRecognize | `references/EffectSkuRecognize.md` | SKU 图片识别 |
|
|
45
|
+
| EffectSkuSelect | `references/EffectSkuSelect.md` | SKU 选择器 |
|
|
46
|
+
| EffectSkuTable | `references/EffectSkuTable.md` | SKU 联动表格 |
|
|
47
|
+
| EffectSpuSelect | `references/EffectSpuSelect.md` | SPU 选择器 |
|
|
48
|
+
| EffectStaffSelect | `references/EffectStaffSelect.md` | 员工选择器 |
|
|
49
|
+
| EffectWarehouseSelect | `references/EffectWarehouseSelect.md` | 仓库选择器 |
|
|
50
|
+
| EffectWithFilePanel | `references/EffectWithFilePanel.md` | 文件上传面板 |
|
|
51
|
+
| WithPanel | `references/WithPanel.md` | 高阶侧边栏组件 |
|
|
52
|
+
| CInput | `references/CInput.md` | 增强输入框(自动 trim) |
|
|
53
|
+
| CTable | `references/CTable.md` | 拖拽排序表格 |
|
|
54
|
+
| CVideo | `references/CVideo.md` | 视频播放器 |
|
|
55
|
+
| OSSImage | `references/OSSImage.md` | OSS 图片组件 |
|
|
56
|
+
| MultiWindow | `references/MultiWindow.md` | 多窗口 Tab 容器 |
|
|
57
|
+
| SearchForm | `references/SearchForm.md` | 搜索表单 |
|
|
58
|
+
| SearchList | `references/SearchList.md` | 搜索列表容器 |
|
|
59
|
+
| FileUpload | `references/FileUpload.md` | 基础文件上传 |
|
|
60
|
+
| RichTextEditor | `references/RichTextEditor.md` | 富文本编辑器 |
|
|
61
|
+
| QRCode | `references/QRCode.md` | 二维码组件 |
|
|
62
|
+
| Clock | `references/Clock.md` | 实时时钟 |
|
|
63
|
+
| Countdown | `references/Countdown.md` | 倒计时 |
|
|
64
|
+
| Counter | `references/Counter.md` | 计数器 |
|
|
65
|
+
| Currency | `references/Currency.md` | 金额展示 |
|
|
66
|
+
| Iconfont | `references/Iconfont.md` | 自定义图标 |
|
|
67
|
+
| Loading | `references/Loading.md` | 加载状态 |
|
|
68
|
+
| PrivacyField | `references/PrivacyField.md` | 隐私脱敏字段 |
|
|
69
|
+
| commonFn | `references/commonFn.md` | 通用工具函数 |
|
|
70
|
+
| ApiService | `references/ApiService.md` | API 服务接口定义 |
|
|
71
|
+
|
|
72
|
+
## 常见陷阱
|
|
73
|
+
|
|
74
|
+
- ❌ 直接在未包裹 `ConfigProvider` 的环境中使用 Effect 组件 — 会因缺少 `apiService` 报错
|
|
75
|
+
- ❌ 给 Effect 选择器组件传 `options` prop — 数据由组件内部 API 获取,不接受外部 options
|
|
76
|
+
- ❌ `WithModal` 的 `onSave` 返回 `false` 不能阻止关闭 — 需要返回 `Promise<false>` 或显式 `return false`
|
|
77
|
+
- ❌ `EffectFileUpload` 不调用 `ref.current.handleUpload()` 就提交表单 — 文件不会真正上传
|
|
78
|
+
- ✅ Effect 组件的级联依赖链:分类 → 品牌 → 系列 → SPU → SKU,上游变化时下游自动重置
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# 组件 Skill Reference 模板
|
|
2
|
+
|
|
3
|
+
> 本文件是编写组件 reference 文档的统一模板。
|
|
4
|
+
> 编写时请删除所有 `<!-- ... -->` 注释和不适用的章节。
|
|
5
|
+
> 文件命名:`references/{ComponentName}.md`
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# {ComponentName}
|
|
10
|
+
|
|
11
|
+
> {一句话功能描述,说明组件做什么、解决什么问题}
|
|
12
|
+
|
|
13
|
+
## 导入
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { ComponentName } from '@xfe-repo/web-components'
|
|
17
|
+
// 如有额外导出的类型
|
|
18
|
+
import type { ComponentNameProps, OtherType } from '@xfe-repo/web-components'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 基本用法
|
|
22
|
+
|
|
23
|
+
<!-- 最简可运行示例,覆盖最常见场景。绝大多数组件在业务中通过 Form.Item 使用 -->
|
|
24
|
+
|
|
25
|
+
### Form.Item 集成(最常用)
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
<Form.Item name="fieldName" label="字段名" rules={[{ required: true }]}>
|
|
29
|
+
<ComponentName placeholder="请选择" />
|
|
30
|
+
</Form.Item>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 独立受控模式
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
<ComponentName value={value} onChange={(val) => setValue(val)} />
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 进阶用法
|
|
40
|
+
|
|
41
|
+
<!-- 如组件有多个重要使用场景,按场景分小节。不重要的场景可省略 -->
|
|
42
|
+
|
|
43
|
+
### {场景名称}
|
|
44
|
+
|
|
45
|
+
<!-- 说明为什么需要这种用法,1-2 句话 -->
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
// 代码示例
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Props
|
|
52
|
+
|
|
53
|
+
<!-- 完整 Props 类型定义,从源码复制 -->
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
interface ComponentNameProps {
|
|
57
|
+
// ...
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
<!-- Props 表格,只列出开发者需要关注的属性。继承自 Antd 的通用属性(如 className、style、disabled)可省略或简述 -->
|
|
62
|
+
|
|
63
|
+
| 属性 | 类型 | 必填 | 默认值 | 说明 |
|
|
64
|
+
| -------- | ------------------------- | ---- | ------ | ---------- |
|
|
65
|
+
| value | `string` | 否 | - | 受控值 |
|
|
66
|
+
| onChange | `(value: string) => void` | 否 | - | 值变化回调 |
|
|
67
|
+
|
|
68
|
+
## 导出类型
|
|
69
|
+
|
|
70
|
+
<!-- 【条件章节】仅当组件导出了额外类型时包含 -->
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// 列出所有从该组件导出的类型
|
|
74
|
+
export type SomeType = {
|
|
75
|
+
/* ... */
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API 数据源
|
|
80
|
+
|
|
81
|
+
<!-- 【条件章节】仅 Effect 副作用组件需要 -->
|
|
82
|
+
<!-- 说明组件内部调用了哪个 API,数据从哪里来 -->
|
|
83
|
+
|
|
84
|
+
- **内部接口**:`apiService.{methodName}`
|
|
85
|
+
- **可覆盖**:通过 `<ConfigProvider apiService={{ methodName: customFn }}>` 替换默认实现
|
|
86
|
+
|
|
87
|
+
## 依赖 Props
|
|
88
|
+
|
|
89
|
+
<!-- 【条件章节】仅当组件的数据或行为依赖其他组件传入的 ID 时包含 -->
|
|
90
|
+
<!-- 典型场景:EffectSeriesSelect 依赖 categoryId + brandId -->
|
|
91
|
+
|
|
92
|
+
| 依赖属性 | 类型 | 来源 | 说明 |
|
|
93
|
+
| ---------- | -------- | ---------------------------- | ------------------ |
|
|
94
|
+
| categoryId | `number` | EffectCategoryCascade 的输出 | 不传则加载全部数据 |
|
|
95
|
+
| brandId | `number` | EffectBrandSelect 的输出 | 不传则不过滤品牌 |
|
|
96
|
+
|
|
97
|
+
### 联动示例
|
|
98
|
+
|
|
99
|
+
<!-- 展示多个组件如何配合使用,推荐使用 Form.useWatch -->
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
const categoryIds = Form.useWatch('categoryIds', form)
|
|
103
|
+
const categoryId = categoryIds?.at(-1)
|
|
104
|
+
const brandId = Form.useWatch('brandId', form)
|
|
105
|
+
|
|
106
|
+
<Form.Item name="categoryIds" label="分类">
|
|
107
|
+
<EffectCategoryCascade changeOnSelect />
|
|
108
|
+
</Form.Item>
|
|
109
|
+
<Form.Item name="brandId" label="品牌">
|
|
110
|
+
<EffectBrandSelect categoryId={categoryId} key={categoryId} />
|
|
111
|
+
</Form.Item>
|
|
112
|
+
<Form.Item name="seriesId" label="系列">
|
|
113
|
+
<EffectSeriesSelect categoryId={categoryId} brandId={brandId} key={`${categoryId}-${brandId}`} />
|
|
114
|
+
</Form.Item>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Ref 方法
|
|
118
|
+
|
|
119
|
+
<!-- 【条件章节】仅当组件通过 forwardRef + useImperativeHandle 暴露方法时包含 -->
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
interface ComponentNameRef {
|
|
123
|
+
someMethod: () => void
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 使用方式
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
const ref = useRef<ComponentNameRef>(null)
|
|
131
|
+
|
|
132
|
+
<ComponentName ref={ref} />
|
|
133
|
+
|
|
134
|
+
// 调用
|
|
135
|
+
ref.current?.someMethod()
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## 子组件
|
|
139
|
+
|
|
140
|
+
<!-- 【条件章节】仅复合组件包含(如 CInput.TextArea、OSSImage.PreviewGroup) -->
|
|
141
|
+
|
|
142
|
+
### ComponentName.SubComponent
|
|
143
|
+
|
|
144
|
+
> {子组件功能描述}
|
|
145
|
+
|
|
146
|
+
```tsx
|
|
147
|
+
<ComponentName.SubComponent prop1="value" />
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
| 属性 | 类型 | 说明 |
|
|
151
|
+
| ----- | -------- | ---- |
|
|
152
|
+
| prop1 | `string` | ... |
|
|
153
|
+
|
|
154
|
+
## 常见陷阱
|
|
155
|
+
|
|
156
|
+
<!-- 列出使用该组件容易犯的错误,格式统一为:❌ 错误 → ✅ 正确 -->
|
|
157
|
+
|
|
158
|
+
- ❌ `<ComponentName value="string" />` — value 类型是 number,不是 string
|
|
159
|
+
- ✅ `<ComponentName value={123} />`
|
|
160
|
+
|
|
161
|
+
## 相关组件
|
|
162
|
+
|
|
163
|
+
<!-- 【条件章节】仅当该组件常与库中其他组件搭配使用时包含 -->
|
|
164
|
+
<!-- 表格格式更利于 Agent 快速解析依赖关系 -->
|
|
165
|
+
|
|
166
|
+
| 场景 | 组件 | 说明 |
|
|
167
|
+
| ------------ | ----------------------- | ----------------------------------------- |
|
|
168
|
+
| 弹窗中使用 | `WithModal` | 用 handleElement 触发,在弹窗内渲染本组件 |
|
|
169
|
+
| API 数据覆盖 | `ConfigProvider` | 通过 apiService prop 替换默认 API 实现 |
|
|
170
|
+
| 级联上游 | `EffectCategoryCascade` | 提供 categoryId 作为本组件的过滤条件 |
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# ApiService
|
|
2
|
+
|
|
3
|
+
> API 服务接口定义和默认实现(saasApiService),定义了所有 Effect 组件内部调用的 BFF 接口方法。
|
|
4
|
+
|
|
5
|
+
## 导入
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { saasApiService } from '@xfe-repo/web-components'
|
|
9
|
+
import type { IApiService } from '@xfe-repo/web-components'
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 基本用法
|
|
13
|
+
|
|
14
|
+
`ApiService` 通常不直接使用,而是通过 `ConfigProvider` 的 `apiService` 属性注入,Effect 组件内部通过 `useRequestConfig` Hook 获取。
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { ConfigProvider } from '@xfe-repo/web-components'
|
|
18
|
+
|
|
19
|
+
// 使用默认的 saasApiService(默认行为,无需显式传入)
|
|
20
|
+
;<ConfigProvider apiPayload={payload}>
|
|
21
|
+
<App />
|
|
22
|
+
</ConfigProvider>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 进阶用法
|
|
26
|
+
|
|
27
|
+
### 自定义部分接口
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { ConfigProvider } from '@xfe-repo/web-components'
|
|
31
|
+
import type { IApiService } from '@xfe-repo/web-components'
|
|
32
|
+
|
|
33
|
+
const customService: Partial<IApiService> = {
|
|
34
|
+
brandComboBox: async (params, config) => {
|
|
35
|
+
return await myApi.getBrands(params)
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
<ConfigProvider apiService={customService} apiPayload={payload}>
|
|
40
|
+
<App />
|
|
41
|
+
</ConfigProvider>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 在组件中获取 API 服务
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { useRequestConfig } from '@xfe-repo/web-components'
|
|
48
|
+
|
|
49
|
+
function MyComponent() {
|
|
50
|
+
const { apiService, config } = useRequestConfig()
|
|
51
|
+
|
|
52
|
+
const fetchBrands = async () => {
|
|
53
|
+
const result = await apiService.brandComboBox({}, config)
|
|
54
|
+
console.log(result)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 接口定义
|
|
60
|
+
|
|
61
|
+
### IApiService
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
export interface IApiService {
|
|
65
|
+
// 商品相关
|
|
66
|
+
categoryListToTree: Request<InQueryCategoryListToTree, OutListToTreeCategoryDto> // 分类树
|
|
67
|
+
brandComboBox: Request<InQueryBrandComboBox, OutComboBoxBrandDto> // 品牌下拉
|
|
68
|
+
seriesComboBox: Request<InQuerySeriesComboBox, OutComboBoxSeriesDto> // 系列下拉
|
|
69
|
+
seriesList: Request<InQuerySeriesList, OutListSeriesDto> // 系列列表
|
|
70
|
+
skuFindOne: Request<InPathSkuFindOne, OutFindOneSkuDto> // SKU 详情
|
|
71
|
+
skuListV2: Request<InQuerySkuListV2, OutListSkuV2Dto> // SKU 列表
|
|
72
|
+
spuList: Request<InQuerySpuList, OutListSpuDto> // SPU 列表
|
|
73
|
+
productImageSpuSkuList: Request<InQueryProductImageSpuSkuList, OutListProductImageSpuSkuDto> // 商品图片列表
|
|
74
|
+
|
|
75
|
+
// 通用服务
|
|
76
|
+
uploadUploadFile: Request<InUploadFileDto, OutUploadFileDto> // 文件上传
|
|
77
|
+
uploadRemoteCreate: Request<InRemoteCreateDto, OutRemoteCreateDto> // 远程文件创建
|
|
78
|
+
commonAddressList: Request<InPathCommonAddressList, OutAddressListDto> // 地址列表
|
|
79
|
+
|
|
80
|
+
// 仓库相关
|
|
81
|
+
storeComboBox: Request<InPathStoreComboBox & InQueryStoreComboBox, OutComboBoxWarehouseStoreDto> // 仓库下拉
|
|
82
|
+
reservoirList: Request<InQueryReservoirList, OutListReservoirDto> // 库区列表
|
|
83
|
+
shelveList: Request<InQueryShelveList, OutShelveListV2Dto> // 货架列表
|
|
84
|
+
|
|
85
|
+
// 业务相关
|
|
86
|
+
merchantList: Request<InMerchantListBusDto, OutMerchantListBusDto> // 商户列表
|
|
87
|
+
businessList: Request<InQueryBusinessList, OutListBusDto> // 业务线列表
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### saasApiService
|
|
92
|
+
|
|
93
|
+
默认的 SaaS BFF 服务实现,包含所有接口方法:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
export const saasApiService: IApiService
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### useRequestConfig
|
|
100
|
+
|
|
101
|
+
内部 Hook,返回合并后的请求配置、API 载荷和 API 服务实例。
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
type OutUseRequestConfig = {
|
|
105
|
+
config: BFFRequestConfig // 合并后的请求配置(含 baseURL、headers、jwt 等)
|
|
106
|
+
apiPayload: Partial<IApiPayload>
|
|
107
|
+
apiService: IApiService
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const useRequestConfig: (config?: BFFRequestConfig) => OutUseRequestConfig
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
> `useRequestConfig` 必须在 `ConfigProvider` 内部使用,否则会抛出错误。
|
|
114
|
+
|
|
115
|
+
## 接口与 Effect 组件映射
|
|
116
|
+
|
|
117
|
+
| 接口方法 | 依赖的 Effect 组件 |
|
|
118
|
+
| ------------------------------- | -------------------------------------------- |
|
|
119
|
+
| `categoryListToTree` | `EffectCategoryCascade` |
|
|
120
|
+
| `brandComboBox` | `EffectBrandSelect`、`EffectBrandTransfer` |
|
|
121
|
+
| `seriesComboBox` / `seriesList` | `EffectSeriesSelect`、`EffectSeriesSelectV2` |
|
|
122
|
+
| `skuFindOne` / `skuListV2` | `EffectSkuSelect`、`EffectSkuTable` |
|
|
123
|
+
| `spuList` | `EffectSpuSelect` |
|
|
124
|
+
| `uploadUploadFile` | `EffectFileUpload`、`RichTextEditor` |
|
|
125
|
+
| `uploadRemoteCreate` | `FileUpload`(remote 模式) |
|
|
126
|
+
| `commonAddressList` | `EffectAddressCascade` |
|
|
127
|
+
| `storeComboBox` | `EffectWarehouseSelect` |
|
|
128
|
+
| `reservoirList` / `shelveList` | `EffectReservoirSelect` |
|
|
129
|
+
| `merchantList` | `EffectMerchantSelect` |
|
|
130
|
+
| `businessList` | `EffectScopeSelect` |
|
|
131
|
+
|
|
132
|
+
## 相关组件
|
|
133
|
+
|
|
134
|
+
| 场景 | 组件 | 说明 |
|
|
135
|
+
| -------- | ---------------- | ----------------------------- |
|
|
136
|
+
| 全局配置 | `ConfigProvider` | 注入 apiPayload 和 apiService |
|