This commit is contained in:
张成
2025-10-08 20:08:31 +08:00
parent b27c047930
commit 07aa8d493a
2 changed files with 32 additions and 20 deletions

View File

@@ -115,12 +115,13 @@ class AdminFramework {
* @param {Object} options.VueRouter - VueRouter 实例(可选)
* @param {Object} options.Vuex - Vuex 实例(可选)
* @param {Function} options.createPersistedState - vuex-persistedstate可选
* @param {Object} options.componentMap - 自定义组件映射表(可选)
*/
install(Vue, options = {}) {
if (this.installed) return
this.installed = true
const { config = {}, ViewUI, VueRouter, Vuex, createPersistedState } = options
const { config = {}, ViewUI, VueRouter, Vuex, createPersistedState, componentMap } = options
this.config = config
// 自动注册 ViewUI
@@ -147,8 +148,8 @@ class AdminFramework {
// 自动注册全局组件
this.registerGlobalComponents(Vue)
// 自动设置组件映射表
this.setupComponentMap()
// 自动设置组件映射表(包含外部传入的映射)
this.setupComponentMap(componentMap)
// 如果提供了 Vuex自动创建 Store
if (Vuex && !this.store) {
@@ -192,9 +193,10 @@ class AdminFramework {
/**
* 设置组件映射表(将后端返回的路径映射到实际组件)
* @param {Object} customMap - 外部传入的自定义组件映射
*/
setupComponentMap() {
// 组件列表:路径 => 组件
setupComponentMap(customMap = {}) {
// 框架内置组件列表:路径 => 组件
const components = {
'home/index': HomePage,
'system/sys_log': SysLog,
@@ -203,14 +205,17 @@ class AdminFramework {
'system/sys_user': SysUser,
'system_high/sys_control': SysControl,
'system_high/sys_menu': SysMenu,
'system_high/sys_title': SysTitle
'system_high/sys_title': SysTitle,
// 合并外部传入的组件映射
...customMap
}
// 自动生成带 .vue 和不带 .vue 的映射
const map = {}
Object.keys(components).forEach(path => {
map[path] = components[path]
map[path + '.vue'] = components[path]
const cleanPath = path.replace(/\.vue$/, '')
map[cleanPath] = components[path]
map[cleanPath + '.vue'] = components[path]
})
uiTool.setComponentMap(map)