feat(jd-collect): 采集进度卡片显示百分比——countLabel 带分母「已采集 N/M 个商品(X%)」(TaskItemCard 有 countLabel 就不显示总进度行,百分比只能随 countLabel 出;无 total 仍不编造分母)

This commit is contained in:
2026-11-15 12:26:14 +08:00
parent ab6e49b5e2
commit 1c3395869e
2 changed files with 13 additions and 2 deletions
+11 -1
View File
@@ -109,7 +109,7 @@ function toJdTaskView(item: JdCollectHistoryItemVo): TaskItemView {
: []),
...(item.errorMessage ? [`错误:${userNotice(item.errorMessage)}`] : []),
],
progress: showProgress ? { percent: progressPercent(item), countLabel: `已采集 ${item.itemsReceived ?? item.rowCount ?? 0} 个商品` } : null,
progress: showProgress ? { percent: progressPercent(item), countLabel: progressCountLabel(item) } : null,
source: item,
}
}
@@ -155,6 +155,16 @@ function progressPercent(item: JdCollectHistoryItemVo) {
return Math.max(0, Math.min(99, Math.round((done * 100) / total)))
}
/** 计数文案:有 total 带分母和百分比「已采集 30/100 个商品(30%)」——TaskItemCard 的
* countLabel 会顶掉「总进度 X%」那行字,百分比只能随 countLabel 一起出;
* 没有 total 保持只报行数,不编造分母(与本页 progressPercent 同一口径)。 */
function progressCountLabel(item: JdCollectHistoryItemVo) {
const received = item.itemsReceived ?? item.rowCount ?? 0
const total = typeof item.total === 'number' && item.total > 0 ? item.total : null
if (!total) return `已采集 ${received} 个商品`
return `已采集 ${received}/${total} 个商品(${progressPercent(item)}%)`
}
/** 失败/已中断的任务能续跑:在原任务上复位(不新建任务),成功/进行中的任务不该出现这个按钮。 */
function canRetryTask(item: JdCollectHistoryItemVo | null | undefined): boolean {
if (!item?.taskId) return false
@@ -172,7 +172,8 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
const bar = w.find('.file-progress-bar')
expect(bar.exists()).toBe(true)
expect(bar.attributes('style')).toContain('width: 30%')
expect(w.find('.file-progress-meta').text()).toContain('已采集 30 个商品')
// 百分比文字随 countLabel 一起出(TaskItemCard 有 countLabel 就不显示「总进度 X%」)
expect(w.find('.file-progress-meta').text()).toContain('已采集 30/100 个商品(30%)')
})
it('没有分母(total 缺失)时只显示已采集行数,不编造百分比', async () => {