index.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { RootState } from "@/store";
  2. import { getExhibitListAPI } from "@/store/action/exhibit";
  3. import { ExhibitTableType } from "@/types/api/exhibit";
  4. import { Button, Table } from "antd";
  5. import React, {
  6. useCallback,
  7. useEffect,
  8. useMemo,
  9. useRef,
  10. useState,
  11. } from "react";
  12. import { useDispatch, useSelector } from "react-redux";
  13. import ExhibitEdit from "./Edit";
  14. import styles from "./index.module.scss";
  15. function Exhibit() {
  16. const dispatch = useDispatch();
  17. useEffect(() => {
  18. dispatch(getExhibitListAPI());
  19. }, [dispatch]);
  20. // 从仓库中获取列表数据
  21. const results = useSelector((state: RootState) => state.ExhibitReducer.list);
  22. // 点击编辑
  23. const editTableFu = useCallback((id: number) => {
  24. editIdRef.current = id;
  25. setOpen(true);
  26. }, []);
  27. const columns = useMemo(() => {
  28. return [
  29. {
  30. width: 100,
  31. title: "序号",
  32. render: (text: any, record: any, index: any) => index + 1,
  33. },
  34. {
  35. title: "展馆名称",
  36. dataIndex: "name",
  37. },
  38. {
  39. title: "展馆简介",
  40. render: (item: ExhibitTableType) =>
  41. item.description ? (
  42. item.description.length >= 20 ? (
  43. <span style={{ cursor: "pointer" }} title={item.description}>
  44. {item.description.substring(0, 20) + "..."}
  45. </span>
  46. ) : (
  47. item.description
  48. )
  49. ) : (
  50. "(空)"
  51. ),
  52. },
  53. // {
  54. // title: "展馆封面",
  55. // render: (item: ExhibitTableType) => (
  56. // <div className="tableImgAuto">
  57. // <ImageLazy width={60} height={60} src={item.thumb} />
  58. // </div>
  59. // ),
  60. // },
  61. {
  62. title: "联系电话",
  63. dataIndex: "phone",
  64. },
  65. {
  66. title: "展馆地址",
  67. dataIndex: "address",
  68. },
  69. {
  70. title: "开放时间",
  71. dataIndex: "openTime",
  72. },
  73. {
  74. title: "操作",
  75. render: (item: ExhibitTableType, _: any, index: any) => (
  76. <>
  77. <Button
  78. size="small"
  79. type="text"
  80. onClick={() => editTableFu(item.id)}
  81. >
  82. 编辑
  83. </Button>
  84. </>
  85. ),
  86. },
  87. ];
  88. }, [editTableFu]);
  89. // 点击编辑打开弹窗
  90. const [open, setOpen] = useState(false);
  91. const editIdRef = useRef(0);
  92. return (
  93. <div className={styles.Exhibit}>
  94. <div className="pageTitlt">展馆管理</div>
  95. {/* 表格主体 */}
  96. <div className="tableBox">
  97. <Table
  98. // size="small"
  99. scroll={{ y: 700 }}
  100. dataSource={results}
  101. columns={columns}
  102. rowKey="id"
  103. pagination={false}
  104. />
  105. </div>
  106. {/* 点击编辑打开的页面 */}
  107. {open ? (
  108. <ExhibitEdit
  109. id={editIdRef.current}
  110. closeFu={() => setOpen(false)}
  111. upList={() => dispatch(getExhibitListAPI())}
  112. />
  113. ) : null}
  114. </div>
  115. );
  116. }
  117. const MemoExhibit = React.memo(Exhibit);
  118. export default MemoExhibit;