fix: 修改拖拽的问题

This commit is contained in:
奔跑的面条 2022-04-11 18:17:09 +08:00
parent 100ec84d57
commit e9c263728b
6 changed files with 33 additions and 23 deletions

View File

@ -14,6 +14,7 @@ export enum EditCanvasTypeEnum {
SCALE = 'scale', SCALE = 'scale',
USER_SCALE = 'userScale', USER_SCALE = 'userScale',
LOCK_SCALE = 'lockScale', LOCK_SCALE = 'lockScale',
IS_CREATE = 'isCreate',
IS_DRAG = 'isDrag', IS_DRAG = 'isDrag',
} }
@ -30,6 +31,8 @@ export type EditCanvasType = {
[EditCanvasTypeEnum.USER_SCALE]: number [EditCanvasTypeEnum.USER_SCALE]: number
// 锁定缩放 // 锁定缩放
[EditCanvasTypeEnum.LOCK_SCALE]: boolean [EditCanvasTypeEnum.LOCK_SCALE]: boolean
// 初始化创建
[EditCanvasTypeEnum.IS_CREATE]: boolean
// 拖拽中 // 拖拽中
[EditCanvasTypeEnum.IS_DRAG]: boolean [EditCanvasTypeEnum.IS_DRAG]: boolean
} }

View File

@ -43,6 +43,8 @@ export const useChartEditStore = defineStore({
userScale: 1, userScale: 1,
// 锁定缩放 // 锁定缩放
lockScale: false, lockScale: false,
// 初始化
isCreate: false,
// 拖拽中 // 拖拽中
isDrag: false isDrag: false
}, },

View File

@ -6,7 +6,8 @@
v-for="(item, index) in menuOptions" v-for="(item, index) in menuOptions"
:key="index" :key="index"
draggable draggable
@dragstart="handleDragStart($event, item)" @dragstart="dragStartHandle($event, item)"
@dragend="dragendHandle"
> >
<div class="list-header"> <div class="list-header">
<mac-os-control-btn :mini="true" :disabled="true"></mac-os-control-btn> <mac-os-control-btn :mini="true" :disabled="true"></mac-os-control-btn>
@ -22,11 +23,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { PropType } from 'vue' import { PropType } from 'vue'
import { MacOsControlBtn } from '@/components/MacOsControlBtn/index' import { MacOsControlBtn } from '@/components/MacOsControlBtn/index'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
import { componentInstall } from '@/utils' import { componentInstall } from '@/utils'
import { DragKeyEnum } from '@/enums/editPageEnum' import { DragKeyEnum } from '@/enums/editPageEnum'
import { ConfigType } from '@/packages/index.d' import { ConfigType } from '@/packages/index.d'
import { fetchConfigComponent, fetchChartComponent } from '@/packages/index' import { fetchConfigComponent, fetchChartComponent } from '@/packages/index'
import omit from 'lodash/omit' import omit from 'lodash/omit'
const chartEditStore = useChartEditStore()
defineProps({ defineProps({
menuOptions: { menuOptions: {
@ -36,12 +40,19 @@ defineProps({
}) })
// //
const handleDragStart = (e: DragEvent, item: ConfigType) => { const dragStartHandle = (e: DragEvent, item: ConfigType) => {
// //
componentInstall(item.chartKey, fetchChartComponent(item)) componentInstall(item.chartKey, fetchChartComponent(item))
componentInstall(item.conKey, fetchConfigComponent(item)) componentInstall(item.conKey, fetchConfigComponent(item))
// //
e!.dataTransfer!.setData(DragKeyEnum.DROG_KEY, JSON.stringify(omit(item, ['image']))) e!.dataTransfer!.setData(DragKeyEnum.DROG_KEY, JSON.stringify(omit(item, ['image'])))
//
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, true)
}
//
const dragendHandle = () => {
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, false)
} }
</script> </script>

View File

@ -75,10 +75,6 @@ const rangeModelStyle = computed(() => {
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
border-radius: 15px;
border: 1px solid rgba(0, 0, 0, 0);
background-color: greenyellow;
opacity: 1;
} }
} }
</style> </style>

