refactor(i18n): 完善remote-only模式下的首屏渲染和请求门控

1. 补充getCachedBundle的注释说明TTL过期缓存返回null
2. 修复globalConfig中onShow的重复判断逻辑,增加boot完成检查
3. 给http请求增加remote-only模式下的boot门控,等待国际化就绪后再发送业务请求
4. 重构main.js的平台差异化处理逻辑,统一各端初始化流程
5. 优化App.vue的boot流程,为小程序/鸿蒙增加加载遮罩
6. 新增bootCompleted状态标志和并发去重机制,完善lang.js的remote-only适配逻辑
7. 补充lang()方法在boot未完成时返回空串的逻辑,避免首屏raw key
This commit is contained in:
2026-06-30 15:29:45 +08:00
parent 07c38c1b1b
commit eef59211d3
6 changed files with 152 additions and 44 deletions

44
main.js
View File

@@ -14,18 +14,18 @@ import globalConfig from './common/js/golbalConfig.js';
import {
uniStorage
} from './common/js/storage.js'
import configExternal, { langConfig } from './common/js/config-external.js'
Vue.prototype.$store = store //挂在vue
Vue.config.productionTip = false
Vue.prototype.$util = Util;
Vue.prototype.$api = Http;
Vue.prototype.$langConfig = Lang; //语言包对象
Vue.prototype.$lang = Lang.lang; //解析语言包
import configExternal from './common/js/config-external.js'
Vue.prototype.$store = store //挂在vue
Vue.config.productionTip = false
Vue.prototype.$util = Util;
Vue.prototype.$api = Http;
Vue.prototype.$langConfig = Lang; //语言包对象
Vue.prototype.$lang = Lang.lang; //解析语言包
Vue.prototype.$config = Config;
@@ -55,14 +55,22 @@ uniStorage();
// 组件已改为按需引入,不再全局注册
// H5 平台: remote-only 下先 await Lang.boot() 再挂载 Vue,避免首屏 raw key
// 小程序/鸿蒙: 同步注册 App,Lang.boot() 在 App.onLaunch 中异步执行(不阻塞挂载)
// 原因: 小程序/鸿蒙的 App() 必须同步注册,async bootstrap 会导致 App 注册延迟,白屏
// ============================================================
// 平台差异处理:
// H5: 可在 $mount() 前 await boot, 首屏直接有翻译
// 小程序/鸿蒙: App() 必须同步注册, $mount() 不能推迟
// → 同步 $mount() + lang() 短路返回空串 + boot 完成后 $forceUpdate
//
// 以下代码所有平台共享:
// - lang.js: bootCompleted 标志, boot 未完成时 lang() 返回空串
// - http.js: sendRequest 门控, boot 未完成时业务请求排队
// - App.vue: onLaunch 中 showLoading + await boot + hideLoading
// ============================================================
// #ifdef H5
// H5: remote-only 下先 await boot 再 $mount(), 首屏直接有翻译数据
async function bootstrap() {
const isRemoteOnly = langConfig && langConfig.source === 'remote-only';
if (isRemoteOnly) {
if (Lang.isRemoteOnly && Lang.isRemoteOnly()) {
let _hideLoading = false;
try {
uni.showLoading({ title: '加载中...', mask: true });
@@ -89,6 +97,8 @@ bootstrap()
// #endif
// #ifndef H5
// 小程序/鸿蒙: 同步 $mount(), boot 在 App.vue onLaunch 中异步执行
// lang() 在 boot 未完成时返回空串, boot 完成后 emitUpdated 触发 $forceUpdate
const app = new Vue({
...App,
store