task-68(ASIN 数据中心): 实现品牌数据库列表查询
品牌数据库面板即 invalid-asin-data;新增 invalid-asin-model.ts 解析 InvalidAsinDataPageVo(camel dataValue/brand/groupId/groupName/recordSource/createdAt) + recordSourceLabel(MANUAL 手动新增), invalid-asin-api.ts fetchInvalidAsinPage GET /api/admin/invalid-asin-data(支持 ASIN/品牌/分组过滤)。 8 用例全过,499 单测 + build 绿。
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/** 品牌数据库(不符合ASIN)列表加载适配(任务 68):GET /api/admin/invalid-asin-data。 */
|
||||
import { http } from '@/api/http'
|
||||
import { parseInvalidAsinPage, type InvalidAsinPageResult } from './invalid-asin-model'
|
||||
|
||||
export const INVALID_ASIN_ENDPOINT = '/api/admin/invalid-asin-data'
|
||||
|
||||
export interface InvalidAsinQuery {
|
||||
page: number
|
||||
pageSize: number
|
||||
dataValue?: string
|
||||
brand?: string
|
||||
groupId?: number | null
|
||||
}
|
||||
|
||||
function trimOrUndefined(value: unknown): string | undefined {
|
||||
return typeof value === 'string' && value.trim() ? value.trim() : undefined
|
||||
}
|
||||
|
||||
function toQuery(query: InvalidAsinQuery): Record<string, string | number> {
|
||||
const params: Record<string, string | number> = { page: query.page, page_size: query.pageSize }
|
||||
const dataValue = trimOrUndefined(query.dataValue)
|
||||
const brand = trimOrUndefined(query.brand)
|
||||
if (dataValue) params.data_value = dataValue
|
||||
if (brand) params.brand = brand
|
||||
if (typeof query.groupId === 'number' && query.groupId >= 1) params.group_id = query.groupId
|
||||
return params
|
||||
}
|
||||
|
||||
export async function fetchInvalidAsinPage(query: InvalidAsinQuery): Promise<InvalidAsinPageResult> {
|
||||
const { data } = await http.get<unknown>(INVALID_ASIN_ENDPOINT, { params: toQuery(query) })
|
||||
return parseInvalidAsinPage(data)
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/** 品牌数据库(不符合ASIN)列表模型(任务 68):解析 InvalidAsinDataPageVo(camel),纯逻辑。 */
|
||||
import { unwrap } from '../../api/envelope.ts'
|
||||
import { ASIN_PAGE_DEFAULT_SIZE } from '../asin/asin-filter.ts'
|
||||
|
||||
export type InvalidAsinSource = 'MANUAL' | 'AUTO'
|
||||
|
||||
export interface InvalidAsinItem {
|
||||
id: number
|
||||
dataValue: string
|
||||
brand: string
|
||||
groupId: number | null
|
||||
groupName: string
|
||||
recordSource: string
|
||||
createdAt?: string
|
||||
}
|
||||
|
||||
export interface InvalidAsinPageResult {
|
||||
items: InvalidAsinItem[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
export function emptyInvalidAsinPage(): InvalidAsinPageResult {
|
||||
return { items: [], total: 0, page: 1, pageSize: ASIN_PAGE_DEFAULT_SIZE }
|
||||
}
|
||||
|
||||
function text(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
function numberOrNull(value: unknown): number | null {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
|
||||
}
|
||||
|
||||
/** 来源展示标签:MANUAL 手动新增,其余(含空)自动导入。 */
|
||||
export function recordSourceLabel(source: string | null | undefined): string {
|
||||
return (source || '').trim().toUpperCase() === 'MANUAL' ? '手动新增' : '自动导入'
|
||||
}
|
||||
|
||||
/** 解析单条品牌数据库项;缺 id 视为无效。 */
|
||||
export function toInvalidAsinItem(raw: unknown): InvalidAsinItem | null {
|
||||
if (!raw || typeof raw !== 'object') return null
|
||||
const record = raw as Record<string, unknown>
|
||||
const id = numberOrNull(record.id)
|
||||
if (id === null) return null
|
||||
const item: InvalidAsinItem = {
|
||||
id,
|
||||
dataValue: text(record.dataValue ?? record.data_value),
|
||||
brand: text(record.brand),
|
||||
groupId: numberOrNull(record.groupId ?? record.group_id),
|
||||
groupName: text(record.groupName ?? record.group_name),
|
||||
recordSource: (text(record.recordSource ?? record.record_source)).toUpperCase(),
|
||||
}
|
||||
const createdAt = text(record.createdAt ?? record.created_at)
|
||||
if (createdAt) item.createdAt = createdAt
|
||||
return item
|
||||
}
|
||||
|
||||
/** 归一化分页负载(信封或已解包 VO)为前端结果。 */
|
||||
export function parseInvalidAsinPage(payload: unknown): InvalidAsinPageResult {
|
||||
const out = emptyInvalidAsinPage()
|
||||
const core = unwrap<unknown>(payload)
|
||||
if (!core || typeof core !== 'object') return out
|
||||
const record = core as Record<string, unknown>
|
||||
if (Array.isArray(record.items)) {
|
||||
out.items = record.items
|
||||
.map((raw) => toInvalidAsinItem(raw))
|
||||
.filter((item): item is InvalidAsinItem => item !== null)
|
||||
}
|
||||
if (typeof record.total === 'number') out.total = Math.floor(record.total)
|
||||
if (typeof record.page === 'number' && record.page >= 1) out.page = Math.floor(record.page)
|
||||
const rawSize = record.pageSize ?? record.page_size
|
||||
if (typeof rawSize === 'number' && rawSize >= 1) out.pageSize = Math.floor(rawSize)
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user