From 52c11e754066ea8384bfbf912669a5998201a13a Mon Sep 17 00:00:00 2001 From: hjhan Date: Thu, 30 Jul 2026 14:37:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(diag):=20=E7=AE=80=E5=8C=96=20otcDebug=20?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E5=BC=80=E5=85=B3=E5=91=BD=E5=90=8D=E5=B9=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20localStorage=20=E6=8C=81=E4=B9=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - __otcDiag 双源对象拆为 __diag(版本元数据, 仅供 banner 展示) + __debug(调试开关布尔值, 唯一真相来源), 消除 __私有对象 与 otcDebug.API 大小写混搭。 - __debug 解析顺序: URL ?otcdebug=1(命中即写回 localStorage) -> localStorage -> 兜底 __diag.debug。同源父子 frame 共享 localStorage, 使 _InfoLayout iframe 弹窗(新增互换交易)自动继承父页面开过的调试开关, 修复弹窗内无调试日志。 --- YLErpWeb/wwwroot/Scripts/base/main.js | 38 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/YLErpWeb/wwwroot/Scripts/base/main.js b/YLErpWeb/wwwroot/Scripts/base/main.js index c4ba78a0..23038a02 100644 --- a/YLErpWeb/wwwroot/Scripts/base/main.js +++ b/YLErpWeb/wwwroot/Scripts/base/main.js @@ -1,29 +1,35 @@ //依赖类库:lodash.js + jquery + jquery.validate + bootstrap.emodal.js // 统一调试日志工具:仅在 otcdebug 开启时输出,默认静默(生产零噪音)。 -// 开启方式:URL 加 ?otcdebug=1,或控制台 localStorage.setItem('otcdebug','1')。 -// 业务脚本逐步改用 otcDebug.banner / otcDebug.log 替代裸 console.log, -// 既能在排查时一键全开,又能避免版本标记散落硬编码(见 swapTradeEdit.js / fastVue.base.js 用法)。 +// 开启:URL 加 ?otcdebug=1(会自动写入 localStorage,同源 iframe/弹窗自动继承); +// 或控制台 localStorage.setItem('otcdebug','1')。关闭:localStorage.removeItem('otcdebug')。 +// 业务脚本用 otcDebug.banner / otcDebug.log 替代裸 console.log(见 swapTradeEdit.js / fastVue.base.js)。 // -// ⚠️ 双源读取:优先用 _MainLayout 灌入的 ylotc.__diag(含 jsVersion/git/built 元数据); -// 若 layout 未灌入(如 _InfoLayout / TradeEdit 页面),则从 URL/localStorage 直接读 debug 开关, -// 确保 ?otcdebug=1 在所有页面生效,不因 layout 差异而哑火。(2026-07-30 修复) -var __otcDiag = (window.ylotc && window.ylotc.__diag && window.ylotc.__diag.debug !== undefined) - ? window.ylotc.__diag - : { - debug: /[?&]otcdebug=1/.test(location.search) || (function () { try { return localStorage.getItem('otcdebug') === '1'; } catch (e) { return false; } })() - }; +// 命名约定(避免 __私有对象 + otcDebug.API 大小写混搭): +// __diag —— 版本元数据对象(仅 _MainLayout 灌入 ylotc.__diag 时存在,仅供 banner 展示,不参与开关判定) +// __debug —— 调试开关布尔值(唯一真相来源:localStorage 优先 → URL 参数 → 兜底 __diag.debug) +var __diag = (window.ylotc && window.ylotc.__diag) || {}; +var __debug = (function () { + try { + // 1) URL 参数优先(排查最直观);命中即写入 localStorage,供同源 iframe/弹窗继承 + if (/[?&]otcdebug=1/.test(location.search)) { localStorage.setItem('otcdebug', '1'); return true; } + // 2) 已持久化的开关(父页面开过一次,_InfoLayout 弹窗自动生效) + if (localStorage.getItem('otcdebug') === '1') return true; + } catch (e) { /* localStorage 不可用时忽略,继续走兜底 */ } + // 3) 兜底:layout 灌入的 ylotc.__diag.debug(仅 _MainLayout 有) + return !!__diag.debug; +})(); window.otcDebug = { - // 模块加载横幅:F12 一眼看到模块名+bundle版本+git sha,用于排查"是不是加载了旧代码/旧缓存" + // 模块加载横幅:F12 一眼看到模块名+版本,用于排查"是不是加载了旧代码/旧缓存" banner: function (name, ver) { - if (!__otcDiag.debug || !window.console) return; - var git = (__otcDiag.git || '').slice(0, 7); - console.log('%c[' + name + '] v' + ver + ' (bundle=' + __otcDiag.jsVersion + ', git=' + git + ', built=' + __otcDiag.built + ')', + if (!__debug || !window.console) return; + var git = (__diag.git || '').slice(0, 7); + console.log('%c[' + name + '] v' + ver + ' (bundle=' + __diag.jsVersion + ', git=' + git + ', built=' + __diag.built + ')', 'color:#06c;font-weight:bold'); }, // 普通调试日志:透传参数,仅 debug 开启时输出 log: function () { - if (!__otcDiag.debug || !window.console) return; + if (!__debug || !window.console) return; console.log.apply(console, arguments); } };