fix: 适配多平台语言包加载逻辑,优化首屏渲染

调整语言包加载时机,区分H5和小程序/鸿蒙平台:
H5 remote-only模式下先await Lang.boot()再挂载Vue避免首屏raw key
小程序/鸿蒙平台同步注册App,Lang.boot()放到App.onLaunch异步执行不阻塞挂载
移除了无用的加载语言包错误日志注释
This commit is contained in:
2026-06-30 14:30:22 +08:00
parent de4314ec9b
commit 07c38c1b1b
2 changed files with 14 additions and 3 deletions

View File

@@ -528,7 +528,6 @@ function loadLangPackSync(lang, path) {
loadedLangPacks[`${lang}_${path}`] = langData;
return langData;
} catch (error) {
// console.error(`加载语言包 ${lang}/${path} 失败:`, error);
return {};
}
}

16
main.js
View File

@@ -55,10 +55,14 @@ uniStorage();
// 组件已改为按需引入,不再全局注册
// H5 平台: remote-only 下先 await Lang.boot() 再挂载 Vue,避免首屏 raw key
// 小程序/鸿蒙: 同步注册 App,Lang.boot() 在 App.onLaunch 中异步执行(不阻塞挂载)
// 原因: 小程序/鸿蒙的 App() 必须同步注册,async bootstrap 会导致 App 注册延迟,白屏
// #ifdef H5
async function bootstrap() {
const isRemoteOnly = langConfig && langConfig.source === 'remote-only';
if (isRemoteOnly) {
// remote-only 模式下必须等 bundle 就绪后再挂载 Vue,避免首屏组件在翻译就绪前渲染
let _hideLoading = false;
try {
uni.showLoading({ title: '加载中...', mask: true });
@@ -81,5 +85,13 @@ async function bootstrap() {
});
app.$mount();
}
bootstrap()
// #endif
bootstrap()
// #ifndef H5
const app = new Vue({
...App,
store
});
app.$mount();
// #endif