import { createSSRApp } from 'vue'; import { createPinia } from 'pinia'; import App from './App.vue'; import { useUserStore } from './store/user'; // #ifdef H5 import VConsole from 'vconsole'; // #endif /** * 在 #app 之外创建启动态浮层 DOM(独立于 Vue 渲染树), * App.vue 通过 watch 控制其显示/隐藏/内容。 * * 原因:uni-app H5 的 page HOC 会吞掉 App.vue 模板里非 router-view 子节点, * 把 splash 放在 Vue 渲染树里会导致 v-if 完全不生效。 */ function ensureBootSplash() { if (typeof document === 'undefined') return; if (document.getElementById('boot-splash')) return; const div = document.createElement('div'); div.id = 'boot-splash'; div.className = 'boot-splash'; div.style.display = 'none'; document.body.appendChild(div); } // H5 平台下立即创建(其它平台不需要此浮层) // #ifdef H5 ensureBootSplash(); // #endif export function createApp() { // 再次确保(main.ts 在不同入口可能被多次调用) // #ifdef H5 ensureBootSplash(); // #endif const app = createSSRApp(App); const pinia = createPinia(); app.use(pinia); // 初始化用户状态 const userStore = useUserStore(); userStore.initUser(); // #ifdef H5 // vConsole 开启,用于调试微信支付问题 new VConsole(); // #endif return { app, pinia, }; }