电站专题引入更改
This commit is contained in:
parent
43fc39451f
commit
2ed06cc2d5
@ -44,6 +44,7 @@ import { useMapViewStore } from '@/modules/map/stores/map-view.store';
|
|||||||
import { getModuleComponent } from './moduleMap';
|
import { getModuleComponent } from './moduleMap';
|
||||||
import { LAYOUT_GRID_SKELETONS } from './layoutGridSkeletons';
|
import { LAYOUT_GRID_SKELETONS } from './layoutGridSkeletons';
|
||||||
import { setMapLegendPos } from '@/components/gis/gisUtils';
|
import { setMapLegendPos } from '@/components/gis/gisUtils';
|
||||||
|
// import add from '@/modules'
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'DianZhanZhuanTi'
|
name: 'DianZhanZhuanTi'
|
||||||
});
|
});
|
||||||
@ -243,11 +244,50 @@ function switchToVector() {
|
|||||||
mapViewStore.setActiveBaseLayerKey('s_province_boundaries');
|
mapViewStore.setActiveBaseLayerKey('s_province_boundaries');
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
// ==================== 模块组件解析 ====================
|
||||||
|
// 后端返回的 code 格式不固定(如 dianzhanzhuantiMod/ShuiDianZhanJieShao/、
|
||||||
|
// ../../modules/xxx/index.vue、@/modules/xxx/index.vue 等),统一归一化后再匹配。
|
||||||
|
// 构建时用 import.meta.glob 静态收集 @/modules 下所有 index.vue,线上打包后仍可正常按需加载
|
||||||
|
// (不能用运行时字符串 import(url),Vite 无法静态分析,打包后浏览器会直接请求 .vue 源文件导致失败)
|
||||||
|
const moduleLoaders = import.meta.glob('@/modules/**/index.vue');
|
||||||
|
|
||||||
|
/** 将各种来源的模块路径归一化为统一格式:modules/xxx/index.vue */
|
||||||
|
function canonicalModulePath(p: string): string {
|
||||||
|
let s = p
|
||||||
|
.replace(/^@\//, '')
|
||||||
|
.replace(/^\.\.\/\.\.\//, '')
|
||||||
|
.replace(/^\.\//, '')
|
||||||
|
.replace(/^\//, '')
|
||||||
|
.replace(/^src\//, '')
|
||||||
|
.replace(/\/+$/, '');
|
||||||
|
if (!s.startsWith('modules/')) s = `modules/${s}`;
|
||||||
|
if (!s.endsWith('.vue')) s = `${s}/index.vue`;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 归一化路径 → 加载器索引(只构建一次) */
|
||||||
|
const moduleLoaderIndex = new Map<string, () => Promise<unknown>>();
|
||||||
|
Object.entries(moduleLoaders).forEach(([key, loader]) => {
|
||||||
|
moduleLoaderIndex.set(canonicalModulePath(key), loader);
|
||||||
|
});
|
||||||
|
|
||||||
//处理返回来的路径(按 code 缓存组件,避免每次渲染都新建导致面板反复卸载重挂载)
|
//处理返回来的路径(按 code 缓存组件,避免每次渲染都新建导致面板反复卸载重挂载)
|
||||||
const moduleComponentCache = new Map<string, any>();
|
const moduleComponentCache = new Map<string, any>();
|
||||||
const getModuleComponenturl = (url: string) => {
|
const getModuleComponenturl = (url: string) => {
|
||||||
if (!moduleComponentCache.has(url)) {
|
if (!moduleComponentCache.has(url)) {
|
||||||
moduleComponentCache.set(url, defineAsyncComponent(() => import(url)));
|
// 优先取构建期静态收集的模块组件;未命中再回退 moduleMap 的手工映射
|
||||||
|
const loader = moduleLoaderIndex.get(canonicalModulePath(url));
|
||||||
|
const mapped = getModuleComponent(url);
|
||||||
|
moduleComponentCache.set(
|
||||||
|
url,
|
||||||
|
loader
|
||||||
|
? defineAsyncComponent(loader)
|
||||||
|
: mapped
|
||||||
|
? mapped
|
||||||
|
: defineAsyncComponent(() =>
|
||||||
|
Promise.reject(new Error(`未找到模块组件: ${url}`))
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return moduleComponentCache.get(url);
|
return moduleComponentCache.get(url);
|
||||||
};
|
};
|
||||||
@ -300,6 +340,7 @@ watch(
|
|||||||
(items || []).forEach((item: any) => {
|
(items || []).forEach((item: any) => {
|
||||||
if (item.code) map[item.code] = getModuleComponenturl(item.code);
|
if (item.code) map[item.code] = getModuleComponenturl(item.code);
|
||||||
});
|
});
|
||||||
|
console.log('panelComponents', map)
|
||||||
panelComponents.value = map;
|
panelComponents.value = map;
|
||||||
},
|
},
|
||||||
{ deep: true }
|
{ deep: true }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user