mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-22 05:26:23 +08:00
fix:修改删除的bug
This commit is contained in:
parent
c92510863f
commit
b9501cee37
@ -47,8 +47,8 @@ export type MousePositionType = {
|
|||||||
|
|
||||||
// 操作目标
|
// 操作目标
|
||||||
export type TargetChartType = {
|
export type TargetChartType = {
|
||||||
hoverIndex?: string
|
hoverId?: string
|
||||||
selectIndex?: string
|
selectId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store 枚举
|
// Store 枚举
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import debounce from 'lodash/debounce'
|
import debounce from 'lodash/debounce'
|
||||||
import { loadingStart, loadingFinish, loadingError } from '@/utils'
|
import { loadingStart, loadingFinish, loadingError } from '@/utils'
|
||||||
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
import {
|
import {
|
||||||
chartEditStoreType,
|
chartEditStoreType,
|
||||||
EditCanvasType,
|
EditCanvasType,
|
||||||
@ -41,8 +42,8 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
},
|
},
|
||||||
// 目标图表
|
// 目标图表
|
||||||
targetChart: {
|
targetChart: {
|
||||||
hoverIndex: undefined,
|
hoverId: undefined,
|
||||||
selectIndex: undefined
|
selectId: undefined
|
||||||
},
|
},
|
||||||
// 图表数组
|
// 图表数组
|
||||||
componentList: []
|
componentList: []
|
||||||
@ -74,27 +75,22 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
this.rightMenuShow = value
|
this.rightMenuShow = value
|
||||||
},
|
},
|
||||||
// * 设置目标数据 hover
|
// * 设置目标数据 hover
|
||||||
setTargetHoverChart(hoverIndex?:TargetChartType["hoverIndex"]) {
|
setTargetHoverChart(hoverId?:TargetChartType["hoverId"]) {
|
||||||
this.targetChart.hoverIndex = hoverIndex
|
this.targetChart.hoverId = hoverId
|
||||||
},
|
},
|
||||||
// * 设置目标数据 select
|
// * 设置目标数据 select
|
||||||
setTargetSelectChart(selectIndex?:TargetChartType["selectIndex"]) {
|
setTargetSelectChart(selectId?:TargetChartType["selectId"]) {
|
||||||
this.targetChart.selectIndex = selectIndex
|
this.targetChart.selectId = selectId
|
||||||
},
|
},
|
||||||
// * 新增组件列表
|
// * 新增组件列表
|
||||||
addComponentList<T>(chartData: T): void {
|
addComponentList<T>(chartData: T): void {
|
||||||
this.componentList.push(chartData)
|
this.componentList.push(chartData)
|
||||||
},
|
},
|
||||||
// * 删除组件列表
|
// * 删除组件列表
|
||||||
removeComponentList<T extends { key: string }>(chartData: T | number): void {
|
removeComponentList(): void {
|
||||||
loadingStart()
|
loadingStart()
|
||||||
try {
|
try {
|
||||||
if(typeof chartData === 'number') {
|
const i = this.componentList.findIndex(e => e.id === this.getTargetChart.selectId)
|
||||||
this.componentList.splice(chartData, 1)
|
|
||||||
loadingFinish()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const i = this.componentList.findIndex(e => e.key === chartData.key)
|
|
||||||
if (i !== -1) {
|
if (i !== -1) {
|
||||||
this.componentList.splice(i, 1)
|
this.componentList.splice(i, 1)
|
||||||
loadingFinish()
|
loadingFinish()
|
||||||
|
@ -31,11 +31,11 @@ const chartEditStore = useChartEditStoreStore()
|
|||||||
|
|
||||||
// 计算当前选中目标
|
// 计算当前选中目标
|
||||||
const hover = computed(() => {
|
const hover = computed(() => {
|
||||||
return props.item.id === chartEditStore.getTargetChart.hoverIndex
|
return props.item.id === chartEditStore.getTargetChart.hoverId
|
||||||
})
|
})
|
||||||
|
|
||||||
const select = computed(() => {
|
const select = computed(() => {
|
||||||
return props.item.id === chartEditStore.getTargetChart.selectIndex
|
return props.item.id === chartEditStore.getTargetChart.selectId
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ export const mousedownHandleUnStop = (
|
|||||||
chartEditStore.setTargetSelectChart(item.id)
|
chartEditStore.setTargetSelectChart(item.id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
chartEditStore.setTargetSelectChart(item)
|
chartEditStore.setTargetSelectChart(undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移动图表
|
// 移动图表
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
@mousedown="mousedownHandle($event, item)"
|
@mousedown="mousedownHandle($event, item)"
|
||||||
@mouseenter="mouseenterHandle($event, item)"
|
@mouseenter="mouseenterHandle($event, item)"
|
||||||
@mouseleave="mouseleaveHandle($event, item)"
|
@mouseleave="mouseleaveHandle($event, item)"
|
||||||
@contextmenu="handleContextMenu($event, index)"
|
@contextmenu="handleContextMenu($event, item)"
|
||||||
>
|
>
|
||||||
<component
|
<component
|
||||||
class="edit-content-chart"
|
class="edit-content-chart"
|
||||||
|
@ -43,11 +43,11 @@ const { image, title } = toRefs(props.componentData.chartData)
|
|||||||
|
|
||||||
// 计算当前选中目标
|
// 计算当前选中目标
|
||||||
const select = computed(() => {
|
const select = computed(() => {
|
||||||
return props.componentData.id === chartEditStore.getTargetChart.selectIndex
|
return props.componentData.id === chartEditStore.getTargetChart.selectId
|
||||||
})
|
})
|
||||||
|
|
||||||
const hover = computed(() => {
|
const hover = computed(() => {
|
||||||
return props.componentData.id === chartEditStore.getTargetChart.hoverIndex
|
return props.componentData.id === chartEditStore.getTargetChart.hoverId
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -14,13 +14,13 @@
|
|||||||
|
|
||||||
<!-- 图层内容 -->
|
<!-- 图层内容 -->
|
||||||
<ListItem
|
<ListItem
|
||||||
v-for="item in chartEditStore.getComponentList"
|
v-for="(item) in chartEditStore.getComponentList"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:componentData="item"
|
:componentData="item"
|
||||||
@mousedown="mousedownHandle(item)"
|
@mousedown="mousedownHandle(item)"
|
||||||
@mouseenter="mouseenterHandle(item)"
|
@mouseenter="mouseenterHandle(item)"
|
||||||
@mouseleave="mouseleaveHandle(item)"
|
@mouseleave="mouseleaveHandle(item)"
|
||||||
@contextmenu="handleContextMenu($event, index)"
|
@contextmenu="handleContextMenu($event, item)"
|
||||||
/>
|
/>
|
||||||
</ContentBox>
|
</ContentBox>
|
||||||
</template>
|
</template>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { ref, nextTick } from 'vue'
|
import { ref, nextTick } from 'vue'
|
||||||
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
import { loadingError } from '@/utils'
|
import { loadingError } from '@/utils'
|
||||||
|
|
||||||
const chartEditStore = useChartEditStoreStore()
|
const chartEditStore = useChartEditStoreStore()
|
||||||
@ -27,8 +28,6 @@ export const useContextMenu = (menuOption?: {
|
|||||||
const selfOptions = menuOption?.selfOptions
|
const selfOptions = menuOption?.selfOptions
|
||||||
const optionsHandle = menuOption?.optionsHandle
|
const optionsHandle = menuOption?.optionsHandle
|
||||||
|
|
||||||
const targetIndex = ref<number>(0)
|
|
||||||
|
|
||||||
// * 默认选项
|
// * 默认选项
|
||||||
const defaultOptions: MenuOptionsItemType[] = [
|
const defaultOptions: MenuOptionsItemType[] = [
|
||||||
{
|
{
|
||||||
@ -42,10 +41,9 @@ export const useContextMenu = (menuOption?: {
|
|||||||
const menuOptions: MenuOptionsItemType[] = selfOptions || defaultOptions
|
const menuOptions: MenuOptionsItemType[] = selfOptions || defaultOptions
|
||||||
|
|
||||||
// * 右键处理
|
// * 右键处理
|
||||||
const handleContextMenu = (e: MouseEvent, index: number) => {
|
const handleContextMenu = (e: MouseEvent, item: CreateComponentType) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
targetIndex.value = index
|
|
||||||
let target = e.target
|
let target = e.target
|
||||||
while (target instanceof SVGElement) {
|
while (target instanceof SVGElement) {
|
||||||
target = target.parentNode
|
target = target.parentNode
|
||||||
@ -69,9 +67,9 @@ export const useContextMenu = (menuOption?: {
|
|||||||
(e: MenuOptionsItemType) => e.key === key
|
(e: MenuOptionsItemType) => e.key === key
|
||||||
)
|
)
|
||||||
if (!targetItem) loadingError()
|
if (!targetItem) loadingError()
|
||||||
if (targetItem.length) targetItem.pop()?.fnHandle(targetIndex.value)
|
if (targetItem.length) targetItem.pop()?.fnHandle()
|
||||||
}
|
}
|
||||||
console.log(optionsHandle ? optionsHandle(menuOptions) : menuOptions)
|
|
||||||
return {
|
return {
|
||||||
menuOptions: optionsHandle ? optionsHandle(menuOptions) : menuOptions,
|
menuOptions: optionsHandle ? optionsHandle(menuOptions) : menuOptions,
|
||||||
handleContextMenu,
|
handleContextMenu,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user