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

Commit

Permalink
feat: add context-menu demo (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
DesignHhuang authored Jan 10, 2024
1 parent 4e54f09 commit baad5a9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
72 changes: 72 additions & 0 deletions apps/admin/src/pages/demo/feat/context-menu.vue
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>
1 change: 1 addition & 0 deletions packages/locale/src/lang/en/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default {
requestDemo: 'Retry request demo',
sessionTimeout: 'Session Timeout',
icon: 'Icon',
contextMenu: 'Context Menu',
},
page: {
page: 'Page',
Expand Down
1 change: 1 addition & 0 deletions packages/locale/src/lang/zh-CN/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default {
requestDemo: '测试请求重试',
sessionTimeout: '登录过期',
icon: '图标',
contextMenu: '右键菜单',
},
page: {
page: '页面',
Expand Down
8 changes: 8 additions & 0 deletions packages/router/src/routes/modules/demo/feat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ const feat: RouteRecordItem = {
title: 'routes.demo.feat.icon',
},
},
{
path: 'context-menu',
name: 'ContextMenuDemo',
component: () => import('@/pages/demo/feat/context-menu.vue'),
meta: {
title: 'routes.demo.feat.contextMenu',
},
},
],
}

Expand Down

0 comments on commit baad5a9

Please sign in to comment.