|
|
@@ -1,61 +0,0 @@
|
|
|
-import WujieVue from 'wujie-vue3'
|
|
|
-import { isMicro } from '@/utils/micro'
|
|
|
-import { microList } from '@/config/mainMicro'
|
|
|
-import { useUserStore } from '@/stores/user'
|
|
|
-import router from '@/router'
|
|
|
-import type { App } from 'vue'
|
|
|
-
|
|
|
-export const useMainMicro = (microName?: string) => {
|
|
|
- const getMicroByName = (name: string) => {
|
|
|
- return microList.find(item => item.name === name)
|
|
|
- }
|
|
|
- const micro = getMicroByName(microName || '')
|
|
|
-
|
|
|
- const initWatch = () => {
|
|
|
- const route = useRoute()
|
|
|
- watch(
|
|
|
- () => route.path,
|
|
|
- () => {
|
|
|
- WujieVue.bus.$emit(microName + '-router-change', route.path)
|
|
|
- },
|
|
|
- {
|
|
|
- immediate: true
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- // 主服务初始化微服务
|
|
|
- const initMicro = (app: App) => {
|
|
|
- if (!isMicro) {
|
|
|
- const { setupApp, preloadApp, bus } = WujieVue
|
|
|
-
|
|
|
- microList.forEach((item: any) => {
|
|
|
- setupApp(item)
|
|
|
- preloadApp({ name: item.name, url: item.url })
|
|
|
- })
|
|
|
-
|
|
|
- // 在 xxx-sub 路由下子应用将激活路由同步给主应用,主应用跳转对应路由高亮菜单栏
|
|
|
- bus.$on('sub-route-change', (name: string, path: string) => {
|
|
|
- const mainPath = `/${name}${path}`
|
|
|
- const currentName = router.currentRoute.value.name
|
|
|
- const currentPath = router.currentRoute.value.path
|
|
|
- if (name === currentName && mainPath !== currentPath) {
|
|
|
- router.push({ path: mainPath })
|
|
|
- }
|
|
|
- })
|
|
|
- // 监听退出登录
|
|
|
- bus.$on('logout', () => {
|
|
|
- const userStore = useUserStore()
|
|
|
- userStore.logout()
|
|
|
- })
|
|
|
-
|
|
|
- app.use(WujieVue)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- micro,
|
|
|
- initWatch,
|
|
|
- initMicro
|
|
|
- }
|
|
|
-}
|