This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e54f09
commit baad5a9
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<script lang="ts" setup> | ||
import { h, nextTick, ref } from 'vue' | ||
import { Icon } from '@vben/components/index' | ||
import { useMsg } from '@vben/vbencomponents' | ||
const msg = useMsg() | ||
const renderIcon = (icon: string) => { | ||
return () => h(Icon, { class: 'mr-2', icon }) | ||
} | ||
const x = ref(0) | ||
const y = ref(0) | ||
const showDropdown = ref(false) | ||
const options = [ | ||
{ | ||
key: 'New', | ||
label: 'New', | ||
icon: renderIcon('bi:plus'), | ||
children: [ | ||
{ | ||
key: 'New1-1', | ||
label: 'New1-1', | ||
icon: renderIcon('bi:plus'), | ||
children: [ | ||
{ key: 'New1-1-1', label: 'New1-1-1' }, | ||
{ key: 'New1-2-1', label: 'New1-2-1', disabled: true }, | ||
], | ||
}, | ||
{ key: 'New1-2', label: 'New1-2', icon: renderIcon('bi:plus') }, | ||
], | ||
}, | ||
] | ||
const handleSelect = (key: string | number) => { | ||
showDropdown.value = false | ||
msg.info(String(key)) | ||
} | ||
const handleContextMenu = (e: MouseEvent) => { | ||
e.preventDefault() | ||
showDropdown.value = false | ||
nextTick().then(() => { | ||
showDropdown.value = true | ||
x.value = e.clientX | ||
y.value = e.clientY | ||
}) | ||
} | ||
const onClickoutside = () => { | ||
msg.info('clickoutside') | ||
showDropdown.value = false | ||
} | ||
</script> | ||
|
||
<template> | ||
<VbenCard title="右键菜单示例"> | ||
<VbenCard title="Simple"> | ||
<VbenButton type="primary" @contextmenu="handleContextMenu"> | ||
Right Click on me | ||
</VbenButton> | ||
<VbenDropdown | ||
placement="bottom-start" | ||
trigger="manual" | ||
:x="x" | ||
:y="y" | ||
:options="options" | ||
:show="showDropdown" | ||
:on-clickoutside="onClickoutside" | ||
@select="handleSelect" | ||
/> | ||
</VbenCard> | ||
</VbenCard> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters