/** 去重汇总导出等待模型(任务 64):导出 URL 构建 + 运行等待态提示,纯逻辑。 */ import { validIsoDateOrUndefined } from './asin-filter.ts' import type { DedupeTotalFilterState } from './dedupe-total-filter.ts' export const DEDUPE_TOTAL_EXPORT_ENDPOINT = '/api/admin/dedupe-total-data/export' export type DedupeExportStage = 'idle' | 'running' | 'done' | 'error' /** 运行中/完成等待提示;idle 无提示。 */ export function exportStageHint(stage: DedupeExportStage): string | undefined { switch (stage) { case 'running': return '正在生成并下载导出文件,请稍候…' case 'done': return '导出完成' case 'error': return '导出失败,请重试' default: return undefined } } /** 按导出可用筛选(用户名/日期区间/分组/国家)构建查询串;空白/非法条件不下发。 */ export function buildDedupeExportQuery(state: DedupeTotalFilterState): string { const params = new URLSearchParams() const username = (state.username || '').trim() const country = (state.country || '').trim() if (username) params.set('username', username) if (country) params.set('country', country) const startDate = validIsoDateOrUndefined(state.startDate) const endDate = validIsoDateOrUndefined(state.endDate) if (startDate) params.set('start_date', startDate) if (endDate) params.set('end_date', endDate) if (typeof state.groupId === 'number' && state.groupId >= 1) params.set('group_id', String(state.groupId)) return params.toString() } /** 导出下载地址:浏览器直接访问该 URL 触发流式下载。 */ export function toExportUrl(state: DedupeTotalFilterState): string { const query = buildDedupeExportQuery(state) return query ? `${DEDUPE_TOTAL_EXPORT_ENDPOINT}?${query}` : DEDUPE_TOTAL_EXPORT_ENDPOINT }