fix: 解决组件移动未加入历史栈

This commit is contained in:
yangwq7
2022-08-25 20:27:57 +08:00
parent 558512220e
commit a1233aa1fe
4 changed files with 95 additions and 11 deletions
@@ -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,10 @@ export const useMouseHandle = () => {
const mouseup = () => {
chartEditStore.setMousePosition(0, 0, 0, 0)
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_DRAG, false)
// 加入历史栈
if(prevComponentInstance){
chartEditStore.moveComponentList(prevComponentInstance)
}
document.removeEventListener('mousemove', mousemove)
document.removeEventListener('mouseup', mouseup)
}