From efd7cdb8d72b65f2a39ee6b415ef803f498a1449 Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Tue, 16 Jun 2026 16:53:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(lang):=20=E4=BF=AE=E5=A4=8D=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E8=AF=AD=E8=A8=80=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 兼容_page不存在的场景,优先使用common语言包 2. 优化路由路径获取逻辑,支持$page.path作为备选 3. 避免深拷贝污染语言包缓存,仅在langPath有效时加载页面包 --- common/js/lang.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/common/js/lang.js b/common/js/lang.js index 7029c04..f8bb9a3 100644 --- a/common/js/lang.js +++ b/common/js/lang.js @@ -494,7 +494,6 @@ export default { _langRecursionDepth++; try { let _page = getCurrentPages()[getCurrentPages().length - 1]; - if (!_page) return typeof field === 'string' ? field : String(field || ''); const locale = getCurrentLocale(); @@ -505,11 +504,15 @@ export default { var lang = loadLangPackSync(locale, 'common'); //当前页面语言包(同步加载) - let route = _page.route; - langPath = processRoutePath(route); + // 关键修复:不依赖 _page 是否存在,页面未完全初始化时至少能使用 common 语言包 + let route = ''; + if (_page) { + route = _page.route || (_page.$page && _page.$page.path) || ''; + } + langPath = route ? processRoutePath(route) : ''; - // 加载当前页面语言包 - let currentPageLang = loadLangPackSync(locale, langPath); + // 加载当前页面语言包,langPath 为空时返回空对象(只使用 common) + let currentPageLang = langPath ? loadLangPackSync(locale, langPath) : {}; // 合并语言包 + 远端 KV 覆写 // 关键修复:使用深复制代替 Object.assign,避免 applyOverrides 污染 loadedLangPacks 缓存