feat: 高级列表
This commit is contained in:
58
src/utils/antd/tableHelpers.ts
Normal file
58
src/utils/antd/tableHelpers.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
// 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)}`;
|
||||
};
|
||||
Reference in New Issue
Block a user