- 业务源码统一迁入 src/,H5 模板移到 public/index.html - 新增 @vue/cli 4.5 + @dcloudio 2.0.2-5020620260917001 全套依赖与 scripts - 保留 vue.config.js 的 ROUTES 注入(uni-simple-router 运行时依赖) - 新增 scripts/node-compat.cjs 兼容 Node 23+ 移除的 util.isRegExp 等 API - README 补充构建/运行/回退说明
125 lines
4.0 KiB
JavaScript
125 lines
4.0 KiB
JavaScript
import Vue from 'vue'
|
||
import App from './App'
|
||
import core from "@/core";
|
||
|
||
// 引入全局uView
|
||
import uView from '@/uni_modules/uview-ui'
|
||
|
||
import mixin from './common/mixin'
|
||
import {
|
||
router,
|
||
RouterMount
|
||
} from "@/core/router";
|
||
import store from "@/core/store";
|
||
|
||
Vue.config.productionTip = false
|
||
App.mpType = 'app'
|
||
|
||
// 插件安装
|
||
Vue.use(uView)
|
||
Vue.use(router)
|
||
Vue.use(core)
|
||
|
||
const app = new Vue({
|
||
store,
|
||
...App
|
||
});
|
||
|
||
// 应用启动逻辑
|
||
async function initializeApp() {
|
||
try {
|
||
console.log('[App] 启动初始化...')
|
||
|
||
// 1. 必须先初始化设置模块(广播模块依赖它)
|
||
await store.dispatch('setting/initSettings');
|
||
console.log('[App] 设置模块初始化完成')
|
||
|
||
// 2. 初始化广播模块(它会自动读取setting模块的配置)
|
||
await store.dispatch('broadcast/init');
|
||
console.log('[App] 广播模块初始化完成')
|
||
|
||
await store.dispatch("bluetoothPrint/initializeBluetooth");
|
||
// 3. 初始化安卓消息窗口模块(APP环境)
|
||
await initializeFloatWindow();
|
||
|
||
// 4. 挂载路由和App
|
||
RouterMount(app, router, "#app");
|
||
console.log('[App] 应用启动完成')
|
||
|
||
} catch (error) {
|
||
console.error('[App] 启动失败:', error)
|
||
// 错误处理:可以显示错误页面或降级处理
|
||
// app.$router.push('/error') 或使用其他方式通知用户
|
||
}
|
||
}
|
||
|
||
// 初始化浮窗函数
|
||
async function initializeFloatWindow() {
|
||
return new Promise((resolve) => {
|
||
// #ifdef APP-PLUS
|
||
console.log('[App] 开始初始化浮窗模块')
|
||
|
||
// 检查 plus 对象是否就绪
|
||
if (typeof plus !== 'undefined' && plus.nativeObj) {
|
||
// plus 对象已就绪,立即初始化
|
||
store.dispatch('floatWindowManager/initialize')
|
||
.then(() => {
|
||
console.log('[App] 浮窗模块初始化完成')
|
||
resolve(true);
|
||
})
|
||
.catch((error) => {
|
||
console.warn('[App] 浮窗模块初始化失败:', error)
|
||
resolve(false); // 浮窗初始化失败不应阻止应用启动
|
||
});
|
||
} else {
|
||
// plus 对象未就绪,延迟初始化
|
||
console.log('[App] plus对象未就绪,延迟初始化浮窗')
|
||
|
||
const maxAttempts = 10;
|
||
let attempts = 0;
|
||
|
||
const checkPlusReady = setInterval(() => {
|
||
attempts++;
|
||
|
||
if (typeof plus !== 'undefined' && plus.nativeObj) {
|
||
clearInterval(checkPlusReady);
|
||
|
||
store.dispatch('floatWindowManager/initialize')
|
||
.then(() => {
|
||
console.log('[App] 浮窗模块初始化完成')
|
||
resolve(true);
|
||
})
|
||
.catch((error) => {
|
||
console.warn('[App] 浮窗模块初始化失败:', error)
|
||
resolve(false);
|
||
});
|
||
} else if (attempts >= maxAttempts) {
|
||
clearInterval(checkPlusReady);
|
||
console.warn('[App] plus对象等待超时,跳过浮窗初始化')
|
||
resolve(false);
|
||
} else {
|
||
console.log(`[App] 等待plus对象... (${attempts}/${maxAttempts})`)
|
||
}
|
||
}, 300); // 每300ms检查一次
|
||
}
|
||
|
||
// #endif
|
||
|
||
// #ifndef APP-PLUS
|
||
console.log('[App] 非APP环境,跳过浮窗初始化')
|
||
resolve(true); // 非APP环境直接返回成功
|
||
// #endif
|
||
});
|
||
}
|
||
|
||
// #ifdef MP
|
||
// 引入uView对小程序分享的mixin封装
|
||
const mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js')
|
||
Vue.mixin(mpShare)
|
||
// #endif
|
||
|
||
Vue.mixin(mixin)
|
||
|
||
// 启动应用
|
||
initializeApp();
|
||
app.$mount(); |