Skip to content

Commit 2571d67

Browse files
committed
fix: 优化注册中心使用
1 parent d169c17 commit 2571d67

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/store/application.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ export const useApplication = defineStore('application', () => {
3434
// { id: 'authentication-manager', name: 'authentication-manager-ui', path: 'http://localhost:8082/'}
3535
// ]
3636
if (import.meta.env.VITE_MODULE_NAME && !isSubApp) { // 子模块编译之后独立运行时,排除自身
37-
result = result.filter((item: any) => item.name !== import.meta.env.VITE_MODULE_NAME)
37+
result = result.filter((item: any) => (item.name + '-ui') !== import.meta.env.VITE_MODULE_NAME)
3838
}
3939

4040
// 获取是否已在本地注册子模块分享出来的apis,components等
4141
for (const item of result) {
42-
if (!moduleRegistry.hasModule(item.name)) { // 没有本地模块注册,获取微前端模块进行注册
42+
const name = item.id + '-ui'
43+
if (!moduleRegistry.hasModule(name)) { // 没有本地模块注册,获取微前端模块进行注册
4344
const path = [item.path, item.path.endsWith('/') ? '' : '/', 'assets/remoteEntry.js' ].join('')
44-
await moduleRegistry.loadRemoteModule(item.name, path)
45+
await moduleRegistry.loadRemoteModule(name, path)
4546
}
4647
}
4748

src/store/menu.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import router from '@/router'
33
import {cloneDeep} from 'lodash-es'
44
import {setParamsValue} from '@jetlinks-web/hooks'
55
import {onlyMessage} from '@jetlinks-web/utils'
6-
import {handleMenus} from '@/utils'
6+
import { handleMenus, modules } from '@/utils'
77
import {getOwnMenuThree} from '@/api/system/menu'
88
import {getGlobModules} from '@/router/globModules'
99
import {getExtraRouters} from '@/router/extraMenu'
10-
import {USER_CENTER_ROUTE, INIT_HOME, EDGE_TOKEN_ROUTE} from '@/router/basic'
10+
import {USER_CENTER_ROUTE, INIT_HOME} from '@/router/basic'
1111
import {useAuthStore, useApplication} from '@/store'
12-
import { isSubApp, OWNER_KEY } from '@/utils/consts'
12+
import { OWNER_KEY } from '@/utils/consts'
1313
import i18n from "@/locales";
1414
import {BASE_API} from "@jetlinks-web/constants";
1515
import type { RouteRecordRaw } from 'vue-router'
@@ -175,10 +175,11 @@ export const useMenuStore = defineStore('menu', () => {
175175
let isLocal = false
176176

177177
if (import.meta.env.DEV) {
178-
// isLocal = Object.values(modulesFile).some(v => {
179-
// const localMenus = (v as any).default.getAsyncRoutesMap()
180-
// return localMenus[node.code]
181-
// })
178+
const modulesFiles = modules()
179+
isLocal = Object.values(modulesFiles).some(v => {
180+
const localMenus = (v as any).default.getAsyncRoutesMap()
181+
return localMenus[node.code]
182+
})
182183
}
183184

184185
if (!isLocal) {

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const federationSharedMap = {
3232
'@jetlinks-web/core': ['@jetlinks-web/core'],
3333
'@jetlinks-web/hooks': ['@jetlinks-web/hooks'],
3434
'@jetlinks-web/constants': ['@jetlinks-web/constants'],
35-
'@jetlinks-web/utils': ['@jetlinks-web/utils'],
35+
// '@jetlinks-web/utils': ['@jetlinks-web/utils'],
3636
}
3737
// https://vitejs.dev/config/
3838
export default defineConfig(({mode}) => {

0 commit comments

Comments
 (0)