mirror of
https://gitee.com/dromara/go-view.git
synced 2024-12-02 03:38:27 +08:00
fix: 解决重叠拖拽放置位置错误的bug
This commit is contained in:
parent
c968853092
commit
0b58dd4d17
@ -7,6 +7,8 @@
|
||||
<style lang="scss" scoped>
|
||||
@include go('loading-svg') {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: transparent;
|
||||
img {
|
||||
height: 50px;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ export enum EditCanvasTypeEnum {
|
||||
SCALE = 'scale',
|
||||
USER_SCALE = 'userScale',
|
||||
LOCK_SCALE = 'lockScale',
|
||||
Is_Drag= 'isDrag',
|
||||
}
|
||||
|
||||
// 编辑区域
|
||||
@ -24,6 +25,8 @@ export type EditCanvasType = {
|
||||
[EditCanvasTypeEnum.USER_SCALE]: number
|
||||
// 锁定缩放
|
||||
[EditCanvasTypeEnum.LOCK_SCALE]: boolean
|
||||
// 拖拽中
|
||||
[EditCanvasTypeEnum.Is_Drag]: boolean
|
||||
}
|
||||
|
||||
// 滤镜
|
||||
|
@ -35,6 +35,8 @@ export const useChartEditStoreStore = defineStore({
|
||||
userScale: 1,
|
||||
// 锁定缩放
|
||||
lockScale: false,
|
||||
// 拖拽中
|
||||
isDrag: false
|
||||
},
|
||||
// 画布属性(需存储给后端)
|
||||
editCanvasConfig: {
|
||||
@ -102,10 +104,10 @@ export const useChartEditStoreStore = defineStore({
|
||||
},
|
||||
actions: {
|
||||
// * 设置 editCanvas 数据项
|
||||
setEditCanvasItem<T extends keyof EditCanvasType, K extends EditCanvasType[T]>(key: T, value: K) {
|
||||
setEditCanvas<T extends keyof EditCanvasType, K extends EditCanvasType[T]>(key: T, value: K) {
|
||||
this.editCanvas[key] = value
|
||||
},
|
||||
setCanvasConfig<T extends keyof EditCanvasConfigType, K extends EditCanvasConfigType[T]>(key: T, value: K) {
|
||||
setEditCanvasConfig<T extends keyof EditCanvasConfigType, K extends EditCanvasConfigType[T]>(key: T, value: K) {
|
||||
this.editCanvasConfig[key] = value
|
||||
},
|
||||
// * 设置右键菜单
|
||||
|
@ -57,7 +57,7 @@ const fetchShowColors = (colors: Array<string>) => {
|
||||
}
|
||||
|
||||
const selectTheme = (theme: string) => {
|
||||
chartEditStoreStore.setCanvasConfig(EditCanvasConfigEnum.CHART_THEME, theme)
|
||||
chartEditStoreStore.setEditCanvasConfig(EditCanvasConfigEnum.CHART_THEME, theme)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -179,21 +179,21 @@ const beforeUploadHandle = async ({ file }) => {
|
||||
|
||||
// 清除背景
|
||||
const clearImage = () => {
|
||||
chartEditStoreStore.setCanvasConfig(
|
||||
chartEditStoreStore.setEditCanvasConfig(
|
||||
EditCanvasConfigEnum.BACKGROUND_IAMGE,
|
||||
undefined
|
||||
)
|
||||
chartEditStoreStore.setCanvasConfig(EditCanvasConfigEnum.SELECT_COLOR, true)
|
||||
chartEditStoreStore.setEditCanvasConfig(EditCanvasConfigEnum.SELECT_COLOR, true)
|
||||
}
|
||||
|
||||
// 清除颜色
|
||||
const clearColor = () => {
|
||||
chartEditStoreStore.setCanvasConfig(
|
||||
chartEditStoreStore.setEditCanvasConfig(
|
||||
EditCanvasConfigEnum.BACKGROUND,
|
||||
undefined
|
||||
)
|
||||
if (canvasConfig.backgroundImage) {
|
||||
chartEditStoreStore.setCanvasConfig(
|
||||
chartEditStoreStore.setEditCanvasConfig(
|
||||
EditCanvasConfigEnum.SELECT_COLOR,
|
||||
false
|
||||
)
|
||||
@ -224,11 +224,11 @@ const customRequest = (options: UploadCustomRequestOptions) => {
|
||||
nextTick(() => {
|
||||
if (file.file) {
|
||||
const ImageUrl = fileToUrl(file.file)
|
||||
chartEditStoreStore.setCanvasConfig(
|
||||
chartEditStoreStore.setEditCanvasConfig(
|
||||
EditCanvasConfigEnum.BACKGROUND_IAMGE,
|
||||
ImageUrl
|
||||
)
|
||||
chartEditStoreStore.setCanvasConfig(
|
||||
chartEditStoreStore.setEditCanvasConfig(
|
||||
EditCanvasConfigEnum.SELECT_COLOR,
|
||||
false
|
||||
)
|
||||
|
@ -115,7 +115,7 @@ const selectHandle = (v: number) => {
|
||||
|
||||
// 点击锁处理
|
||||
const lockHandle = () => {
|
||||
chartEditStore.setEditCanvasItem(
|
||||
chartEditStore.setEditCanvas(
|
||||
ChartEditStoreEnum.LOCK_SCALE,
|
||||
!lockScale.value
|
||||
)
|
||||
|
@ -1,22 +1,23 @@
|
||||
<template>
|
||||
<div
|
||||
class="go-edit-range"
|
||||
:style="style"
|
||||
:style="rangeStyle"
|
||||
@mousedown="mousedownHandleUnStop($event, undefined)"
|
||||
>
|
||||
<slot></slot>
|
||||
</div>
|
||||
<div class="go-edit-range-model" :style="rangeModelStyle"></div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { toRefs, computed } from 'vue'
|
||||
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||
import { useSizeStyle } from '../../hooks/useStyle.hook'
|
||||
import { mousedownHandleUnStop } from '../../hooks/useDrop.hook'
|
||||
import { mousedownHandleUnStop } from '../../hooks/useDrag.hook'
|
||||
|
||||
const chartEditStoreStore = useChartEditStoreStore()
|
||||
|
||||
const { getEditCanvasConfig } = toRefs(chartEditStoreStore)
|
||||
const { getEditCanvasConfig, getEditCanvas } = toRefs(chartEditStoreStore)
|
||||
|
||||
const size = computed(() => {
|
||||
return {
|
||||
@ -25,16 +26,23 @@ const size = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
const style = computed(() => {
|
||||
const rangeStyle = computed(() => {
|
||||
const background = getEditCanvasConfig.value.background
|
||||
const backgroundImage = getEditCanvasConfig.value.backgroundImage
|
||||
const selectColor = getEditCanvasConfig.value.selectColor
|
||||
const backgroundColor = background ? background : null
|
||||
const computed = selectColor
|
||||
const computedBackground = selectColor
|
||||
? { background: backgroundColor }
|
||||
: { background: `url(${backgroundImage}) no-repeat center/100% !important` }
|
||||
// @ts-ignore
|
||||
return { ...useSizeStyle(size.value), ...computed }
|
||||
return { ...useSizeStyle(size.value), ...computedBackground }
|
||||
})
|
||||
|
||||
// 模态层
|
||||
const rangeModelStyle = computed(() => {
|
||||
const dragStyle = getEditCanvas.value.isDrag && {'z-index': 99999 }
|
||||
// @ts-ignore
|
||||
return { ...useSizeStyle(size.value), ...dragStyle}
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -48,4 +56,12 @@ const style = computed(() => {
|
||||
@include filter-border-color('hover-border-color');
|
||||
@include fetch-theme-custom('border-color', 'background-color4');
|
||||
}
|
||||
@include go(edit-range-model) {
|
||||
z-index: -1;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
border-radius: 15px;
|
||||
border: 1px solid rgba(0, 0, 0, 0);
|
||||
}
|
||||
</style>
|
||||
|
@ -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 {
|
||||
@ -26,6 +27,9 @@ export const handleDrop = async (e: DragEvent) => {
|
||||
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 = {
|
||||
|
@ -7,7 +7,7 @@
|
||||
:showBottom="true"
|
||||
:depth="1"
|
||||
:xScroll="true"
|
||||
@drop="handleDrop"
|
||||
@drop="handleDrag"
|
||||
@dragover="handleDragOver"
|
||||
>
|
||||
<div id="go-chart-edit-content">
|
||||
@ -52,7 +52,7 @@ import { EditShapeBox } from './components/EditShapeBox/index'
|
||||
|
||||
import { useLayout } from './hooks/useLayout.hook'
|
||||
import { useAddKeyboard } from '../hooks/useKeyboard.hook'
|
||||
import { handleDrop, handleDragOver, useMouseHandle } from './hooks/useDrop.hook'
|
||||
import { handleDrag, handleDragOver, useMouseHandle } from './hooks/useDrag.hook'
|
||||
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
|
||||
import { getChartEditStore } from './hooks/useStore.hook'
|
||||
import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
|
||||
@ -93,7 +93,7 @@ onMounted(() => {
|
||||
@extend .go-point-bg;
|
||||
@include goId(chart-edit-content) {
|
||||
margin: 20px;
|
||||
overflow: hidden;
|
||||
/* overflow: hidden; */
|
||||
transform-origin: left top;
|
||||
border: 1px solid rgba(0, 0, 0, 0);
|
||||
@extend .go-transition;
|
||||
|
Loading…
Reference in New Issue
Block a user