diff --git a/frontend-vue/src/pages/jd/JdCollectTab.vue b/frontend-vue/src/pages/jd/JdCollectTab.vue index 49f920435..28f908ef3 100644 --- a/frontend-vue/src/pages/jd/JdCollectTab.vue +++ b/frontend-vue/src/pages/jd/JdCollectTab.vue @@ -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 diff --git a/frontend-vue/tests/mount/jd-collect-progress.mount.test.ts b/frontend-vue/tests/mount/jd-collect-progress.mount.test.ts index dd882ff09..40170775c 100644 --- a/frontend-vue/tests/mount/jd-collect-progress.mount.test.ts +++ b/frontend-vue/tests/mount/jd-collect-progress.mount.test.ts @@ -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 () => {