|
@@ -1,9 +1,9 @@
|
|
|
import { InfiniteScroll } from "antd-mobile";
|
|
|
import clsx from "clsx";
|
|
|
-import { FC, ReactNode } from "react";
|
|
|
+import { FC, JSX, ReactNode } from "react";
|
|
|
type position = "left" | "right" | "center";
|
|
|
-interface TableHeaderItem {
|
|
|
- title: string;
|
|
|
+export interface TableHeaderItem {
|
|
|
+ title: string | JSX.Element;
|
|
|
dataIndex: string;
|
|
|
width?: string | number;
|
|
|
align?: position;
|
|
@@ -21,6 +21,8 @@ interface Props {
|
|
|
// loadMore 加载更多
|
|
|
loadMore: (isRetry: boolean) => Promise<void>;
|
|
|
hasMore: boolean;
|
|
|
+ isLoadMore?: boolean;
|
|
|
+ isBackground?: boolean;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -43,12 +45,25 @@ const TbodyItem = ({ data, config, index, children }: any) => {
|
|
|
};
|
|
|
|
|
|
const Table: FC<Props> = (props) => {
|
|
|
- const { columns, loadMore, dataSource, maxHeight, hasMore, threshold = 100 } = props;
|
|
|
+ const {
|
|
|
+ columns,
|
|
|
+ loadMore,
|
|
|
+ dataSource,
|
|
|
+ maxHeight,
|
|
|
+ hasMore,
|
|
|
+ threshold = 100,
|
|
|
+ isLoadMore = true,
|
|
|
+ isBackground = false,
|
|
|
+ } = props;
|
|
|
|
|
|
const cls = clsx(" table-header-group text-[grey] text-[.11rem]");
|
|
|
|
|
|
const bodyCls = clsx(maxHeight ? ` max-h-[${maxHeight}]` : "", "overflow-y-scroll");
|
|
|
|
|
|
+ const headerTrCls = clsx(
|
|
|
+ "h-[40px] border-b-1 border-[#e8e8e8]",
|
|
|
+ isBackground && "odd:bg-[#dedede] even:bg-[#d1d1d1]"
|
|
|
+ );
|
|
|
const colGroup = columns.map((item, index) => {
|
|
|
return <col key={index} style={{ width: item.width }} />;
|
|
|
});
|
|
@@ -58,7 +73,7 @@ const Table: FC<Props> = (props) => {
|
|
|
<table className={"w-[100%]"} style={{ tableLayout: "fixed" }}>
|
|
|
<colgroup>{colGroup}</colgroup>
|
|
|
<thead className={cls}>
|
|
|
- <tr className={`h-[40px] border-b-1 border-[#e8e8e8]`}>
|
|
|
+ <tr className={headerTrCls}>
|
|
|
{columns.map((headItem, index) => (
|
|
|
<TheadItem headItem={headItem} key={index}></TheadItem>
|
|
|
))}
|
|
@@ -69,12 +84,9 @@ const Table: FC<Props> = (props) => {
|
|
|
<div className={bodyCls} style={{ maxHeight: maxHeight }}>
|
|
|
<table className={"w-[100%]"} style={{ tableLayout: "fixed" }}>
|
|
|
<colgroup>{colGroup}</colgroup>
|
|
|
- <tbody>
|
|
|
+ <tbody className={""}>
|
|
|
{dataSource.map((item, index) => (
|
|
|
- <tr
|
|
|
- key={index}
|
|
|
- className={`h-[40px] border-b-1 border-[#e8e8e8] text-center text-[#999]`}
|
|
|
- >
|
|
|
+ <tr key={index} className={`${headerTrCls} text-center text-[#999]`}>
|
|
|
{columns.map((head, headIndex) => (
|
|
|
<TbodyItem
|
|
|
index={index + 1}
|
|
@@ -89,7 +101,10 @@ const Table: FC<Props> = (props) => {
|
|
|
))}
|
|
|
</tbody>
|
|
|
</table>
|
|
|
- <InfiniteScroll loadMore={loadMore} hasMore={hasMore}></InfiniteScroll>
|
|
|
+
|
|
|
+ {isLoadMore && (
|
|
|
+ <InfiniteScroll loadMore={loadMore} hasMore={hasMore}></InfiniteScroll>
|
|
|
+ )}
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|