This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
type ParamsType,
|
||||
ProTable,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, Space } from 'antd';
|
||||
import { Button, Space, Table } from 'antd';
|
||||
import React, { forwardRef, useCallback, useMemo, useState } from 'react';
|
||||
import { formatPaginationTotal } from '@/utils/antd/tableHelpers';
|
||||
import type { BaseRecord, EnhancedProTableProps } from './types';
|
||||
@@ -33,7 +33,7 @@ function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
||||
// onExport,
|
||||
// customToolbarRender,
|
||||
customActionRender,
|
||||
rowKey,
|
||||
rowKey = 'id',
|
||||
...restProps
|
||||
} = props;
|
||||
|
||||
@@ -42,84 +42,48 @@ function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
||||
// 行选择配置
|
||||
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.id?.toString(),
|
||||
name: record[rowKey]?.toString(),
|
||||
}),
|
||||
};
|
||||
}, [showSelection, selectedRowKeys]);
|
||||
|
||||
// 表格提醒渲染
|
||||
const tableAlertRender = useCallback(
|
||||
({ selectedRowKeys, onCleanSelected }: any) => {
|
||||
if (!showSelection || selectedRowKeys.length === 0) return false;
|
||||
|
||||
return (
|
||||
<Space size={24}>
|
||||
<span>
|
||||
已选 {selectedRowKeys.length} 项
|
||||
<a style={{ marginLeft: 8 }} onClick={onCleanSelected}>
|
||||
取消选择
|
||||
</a>
|
||||
</span>
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
[showSelection],
|
||||
);
|
||||
|
||||
const toolBarRender = useCallback(() =>
|
||||
// action: ActionType | undefined,
|
||||
// rows: {
|
||||
// selectedRowKeys?: (string | number)[] | undefined;
|
||||
// selectedRows?: T[] | undefined;
|
||||
// }
|
||||
{
|
||||
const toolbarElements =
|
||||
toolbarActions?.map((action) => {
|
||||
return (
|
||||
<Button
|
||||
key={action.key}
|
||||
type={action.type}
|
||||
danger={action.danger}
|
||||
disabled={action.disabled}
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => action.onClick(selectedRowKeys, selectedRows)}
|
||||
>
|
||||
{action.label}
|
||||
</Button>
|
||||
);
|
||||
}) || [];
|
||||
// return [
|
||||
// <Button
|
||||
// key="button"
|
||||
// icon={<PlusOutlined />}
|
||||
// onClick={}
|
||||
// type="primary"
|
||||
// >
|
||||
// 新建
|
||||
// </Button>,
|
||||
// ];
|
||||
return toolbarElements;
|
||||
}, [toolbarActions]);
|
||||
const toolBarRender = useCallback(() => {
|
||||
const toolbarElements =
|
||||
toolbarActions?.map((action) => {
|
||||
return (
|
||||
<Button
|
||||
key={action.key}
|
||||
type={action.type}
|
||||
danger={action.danger}
|
||||
disabled={action.disabled}
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => action.onClick(selectedRowKeys, selectedRows)}
|
||||
>
|
||||
{action.label}
|
||||
</Button>
|
||||
);
|
||||
}) || [];
|
||||
return toolbarElements;
|
||||
}, [toolbarActions]);
|
||||
return (
|
||||
<ProTable<T, U>
|
||||
{...restProps}
|
||||
columns={columns}
|
||||
actionRef={ref}
|
||||
request={request}
|
||||
rowKey={rowKey || 'id'}
|
||||
rowKey={rowKey}
|
||||
rowSelection={rowSelection}
|
||||
toolBarRender={toolBarRender}
|
||||
manualRequest={false}
|
||||
showSorterTooltip
|
||||
tableAlertRender={tableAlertRender}
|
||||
scroll={{ x: 'max-content' }}
|
||||
search={{
|
||||
labelWidth: 'auto',
|
||||
|
||||
Reference in New Issue
Block a user