fix(jd-publish): 校验失败弹窗跨进页只提示一次——已提示任务代落 localStorage

- 前端只靠内存 Set 去重,重进页面即复位 ⇒ 11-21 已修好的任务 35147 每次打开「商品上架」
  都重弹「本店源商品校验失败:…京麦克隆响应未确认本店源商品身份」,用户误以为新任务又失败
  (今日客户端日志 0 次该商品/该文案;今日上架 02:45 已走「productId=0 放行」新口径成功)
- 已提示过的 taskId:resumeAttempt 落 `jd-publish:validation-notices:<uid>`(封顶 200 条):
  同一任务代跨刷新/重进只提示一次,重试后 attempt+1 仍提示;读失败按「没提示过」、写失败
  「放弃跨页面去重」降级,弹窗本身不受影响
- 判据:mount 用例「同一任务代的校验失败跨重进页面只提示一次,新代仍再提示」(反向验证去掉
  落盘调用即红);catch 静默棘轮 blocks 332→334 记名(两支均非静默)
This commit is contained in:
2026-11-23 16:24:58 +08:00
parent d021bc049a
commit 7e9618e425
3 changed files with 58 additions and 2 deletions
+37 -1
View File
@@ -396,7 +396,42 @@ function validationFailureNotice(item: JdPublishHistoryItemVo) {
} }
} }
const shownValidationFailures = new Set<string>() /**
* 已提示过的校验失败(`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<string>(loadShownValidationFailures())
watch( watch(
() => board.historyItems.value.map((item) => ({ () => board.historyItems.value.map((item) => ({
taskId: item.taskId, attempt: item.resumeAttempt ?? 0, notice: validationFailureNotice(item), taskId: item.taskId, attempt: item.resumeAttempt ?? 0, notice: validationFailureNotice(item),
@@ -407,6 +442,7 @@ watch(
const key = `${taskId}:${attempt}` const key = `${taskId}:${attempt}`
if (shownValidationFailures.has(key)) continue if (shownValidationFailures.has(key)) continue
shownValidationFailures.add(key) shownValidationFailures.add(key)
rememberShownValidationFailure(key)
void ElMessageBox.alert(notice.body, notice.title, { void ElMessageBox.alert(notice.body, notice.title, {
type: 'warning', confirmButtonText: '知道了', dangerouslyUseHTMLString: false, type: 'warning', confirmButtonText: '知道了', dangerouslyUseHTMLString: false,
}) })
@@ -105,7 +105,11 @@ const BASELINE = {
// false 与兜底提示都交给调用方弹给用户)+ acd61aa1 JdCollectTab.vue 登录京麦 1 支 + // false 与兜底提示都交给调用方弹给用户)+ acd61aa1 JdCollectTab.vue 登录京麦 1 支 +
// 81869f75 stopLocalJdWorker 1 支 + f96d5118 采集状态多选 1 支,全部非静默 // 81869f75 stopLocalJdWorker 1 支 + f96d5118 采集状态多选 1 支,全部非静默
// (同步批给三支 console-only catch 补了「先算 detail 再留痕」的形状,silent 一格没涨)。 // (同步批给三支 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 行,面板里那处 // 2026-10-30(ops Phase 6/可读棘轮):ApiSecretSettingsPanel.vue 1113→775 行,面板里那处
// 静默 catch(余额查询失败只 console.warn、界面留空)随 loadBalance 整块搬进 // 静默 catch(余额查询失败只 console.warn、界面留空)随 loadBalance 整块搬进
// useProxyPlan.ts。不是新增静默:面板 1→0、新文件记 1,silent 总数与 blocks 都一格没动, // useProxyPlan.ts。不是新增静默:面板 1→0、新文件记 1,silent 总数与 blocks 都一格没动,
@@ -250,6 +250,22 @@ it('轮询只凭任务头识别失败,历史和重复轮询不重弹,新代
expect(api.alert).toHaveBeenCalledTimes(2) 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 () => { it('修改品牌走专用原位重试,原样投递新载荷并拒绝旧代进度', async () => {
api.history.mockResolvedValue({ items: [row('FAILED', 3, brandError)] }) api.history.mockResolvedValue({ items: [row('FAILED', 3, brandError)] })
api.progress.mockResolvedValue(batch(row('FAILED', 3, brandError))) api.progress.mockResolvedValue(batch(row('FAILED', 3, brandError)))