fix(lang): 修复页面未初始化时获取语言失败的问题

1.  兼容_page不存在的场景,优先使用common语言包
2.  优化路由路径获取逻辑,支持$page.path作为备选
3.  避免深拷贝污染语言包缓存,仅在langPath有效时加载页面包
This commit is contained in:
2026-06-16 16:53:31 +08:00
parent e51c03235f
commit efd7cdb8d7

View File

@@ -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 缓存