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
107 lines
3.0 KiB
JavaScript
107 lines
3.0 KiB
JavaScript
// #ifdef H5
|
|
import './common/js/pc'
|
|
// #endif
|
|
import Vue from 'vue'
|
|
import App from './App'
|
|
import store from './store'
|
|
import Util from './common/js/util.js'
|
|
import Http from './common/js/http.js'
|
|
import Lang from './common/js/lang.js'
|
|
import Config from './common/js/config.js'
|
|
import EventBus from './common/js/event-bus.js'
|
|
import DomEventBridge from './common/js/dom-event-bridge.js'
|
|
import globalConfig from './common/js/golbalConfig.js';
|
|
import {
|
|
uniStorage
|
|
} from './common/js/storage.js'
|
|
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;
|
|
|
|
|
|
// #ifdef H5
|
|
EventBus.setDomBridge(DomEventBridge)
|
|
// #endif
|
|
Vue.prototype.$eventBus = EventBus;
|
|
|
|
Vue.mixin(globalConfig);
|
|
|
|
// 远端 i18n 翻译热更新:复用项目原有"componentRefresh"机制(同 diy.js 下拉刷新)
|
|
// lang.js 在翻译覆写更新时 commit('setComponentRefresh'),
|
|
// golbalConfig.js 已把 componentRefresh 注册为全局 computed,
|
|
// 在此 watch 它并 $forceUpdate,触发所有页面内 {{$lang('xxx')}} 重新求值
|
|
Vue.mixin({
|
|
watch: {
|
|
componentRefresh() {
|
|
this.$forceUpdate();
|
|
}
|
|
}
|
|
});
|
|
|
|
App.mpType = 'app';
|
|
|
|
// 重写存储,增加前缀
|
|
uniStorage();
|
|
|
|
// 组件已改为按需引入,不再全局注册
|
|
|
|
// ============================================================
|
|
// 平台差异处理:
|
|
// 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() {
|
|
if (Lang.isRemoteOnly && Lang.isRemoteOnly()) {
|
|
let _hideLoading = false;
|
|
try {
|
|
uni.showLoading({ title: '加载中...', mask: true });
|
|
_hideLoading = true;
|
|
} catch (e) {}
|
|
try {
|
|
await Lang.boot();
|
|
} catch (e) {
|
|
console.warn('[i18n] remote-only boot fail', e);
|
|
} finally {
|
|
if (_hideLoading) {
|
|
try { uni.hideLoading(); } catch (e) {}
|
|
}
|
|
}
|
|
}
|
|
|
|
const app = new Vue({
|
|
...App,
|
|
store
|
|
});
|
|
app.$mount();
|
|
}
|
|
bootstrap()
|
|
// #endif
|
|
|
|
// #ifndef H5
|
|
// 小程序/鸿蒙: 同步 $mount(), boot 在 App.vue onLaunch 中异步执行
|
|
// lang() 在 boot 未完成时返回空串, boot 完成后 emitUpdated 触发 $forceUpdate
|
|
const app = new Vue({
|
|
...App,
|
|
store
|
|
});
|
|
app.$mount();
|
|
// #endif
|