View File

@ -3,7 +3,7 @@ import { createComponent } from '@/packages'
import { ConfigType } from '@/packages/index.d' import { ConfigType } from '@/packages/index.d'
import { import {
CreateComponentType, CreateComponentType,
PickCreateComponentType PickCreateComponentType,
} from '@/packages/index.d' } from '@/packages/index.d'
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook' import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
@ -15,11 +15,12 @@ const chartEditStore = useChartEditStore()
const { onClickOutSide } = useContextMenu() const { onClickOutSide } = useContextMenu()
// * 拖拽到编辑区域里 // * 拖拽到编辑区域里
export const handleDrag = async (e: DragEvent) => { export const dragHandle = async (e: DragEvent) => {
e.preventDefault() e.preventDefault()
try { try {
loadingStart() loadingStart()
// 获取拖拽数据 // 获取拖拽数据
const drayDataString = e!.dataTransfer!.getData(DragKeyEnum.DROG_KEY) const drayDataString = e!.dataTransfer!.getData(DragKeyEnum.DROG_KEY)
if (!drayDataString) { if (!drayDataString) {
@ -27,9 +28,9 @@ export const handleDrag = async (e: DragEvent) => {
return return
} }
const dropData: Exclude<ConfigType, ['image']> = JSON.parse( // 修改状态
drayDataString chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, false)
) const dropData: Exclude<ConfigType, ['image']> = JSON.parse(drayDataString)
// 创建新图表组件 // 创建新图表组件
let newComponent: CreateComponentType = await createComponent(dropData) let newComponent: CreateComponentType = await createComponent(dropData)
@ -47,8 +48,8 @@ export const handleDrag = async (e: DragEvent) => {
} }
} }
// * 拖拽中 // * 进入拖拽区域
export const handleDragOver = (e: DragEvent) => { export const dragoverHandle = (e: DragEvent) => {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
@ -179,8 +180,8 @@ export const useMousePointHandle = (
const isLeft = /l/.test(point) const isLeft = /l/.test(point)
const isRight = /r/.test(point) const isRight = /r/.test(point)
const newHeight = itemAttrH + (isTop ? -currY : (isBottom ? currY : 0)) const newHeight = itemAttrH + (isTop ? -currY : isBottom ? currY : 0)
const newWidth = itemAttrW + (isLeft ? -currX : (isRight ? currX : 0)) const newWidth = itemAttrW + (isLeft ? -currX : isRight ? currX : 0)
attr.h = newHeight > 0 ? newHeight : 0 attr.h = newHeight > 0 ? newHeight : 0
attr.w = newWidth > 0 ? newWidth : 0 attr.w = newWidth > 0 ? newWidth : 0

View File

@ -6,8 +6,9 @@
:showBottom="true" :showBottom="true"
:depth="1" :depth="1"
:xScroll="true" :xScroll="true"
@drop="handleDrag" @drop="dragHandle"
@dragover="handleDragOver" @dragover="dragoverHandle"
@dragenter="dragoverHandle"
> >
<!-- 画布主体 --> <!-- 画布主体 -->
<div id="go-chart-edit-content" @contextmenu="handleContextMenu"> <div id="go-chart-edit-content" @contextmenu="handleContextMenu">
@ -60,11 +61,7 @@ import { EditTools } from './components/EditTools'
import { useLayout } from './hooks/useLayout.hook' import { useLayout } from './hooks/useLayout.hook'
import { useAddKeyboard } from '../hooks/useKeyboard.hook' import { useAddKeyboard } from '../hooks/useKeyboard.hook'
import { import { dragHandle, dragoverHandle, useMouseHandle } from './hooks/useDrag.hook'
handleDrag,
handleDragOver,
useMouseHandle
} from './hooks/useDrag.hook'
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook' import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook' import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'