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:
@@ -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(
|
||||
() => 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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user