Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit baad5a9

Browse files
authored
feat: add context-menu demo (#324)
1 parent 4e54f09 commit baad5a9

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<script lang="ts" setup>
2+
import { h, nextTick, ref } from 'vue'
3+
import { Icon } from '@vben/components/index'
4+
import { useMsg } from '@vben/vbencomponents'
5+
6+
const msg = useMsg()
7+
8+
const renderIcon = (icon: string) => {
9+
return () => h(Icon, { class: 'mr-2', icon })
10+
}
11+
12+
const x = ref(0)
13+
const y = ref(0)
14+
const showDropdown = ref(false)
15+
const options = [
16+
{
17+
key: 'New',
18+
label: 'New',
19+
icon: renderIcon('bi:plus'),
20+
children: [
21+
{
22+
key: 'New1-1',
23+
label: 'New1-1',
24+
icon: renderIcon('bi:plus'),
25+
children: [
26+
{ key: 'New1-1-1', label: 'New1-1-1' },
27+
{ key: 'New1-2-1', label: 'New1-2-1', disabled: true },
28+
],
29+
},
30+
{ key: 'New1-2', label: 'New1-2', icon: renderIcon('bi:plus') },
31+
],
32+
},
33+
]
34+
35+
const handleSelect = (key: string | number) => {
36+
showDropdown.value = false
37+
msg.info(String(key))
38+
}
39+
const handleContextMenu = (e: MouseEvent) => {
40+
e.preventDefault()
41+
showDropdown.value = false
42+
nextTick().then(() => {
43+
showDropdown.value = true
44+
x.value = e.clientX
45+
y.value = e.clientY
46+
})
47+
}
48+
const onClickoutside = () => {
49+
msg.info('clickoutside')
50+
showDropdown.value = false
51+
}
52+
</script>
53+
54+
<template>
55+
<VbenCard title="右键菜单示例">
56+
<VbenCard title="Simple">
57+
<VbenButton type="primary" @contextmenu="handleContextMenu">
58+
Right Click on me
59+
</VbenButton>
60+
<VbenDropdown
61+
placement="bottom-start"
62+
trigger="manual"
63+
:x="x"
64+
:y="y"
65+
:options="options"
66+
:show="showDropdown"
67+
:on-clickoutside="onClickoutside"
68+
@select="handleSelect"
69+
/>
70+
</VbenCard>
71+
</VbenCard>
72+
</template>

packages/locale/src/lang/en/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export default {
7676
requestDemo: 'Retry request demo',
7777
sessionTimeout: 'Session Timeout',
7878
icon: 'Icon',
79+
contextMenu: 'Context Menu',
7980
},
8081
page: {
8182
page: 'Page',

packages/locale/src/lang/zh-CN/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export default {
7777
requestDemo: '测试请求重试',
7878
sessionTimeout: '登录过期',
7979
icon: '图标',
80+
contextMenu: '右键菜单',
8081
},
8182
page: {
8283
page: '页面',

packages/router/src/routes/modules/demo/feat.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ const feat: RouteRecordItem = {
108108
title: 'routes.demo.feat.icon',
109109
},
110110
},
111+
{
112+
path: 'context-menu',
113+
name: 'ContextMenuDemo',
114+
component: () => import('@/pages/demo/feat/context-menu.vue'),
115+
meta: {
116+
title: 'routes.demo.feat.contextMenu',
117+
},
118+
},
111119
],
112120
}
113121

0 commit comments

Comments
 (0)