Files
short-drama-agent-front/src/components/ui/ActionMenu.vue
T

33 lines
1.1 KiB
Vue

<script setup lang="ts">
import { ref } from 'vue'
import { NButton, NDropdown } from 'naive-ui'
import { Ellipsis } from '@lucide/vue'
/** 低频操作集中到键盘可访问的菜单;选中禁用项也不会向外触发动作。 */
const props = withDefaults(
defineProps<{ label?: string; items: { key: string; label: string; disabled?: boolean }[] }>(),
{ label: '更多操作' }
)
const emit = defineEmits<{ select: [key: string] }>()
const open = ref(false)
function select(key: string) {
const item = props.items.find(option => option.key === key)
if (!item || item.disabled) return
emit('select', key)
open.value = false
}
</script>
<template>
<NDropdown trigger="click" placement="bottom-end" :options="items" v-model:show="open" @select="select">
<NButton
quaternary
class="icon-button"
:aria-label="label"
:title="label"
aria-haspopup="menu"
:aria-expanded="open"
><template #icon><Ellipsis :size="18" /></template
></NButton>
</NDropdown>
</template>