??????????????????????????????? H5/????? Co-authored-by: Cursor <cursoragent@cursor.com>
125 lines
3.2 KiB
TypeScript
125 lines
3.2 KiB
TypeScript
import { createApp } from 'vue';
|
||
import ArcoVue from '@arco-design/web-vue';
|
||
import ArcoVueIcon from '@arco-design/web-vue/es/icon';
|
||
// eslint-disable-next-line import/no-unresolved
|
||
import 'uno.css';
|
||
import router from './router';
|
||
import store, { useAppStore } from './store';
|
||
import i18n, { initPreferredLocale, ensureFullLocaleMessages } from './locale';
|
||
import directive from './directive';
|
||
import globalProperties from './plugins/globalProperties';
|
||
import {
|
||
bindHeavyPluginsContext,
|
||
ensureHeavyPlugins,
|
||
} from './plugins/heavy-plugins';
|
||
import { initAuthKeepAlive } from '@/utils/auth-keepalive';
|
||
import { installWeChatH5HistoryGuard } from '@/utils/device';
|
||
import { setAuthToken } from './api/rbac';
|
||
import { applyThemeColor } from '@/utils/themeColor';
|
||
import { useRbacUserStore } from '@/store/modules/rbac-user';
|
||
import { applyRbacUserToUserStore } from '@/utils/enter-system';
|
||
import App from './App.vue';
|
||
import '@/assets/style/global.less';
|
||
|
||
if (import.meta.env.DEV) {
|
||
void import('./mock');
|
||
}
|
||
|
||
/** Login / public pages: no EP/VXE on critical path */
|
||
const LIGHT_ENTRY_PATHS = [
|
||
'/',
|
||
'/admin',
|
||
'/login',
|
||
'/register',
|
||
'/track/query',
|
||
'/wechat/register',
|
||
'/wechat/bind',
|
||
'/h5',
|
||
];
|
||
|
||
/** Home uses Arco (+ optional echarts); do not block on EP/VXE */
|
||
function isHomePath(path: string) {
|
||
return path === '/home' || path.startsWith('/home/');
|
||
}
|
||
|
||
function isLightEntry(path: string) {
|
||
const normalized = path.split('?')[0] || '/';
|
||
return LIGHT_ENTRY_PATHS.some(
|
||
(p) => normalized === p || normalized.startsWith(`${p}/`),
|
||
);
|
||
}
|
||
|
||
function routeNeedsHeavyPlugins(path: string) {
|
||
const normalized = path.split('?')[0] || '/';
|
||
if (isLightEntry(normalized) || isHomePath(normalized)) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
const app = createApp(App);
|
||
|
||
app.use(ArcoVue, {});
|
||
app.use(ArcoVueIcon);
|
||
app.use(router);
|
||
app.use(store);
|
||
applyThemeColor(useAppStore().themeColor);
|
||
app.use(i18n);
|
||
app.use(directive);
|
||
app.use(globalProperties);
|
||
|
||
bindHeavyPluginsContext(app, i18n);
|
||
|
||
const rbacAccessToken =
|
||
localStorage.getItem('rbac_access_token') ||
|
||
localStorage.getItem('rbac_token');
|
||
if (rbacAccessToken) {
|
||
setAuthToken(rbacAccessToken);
|
||
}
|
||
|
||
router.beforeEach(async (to) => {
|
||
if (!isLightEntry(to.path)) {
|
||
void ensureFullLocaleMessages();
|
||
}
|
||
if (routeNeedsHeavyPlugins(to.path)) {
|
||
await ensureHeavyPlugins();
|
||
}
|
||
});
|
||
|
||
async function bootstrap() {
|
||
const entryPath =
|
||
typeof window !== 'undefined' ? window.location.pathname : '/';
|
||
const light = isLightEntry(entryPath);
|
||
|
||
const rbacUserStore = useRbacUserStore();
|
||
// F5:本地身份先灌进 userStore;缺 menus 时与 i18n 并行预取
|
||
if (rbacUserStore.isLoggedIn && rbacUserStore.userInfo?.id) {
|
||
applyRbacUserToUserStore(rbacUserStore.userInfo);
|
||
}
|
||
if (!light) {
|
||
rbacUserStore.prefetchCurrentUser();
|
||
}
|
||
|
||
await initPreferredLocale();
|
||
|
||
// Business / home refresh: need full i18n before paint
|
||
if (!light) {
|
||
await ensureFullLocaleMessages();
|
||
}
|
||
|
||
if (routeNeedsHeavyPlugins(entryPath)) {
|
||
await ensureHeavyPlugins();
|
||
}
|
||
|
||
app.mount('#app');
|
||
;(window as any).__APP_MOUNTED__ = true;
|
||
installWeChatH5HistoryGuard(router);
|
||
initAuthKeepAlive();
|
||
|
||
if (light || isHomePath(entryPath)) {
|
||
void ensureHeavyPlugins();
|
||
}
|
||
}
|
||
|
||
void bootstrap();
|