|
|
@@ -7,7 +7,7 @@ import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
|
|
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
|
|
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
|
|
import { loadingStart, loadingFinish, loadingError } from '@/utils'
|
|
|
-import throttle from 'lodash/throttle'
|
|
|
+import { throttle, cloneDeep } from 'lodash'
|
|
|
|
|
|
const chartEditStore = useChartEditStore()
|
|
|
const { onClickOutSide } = useContextMenu()
|
|
|
@@ -222,6 +222,16 @@ export const useMouseHandle = () => {
|
|
|
const startX = e.screenX
|
|
|
const startY = e.screenY
|
|
|
|
|
|
+ // 记录历史位置
|
|
|
+ let prevComponentInstance:CreateComponentType | CreateComponentGroupType
|
|
|
+ chartEditStore.getTargetChart.selectId.forEach(id => {
|
|
|
+ if (!targetMap.has(id)) return
|
|
|
+
|
|
|
+ const index = chartEditStore.fetchTargetIndex(id)
|
|
|
+ // 拿到初始位置数据
|
|
|
+ prevComponentInstance = cloneDeep(chartEditStore.getComponentList[index])
|
|
|
+ })
|
|
|
+
|
|
|
// 记录初始位置
|
|
|
chartEditStore.setMousePosition(undefined, undefined, startX, startY)
|
|
|
|
|
|
@@ -267,6 +277,19 @@ export const useMouseHandle = () => {
|
|
|
const mouseup = () => {
|
|
|
chartEditStore.setMousePosition(0, 0, 0, 0)
|
|
|
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_DRAG, false)
|
|
|
+ // 加入历史栈
|
|
|
+ if(prevComponentInstance){
|
|
|
+ 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
|
|
|
+ })
|
|
|
+ })
|
|
|
+ chartEditStore.moveComponentList(prevComponentInstance)
|
|
|
+ }
|
|
|
document.removeEventListener('mousemove', mousemove)
|
|
|
document.removeEventListener('mouseup', mouseup)
|
|
|
}
|