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)