mirror of
https://gitee.com/dromara/go-view.git
synced 2026-04-23 00:00:12 +08:00
fix: 新增右键和删除功能
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { reactive, ref, nextTick } from 'vue'
|
||||
import { getChartEditStore } from './useStore.hook'
|
||||
const chartEditStore = getChartEditStore()
|
||||
|
||||
enum MenuEnum {
|
||||
DELETE = 'delete'
|
||||
}
|
||||
|
||||
export const useContextMenu = () => {
|
||||
const showDropdownRef = ref(false)
|
||||
const targetIndex = ref<number>(0)
|
||||
|
||||
// * 右键选项
|
||||
const menuOptions = reactive([
|
||||
{
|
||||
label: '删除',
|
||||
key: MenuEnum.DELETE
|
||||
}
|
||||
])
|
||||
|
||||
// * 右键处理
|
||||
const handleContextMenu = (e: MouseEvent, index: number) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
targetIndex.value = index
|
||||
let target = e.target
|
||||
while (target instanceof SVGElement) {
|
||||
target = target.parentNode
|
||||
}
|
||||
showDropdownRef.value = false
|
||||
nextTick().then(() => {
|
||||
chartEditStore.setMousePosition(e.clientX, e.clientY)
|
||||
showDropdownRef.value = true
|
||||
})
|
||||
}
|
||||
|
||||
// * 失焦
|
||||
const onClickoutside = (e: MouseEvent) => {
|
||||
showDropdownRef.value = false
|
||||
}
|
||||
|
||||
// * 事件处理
|
||||
const handleMenuSelect = (key: string) => {
|
||||
showDropdownRef.value = false
|
||||
switch (key) {
|
||||
case MenuEnum.DELETE:
|
||||
chartEditStore.removeComponentList(targetIndex.value)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
showDropdownRef,
|
||||
menuOptions,
|
||||
handleContextMenu,
|
||||
onClickoutside,
|
||||
handleMenuSelect,
|
||||
mousePosition: chartEditStore.getMousePosition
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import { onUnmounted, onMounted } from 'vue'
|
||||
import { onUnmounted, onMounted, ref, nextTick } from 'vue'
|
||||
import { getChartEditStore } from './useStore.hook'
|
||||
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||
|
||||
const chartEditStore = getChartEditStore()
|
||||
|
||||
// 布局处理
|
||||
export const useLayout = () => {
|
||||
onMounted(() => {
|
||||
// 设置 Dom 值(ref 不生效先用 document)
|
||||
@@ -26,4 +27,4 @@ export const useLayout = () => {
|
||||
removeScale()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user