diff --git a/src/App.vue b/src/App.vue index 55da46d..a0310a4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -19,34 +19,43 @@ const listConfig = { // 自定义菜单项 const menuItems = [ - { id: 'refresh', label: '刷新列表' }, - { id: 'clear', label: '清空选择' }, - { id: 'export', label: '导出数据' }, + { + id: 'refresh', + label: '刷新列表', + action: (item) => { + console.log('当前选中项:', item) + } + }, + { + id: 'clear', + label: '清空选择', + action: (item) => { + console.log('清空前选中项:', item) + } + }, + { + id: 'export', + label: '导出数据', + action: (item) => { + console.log('当前选中项:', item) + } + }, ] -// 选中项 -const selectedItem = ref(null) - -// 事件处理 -const handleSelect = (item) => { - console.log('Selected:', item) -} - -const handleMenuClick = (item) => { - console.log('Menu clicked:', item) +// 列表项点击事件处理 +const handleItemClick = (item) => { + console.log('点击列表项:', item) } diff --git a/src/components/ProjectList.vue b/src/components/ProjectList.vue index 9b01c6a..c18d648 100644 --- a/src/components/ProjectList.vue +++ b/src/components/ProjectList.vue @@ -22,9 +22,21 @@ const props = defineProps({ menuItems: { type: Array, default: () => [ - { id: 'refresh', label: '刷新列表' }, - { id: 'clear', label: '清空选择' }, - { id: 'export', label: '导出数据' }, + { + id: 'refresh', + label: '刷新列表', + action: (selectedItem) => console.log('刷新列表', selectedItem) + }, + { + id: 'clear', + label: '清空选择', + action: (selectedItem) => console.log('清空选择', selectedItem) + }, + { + id: 'export', + label: '导出数据', + action: (selectedItem) => console.log('导出数据', selectedItem) + }, ] }, // 是否显示工具栏 @@ -43,7 +55,6 @@ const props = defineProps({ const emit = defineEmits([ 'select', // 选中项变化 'click', // 点击项目 - 'menu-click', // 点击菜单项 'context-menu', // 右键菜单 'update:selected' // 支持 v-model:selected ]) @@ -93,7 +104,7 @@ const closeMenu = () => { } const handleMenuClick = (item) => { - emit('menu-click', item) + item.action?.(selectedItem.value) closeMenu() }