电站专题引入更改

This commit is contained in:
王兴凯 2026-08-27 13:44:10 +08:00
parent 43fc39451f
commit 2ed06cc2d5

View File

@ -44,6 +44,7 @@ import { useMapViewStore } from '@/modules/map/stores/map-view.store';
import { getModuleComponent } from './moduleMap';
import { LAYOUT_GRID_SKELETONS } from './layoutGridSkeletons';
import { setMapLegendPos } from '@/components/gis/gisUtils';
// import add from '@/modules'
defineOptions({
name: 'DianZhanZhuanTi'
});
@ -243,11 +244,50 @@ function switchToVector() {
mapViewStore.setActiveBaseLayerKey('s_province_boundaries');
} 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
const moduleComponentCache = new Map<string, any>();
const getModuleComponenturl = (url: string) => {
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);
};
@ -300,6 +340,7 @@ watch(
(items || []).forEach((item: any) => {
if (item.code) map[item.code] = getModuleComponenturl(item.code);
});
console.log('panelComponents', map)
panelComponents.value = map;
},
{ deep: true }