table.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import AuthButton from "@/components/AuthButton";
  2. import { RootState } from "@/store";
  3. import { getObj2LogListAPI } from "@/store/action/object2";
  4. import { logTypeObj, logTypeOpenObj } from "@/utils/dataChange";
  5. import { getPowerInfo } from "@/utils/storage";
  6. import { Table } from "antd";
  7. import React, {
  8. useCallback,
  9. useEffect,
  10. useMemo,
  11. useRef,
  12. useState,
  13. } from "react";
  14. import { useDispatch, useSelector } from "react-redux";
  15. type Props = {
  16. id: number;
  17. };
  18. // 根据权限来判断
  19. const powerInfo = getPowerInfo();
  20. function LookObject2Log({ id }: Props) {
  21. const dispatch = useDispatch();
  22. const pageNumRef = useRef(1);
  23. const pagePageRef = useRef(10);
  24. const [tableSelect, setTableSelect] = useState({
  25. pageNum: 1,
  26. pageSize: 10,
  27. goodsId: id,
  28. });
  29. useEffect(() => {
  30. dispatch(getObj2LogListAPI(tableSelect));
  31. }, [dispatch, tableSelect]);
  32. const paginationChange = (pageNum: number, pageSize: number) => {
  33. pageNumRef.current = pageNum;
  34. pagePageRef.current = pageSize;
  35. setTableSelect({ ...tableSelect, pageNum, pageSize });
  36. };
  37. // 从仓库中获取列表信息
  38. const logResults = useSelector(
  39. (state: RootState) => state.object2Store.logList
  40. );
  41. // 点击操作记录里面的查看,打开新的页面
  42. const openURL = useCallback((url: string) => {
  43. window.open(url);
  44. }, []);
  45. const columns = useMemo(() => {
  46. const tempArr = [
  47. {
  48. title: "序号",
  49. render: (text: any, record: any, index: any) =>
  50. index + 1 + (pageNumRef.current - 1) * pagePageRef.current,
  51. },
  52. {
  53. title: "业务单号",
  54. dataIndex: "num",
  55. },
  56. {
  57. title: "业务类型",
  58. render: (item: any) => logTypeObj[item.type],
  59. },
  60. {
  61. title: "完成时间",
  62. dataIndex: "day",
  63. },
  64. {
  65. title: "操作",
  66. render: (item: any) => {
  67. let falg = false;
  68. powerInfo.forEach((v: any) => {
  69. if (
  70. (item.type === "in" && v.id === 300) ||
  71. (item.type === "out" && v.id === 400) ||
  72. (item.type === "move" && v.id === 800) ||
  73. (item.type === "edit" && v.id === 500)
  74. )
  75. falg = true;
  76. });
  77. // 暂时不处理权限问题,后面在完善
  78. return falg ? (
  79. <AuthButton
  80. id={-1}
  81. type="text"
  82. danger
  83. onClick={() => openURL(logTypeOpenObj[item.type] + item.id)}
  84. >
  85. 查看
  86. </AuthButton>
  87. ) : (
  88. "-"
  89. );
  90. },
  91. },
  92. ];
  93. return tempArr;
  94. }, [openURL]);
  95. return (
  96. <Table
  97. size="small"
  98. scroll={{ y: 300 }}
  99. dataSource={logResults.list}
  100. columns={columns}
  101. rowKey="id"
  102. pagination={{
  103. showQuickJumper: true,
  104. position: ["bottomCenter"],
  105. showSizeChanger: true,
  106. current: tableSelect.pageNum,
  107. pageSize: tableSelect.pageSize,
  108. total: logResults.total,
  109. onChange: paginationChange,
  110. }}
  111. />
  112. );
  113. }
  114. const MemoLookObject2Log = React.memo(LookObject2Log);
  115. export default MemoLookObject2Log;