fix: action绑定

This commit is contained in:
xingyu4j
2025-07-19 17:22:50 +08:00
parent cf27fd8ce9
commit cc3bf7e8a3

View File

@@ -4,7 +4,7 @@ import type { PropType } from 'vue';
import type { ActionItem, PopConfirm } from './typing';
import { computed, unref } from 'vue';
import { computed, unref, watch } from 'vue';
import { useAccess } from '@vben/access';
import { IconifyIcon } from '@vben/icons';
@@ -60,21 +60,20 @@ function isIfShow(action: ActionItem): boolean {
/** 处理按钮 actions */
const getActions = computed(() => {
return (props.actions || []).filter((action: ActionItem) => isIfShow(action));
const actions = props.actions || [];
return actions.filter((action: ActionItem) => isIfShow(action));
});
/** 处理下拉菜单 actions */
const getDropdownList = computed(() => {
return (props.dropDownActions || []).filter((action: ActionItem) =>
isIfShow(action),
);
const dropDownActions = props.dropDownActions || [];
return dropDownActions.filter((action: ActionItem) => isIfShow(action));
});
/** Space 组件的 size */
const spaceSize = computed(() => {
return unref(getActions)?.some((item: ActionItem) => item.type === 'link')
? 0
: 8;
const actions = unref(getActions);
return actions?.some((item: ActionItem) => item.type === 'link') ? 0 : 8;
});
/** 获取 PopConfirm 属性 */
@@ -137,6 +136,15 @@ function handleButtonClick(action: ActionItem) {
action.onClick();
}
}
// 监听props变化强制重新计算
watch(
() => [props.actions, props.dropDownActions],
() => {
// 这里不需要额外处理computed会自动重新计算
},
{ deep: true },
);
</script>
<template>