import { computed, defineComponent, ref } from 'vue'; import type { PropType } from 'vue'; import { ElButton, ElPopover } from 'element-plus'; import { $t } from '@/locales'; export type BusinessTableAction = { key: string; label: string; buttonType?: 'primary' | 'success' | 'warning' | 'danger' | 'info'; disabled?: boolean; onClick: () => void | Promise; }; export default defineComponent({ name: 'BusinessTableActionCell', props: { actions: { type: Array as PropType, required: true } }, setup(props) { const popoverVisible = ref(false); const directActions = computed(() => { if (props.actions.length <= 2) { return props.actions; } return props.actions.slice(0, 1); }); const moreActions = computed(() => { if (props.actions.length <= 2) { return []; } return props.actions.slice(1); }); async function handleAction(action: BusinessTableAction) { if (action.disabled) { return; } popoverVisible.value = false; await action.onClick(); } return () => (
event.stopPropagation()}> {directActions.value.map(action => ( handleAction(action)} > {action.label} ))} {moreActions.value.length > 0 && ( {{ reference: () => ( event.stopPropagation()} > {$t('common.more')} ), default: () => (
{moreActions.value.map(action => ( handleAction(action)} > {action.label} ))}
) }}
)}
); } });