From 6420fd91fe2ce3f53e773ecb957de3156aeafe96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=B8=E7=86=9F=E5=90=B4=E5=BD=A6=E7=A5=96?= Date: Fri, 10 Jul 2026 13:28:44 +0800 Subject: [PATCH] bug --- .../js/pdaOther/productionBagReturnStep1.js | 52 +++++++++++++---- .../js/pdaOther/productionBagReturnStep2.js | 56 ++++++++++++++++--- .../pdaOther/productionBagReturnStep1.ftl | 2 +- .../pdaOther/productionBagReturnStep2.ftl | 2 +- 4 files changed, 93 insertions(+), 19 deletions(-) diff --git a/src/main/resources/static/js/pdaOther/productionBagReturnStep1.js b/src/main/resources/static/js/pdaOther/productionBagReturnStep1.js index 818a942..e8e487c 100644 --- a/src/main/resources/static/js/pdaOther/productionBagReturnStep1.js +++ b/src/main/resources/static/js/pdaOther/productionBagReturnStep1.js @@ -8,21 +8,49 @@ var currentData = null; const COOKIE_ORDER = "prodBagRetPdaOrder"; const COOKIE_TABLE = "prodBagRetPdaTable"; +// 兼容清理历史 path Cookie,避免同名 Cookie 导致读取不稳定 - rqrq +function clearOrderCookie () { + $.cookie(COOKIE_ORDER, "", { expires: -1, path: "/" }); + $.cookie(COOKIE_ORDER, "", { expires: -1 }); +} + +// 兼容清理历史 path Cookie,避免同名 Cookie 导致读取不稳定 - rqrq +function clearTableCookie () { + $.cookie(COOKIE_TABLE, "", { expires: -1, path: "/" }); + $.cookie(COOKIE_TABLE, "", { expires: -1 }); +} + +// 退出到菜单时清理步骤缓存,防止下次进入串单 - rqrq +function clearBagReturnCookies () { + clearOrderCookie(); + clearTableCookie(); +} + +// 读取订单缓存并做容错,异常时清理坏数据 - rqrq +function readOrderCookieSafe () { + var saved = $.cookie(COOKIE_ORDER); + if (saved == null || saved === "") { + return null; + } + try { + return JSON.parse(saved); + } catch (e) { + clearOrderCookie(); + return null; + } +} + $(function () { if (titleName != null && titleName !== "") { $("#titleName").text(titleName); } else { window.location.href = "/login"; } - var saved = $.cookie(COOKIE_ORDER); - if (saved != null && saved !== "") { - try { - currentData = JSON.parse(saved); - initVal(); - } catch (e) { - currentData = null; - } - $.cookie(COOKIE_ORDER, ""); + currentData = readOrderCookieSafe(); + if (currentData != null) { + initVal(); + // Step2 回到 Step1 的一次性订单缓存,读取后立即清理 - rqrq + clearOrderCookie(); } $("#orderNo_search").focus(); }); @@ -58,7 +86,8 @@ function getOrderNoData () { return false; } } - $.cookie(COOKIE_TABLE, "", { expires: -1, path: "/" }); + // 重新扫描新订单时清空步骤2缓存(兼容历史 path)- rqrq + clearTableCookie(); initVal(); } else { layer.msg("未解析到生产订单!"); @@ -95,6 +124,7 @@ function pageJump () { layer.msg("当前无生产订单信息!"); return false; } + // 写入根路径 Cookie,确保 Step2 稳定读取 - rqrq $.cookie(COOKIE_ORDER, JSON.stringify(currentData), { path: "/" }); var menuId = $("#menuId").val(); var superiorName = $("#current_titleName").val(); @@ -102,5 +132,7 @@ function pageJump () { } function pdaBaseJump () { + // 退出菜单时清理全部缓存,避免下一单残留 - rqrq + clearBagReturnCookies(); window.location.href = "/pda/pdaBase"; } diff --git a/src/main/resources/static/js/pdaOther/productionBagReturnStep2.js b/src/main/resources/static/js/pdaOther/productionBagReturnStep2.js index fd565e1..9576e1c 100644 --- a/src/main/resources/static/js/pdaOther/productionBagReturnStep2.js +++ b/src/main/resources/static/js/pdaOther/productionBagReturnStep2.js @@ -12,6 +12,40 @@ var confirmSubmitting = false; const COOKIE_ORDER = "prodBagRetPdaOrder"; const COOKIE_TABLE = "prodBagRetPdaTable"; +// 兼容清理历史 path Cookie,避免同名 Cookie 导致读取不稳定 - rqrq +function clearOrderCookie () { + $.cookie(COOKIE_ORDER, "", { expires: -1, path: "/" }); + $.cookie(COOKIE_ORDER, "", { expires: -1 }); +} + +// 兼容清理历史 path Cookie,避免同名 Cookie 导致读取不稳定 - rqrq +function clearTableCookie () { + $.cookie(COOKIE_TABLE, "", { expires: -1, path: "/" }); + $.cookie(COOKIE_TABLE, "", { expires: -1 }); +} + +// 退出菜单或异常场景统一清理缓存 - rqrq +function clearBagReturnCookies () { + clearOrderCookie(); + clearTableCookie(); +} + +// 读取 JSON Cookie 并容错,坏数据自动清理 - rqrq +function readJsonCookieSafe (cookieName, clearFn) { + var raw = $.cookie(cookieName); + if (raw == null || raw === "") { + return null; + } + try { + return JSON.parse(raw); + } catch (e) { + if (clearFn) { + clearFn(); + } + return null; + } +} + /** 与本单已录入行比对:seqNo_itemNo(与二维码第4、5段一致)- rqrq */ function bagLabelDupKey(seqNo, itemNo) { return String(seqNo) + "_" + String(itemNo); @@ -23,19 +57,21 @@ $(function () { } else { window.location.href = "/login"; } - var orderCookie = $.cookie(COOKIE_ORDER); - if (orderCookie != null && orderCookie !== "") { - currentData = JSON.parse(orderCookie); + var orderCookie = readJsonCookieSafe(COOKIE_ORDER, clearOrderCookie); + if (orderCookie != null) { + currentData = orderCookie; } else { + // 缺少订单上下文时清空残留缓存并返回步骤1 - rqrq + clearBagReturnCookies(); layer.msg("请先扫袋装标签选择订单"); var menuId = $("#menuId").val(); var superiorName = $("#current_titleName").val(); window.location.href = "/pdaOther/productionBagReturnStep1?menuId=" + encodeURIComponent(menuId || "") + "&titleName=" + encodeURIComponent(superiorName || ""); return; } - var list = $.cookie(COOKIE_TABLE); - if (list != null && list !== "") { - tableList = JSON.parse(list); + var list = readJsonCookieSafe(COOKIE_TABLE, clearTableCookie); + if (Array.isArray(list)) { + tableList = list; changeTable(); } $("#partNo_search").focus(); @@ -211,7 +247,7 @@ function confirmReturn () { success: function (data) { if (data.code === 0) { layer.msg(data.msg || "操作成功!"); - $.cookie(COOKIE_TABLE, "", { expires: -1, path: "/" }); + clearTableCookie(); tableList = []; changeTable(); $("#wareHouse").val(""); @@ -244,3 +280,9 @@ function superiorJump () { var superiorName = $("#current_titleName").val(); window.location.href = "/pdaOther/productionBagReturnStep1?menuId=" + encodeURIComponent(menuId || "") + "&titleName=" + encodeURIComponent(superiorName || ""); } + +function pdaBaseJump () { + // 直接返回菜单时清理步骤缓存,避免下次进入串单 - rqrq + clearBagReturnCookies(); + window.location.href = "/pda/pdaBase"; +} diff --git a/src/main/resources/templates/pdaOther/productionBagReturnStep1.ftl b/src/main/resources/templates/pdaOther/productionBagReturnStep1.ftl index a5046e6..ba8609f 100644 --- a/src/main/resources/templates/pdaOther/productionBagReturnStep1.ftl +++ b/src/main/resources/templates/pdaOther/productionBagReturnStep1.ftl @@ -58,7 +58,7 @@
- +
diff --git a/src/main/resources/templates/pdaOther/productionBagReturnStep2.ftl b/src/main/resources/templates/pdaOther/productionBagReturnStep2.ftl index de668f1..941ad90 100644 --- a/src/main/resources/templates/pdaOther/productionBagReturnStep2.ftl +++ b/src/main/resources/templates/pdaOther/productionBagReturnStep2.ftl @@ -58,7 +58,7 @@
- +