59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
// utils/tableHelpers.ts
|
|
import { TableDropdownMenuItem } from "@/components/EnhancedProTable/types";
|
|
|
|
/**
|
|
* 构建 TableDropdown 菜单项
|
|
*/
|
|
export const buildTableDropdownMenuItems = (
|
|
actions: Array<{
|
|
key: string;
|
|
label: string;
|
|
icon?: React.ReactNode;
|
|
danger?: boolean;
|
|
disabled?: boolean;
|
|
}>
|
|
): TableDropdownMenuItem[] => {
|
|
return actions.map((action) => ({
|
|
key: action.key,
|
|
name: action.label,
|
|
icon: action.icon,
|
|
danger: action.danger,
|
|
disabled: action.disabled,
|
|
}));
|
|
};
|
|
|
|
/**
|
|
* 处理 TableDropdown 选择事件
|
|
*/
|
|
export const handleTableDropdownSelect = <T>(
|
|
key: string | number,
|
|
actions: Array<{
|
|
key: string;
|
|
onClick: (record: T, action?: any) => void;
|
|
}>,
|
|
record: T,
|
|
action?: any
|
|
) => {
|
|
const selectedAction = actions.find((item) => item.key === key);
|
|
if (selectedAction) {
|
|
selectedAction.onClick(record, action);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 格式化分页显示文本
|
|
*/
|
|
export const formatPaginationTotal = (
|
|
total: number,
|
|
range: [number, number]
|
|
) => {
|
|
return `第 ${range[0]}-${range[1]} 条/总共 ${total} 条`;
|
|
};
|
|
|
|
/**
|
|
* 生成唯一的表格键
|
|
*/
|
|
export const generateTableKey = (prefix: string) => {
|
|
return `${prefix}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
};
|