mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
fix: 同步时出现特殊key时, 加载进度始终显示, 且无法继续解析后续内容
perf: 大量使用相同组件时, 提升createComponent性能
This commit is contained in:
parent
95b50c7d76
commit
51ba52ae45
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,4 +3,6 @@ node_modules
|
|||||||
dist
|
dist
|
||||||
dist-ssr
|
dist-ssr
|
||||||
*.local
|
*.local
|
||||||
|
pnpm-lock.yaml
|
||||||
.vscode
|
.vscode
|
||||||
|
.idea
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { ChartList } from '@/packages/components/Charts/index'
|
import {ChartList} from '@/packages/components/Charts/index'
|
||||||
import { DecorateList } from '@/packages/components/Decorates/index'
|
import {DecorateList} from '@/packages/components/Decorates/index'
|
||||||
import { InformationList } from '@/packages/components/Informations/index'
|
import {InformationList} from '@/packages/components/Informations/index'
|
||||||
import { TableList } from '@/packages/components/Tables/index'
|
import {TableList} from '@/packages/components/Tables/index'
|
||||||
import { PhotoList } from '@/packages/components/Photos/index'
|
import {PhotoList} from '@/packages/components/Photos/index'
|
||||||
import { IconList } from '@/packages/components/Icons/index'
|
import {IconList} from '@/packages/components/Icons/index'
|
||||||
import { PackagesCategoryEnum, PackagesType, ConfigType, FetchComFlagType } from '@/packages/index.d'
|
import { PackagesCategoryEnum, PackagesType, ConfigType, FetchComFlagType } from '@/packages/index.d'
|
||||||
|
|
||||||
const configModules: Record<string, { default: string }> = import.meta.glob('./components/**/config.vue', {
|
const configModules: Record<string, { default: string }> = import.meta.glob('./components/**/config.vue', {
|
||||||
@ -26,6 +26,16 @@ export let packagesList: PackagesType = {
|
|||||||
[PackagesCategoryEnum.ICONS]: IconList
|
[PackagesCategoryEnum.ICONS]: IconList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 组件缓存, 可以大幅度提升组件加载速度
|
||||||
|
const componentCacheMap = new Map<string, any>()
|
||||||
|
const loadConfig = (packageName: string, categoryName: string, keyName: string) => {
|
||||||
|
const key = packageName + categoryName + keyName
|
||||||
|
if (!componentCacheMap.has(key)) {
|
||||||
|
componentCacheMap.set(key, import(`./components/${packageName}/${categoryName}/${keyName}/config.ts`))
|
||||||
|
}
|
||||||
|
return componentCacheMap.get(key)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 获取目标组件配置信息
|
* * 获取目标组件配置信息
|
||||||
* @param targetData
|
* @param targetData
|
||||||
@ -35,10 +45,10 @@ export const createComponent = async (targetData: ConfigType) => {
|
|||||||
// redirectComponent 是给图片组件库和图标组件库使用的
|
// redirectComponent 是给图片组件库和图标组件库使用的
|
||||||
if (redirectComponent) {
|
if (redirectComponent) {
|
||||||
const [packageName, categoryName, keyName] = redirectComponent.split('/')
|
const [packageName, categoryName, keyName] = redirectComponent.split('/')
|
||||||
const redirectChart = await import(`./components/${packageName}/${categoryName}/${keyName}/config.ts`)
|
const redirectChart = await loadConfig(packageName, categoryName, keyName)
|
||||||
return new redirectChart.default()
|
return new redirectChart.default()
|
||||||
}
|
}
|
||||||
const chart = await import(`./components/${targetData.package}/${category}/${key}/config.ts`)
|
const chart = await loadConfig(targetData.package, category, key)
|
||||||
return new chart.default()
|
return new chart.default()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +72,7 @@ const fetchComponent = (chartName: string, flag: FetchComFlagType) => {
|
|||||||
* @param {ConfigType} dropData 配置项
|
* @param {ConfigType} dropData 配置项
|
||||||
*/
|
*/
|
||||||
export const fetchChartComponent = (dropData: ConfigType) => {
|
export const fetchChartComponent = (dropData: ConfigType) => {
|
||||||
const { key } = dropData
|
const {key} = dropData
|
||||||
return fetchComponent(key, FetchComFlagType.VIEW)?.default
|
return fetchComponent(key, FetchComFlagType.VIEW)?.default
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +81,7 @@ export const fetchChartComponent = (dropData: ConfigType) => {
|
|||||||
* @param {ConfigType} dropData 配置项
|
* @param {ConfigType} dropData 配置项
|
||||||
*/
|
*/
|
||||||
export const fetchConfigComponent = (dropData: ConfigType) => {
|
export const fetchConfigComponent = (dropData: ConfigType) => {
|
||||||
const { key } = dropData
|
const {key} = dropData
|
||||||
return fetchComponent(key, FetchComFlagType.CONFIG)?.default
|
return fetchComponent(key, FetchComFlagType.CONFIG)?.default
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +94,10 @@ export const fetchImages = async (targetData?: ConfigType) => {
|
|||||||
// 正则判断图片是否为 url,是则直接返回该 url
|
// 正则判断图片是否为 url,是则直接返回该 url
|
||||||
if (/^(http|https):\/\/([\w.]+\/?)\S*/.test(targetData.image)) return targetData.image
|
if (/^(http|https):\/\/([\w.]+\/?)\S*/.test(targetData.image)) return targetData.image
|
||||||
// 新数据动态处理
|
// 新数据动态处理
|
||||||
const { image, package: targetDataPackage } = targetData
|
const {
|
||||||
|
image,
|
||||||
|
package: targetDataPackage
|
||||||
|
} = targetData
|
||||||
// 兼容旧数据
|
// 兼容旧数据
|
||||||
if (image.includes('@') || image.includes('base64')) return image
|
if (image.includes('@') || image.includes('base64')) return image
|
||||||
|
|
||||||
|
@ -196,9 +196,7 @@ export const useSync = () => {
|
|||||||
chartHistoryStore.clearForwardStack()
|
chartHistoryStore.clearForwardStack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (key === ChartEditStoreEnum.EDIT_CANVAS_CONFIG || key === ChartEditStoreEnum.REQUEST_GLOBAL_CONFIG) {
|
||||||
// 非组件(顺便排除脏数据)
|
|
||||||
if (key !== 'editCanvasConfig' && key !== 'requestGlobalConfig') return
|
|
||||||
componentMerge(chartEditStore[key], projectData[key], true)
|
componentMerge(chartEditStore[key], projectData[key], true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user