|
|
@@ -1,4 +1,5 @@
|
|
|
-import {Table as OriTable} from 'antd';
|
|
|
+import {Spin} from 'antd';
|
|
|
+import 'antd/lib/table/style';
|
|
|
import {ColumnsType} from 'antd/es/table';
|
|
|
import {
|
|
|
createPageContext,
|
|
|
@@ -8,6 +9,9 @@ import {
|
|
|
} from '@hooks';
|
|
|
import {PAGE_SIZE_LIST, calcColumnsWidth} from '@utils';
|
|
|
import {ReactElement, useMemo} from 'react';
|
|
|
+import {useTable} from './hooks';
|
|
|
+import {flexRender} from '@tanstack/react-table';
|
|
|
+import css from './index.module.css';
|
|
|
|
|
|
type Props<T> = {
|
|
|
columns: ColumnsType<T>;
|
|
|
@@ -34,6 +38,7 @@ function Table<T extends Record<string, any>>(props: Props<T>): ReactElement {
|
|
|
const [isSearching] = useTableSearchState(searchContext);
|
|
|
const colWidth = calcColumnsWidth(columns);
|
|
|
const scrollX = colWidth > 0 ? {x: colWidth} : void 0;
|
|
|
+ const {getHeaderGroups, getRowModel} = useTable(columns, data);
|
|
|
|
|
|
const tableColumns = useMemo(
|
|
|
function () {
|
|
|
@@ -53,27 +58,45 @@ function Table<T extends Record<string, any>>(props: Props<T>): ReactElement {
|
|
|
);
|
|
|
|
|
|
return (
|
|
|
- <OriTable
|
|
|
- data-testid={props['data-testid']}
|
|
|
- columns={tableColumns as ColumnsType<T>}
|
|
|
- dataSource={data}
|
|
|
- pagination={{
|
|
|
- pageSize,
|
|
|
- showQuickJumper: true,
|
|
|
- pageSizeOptions: pageSizeList,
|
|
|
- total: count,
|
|
|
- showSizeChanger: true,
|
|
|
- onChange: onPageChange,
|
|
|
- current: page,
|
|
|
- showTotal(total) {
|
|
|
- return `共${total}条数据`;
|
|
|
- },
|
|
|
- }}
|
|
|
- rowKey={rowKey ?? 'id'}
|
|
|
- loading={isSearching}
|
|
|
- scroll={scrollX}
|
|
|
- bordered
|
|
|
- />
|
|
|
+ <Spin spinning={isSearching}>
|
|
|
+ <div className={css.tableWrapper}>
|
|
|
+ <table className={css.table}>
|
|
|
+ <thead className={css.tableHead}>
|
|
|
+ {getHeaderGroups().map(function ({id, headers}) {
|
|
|
+ return (
|
|
|
+ <tr key={id}>
|
|
|
+ {headers.map(header => (
|
|
|
+ <th key={header.id}>
|
|
|
+ {header.isPlaceholder
|
|
|
+ ? null
|
|
|
+ : flexRender(
|
|
|
+ header.column.columnDef.header,
|
|
|
+ header.getContext(),
|
|
|
+ )}
|
|
|
+ </th>
|
|
|
+ ))}
|
|
|
+ </tr>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </thead>
|
|
|
+ <tbody className={css.tableBody}>
|
|
|
+ {getRowModel().rows.map(function ({id, getVisibleCells}) {
|
|
|
+ return (
|
|
|
+ <tr key={id}>
|
|
|
+ {getVisibleCells().map(function ({id, column, getContext}) {
|
|
|
+ return (
|
|
|
+ <td key={id}>
|
|
|
+ {flexRender(column.columnDef.cell, getContext())}
|
|
|
+ </td>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </tr>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ </div>
|
|
|
+ </Spin>
|
|
|
);
|
|
|
}
|
|
|
|