Files
crawler-plugin/admin-frontend-vue/src/pages/asin/query-asin-api.ts
T

54 lines
2.2 KiB
TypeScript
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.
/** 查询 ASIN 列表查询适配(任务 71):GET /api/admin/query-asins + 分页/筛选归一与 camel 序列化。 */
import { http } from '@/api/http'
import { unwrap } from '@/api/envelope'
import { fetchShopManageList } from '../shop/shop-manage-api.ts'
import { parseQueryAsinPage, type QueryAsinPageResult } from './query-asin-model'
import {
normalizeQueryAsinParams,
toQueryAsinQuery,
type QueryAsinListParams,
} from './query-asin-filter'
export const QUERY_ASIN_ENDPOINT = '/api/admin/query-asins'
export async function fetchQueryAsinList(params: Partial<QueryAsinListParams> = {}): Promise<QueryAsinPageResult> {
const normalized = normalizeQueryAsinParams(params)
const { data } = await http.get<unknown>(QUERY_ASIN_ENDPOINT, { params: toQueryAsinQuery(normalized) })
return parseQueryAsinPage(data)
}
/** 新增/覆盖查询 ASIN 载荷(对齐 Java QueryAsinCreateRequest camelCase)。 */
export interface QueryAsinCreatePayload {
groupId: number
shopName: string
countries: string[]
asin: string
asinMappings: Record<string, string>
}
/** 新增或覆盖查询 ASIN:POST /api/admin/query-asins,返回后端成功消息。 */
export async function createQueryAsin(payload: QueryAsinCreatePayload): Promise<string> {
const { data } = await http.post<unknown>(QUERY_ASIN_ENDPOINT, payload)
const record = unwrap<unknown>(data) as Record<string, unknown> | null | undefined
const message = record && typeof record.message === 'string' ? record.message : ''
return message || '保存成功'
}
/** 按分组加载店铺名列表(对齐 admin.js loadAsinShopNameOptions:100/页翻页聚合去重,上限 20 页)。 */
export async function fetchShopNamesByGroup(groupId: number): Promise<string[]> {
const names: string[] = []
const seen = new Set<string>()
for (let page = 1; page <= 20; page += 1) {
const result = await fetchShopManageList({ page, pageSize: 100, groupId })
for (const shop of result.items) {
const name = (shop.shopName || '').trim()
if (name && !seen.has(name)) {
seen.add(name)
names.push(name)
}
}
if (page * result.pageSize >= result.total) break
}
return names
}