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); } };