main.ts
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router/index.ts'
// import { setupCommonUI } from '@venus/common-ui'
import { registerMicroApps, start, initGlobalState } from 'qiankun'
import appsManifest from './mfe/apps.json'
import pinia from './stores'
import { useAuthStore } from './stores/auth'
// import { usePermissionStore } from './stores/permission'
const app = createApp(App)
app.use(pinia)
app.use(router)
// setupCommonUI(app)
app.mount('#app')
// ------- qiankun 集成与全局状态通信 -------
const actions = initGlobalState({
user: { name: 'BaseUser' },
msg: '',
})
;(window as any).__QIANKUN_ACTIONS__ = actions
// 同步全局状态到 Pinia(在组件外使用 store,需要显式传入 pinia 实例)
const auth = useAuthStore(pinia)
// const perm = usePermissionStore(pinia)
actions.onGlobalStateChange((s: any) => {
auth.setFromGlobal(s.user, s.token)
// perm.setupByRoles(s.user?.roles || [])
}, true)
registerMicroApps(
appsManifest.apps.map((m) => ({
name: m.name,
entry: m.entry,
container: m.container,
// 按路由匹配激活,容器将在路由页面渲染后可用
activeRule: (location) => location.pathname.startsWith(m.route),
// 注入渲染所需的全局 actions
props: { actions: (window as any).__QIANKUN_ACTIONS__ },
}))
)
router.isReady().then(() => {
// 开发阶段关闭 sandbox,但开启资源预取以加快首次进入
start({
sandbox: false,
prefetch: true,
})
})