fix: 解决重叠拖拽放置位置错误的bug

This commit is contained in:
MTrun
2022-02-16 19:18:39 +08:00
parent 825d21a3a9
commit c107c8c440
11 changed files with 60 additions and 34 deletions
@@ -1,20 +1,21 @@
import { toRefs } from 'vue'
import { getChartEditStore } from './useStore.hook'
import { DragKeyEnum } from '@/enums/editPageEnum'
import { createComponent } from '@/packages'
import { ConfigType } from '@/packages/index.d'
import { loadingStart, loadingFinish, loadingError } from '@/utils'
import { CreateComponentType } from '@/packages/index.d'
import throttle from 'lodash/throttle'
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
import { getChartEditStore, getChartEditStoreEnum } from './useStore.hook'
import { loadingStart, loadingFinish, loadingError } from '@/utils'
import throttle from 'lodash/throttle'
const { onClickoutside } = useContextMenu()
const chartEditStore = getChartEditStore()
const chartEditStoreEnum = getChartEditStoreEnum()
const { scale } = toRefs(chartEditStore.getEditCanvas)
// * 拖拽
export const handleDrop = async (e: DragEvent) => {
// * 拖拽到编辑区域里
export const handleDrag = async (e: DragEvent) => {
e.preventDefault()
try {
@@ -24,7 +25,10 @@ export const handleDrop = async (e: DragEvent) => {
if (!drayDataString) {
loadingFinish()
return
}
}
// 设置拖拽状态
chartEditStore.setEditCanvas(chartEditStoreEnum.Is_Drag, false)
const dropData: Exclude<ConfigType, ['node', 'image']> = JSON.parse(
drayDataString
@@ -42,10 +46,13 @@ export const handleDrop = async (e: DragEvent) => {
}
}
// * 拖拽结束
// * 拖拽
export const handleDragOver = (e: DragEvent) => {
e.preventDefault()
e.stopPropagation()
// 设置拖拽状态
chartEditStore.setEditCanvas(chartEditStoreEnum.Is_Drag, true)
if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy'
}
@@ -8,11 +8,11 @@ const chartEditStore = getChartEditStore()
export const useLayout = () => {
onMounted(() => {
// 设置 Dom 值(ref 不生效先用 document)
chartEditStore.setEditCanvasItem(
chartEditStore.setEditCanvas(
EditCanvasTypeEnum.EDIT_LAYOUT_DOM,
document.getElementById('go-chart-edit-layout')
)
chartEditStore.setEditCanvasItem(
chartEditStore.setEditCanvas(
EditCanvasTypeEnum.EDIT_CONTENT_DOM,
document.getElementById('go-chart-edit-content')
)
@@ -1,9 +1,5 @@
interface AttrType {
x: number
y: number
w: number
h: number
}
import { PublicConfigType } from '@/packages/index.d'
type AttrType = Pick<PublicConfigType, 'attr'>['attr']
export const useComponentStyle = (attr: AttrType, index: number) => {
const componentStyle = {