2022-07-07 18:05:46 +00:00
|
|
|
import { reactive, ref } from 'vue'
|
|
|
|
import ContextMenuBase from '@/components/ui/ContextMenuBase.vue'
|
2022-04-20 10:20:09 +00:00
|
|
|
|
|
|
|
export type ContextMenuContext = Record<string, any>
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
|
|
export const useContextMenu = () => {
|
2022-04-24 08:29:14 +00:00
|
|
|
const base = ref<InstanceType<typeof ContextMenuBase>>()
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2022-04-20 10:20:09 +00:00
|
|
|
const context = reactive<ContextMenuContext>({})
|
|
|
|
|
|
|
|
const open = (top: number, left: number, ctx: ContextMenuContext = {}) => {
|
|
|
|
base.value?.open(top, left, ctx)
|
|
|
|
Object.assign(context, ctx)
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const close = () => base.value?.close()
|
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const trigger = (func: Closure) => {
|
|
|
|
close()
|
|
|
|
func()
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
return {
|
|
|
|
base,
|
2022-04-24 08:29:14 +00:00
|
|
|
ContextMenuBase,
|
2022-04-15 17:00:08 +00:00
|
|
|
open,
|
2022-04-20 10:20:09 +00:00
|
|
|
close,
|
2022-06-10 10:47:46 +00:00
|
|
|
trigger,
|
2022-04-20 10:20:09 +00:00
|
|
|
context
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
|
|
|
}
|