From 31ed863d538f09ae4e257d4a0e8e1d2ce589cb80 Mon Sep 17 00:00:00 2001 From: tnt group Date: Wed, 17 May 2023 20:23:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E9=80=9A=E8=BF=87=E6=8B=96?= =?UTF-8?q?=E6=8B=BD=E3=80=81=E5=8F=8C=E5=87=BB=E3=80=81=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E6=96=B9=E5=BC=8F=E5=8A=A8=E6=80=81=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=BB=84=E4=BB=B6=E6=97=B6=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=99=9A=E6=8B=9F=E7=BB=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E6=A0=B9=E6=8D=AE=E9=A2=84=E8=AE=BE=E5=80=BC=E5=92=8C?= =?UTF-8?q?=E9=A2=84=E8=AE=BE=E6=A0=87=E9=A2=98=EF=BC=8C=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/index.d.ts | 2 +- src/packages/index.ts | 8 ++++++-- .../ContentCharts/components/ChartsItemBox/index.vue | 4 ++++ .../chart/ContentCharts/components/ChartsSearch/index.vue | 4 ++++ src/views/chart/ContentEdit/hooks/useDrag.hook.ts | 4 ++++ src/views/chart/hooks/useSync.hook.ts | 6 +++++- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/packages/index.d.ts b/src/packages/index.d.ts index a2dc376a..2a10bfa5 100644 --- a/src/packages/index.d.ts +++ b/src/packages/index.d.ts @@ -122,7 +122,7 @@ export interface PublicConfigType { } filter?: string status: StatusType - interactActions?: InteractActionsType[], + interactActions?: InteractActionsType[] events: { baseEvent: { [K in BaseEvent]?: string diff --git a/src/packages/index.ts b/src/packages/index.ts index b7a60c04..1b387cd8 100644 --- a/src/packages/index.ts +++ b/src/packages/index.ts @@ -27,8 +27,12 @@ export let packagesList: PackagesType = { * @param targetData */ export const createComponent = async (targetData: ConfigType) => { - const { category, key } = targetData - const chart = await import(`./components/${targetData.package}/${category}/${key}/config.ts`) + const { virtualComponent, category, key } = targetData + const chart = await import( + virtualComponent + ? `${virtualComponent}/config.ts` + : `./components/${targetData.package}/${category}/${key}/config.ts` + ) return new chart.default() } diff --git a/src/views/chart/ContentCharts/components/ChartsItemBox/index.vue b/src/views/chart/ContentCharts/components/ChartsItemBox/index.vue index 7ca3b1b0..981e4464 100644 --- a/src/views/chart/ContentCharts/components/ChartsItemBox/index.vue +++ b/src/views/chart/ContentCharts/components/ChartsItemBox/index.vue @@ -92,6 +92,10 @@ const dblclickHandle = async (item: ConfigType) => { componentInstall(item.conKey, fetchConfigComponent(item)) // 创建新图表组件 let newComponent: CreateComponentType = await createComponent(item) + if (item.virtualComponent) { + item.dataset && (newComponent.option.dataset = item.dataset) + newComponent.chartConfig.title = item.title + } // 添加 chartEditStore.addComponentList(newComponent, false, true) // 选中 diff --git a/src/views/chart/ContentCharts/components/ChartsSearch/index.vue b/src/views/chart/ContentCharts/components/ChartsSearch/index.vue index f1a25ddd..6b285625 100644 --- a/src/views/chart/ContentCharts/components/ChartsSearch/index.vue +++ b/src/views/chart/ContentCharts/components/ChartsSearch/index.vue @@ -153,6 +153,10 @@ const selectChartHandle = async (item: ConfigType) => { componentInstall(item.conKey, fetchConfigComponent(item)) // 创建新图表组件 let newComponent: CreateComponentType = await createComponent(item) + if (item.virtualComponent) { + item.dataset && (newComponent.option.dataset = item.dataset) + newComponent.chartConfig.title = item.title + } // 添加 chartEditStore.addComponentList(newComponent, false, true) // 选中 diff --git a/src/views/chart/ContentEdit/hooks/useDrag.hook.ts b/src/views/chart/ContentEdit/hooks/useDrag.hook.ts index 3aae5547..fab672c8 100644 --- a/src/views/chart/ContentEdit/hooks/useDrag.hook.ts +++ b/src/views/chart/ContentEdit/hooks/useDrag.hook.ts @@ -32,6 +32,10 @@ export const dragHandle = async (e: DragEvent) => { // 创建新图表组件 let newComponent: CreateComponentType = await createComponent(dropData) + if (dropData.virtualComponent) { + dropData.dataset && (newComponent.option.dataset = dropData.dataset) + newComponent.chartConfig.title = dropData.title + } setComponentPosition(newComponent, e.offsetX - newComponent.attr.w / 2, e.offsetY - newComponent.attr.h / 2) chartEditStore.addComponentList(newComponent, false, true) diff --git a/src/views/chart/hooks/useSync.hook.ts b/src/views/chart/hooks/useSync.hook.ts index 97221f19..f551c287 100644 --- a/src/views/chart/hooks/useSync.hook.ts +++ b/src/views/chart/hooks/useSync.hook.ts @@ -132,6 +132,10 @@ export const useSync = () => { ) => { // 补充 class 上的方法 let newComponent: CreateComponentType = await createComponent(_componentInstance.chartConfig) + if (_componentInstance.chartConfig.virtualComponent) { + _componentInstance.chartConfig.dataset && (newComponent.option.dataset = _componentInstance.chartConfig.dataset) + newComponent.chartConfig.title = _componentInstance.chartConfig.title + } if (callBack) { if (changeId) { callBack(componentMerge(newComponent, { ..._componentInstance, id: getUUID() })) @@ -156,7 +160,7 @@ export const useSync = () => { // 组件 if (key === ChartEditStoreEnum.COMPONENT_LIST) { let loadIndex = 0 - const listLength = projectData[key].length; + const listLength = projectData[key].length for (const comItem of projectData[key]) { // 设置加载数量 let percentage = parseInt((parseFloat(`${++loadIndex / listLength}`) * 100).toString())