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>
|
<style lang="scss" scoped>
|
||||||
@include go('loading-svg') {
|
@include go('loading-svg') {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: transparent;
|
||||||
img {
|
img {
|
||||||
height: 50px;
|
height: 50px;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ export enum EditCanvasTypeEnum {
|
|||||||
SCALE = 'scale',
|
SCALE = 'scale',
|
||||||
USER_SCALE = 'userScale',
|
USER_SCALE = 'userScale',
|
||||||
LOCK_SCALE = 'lockScale',
|
LOCK_SCALE = 'lockScale',
|
||||||
|
Is_Drag= 'isDrag',
|
||||||
}
|
}
|
||||||
|
|
||||||
// 编辑区域
|
// 编辑区域
|
||||||
@ -24,6 +25,8 @@ export type EditCanvasType = {
|
|||||||
[EditCanvasTypeEnum.USER_SCALE]: number
|
[EditCanvasTypeEnum.USER_SCALE]: number
|
||||||
// 锁定缩放
|
// 锁定缩放
|
||||||
[EditCanvasTypeEnum.LOCK_SCALE]: boolean
|
[EditCanvasTypeEnum.LOCK_SCALE]: boolean
|
||||||
|
// 拖拽中
|
||||||
|
[EditCanvasTypeEnum.Is_Drag]: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// 滤镜
|
// 滤镜
|
||||||
|
@ -35,6 +35,8 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
userScale: 1,
|
userScale: 1,
|
||||||
// 锁定缩放
|
// 锁定缩放
|
||||||
lockScale: false,
|
lockScale: false,
|
||||||
|
// 拖拽中
|
||||||
|
isDrag: false
|
||||||
},
|
},
|
||||||
// 画布属性(需存储给后端)
|
// 画布属性(需存储给后端)
|
||||||
editCanvasConfig: {
|
editCanvasConfig: {
|
||||||
@ -102,10 +104,10 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
// * 设置 editCanvas 数据项
|
// * 设置 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
|
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
|
this.editCanvasConfig[key] = value
|
||||||
},
|
},
|
||||||
// * 设置右键菜单
|
// * 设置右键菜单
|
||||||
|
@ -57,7 +57,7 @@ const fetchShowColors = (colors: Array<string>) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const selectTheme = (theme: string) => {
|
const selectTheme = (theme: string) => {
|
||||||
chartEditStoreStore.setCanvasConfig(EditCanvasConfigEnum.CHART_THEME, theme)
|
chartEditStoreStore.setEditCanvasConfig(EditCanvasConfigEnum.CHART_THEME, theme)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -179,21 +179,21 @@ const beforeUploadHandle = async ({ file }) => {
|
|||||||
|
|
||||||
// 清除背景
|
// 清除背景
|
||||||
const clearImage = () => {
|
const clearImage = () => {
|
||||||
chartEditStoreStore.setCanvasConfig(
|
chartEditStoreStore.setEditCanvasConfig(
|
||||||
EditCanvasConfigEnum.BACKGROUND_IAMGE,
|
EditCanvasConfigEnum.BACKGROUND_IAMGE,
|
||||||
undefined
|
undefined
|
||||||
)
|
)
|
||||||
chartEditStoreStore.setCanvasConfig(EditCanvasConfigEnum.SELECT_COLOR, true)
|
chartEditStoreStore.setEditCanvasConfig(EditCanvasConfigEnum.SELECT_COLOR, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清除颜色
|
// 清除颜色
|
||||||
const clearColor = () => {
|
const clearColor = () => {
|
||||||
chartEditStoreStore.setCanvasConfig(
|
chartEditStoreStore.setEditCanvasConfig(
|
||||||
EditCanvasConfigEnum.BACKGROUND,
|
EditCanvasConfigEnum.BACKGROUND,
|
||||||
undefined
|
undefined
|
||||||
)
|
)
|
||||||
if (canvasConfig.backgroundImage) {
|
if (canvasConfig.backgroundImage) {
|
||||||
chartEditStoreStore.setCanvasConfig(
|
chartEditStoreStore.setEditCanvasConfig(
|
||||||
EditCanvasConfigEnum.SELECT_COLOR,
|
EditCanvasConfigEnum.SELECT_COLOR,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
@ -224,11 +224,11 @@ const customRequest = (options: UploadCustomRequestOptions) => {
|
|||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (file.file) {
|
if (file.file) {
|
||||||
const ImageUrl = fileToUrl(file.file)
|
const ImageUrl = fileToUrl(file.file)
|
||||||
chartEditStoreStore.setCanvasConfig(
|
chartEditStoreStore.setEditCanvasConfig(
|
||||||
EditCanvasConfigEnum.BACKGROUND_IAMGE,
|
EditCanvasConfigEnum.BACKGROUND_IAMGE,
|
||||||
ImageUrl
|
ImageUrl
|
||||||
)
|
)
|
||||||
chartEditStoreStore.setCanvasConfig(
|
chartEditStoreStore.setEditCanvasConfig(
|
||||||
EditCanvasConfigEnum.SELECT_COLOR,
|
EditCanvasConfigEnum.SELECT_COLOR,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
@ -115,7 +115,7 @@ const selectHandle = (v: number) => {
|
|||||||
|
|
||||||
// 点击锁处理
|
// 点击锁处理
|
||||||
const lockHandle = () => {
|
const lockHandle = () => {
|
||||||
chartEditStore.setEditCanvasItem(
|
chartEditStore.setEditCanvas(
|
||||||
ChartEditStoreEnum.LOCK_SCALE,
|
ChartEditStoreEnum.LOCK_SCALE,
|
||||||
!lockScale.value
|
!lockScale.value
|
||||||
)
|
)
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="go-edit-range"
|
class="go-edit-range"
|
||||||
:style="style"
|
:style="rangeStyle"
|
||||||
@mousedown="mousedownHandleUnStop($event, undefined)"
|
@mousedown="mousedownHandleUnStop($event, undefined)"
|
||||||
>
|
>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="go-edit-range-model" :style="rangeModelStyle"></div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { toRefs, computed } from 'vue'
|
import { toRefs, computed } from 'vue'
|
||||||
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
import { useSizeStyle } from '../../hooks/useStyle.hook'
|
import { useSizeStyle } from '../../hooks/useStyle.hook'
|
||||||
import { mousedownHandleUnStop } from '../../hooks/useDrop.hook'
|
import { mousedownHandleUnStop } from '../../hooks/useDrag.hook'
|
||||||
|
|
||||||
const chartEditStoreStore = useChartEditStoreStore()
|
const chartEditStoreStore = useChartEditStoreStore()
|
||||||
|
|
||||||
const { getEditCanvasConfig } = toRefs(chartEditStoreStore)
|
const { getEditCanvasConfig, getEditCanvas } = toRefs(chartEditStoreStore)
|
||||||
|
|
||||||
const size = computed(() => {
|
const size = computed(() => {
|
||||||
return {
|
return {
|
||||||
@ -25,16 +26,23 @@ const size = computed(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const style = computed(() => {
|
const rangeStyle = computed(() => {
|
||||||
const background = getEditCanvasConfig.value.background
|
const background = getEditCanvasConfig.value.background
|
||||||
const backgroundImage = getEditCanvasConfig.value.backgroundImage
|
const backgroundImage = getEditCanvasConfig.value.backgroundImage
|
||||||
const selectColor = getEditCanvasConfig.value.selectColor
|
const selectColor = getEditCanvasConfig.value.selectColor
|
||||||
const backgroundColor = background ? background : null
|
const backgroundColor = background ? background : null
|
||||||
const computed = selectColor
|
const computedBackground = selectColor
|
||||||
? { background: backgroundColor }
|
? { background: backgroundColor }
|
||||||
: { background: `url(${backgroundImage}) no-repeat center/100% !important` }
|
: { background: `url(${backgroundImage}) no-repeat center/100% !important` }
|
||||||
// @ts-ignore
|
// @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>
|
</script>
|
||||||
|
|
||||||
@ -48,4 +56,12 @@ const style = computed(() => {
|
|||||||
@include filter-border-color('hover-border-color');
|
@include filter-border-color('hover-border-color');
|
||||||
@include fetch-theme-custom('border-color', 'background-color4');
|
@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>
|
</style>
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
import { toRefs } from 'vue'
|
import { toRefs } from 'vue'
|
||||||
import { getChartEditStore } from './useStore.hook'
|
|
||||||
import { DragKeyEnum } from '@/enums/editPageEnum'
|
import { DragKeyEnum } from '@/enums/editPageEnum'
|
||||||
import { createComponent } from '@/packages'
|
import { createComponent } from '@/packages'
|
||||||
import { ConfigType } from '@/packages/index.d'
|
import { ConfigType } from '@/packages/index.d'
|
||||||
import { loadingStart, loadingFinish, loadingError } from '@/utils'
|
|
||||||
import { CreateComponentType } from '@/packages/index.d'
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
import throttle from 'lodash/throttle'
|
|
||||||
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
|
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 { onClickoutside } = useContextMenu()
|
||||||
|
|
||||||
const chartEditStore = getChartEditStore()
|
const chartEditStore = getChartEditStore()
|
||||||
|
const chartEditStoreEnum = getChartEditStoreEnum()
|
||||||
const { scale } = toRefs(chartEditStore.getEditCanvas)
|
const { scale } = toRefs(chartEditStore.getEditCanvas)
|
||||||
|
|
||||||
// * 拖拽中
|
// * 拖拽到编辑区域里
|
||||||
export const handleDrop = async (e: DragEvent) => {
|
export const handleDrag = async (e: DragEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -26,6 +27,9 @@ export const handleDrop = async (e: DragEvent) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置拖拽状态
|
||||||
|
chartEditStore.setEditCanvas(chartEditStoreEnum.Is_Drag, false)
|
||||||
|
|
||||||
const dropData: Exclude<ConfigType, ['node', 'image']> = JSON.parse(
|
const dropData: Exclude<ConfigType, ['node', 'image']> = JSON.parse(
|
||||||
drayDataString
|
drayDataString
|
||||||
)
|
)
|
||||||
@ -42,10 +46,13 @@ export const handleDrop = async (e: DragEvent) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// * 拖拽结束
|
// * 拖拽中
|
||||||
export const handleDragOver = (e: DragEvent) => {
|
export const handleDragOver = (e: DragEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|
||||||
|
// 设置拖拽状态
|
||||||
|
chartEditStore.setEditCanvas(chartEditStoreEnum.Is_Drag, true)
|
||||||
if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy'
|
if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy'
|
||||||
}
|
}
|
||||||
|
|
@ -8,11 +8,11 @@ const chartEditStore = getChartEditStore()
|
|||||||
export const useLayout = () => {
|
export const useLayout = () => {
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 设置 Dom 值(ref 不生效先用 document)
|
// 设置 Dom 值(ref 不生效先用 document)
|
||||||
chartEditStore.setEditCanvasItem(
|
chartEditStore.setEditCanvas(
|
||||||
EditCanvasTypeEnum.EDIT_LAYOUT_DOM,
|
EditCanvasTypeEnum.EDIT_LAYOUT_DOM,
|
||||||
document.getElementById('go-chart-edit-layout')
|
document.getElementById('go-chart-edit-layout')
|
||||||
)
|
)
|
||||||
chartEditStore.setEditCanvasItem(
|
chartEditStore.setEditCanvas(
|
||||||
EditCanvasTypeEnum.EDIT_CONTENT_DOM,
|
EditCanvasTypeEnum.EDIT_CONTENT_DOM,
|
||||||
document.getElementById('go-chart-edit-content')
|
document.getElementById('go-chart-edit-content')
|
||||||
)
|
)
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
interface AttrType {
|
import { PublicConfigType } from '@/packages/index.d'
|
||||||
x: number
|
type AttrType = Pick<PublicConfigType, 'attr'>['attr']
|
||||||
y: number
|
|
||||||
w: number
|
|
||||||
h: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useComponentStyle = (attr: AttrType, index: number) => {
|
export const useComponentStyle = (attr: AttrType, index: number) => {
|
||||||
const componentStyle = {
|
const componentStyle = {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
:showBottom="true"
|
:showBottom="true"
|
||||||
:depth="1"
|
:depth="1"
|
||||||
:xScroll="true"
|
:xScroll="true"
|
||||||
@drop="handleDrop"
|
@drop="handleDrag"
|
||||||
@dragover="handleDragOver"
|
@dragover="handleDragOver"
|
||||||
>
|
>
|
||||||
<div id="go-chart-edit-content">
|
<div id="go-chart-edit-content">
|
||||||
@ -52,7 +52,7 @@ import { EditShapeBox } from './components/EditShapeBox/index'
|
|||||||
|
|
||||||
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 { handleDrop, handleDragOver, useMouseHandle } from './hooks/useDrop.hook'
|
import { handleDrag, handleDragOver, useMouseHandle } from './hooks/useDrag.hook'
|
||||||
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
|
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
|
||||||
import { getChartEditStore } from './hooks/useStore.hook'
|
import { getChartEditStore } from './hooks/useStore.hook'
|
||||||
import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
|
import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
|
||||||
@ -93,7 +93,7 @@ onMounted(() => {
|
|||||||
@extend .go-point-bg;
|
@extend .go-point-bg;
|
||||||
@include goId(chart-edit-content) {
|
@include goId(chart-edit-content) {
|
||||||
margin: 20px;
|
margin: 20px;
|
||||||
overflow: hidden;
|
/* overflow: hidden; */
|
||||||
transform-origin: left top;
|
transform-origin: left top;
|
||||||
border: 1px solid rgba(0, 0, 0, 0);
|
border: 1px solid rgba(0, 0, 0, 0);
|
||||||
@extend .go-transition;
|
@extend .go-transition;
|
||||||
|
Loading…
Reference in New Issue
Block a user