xtraderClient/docs/api/category.md
2026-02-14 18:59:36 +08:00

40 lines
1.3 KiB
Markdown
Raw 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.

# category.ts
**路径**`src/api/category.ts`
## 功能用途
分类Tag相关接口与数据结构对接 `/PmTag/getPmTagList`,获取首页顶部分类 Tab 数据。支持树形结构、图标自动匹配、按 sort 排序。
## 核心能力
- `getPmTagMain`:获取主分类树,返回 `CategoryTreeNode[]`
- `enrichWithIcons`:递归为节点补充 MDI 图标(无 icon 时自动匹配)
- `MOCK_CATEGORY_TREE`:模拟分类数据,用于开发/测试
## 类型说明
| 类型 | 说明 |
|------|------|
| `PmTagMainItem` | 接口返回的 PmTag 结构,含 children |
| `CategoryTreeNode` | 前端使用的树节点,含 id、label、slug、icon、sectionTitle、children |
## 使用方式
```typescript
import { getPmTagMain, enrichWithIcons, MOCK_CATEGORY_TREE } from '@/api/category'
// 获取分类
const res = await getPmTagMain()
const tree = res.data // 已包含图标、排序
// 开发时使用 mock
const mockTree = enrichWithIcons(MOCK_CATEGORY_TREE)
```
## 扩展方式
1. **新增分类层级**:在 `CategoryTreeNode` 中扩展字段,`getPmTagMain``mapPmTagToTreeNode` 中映射
2. **自定义图标**:在 `categoryIcons.ts` 中扩展 `ICON_MAP``enrichWithIcons` 会自动使用
3. **过滤逻辑**:在 `getPmTagMain` 中根据 `forceShow`/`forceHide` 过滤节点