调整语言包加载时机,区分H5和小程序/鸿蒙平台: H5 remote-only模式下先await Lang.boot()再挂载Vue避免首屏raw key 小程序/鸿蒙平台同步注册App,Lang.boot()放到App.onLaunch异步执行不阻塞挂载 移除了无用的加载语言包错误日志注释
97 lines
2.5 KiB
JavaScript
97 lines
2.5 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, { 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; //解析语言包
|
|
|
|
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 平台: 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) {
|
|
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
|
|
const app = new Vue({
|
|
...App,
|
|
store
|
|
});
|
|
app.$mount();
|
|
// #endif
|