diff --git a/frontend-vue/src/pages/jd/JdCollectTab.vue b/frontend-vue/src/pages/jd/JdCollectTab.vue index 68d30b278..3c40ca4e4 100644 --- a/frontend-vue/src/pages/jd/JdCollectTab.vue +++ b/frontend-vue/src/pages/jd/JdCollectTab.vue @@ -284,13 +284,23 @@ function statusClass(item: JdCollectHistoryItemVo) { return 'pending' } -/** 百分比:有 total 按已落库商品数算(封顶 99 直到服务端落 SUCCESS);没有 total 不编造分母。 */ +/** 已采计数口径:``rowCount`` 是「已落京东数据库」的真值,``itemsReceived`` 只是服务端 + * 已收下的分片行数——分片被拒/回传失败时后者低估(34959 实录:8 行已落库、分片回传 + * 500 ⇒ itemsReceived=0,卡片 extraLines 显示「已采集 8 个商品」而进度行显示 0, + * 同屏自相矛盾)。进度取两者大者。 */ +function collectedCount(item: JdCollectHistoryItemVo) { + return Math.max(item.itemsReceived ?? 0, item.rowCount ?? 0) +} + +/** 百分比:有 total 按已落库商品数算(封顶 99 直到服务端落 SUCCESS);没有 total 不编造分母。 + * 分母来自服务端游标 cursor.total——客户端在页面级店内分类筛选生效时会写真分母 + * (2026-11-19 起),行级过滤兜底时仍记 0 ⇒ 走无分母口径只报行数。 */ function progressPercent(item: JdCollectHistoryItemVo) { const status = normalizeTaskStatus(item) if (status === 'SUCCESS') return 100 const total = typeof item.total === 'number' && item.total > 0 ? item.total : null if (!total) return 0 - const done = Math.min(item.itemsReceived ?? 0, total) + const done = Math.min(collectedCount(item), total) return Math.max(0, Math.min(99, Math.round((done * 100) / total))) } @@ -298,7 +308,7 @@ function progressPercent(item: JdCollectHistoryItemVo) { * countLabel 会顶掉「总进度 X%」那行字,百分比只能随 countLabel 一起出; * 没有 total 保持只报行数,不编造分母(与本页 progressPercent 同一口径)。 */ function progressCountLabel(item: JdCollectHistoryItemVo) { - const received = item.itemsReceived ?? item.rowCount ?? 0 + const received = collectedCount(item) const total = typeof item.total === 'number' && item.total > 0 ? item.total : null if (!total) return `已采集 ${received} 个商品` return `已采集 ${received}/${total} 个商品(${progressPercent(item)}%)` 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 1e8e5ce42..753dbb271 100644 --- a/frontend-vue/tests/mount/jd-collect-progress.mount.test.ts +++ b/frontend-vue/tests/mount/jd-collect-progress.mount.test.ts @@ -242,6 +242,35 @@ describe('获取店铺数据:一键采集 + 任务面板', () => { expect(w.find('.file-progress-bar').attributes('style')).toContain('width: 0%') }) + it('分片被拒时进度行以落库 rowCount 为准(itemsReceived 低估不再与行数行自相矛盾)', async () => { + // 34959 实录(2026-11-19):8 行已落京东数据库、分片回传 500 ⇒ 服务端 + // itemsReceived=0、rowCount=8,extraLines 显示「已采集 8 个商品」而进度行显示 0。 + api.fetchJdCollectTaskProgressBatch.mockResolvedValue( + batchOf(historyItem({ total: 8, itemsReceived: 0, rowCount: 8 })), + ) + const w = await mountPage() + await startCollect(w) + await flushPromises() + + const meta = w.find('.file-progress-meta') + expect(meta.text()).toContain('已采集 8/8 个商品(99%)') + expect(meta.text()).not.toContain('已采集 0 个') + // 已落库 8/8:条形按 99% 封顶(SUCCESS 才满格) + expect(w.find('.file-progress-bar').attributes('style')).toContain('width: 99%') + }) + + it('没有分母且分片被拒时已采行数也取 rowCount 真值', async () => { + api.fetchJdCollectTaskProgressBatch.mockResolvedValue( + batchOf(historyItem({ total: null, page: null, itemsReceived: 0, rowCount: 8 })), + ) + const w = await mountPage() + await startCollect(w) + await flushPromises() + + expect(w.find('.file-progress-meta').text()).toContain('已采集 8 个商品') + expect(w.find('.file-progress-meta').text()).not.toContain('已采集 0 个') + }) + it('SUCCESS 终态:状态徽章落「获取完成」、进度满格,且从轮询中收手', async () => { const w = await mountPage() await startCollect(w)