59e51671
“wangming”
1
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import { unwrapApiPayload } from './usAppApiRequest'
/** 解析分页 JSON:兼容 items / Items、camelCase / PascalCase、ABP 包装 */
export function extractPagedItems<T>(responseBody: unknown): {
items: T[]
totalCount: number
pageIndex: number
pageSize: number
} {
const raw = unwrapApiPayload<Record<string, unknown>>(responseBody)
if (raw == null || typeof raw !== 'object') {
return { items: [], totalCount: 0, pageIndex: 1, pageSize: 0 }
}
const itemsRaw = raw.items ?? raw.Items
const items = Array.isArray(itemsRaw) ? (itemsRaw as T[]) : []
const totalCount = Number(raw.totalCount ?? raw.TotalCount ?? items.length) || 0
const pageIndex = Number(raw.pageIndex ?? raw.PageIndex ?? 1) || 1
const pageSize = Number(raw.pageSize ?? raw.PageSize ?? items.length) || 0
return { items, totalCount, pageIndex, pageSize }
}
|