feat: 样本管理
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
// components/EnhancedProTable/EnhancedProTable.tsx
|
||||
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import {
|
||||
type ActionType,
|
||||
type ParamsType,
|
||||
ProTable,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, Space, Table } from 'antd';
|
||||
import React, { forwardRef, useCallback, useMemo, useState } from 'react';
|
||||
import { Button } from 'antd';
|
||||
import React, { forwardRef, useCallback } from 'react';
|
||||
import { formatPaginationTotal } from '@/utils/antd/tableHelpers';
|
||||
import type { BaseRecord, EnhancedProTableProps } from './types';
|
||||
|
||||
@@ -20,10 +19,9 @@ function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
||||
request,
|
||||
// actions = [],
|
||||
// permissions = [],
|
||||
checkPermission = () => true,
|
||||
// checkPermission = () => true,
|
||||
toolbarActions,
|
||||
showIndex = true,
|
||||
showSelection = true,
|
||||
// showIndex = true,
|
||||
// showActions = true,
|
||||
// maxActionCount = 2,
|
||||
// onAdd,
|
||||
@@ -32,28 +30,65 @@ function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
||||
// onView,
|
||||
// onExport,
|
||||
// customToolbarRender,
|
||||
customActionRender,
|
||||
// showSelection = true,
|
||||
rowKey = 'id',
|
||||
// onRow,
|
||||
// rowClassName,
|
||||
// enableRowClick = false,
|
||||
// clickableRowClassName = "clickable-row", // 添加可点击样式
|
||||
...restProps
|
||||
} = props;
|
||||
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||
const [selectedRows, setSelectedRows] = useState<T[]>([]);
|
||||
// 行选择配置
|
||||
const rowSelection = useMemo(() => {
|
||||
if (!showSelection) return undefined;
|
||||
return {
|
||||
selectedRowKeys,
|
||||
selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
|
||||
onChange: (keys: React.Key[], rows: T[]) => {
|
||||
setSelectedRowKeys(keys);
|
||||
setSelectedRows(rows);
|
||||
},
|
||||
getCheckboxProps: (record: T) => ({
|
||||
name: record[rowKey]?.toString(),
|
||||
}),
|
||||
};
|
||||
}, [showSelection, selectedRowKeys]);
|
||||
// const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||
// const [selectedRows, setSelectedRows] = useState<T[]>([]);
|
||||
// // 行选择配置
|
||||
// const rowSelection = useMemo(() => {
|
||||
// if (!showSelection) return undefined;
|
||||
// return {
|
||||
// selectedRowKeys,
|
||||
// selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
|
||||
// onChange: (keys: React.Key[], rows: T[]) => {
|
||||
// setSelectedRowKeys(keys);
|
||||
// setSelectedRows(rows);
|
||||
// },
|
||||
// getCheckboxProps: (record: T) => ({
|
||||
// name: record[rowKey]?.toString(),
|
||||
// }),
|
||||
// };
|
||||
// }, [showSelection, selectedRowKeys]);
|
||||
|
||||
// // 处理行点击事件
|
||||
// const handleRowClick = useCallback(
|
||||
// (record: T, index?: number) => {
|
||||
// console.log("handleRowClick");
|
||||
// if (!enableRowClick) return {};
|
||||
// return {
|
||||
// onClick: (event: React.MouseEvent<HTMLElement>) => {
|
||||
// // 阻止事件冒泡到其他元素
|
||||
// event.stopPropagation();
|
||||
|
||||
// // 如果点击的是 checkbox 或其他交互元素,不处理行选中
|
||||
// const target = event.target as HTMLElement;
|
||||
// console.log("handleRowClick");
|
||||
// if (
|
||||
// target.closest(".ant-checkbox") ||
|
||||
// target.closest(".ant-btn") ||
|
||||
// target.closest(".ant-dropdown") ||
|
||||
// target.closest("a")
|
||||
// ) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // // 切换选中状态
|
||||
// // handleRowSelect(record, !isSelected);
|
||||
|
||||
// // // 调用原始的 onRow 点击事件
|
||||
// onRow?.(record, index)?.onClick?.(event);
|
||||
// },
|
||||
// };
|
||||
// },
|
||||
// [enableRowClick, onRow]
|
||||
// );
|
||||
|
||||
const toolBarRender = useCallback(() => {
|
||||
const toolbarElements =
|
||||
@@ -64,8 +99,8 @@ function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
||||
type={action.type}
|
||||
danger={action.danger}
|
||||
disabled={action.disabled}
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => action.onClick(selectedRowKeys, selectedRows)}
|
||||
// icon={action.icon ?? <PlusOutlined />}
|
||||
onClick={() => action.onClick()}
|
||||
>
|
||||
{action.label}
|
||||
</Button>
|
||||
@@ -80,7 +115,7 @@ function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
||||
actionRef={ref}
|
||||
request={request}
|
||||
rowKey={rowKey}
|
||||
rowSelection={rowSelection}
|
||||
rowSelection={props.rowSelection ?? false}
|
||||
toolBarRender={toolBarRender}
|
||||
manualRequest={false}
|
||||
showSorterTooltip
|
||||
|
||||
Reference in New Issue
Block a user