From 7e9618e425f15110675ba1f3fb8be2114d97583c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Mon, 23 Nov 2026 16:24:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(jd-publish):=20=E6=A0=A1=E9=AA=8C=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=BC=B9=E7=AA=97=E8=B7=A8=E8=BF=9B=E9=A1=B5=E5=8F=AA?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=B8=80=E6=AC=A1=E2=80=94=E2=80=94=E5=B7=B2?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BB=BB=E5=8A=A1=E4=BB=A3=E8=90=BD=20localS?= =?UTF-8?q?torage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 前端只靠内存 Set 去重,重进页面即复位 ⇒ 11-21 已修好的任务 35147 每次打开「商品上架」 都重弹「本店源商品校验失败:…京麦克隆响应未确认本店源商品身份」,用户误以为新任务又失败 (今日客户端日志 0 次该商品/该文案;今日上架 02:45 已走「productId=0 放行」新口径成功) - 已提示过的 taskId:resumeAttempt 落 `jd-publish:validation-notices:`(封顶 200 条): 同一任务代跨刷新/重进只提示一次,重试后 attempt+1 仍提示;读失败按「没提示过」、写失败 「放弃跨页面去重」降级,弹窗本身不受影响 - 判据:mount 用例「同一任务代的校验失败跨重进页面只提示一次,新代仍再提示」(反向验证去掉 落盘调用即红);catch 静默棘轮 blocks 332→334 记名(两支均非静默) --- frontend-vue/src/pages/jd/JdPublishTab.vue | 38 ++++++++++++++++++- .../tests/catch-silence-ratchet.test.ts | 6 ++- .../mount/jd-publish-dispatch.mount.test.ts | 16 ++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/frontend-vue/src/pages/jd/JdPublishTab.vue b/frontend-vue/src/pages/jd/JdPublishTab.vue index 3bb579843..5f6af04cc 100644 --- a/frontend-vue/src/pages/jd/JdPublishTab.vue +++ b/frontend-vue/src/pages/jd/JdPublishTab.vue @@ -396,7 +396,42 @@ function validationFailureNotice(item: JdPublishHistoryItemVo) { } } -const shownValidationFailures = new Set() +/** + * 已提示过的校验失败(`taskId:resumeAttempt`)落 localStorage:同一行失败跨刷新/重进页面 + * 只提示一次。内存 Set 只在本次挂载内去重,挡不住重进页面——2026-11-23 实录:11-21 已修好 + * 的 35147 每打开「商品上架」都重弹,用户误以为新任务又失败了。 + */ +const VALIDATION_NOTICE_STORAGE_LIMIT = 200 + +function validationNoticeKey() { + return `jd-publish:validation-notices:${uidForStorage()}` +} + +function loadShownValidationFailures(): string[] { + if (typeof window === 'undefined') return [] + try { + const raw = window.localStorage.getItem(validationNoticeKey()) + const keys = raw ? JSON.parse(raw) : [] + return Array.isArray(keys) ? keys.filter((key): key is string => typeof key === 'string') : [] + } catch { + /* 忽略 localStorage 异常:隐私模式/配额满时退化为每页提示一次 */ + return [] + } +} + +/** 写入失败只退化成「本次挂载内去重」,不拦提示本身。 */ +function rememberShownValidationFailure(key: string) { + if (typeof window === 'undefined') return + try { + const keys = loadShownValidationFailures().filter((value) => value !== key).concat(key) + window.localStorage.setItem(validationNoticeKey(), JSON.stringify(keys.slice(-VALIDATION_NOTICE_STORAGE_LIMIT))) + } catch { + // localStorage 不可用(隐私模式/配额满):放弃跨页面去重,本次挂载仍由内存 Set 挡住重复弹窗。 + return + } +} + +const shownValidationFailures = new Set(loadShownValidationFailures()) watch( () => board.historyItems.value.map((item) => ({ taskId: item.taskId, attempt: item.resumeAttempt ?? 0, notice: validationFailureNotice(item), @@ -407,6 +442,7 @@ watch( const key = `${taskId}:${attempt}` if (shownValidationFailures.has(key)) continue shownValidationFailures.add(key) + rememberShownValidationFailure(key) void ElMessageBox.alert(notice.body, notice.title, { type: 'warning', confirmButtonText: '知道了', dangerouslyUseHTMLString: false, }) diff --git a/frontend-vue/tests/catch-silence-ratchet.test.ts b/frontend-vue/tests/catch-silence-ratchet.test.ts index b2af94bce..19af59984 100644 --- a/frontend-vue/tests/catch-silence-ratchet.test.ts +++ b/frontend-vue/tests/catch-silence-ratchet.test.ts @@ -105,7 +105,11 @@ const BASELINE = { // false 与兜底提示都交给调用方弹给用户)+ acd61aa1 JdCollectTab.vue 登录京麦 1 支 + // 81869f75 stopLocalJdWorker 1 支 + f96d5118 采集状态多选 1 支,全部非静默 // (同步批给三支 console-only catch 补了「先算 detail 再留痕」的形状,silent 一格没涨)。 - blocks: 332, + // 334 = 332 + 2(2026-11-23 京东发布校验失败弹窗跨进页只提示一次):JdPublishTab.vue 的 + // 「已提示任务代」localStorage 读/写各一支 try/catch。读不出一律按「没提示过」处理(return []), + // 写不进去就放弃跨页面去重(return,本次挂载仍由内存 Set 挡住重复弹窗)——两支都没有把 + // 用户可见错误吞掉(弹窗本身不受影响,丢的只是可选优化),silent 一格没涨、perFile 无新增条目。 + blocks: 334, // 2026-10-30(ops Phase 6/可读棘轮):ApiSecretSettingsPanel.vue 1113→775 行,面板里那处 // 静默 catch(余额查询失败只 console.warn、界面留空)随 loadBalance 整块搬进 // useProxyPlan.ts。不是新增静默:面板 1→0、新文件记 1,silent 总数与 blocks 都一格没动, diff --git a/frontend-vue/tests/mount/jd-publish-dispatch.mount.test.ts b/frontend-vue/tests/mount/jd-publish-dispatch.mount.test.ts index 4fe762779..139188b4e 100644 --- a/frontend-vue/tests/mount/jd-publish-dispatch.mount.test.ts +++ b/frontend-vue/tests/mount/jd-publish-dispatch.mount.test.ts @@ -250,6 +250,22 @@ it('轮询只凭任务头识别失败,历史和重复轮询不重弹,新代 expect(api.alert).toHaveBeenCalledTimes(2) }) +it('同一任务代的校验失败跨重进页面只提示一次,新代仍再提示', async () => { + api.history.mockResolvedValue({ items: [row('FAILED', 3, brandError)] }) + const first = await mountPage() + await flushPromises() + expect(api.alert).toHaveBeenCalledTimes(1) + first.unmount() + wrapper = undefined + const second = await mountPage() + await flushPromises() + expect(api.alert).toHaveBeenCalledTimes(1) + api.history.mockResolvedValue({ items: [row('FAILED', 4, brandError)] }) + await second.get('.panel-refresh').trigger('click') + await flushPromises() + expect(api.alert).toHaveBeenCalledTimes(2) +}) + it('修改品牌走专用原位重试,原样投递新载荷并拒绝旧代进度', async () => { api.history.mockResolvedValue({ items: [row('FAILED', 3, brandError)] }) api.progress.mockResolvedValue(batch(row('FAILED', 3, brandError)))