xtraderClient/docs/api/historyRecord.md

87 lines
3.1 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.

# historyRecord.ts
**路径**`src/api/historyRecord.ts`
## 功能用途
历史记录接口,用于 Wallet 页「History」Tab。**Wallet 使用 GET /hr/getHistoryRecordListClient**(需鉴权、按当前用户分页);另提供 GET /hr/getHistoryRecordPublic不需要鉴权备用。
## 核心能力
- `getHistoryRecordListClient`:客户端分页获取历史记录(需鉴权,传 userId、page、pageSize
- `getHistoryRecordPublic`:分页获取历史记录(无需鉴权)
- `getHistoryRecordList`:从响应 data 中解析 list 并映射为 `HistoryDisplayItem[]`,同时返回 total
- `mapHistoryRecordToDisplayItem`:单条 `HistoryRecordItem` → 钱包展示项(与 Wallet.vue HistoryItem 一致)
## GET /hr/getHistoryRecordListClientWallet 使用)
需鉴权x-token、x-user-id。
### 请求参数Query
| 参数 | 类型 | 说明 |
|------|------|------|
| page | number | 页码 |
| pageSize | number | 每页条数 |
| userId | number | 用户 ID |
| keyword | string | 关键字 |
| slug | string | 标识 |
| title | string | 标题 |
| name | string | 名称 |
| bio | string | 简介 |
| createdAtRange | string[] | 创建时间范围 |
### 响应
`{ code, data, msg }``data``PageResult<HistoryRecordItem>`list、page、pageSize、total
## GET /hr/getHistoryRecordPublic
### 请求参数Query可选
| 参数 | 类型 | 说明 |
|------|------|------|
| page | number | 页码 |
| pageSize | number | 每页条数 |
| keyword | string | 关键字 |
| slug | string | 标识 |
| title | string | 标题 |
| name | string | 名称 |
| bio | string | 简介 |
| createdAtRange | string[] | 创建时间范围 |
### 响应
`{ code, data, msg }``data` 可能为 `PageResult<HistoryRecordItem>`list、page、pageSize、total`HistoryRecordItem[]`
### HistoryRecordItem与 doc.json polymarket.HistoryRecord 对齐)
| 字段 | 类型 | 说明 |
|------|------|------|
| ID | number | 主键 |
| title | string | 标题(如「充值资金」) |
| type | string | 类型(如 recharge |
| **usdcSize** | number | **金额USDC**,用于充值等 |
| **icon** | string | **图标路径**(如 uploads/file/btc.png会转为完整 URL 展示 |
| **UpdatedAt** | string | **更新时间**,用于 timeAgo 展示 |
| price | number | 价格 |
| size | number | 大小 |
| outcome | string | 结果 |
| timestamp | number | 时间戳(秒或毫秒) |
| 其他 | - | asset, bio, conditionId, slug, transactionHash 等 |
## 使用方式
```typescript
import { getHistoryRecordPublic, getHistoryRecordList } from '@/api/historyRecord'
const res = await getHistoryRecordPublic({ page: 1, pageSize: 10 })
const { list, total } = getHistoryRecordList(res.data)
// list 为 HistoryDisplayItem[],可直接用于 Wallet 历史列表
```
## 扩展方式
- 若后端固定返回分页结构,可收紧 `HistoryRecordPublicResponse['data']` 类型为 `PageResult<HistoryRecordItem>`
- 展示字段market、activity、value、timeAgo 等)可在 `mapHistoryRecordToDisplayItem` 中按实际接口字段再调整