From fe22e1d33066309f33d698420221a22a0828fe75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E8=B7=91=E7=9A=84=E9=9D=A2=E6=9D=A1?= <1262327911@qq.com> Date: Tue, 30 Aug 2022 19:02:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E9=80=89=E4=B8=AD=E7=A7=BB=E5=8A=A8=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=92=A4=E5=9B=9E=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/chartEditStore/chartEditStore.ts | 4 ++-- .../chart/ContentEdit/hooks/useDrag.hook.ts | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/store/modules/chartEditStore/chartEditStore.ts b/src/store/modules/chartEditStore/chartEditStore.ts index 6f48c788..fffde217 100644 --- a/src/store/modules/chartEditStore/chartEditStore.ts +++ b/src/store/modules/chartEditStore/chartEditStore.ts @@ -332,8 +332,8 @@ export const useChartEditStore = defineStore({ } }, // * 移动组件 - moveComponentList(item: CreateComponentType | CreateComponentGroupType) { - chartHistoryStore.createMoveHistory([item]) + moveComponentList(item: Array) { + chartHistoryStore.createMoveHistory(item) }, // * 更新组件列表某一项的值 updateComponentList(index: number, newData: CreateComponentType | CreateComponentGroupType) { diff --git a/src/views/chart/ContentEdit/hooks/useDrag.hook.ts b/src/views/chart/ContentEdit/hooks/useDrag.hook.ts index f481192d..2e2218b6 100644 --- a/src/views/chart/ContentEdit/hooks/useDrag.hook.ts +++ b/src/views/chart/ContentEdit/hooks/useDrag.hook.ts @@ -223,13 +223,13 @@ export const useMouseHandle = () => { const startY = e.screenY // 记录历史位置 - let prevComponentInstance: CreateComponentType | CreateComponentGroupType + let prevComponentInstance: Array = [] chartEditStore.getTargetChart.selectId.forEach(id => { if (!targetMap.has(id)) return const index = chartEditStore.fetchTargetIndex(id) // 拿到初始位置数据 - prevComponentInstance = cloneDeep(chartEditStore.getComponentList[index]) + prevComponentInstance.push(cloneDeep(chartEditStore.getComponentList[index])) }) // 记录初始位置 @@ -278,14 +278,19 @@ export const useMouseHandle = () => { chartEditStore.setMousePosition(0, 0, 0, 0) chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_DRAG, false) // 加入历史栈 - if (prevComponentInstance) { + if (prevComponentInstance.length) { chartEditStore.getTargetChart.selectId.forEach(id => { if (!targetMap.has(id)) return const index = chartEditStore.fetchTargetIndex(id) const curComponentInstance = chartEditStore.getComponentList[index] - prevComponentInstance.attr = Object.assign(prevComponentInstance.attr, { - offsetX: curComponentInstance.attr.x - prevComponentInstance.attr.x, - offsetY: curComponentInstance.attr.y - prevComponentInstance.attr.y + // 找到记录的所选组件 + prevComponentInstance.forEach(preItem => { + if (preItem.id === id) { + preItem.attr = Object.assign(preItem.attr, { + offsetX: curComponentInstance.attr.x - preItem.attr.x, + offsetY: curComponentInstance.attr.y - preItem.attr.y + }) + } }) }) chartEditStore.moveComponentList(prevComponentInstance)