index.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React, { useCallback, useEffect, useState } from "react";
  2. import styles from "./index.module.scss";
  3. import classNames from "classnames";
  4. import { Pagination } from "antd";
  5. import { envUrl } from "@/utils/env";
  6. import { A2_APIgetKnowData } from "@/store/action/A2Main";
  7. import { useDispatch, useSelector } from "react-redux";
  8. import { RootState } from "@/store";
  9. import ImageLazy from "@/components/ImageLazy";
  10. import Tab5Info from "../Tab5Info";
  11. const list = [
  12. { id: 1, name: "全部", type: "" },
  13. { id: 2, name: "历史", type: "历史" },
  14. { id: 3, name: "军事", type: "军事" },
  15. { id: 4, name: "人物", type: "人物" },
  16. // { id: 5, name: "其他", type: "其他" },
  17. ];
  18. function Tab5() {
  19. const dispatch = useDispatch();
  20. const [fromData, setFromData] = useState({
  21. tagType: "",
  22. pageNum: 1,
  23. pageSize: 10,
  24. });
  25. const getListFu = useCallback(async () => {
  26. dispatch(A2_APIgetKnowData(fromData));
  27. }, [dispatch, fromData]);
  28. useEffect(() => {
  29. getListFu();
  30. }, [getListFu]);
  31. const tab5List = useSelector((state: RootState) => state.A2Main.tab5List);
  32. // 打开详情页的id
  33. const [infoId, setInfoId] = useState(0);
  34. return (
  35. <div
  36. className={styles.Tab5}
  37. style={{ backgroundImage: `url(${envUrl}/goods/bac.jpg)` }}
  38. >
  39. <div className="tab5Top">
  40. {list.map((v) => (
  41. <div
  42. onClick={() =>
  43. setFromData({ ...fromData, tagType: v.type, pageNum: 1 })
  44. }
  45. key={v.id}
  46. className={classNames(
  47. "tab5TopRow",
  48. fromData.tagType === v.type ? "tab5TopRowAc" : ""
  49. )}
  50. >
  51. {v.name}
  52. </div>
  53. ))}
  54. </div>
  55. <div className="tab5Main">
  56. {tab5List.list.map((v) => (
  57. <div
  58. className="tab5Row"
  59. key={v.id}
  60. title={v.name}
  61. onClick={() => setInfoId(v.id)}
  62. >
  63. <div>
  64. <ImageLazy src={v.thumb} width="100%" height="100%" noLook />
  65. </div>
  66. <p>{v.name}</p>
  67. </div>
  68. ))}
  69. </div>
  70. {/* 分页器 */}
  71. <div className="tab5Page">
  72. <Pagination
  73. showQuickJumper
  74. current={fromData.pageNum}
  75. total={tab5List.total}
  76. pageSize={10}
  77. hideOnSinglePage={true}
  78. onChange={(page) => setFromData({ ...fromData, pageNum: page })}
  79. showSizeChanger={false}
  80. />
  81. </div>
  82. {infoId ? <Tab5Info sId={infoId} closeFu={() => setInfoId(0)} /> : null}
  83. </div>
  84. );
  85. }
  86. const MemoTab5 = React.memo(Tab5);
  87. export default MemoTab5;