task-65(ASIN 数据中心): 实现去重汇总导入任务创建
dedupe-import-model.ts 纯解析 importId + isAllowedImportFile(xlsx/xls);dedupe-import-api.ts startDedupeImport 以 FormData(file+groupId) multipart POST /api/admin/dedupe-total-data/import。 8 用例全过,475 单测 + build 绿。
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
/** 去重汇总导入启动适配(任务 65):multipart POST /import(file+groupId) → importId。 */
|
||||
import { http } from '@/api/http'
|
||||
import { parseDedupeImportStart } from './dedupe-import-model'
|
||||
|
||||
export const DEDUPE_IMPORT_ENDPOINT = '/api/admin/dedupe-total-data/import'
|
||||
|
||||
export async function startDedupeImport(file: File, groupId: number): Promise<string> {
|
||||
const form = new FormData()
|
||||
form.append('file', file, file.name)
|
||||
form.append('groupId', String(groupId))
|
||||
const { data } = await http.post<unknown>(DEDUPE_IMPORT_ENDPOINT, form)
|
||||
return parseDedupeImportStart(data)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/** 去重汇总导入模型(任务 65):启动结果解析 + xlsx 文件校验,纯逻辑。 */
|
||||
import { unwrap } from '../../api/envelope.ts'
|
||||
|
||||
export const DEDUPE_IMPORT_ALLOWED_EXT = /\.(xlsx|xls)$/i
|
||||
|
||||
/** 是否为允许导入的 Excel 文件。 */
|
||||
export function isAllowedImportFile(fileName: unknown): boolean {
|
||||
return typeof fileName === 'string' && DEDUPE_IMPORT_ALLOWED_EXT.test(fileName.trim())
|
||||
}
|
||||
|
||||
/** 解包导入启动结果并取回 importId;缺省抛可读错误。 */
|
||||
export function parseDedupeImportStart(payload: unknown): string {
|
||||
const data = unwrap<unknown>(payload)
|
||||
const record = data && typeof data === 'object' ? (data as Record<string, unknown>) : null
|
||||
const importId = typeof record?.importId === 'string' ? record.importId.trim() : ''
|
||||
if (!importId) throw new Error('导入任务响应异常:缺少任务 ID')
|
||||
return importId
|
||||
}
|
||||
Reference in New Issue
Block a user