refactor(品牌工具页): 历史批量删除抽为 runBatchDelete

16 个品牌页逐字相同的 batchDeleteHistory 循环(逐条删除 + 容忍个别失败计数)
收敛为 shared/utils/batch-delete.ts 的 runBatchDelete;各页仅保留自己的删除调用
与提示文案。补单测 4 例(空列表 / 全成功 / 部分失败继续 / 非 Error 异常)。

净减约 120 行;vue-tsc 构建与 699 个前端单测通过。
This commit is contained in:
2026-09-13 23:32:27 +08:00
parent dc6e8924a9
commit 14a723ab1c
18 changed files with 132 additions and 160 deletions
@@ -0,0 +1,26 @@
export interface BatchDeleteResult {
/** 尝试删除的条数 */
total: number
/** 删除失败的条数(单条失败不中断整批) */
failed: number
}
/**
* 历史任务批量删除:逐条删除,容忍个别失败并计数,供各工具页统一提示。
*
* 单条失败继续删剩下的(不中断整批),返回成功的数量给调用方决定文案。
*/
export async function runBatchDelete<T>(
items: readonly T[],
deleteOne: (item: T) => Promise<unknown>,
): Promise<BatchDeleteResult> {
let failed = 0
for (const item of items) {
try {
await deleteOne(item)
} catch {
failed += 1
}
}
return { total: items.length, failed }
}