From 0fa257464e57062d81bbb90611c3eaf6dde4f51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E6=B0=B8=E9=A1=BA?= <971387674@qq.com> Date: Mon, 12 Jun 2023 11:13:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=9B=E5=BE=AE=E8=96=AA=E8=B5=84=E6=A0=B8?= =?UTF-8?q?=E7=AE=97iframe=E8=A1=A8=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/commonTable/index.tsx | 102 ++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/pages/commonTable/index.tsx diff --git a/src/pages/commonTable/index.tsx b/src/pages/commonTable/index.tsx new file mode 100644 index 0000000..4acab2b --- /dev/null +++ b/src/pages/commonTable/index.tsx @@ -0,0 +1,102 @@ +import React, { FC, useEffect, useState } from "react"; +import { Table, Tag, Typography } from "antd"; +import { exceptStr, paginationFun } from "@/utils/common"; +import styles from "@/pages/atdTable/components/index.less"; +import { defaultPage, IPage } from "@/common/types"; + +const { Text } = Typography; +const CommonTable: FC = (props) => { + const [columns, setColumns] = useState>([]); + const [sumRow, setSumRow] = useState>({}); + const [pageInfo, setPageInfo] = useState(defaultPage); + const [dataSource, setDataSource] = useState>([]); + const [showSumrow, setShowSumrow] = useState(false); + + useEffect(() => { + window.parent.postMessage({ type: "init" }, "*"); + window.addEventListener("message", receiveMessageFromIndex, false); + return () => { + window.removeEventListener("message", receiveMessageFromIndex, false); + }; + }, []); + const receiveMessageFromIndex = (event: any) => { + const data: any = exceptStr(event.data); + if (!_.isEmpty(data)) { + const { columns, dataSource, countResult, showSum, pageInfo } = data; + const { current: pageNum, pageSize: size, total } = pageInfo; + setDataSource(dataSource); + setColumns(_.map(columns, item => { + if (item.dataIndex === "salarySob") { + return { + ...item, + render: (text: string, r: { acctTimes?: number }) => { + return
+ {text} + {`第${r?.acctTimes}次`} +
; + } + }; + } + return { ...item }; + })); + setShowSumrow(showSum); + setSumRow(countResult); + setPageInfo({ pageNum, size, total }); + } + }; + const sizeChange = (pageobj: IPage) => { + }; + const onChange = (pageobj: IPage) => { + setPageInfo({ ...pageInfo, ...pageobj }); + window.parent.postMessage( + { + type: "turn", + payload: { id: "PAGEINFO", params: { ...pageInfo, ...pageobj } } + }, + "*" + ); + }; + return { + if (!showSumrow) return; + let totalColumns: any[] = []; + _.forEach(columns, it => { + if (!it.children) { + totalColumns.push(it); + } else { + totalColumns = [...totalColumns, ...it.children]; + } + }); + return ( + + + { + _.map([...totalColumns], (item, index) => { + if (index === 0) { + return 总计; + } + return + {!_.isNil(sumRow[item.dataIndex]) ? sumRow[item.dataIndex] : "-"} + ; + }) + } + + + ); + }} + />; +}; + +export default CommonTable;