perf: table actions

This commit is contained in:
xingyu4j
2025-06-12 16:11:54 +08:00
parent 789f202e55
commit c458a43f58

View File

@@ -43,28 +43,27 @@ const { hasAccessByCodes } = useAccess();
function isIfShow(action: ActionItem): boolean { function isIfShow(action: ActionItem): boolean {
const ifShow = action.ifShow; const ifShow = action.ifShow;
let isIfShow = true; let isIfShow = true;
if (isBoolean(ifShow)) { if (isBoolean(ifShow)) {
isIfShow = ifShow; isIfShow = ifShow;
} }
if (isFunction(ifShow)) { if (isFunction(ifShow)) {
isIfShow = ifShow(action); isIfShow = ifShow(action);
} }
if (isIfShow) {
isIfShow =
hasAccessByCodes(action.auth || []) || (action.auth || []).length === 0;
}
return isIfShow; return isIfShow;
} }
const getActions = computed(() => { const getActions = computed(() => {
return (toRaw(props.actions) || []) const actions = toRaw(props.actions) || [];
.filter((action) => { return actions
return ( .filter((action: ActionItem) => {
(hasAccessByCodes(action.auth || []) || return isIfShow(action);
(action.auth || []).length === 0) &&
isIfShow(action)
);
}) })
.map((action) => { .map((action: ActionItem) => {
const { popConfirm } = action; const { popConfirm } = action;
return { return {
type: action.type || 'link', type: action.type || 'link',
@@ -78,24 +77,21 @@ const getActions = computed(() => {
}); });
const getDropdownList = computed((): any[] => { const getDropdownList = computed((): any[] => {
return (toRaw(props.dropDownActions) || []) const dropDownActions = toRaw(props.dropDownActions) || [];
.filter((action) => { return dropDownActions
return ( .filter((action: ActionItem) => {
(hasAccessByCodes(action.auth || []) || return isIfShow(action);
(action.auth || []).length === 0) &&
isIfShow(action)
);
}) })
.map((action, index) => { .map((action: ActionItem, index: number) => {
const { label, popConfirm } = action; const { label, popConfirm } = action;
delete action.icon;
return { return {
...action, ...action,
...popConfirm, ...popConfirm,
onConfirm: popConfirm?.confirm, onConfirm: popConfirm?.confirm,
onCancel: popConfirm?.cancel, onCancel: popConfirm?.cancel,
text: label, text: label,
divider: divider: index < dropDownActions.length - 1 ? props.divider : false,
index < props.dropDownActions.length - 1 ? props.divider : false,
}; };
}); });
}); });