From b1147f7a3d332d4ff46a7ce15b7da20bb64cdd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Mon, 2 Mar 2026 15:17:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(credit):=20=E6=B7=BB=E5=8A=A0=E9=99=84?= =?UTF-8?q?=E8=BF=91=E4=BC=81=E4=B8=9A=E6=89=B9=E9=87=8F=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 ImportBatchCreditNearbyCompanyItem 和 ImportBatchCreditNearbyCompanyResult 接口定义 - 实现 importBatchCreditNearbyCompany 函数支持多文件循环导入 - 添加 stopOnError 选项控制遇到失败时是否停止导入 - 返回详细的导入结果统计(总数、成功数、失败数及明细) - 确保即使有失败也不 reject,便于上层展示部分成功/失败明细 --- src/api/credit/creditNearbyCompany/index.ts | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/api/credit/creditNearbyCompany/index.ts b/src/api/credit/creditNearbyCompany/index.ts index 5588608..3e1c9d8 100644 --- a/src/api/credit/creditNearbyCompany/index.ts +++ b/src/api/credit/creditNearbyCompany/index.ts @@ -134,3 +134,61 @@ export async function importCreditNearbyCompany( } return Promise.reject(new Error(res.data.message)); } + +export interface ImportBatchCreditNearbyCompanyItem { + fileName: string; + success: boolean; + message: string; +} + +export interface ImportBatchCreditNearbyCompanyResult { + total: number; + success: number; + failure: number; + items: ImportBatchCreditNearbyCompanyItem[]; +} + +/** + * 导入附近企业(多文件) + * + * 说明: + * - 目前复用单文件导入接口,前端循环调用实现“多文件导入” + * - 不会在有失败时 reject(便于上层展示部分成功/失败明细) + */ +export async function importBatchCreditNearbyCompany( + files: File[] | FileList, + companyId?: number, + options?: { + /** 遇到失败是否立即停止,默认 false(继续导入后续文件) */ + stopOnError?: boolean; + } +): Promise { + const list = Array.isArray(files) ? files : Array.from(files); + const items: ImportBatchCreditNearbyCompanyItem[] = []; + const stopOnError = options?.stopOnError ?? false; + + for (const file of list) { + try { + const msg = await importCreditNearbyCompany(file, companyId); + items.push({ fileName: file.name, success: true, message: msg }); + } catch (e: unknown) { + items.push({ + fileName: file.name, + success: false, + message: e instanceof Error ? e.message : String(e) + }); + if (stopOnError) { + break; + } + } + } + + const success = items.filter((d) => d.success).length; + const failure = items.length - success; + return { + total: list.length, + success, + failure, + items + }; +}