mirror of
https://gitee.com/dromara/go-view.git
synced 2025-10-14 22:42:10 +08:00
refactor: replace the deprecate api of vite
This commit is contained in:
parent
68b8809a1e
commit
413c17f4cd
@ -4,9 +4,9 @@ import { InformationList } from '@/packages/components/Informations/index'
|
|||||||
import { TableList } from '@/packages/components/Tables/index'
|
import { TableList } from '@/packages/components/Tables/index'
|
||||||
import { PackagesCategoryEnum, PackagesType, ConfigType, FetchComFlagType } from '@/packages/index.d'
|
import { PackagesCategoryEnum, PackagesType, ConfigType, FetchComFlagType } from '@/packages/index.d'
|
||||||
|
|
||||||
const configModules = import.meta.globEager('./components/**/config.vue')
|
const configModules = import.meta.glob('./components/**/config.vue')
|
||||||
const indexModules = import.meta.globEager('./components/**/index.vue')
|
const indexModules = import.meta.glob('./components/**/index.vue')
|
||||||
const imagesModules = import.meta.globEager('../assets/images/chart/**')
|
const imagesModules = import.meta.glob('../assets/images/chart/**')
|
||||||
|
|
||||||
// * 所有图表
|
// * 所有图表
|
||||||
export let packagesList: PackagesType = {
|
export let packagesList: PackagesType = {
|
||||||
@ -31,12 +31,13 @@ export const createComponent = async (targetData: ConfigType) => {
|
|||||||
* @param {string} chartName 名称
|
* @param {string} chartName 名称
|
||||||
* @param {FetchComFlagType} flag 标识 0为展示组件, 1为配置组件
|
* @param {FetchComFlagType} flag 标识 0为展示组件, 1为配置组件
|
||||||
*/
|
*/
|
||||||
const fetchComponent = (chartName: string, flag: FetchComFlagType) => {
|
const fetchComponent = async (chartName: string, flag: FetchComFlagType) => {
|
||||||
const module = flag === FetchComFlagType.VIEW ? indexModules : configModules
|
const module = flag === FetchComFlagType.VIEW ? indexModules : configModules
|
||||||
for (const key in module) {
|
for (const key in module) {
|
||||||
const urlSplit = key.split('/')
|
const urlSplit = key.split('/')
|
||||||
if (urlSplit[urlSplit.length - 2] === chartName) {
|
if (urlSplit[urlSplit.length - 2] === chartName) {
|
||||||
return module[key]
|
const loader = module[key] as () => Promise<{ default: any }>
|
||||||
|
return (await loader()).default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,18 +46,18 @@ const fetchComponent = (chartName: string, flag: FetchComFlagType) => {
|
|||||||
* * 获取展示组件
|
* * 获取展示组件
|
||||||
* @param {ConfigType} dropData 配置项
|
* @param {ConfigType} dropData 配置项
|
||||||
*/
|
*/
|
||||||
export const fetchChartComponent = (dropData: ConfigType) => {
|
export const fetchChartComponent = async (dropData: ConfigType) => {
|
||||||
const { key } = dropData
|
const { key } = dropData
|
||||||
return fetchComponent(key, FetchComFlagType.VIEW)?.default
|
return await fetchComponent(key, FetchComFlagType.VIEW)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 获取配置组件
|
* * 获取配置组件
|
||||||
* @param {ConfigType} dropData 配置项
|
* @param {ConfigType} dropData 配置项
|
||||||
*/
|
*/
|
||||||
export const fetchConfigComponent = (dropData: ConfigType) => {
|
export const fetchConfigComponent = async (dropData: ConfigType) => {
|
||||||
const { key } = dropData
|
const { key } = dropData
|
||||||
return fetchComponent(key, FetchComFlagType.CONFIG)?.default
|
return await fetchComponent(key, FetchComFlagType.CONFIG)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,7 +75,8 @@ export const fetchImages = async (targetData?: ConfigType) => {
|
|||||||
for (const key in imagesModules) {
|
for (const key in imagesModules) {
|
||||||
const urlSplit = key.split('/')
|
const urlSplit = key.split('/')
|
||||||
if (urlSplit[urlSplit.length - 1] === imageName) {
|
if (urlSplit[urlSplit.length - 1] === imageName) {
|
||||||
return imagesModules[key]?.default
|
const loader = imagesModules[key] as () => Promise<{ default: string }>
|
||||||
|
return (await loader()).default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
|
@ -68,14 +68,15 @@ const chartMode: Ref<ChartModeEnum> = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 拖拽处理
|
// 拖拽处理
|
||||||
const dragStartHandle = (e: DragEvent, item: ConfigType) => {
|
const dragStartHandle = async (e: DragEvent, item: ConfigType) => {
|
||||||
// 动态注册图表组件
|
|
||||||
componentInstall(item.chartKey, fetchChartComponent(item))
|
|
||||||
componentInstall(item.conKey, fetchConfigComponent(item))
|
|
||||||
// 将配置项绑定到拖拽属性上
|
// 将配置项绑定到拖拽属性上
|
||||||
e!.dataTransfer!.setData(DragKeyEnum.DRAG_KEY, JSONStringify(omit(item, ['image'])))
|
e!.dataTransfer!.setData(DragKeyEnum.DRAG_KEY, JSONStringify(omit(item, ['image'])))
|
||||||
// 修改状态
|
// 修改状态
|
||||||
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, true)
|
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, true)
|
||||||
|
|
||||||
|
// 动态注册图表组件
|
||||||
|
componentInstall(item.chartKey, await fetchChartComponent(item))
|
||||||
|
componentInstall(item.conKey, await fetchConfigComponent(item))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拖拽结束
|
// 拖拽结束
|
||||||
@ -88,8 +89,8 @@ const dblclickHandle = async (item: ConfigType) => {
|
|||||||
try {
|
try {
|
||||||
loadingStart()
|
loadingStart()
|
||||||
// 动态注册图表组件
|
// 动态注册图表组件
|
||||||
componentInstall(item.chartKey, fetchChartComponent(item))
|
componentInstall(item.chartKey, await fetchChartComponent(item))
|
||||||
componentInstall(item.conKey, fetchConfigComponent(item))
|
componentInstall(item.conKey, await fetchConfigComponent(item))
|
||||||
// 创建新图表组件
|
// 创建新图表组件
|
||||||
let newComponent: CreateComponentType = await createComponent(item)
|
let newComponent: CreateComponentType = await createComponent(item)
|
||||||
// 添加
|
// 添加
|
||||||
|
@ -149,8 +149,8 @@ const selectChartHandle = async (item: ConfigType) => {
|
|||||||
try {
|
try {
|
||||||
loadingStart()
|
loadingStart()
|
||||||
// 动态注册图表组件
|
// 动态注册图表组件
|
||||||
componentInstall(item.chartKey, fetchChartComponent(item))
|
componentInstall(item.chartKey, await fetchChartComponent(item))
|
||||||
componentInstall(item.conKey, fetchConfigComponent(item))
|
componentInstall(item.conKey, await fetchConfigComponent(item))
|
||||||
// 创建新图表组件
|
// 创建新图表组件
|
||||||
let newComponent: CreateComponentType = await createComponent(item)
|
let newComponent: CreateComponentType = await createComponent(item)
|
||||||
// 添加
|
// 添加
|
||||||
|
Loading…
x
Reference in New Issue
Block a user