|
@@ -0,0 +1,211 @@
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
+import styles from "./index.module.scss";
|
|
|
+import { useSelector } from "react-redux";
|
|
|
+import { RootState } from "@/store";
|
|
|
+import backImg from "@/assets/img/back.png";
|
|
|
+import { baseURL } from "@/utils/http";
|
|
|
+import history from "@/utils/history";
|
|
|
+import classNames from "classnames";
|
|
|
+import { Input, Pagination, Select } from "antd";
|
|
|
+import { SearchOutlined } from "@ant-design/icons";
|
|
|
+import ImageLazy from "@/components/ImageLazy";
|
|
|
+import _ from "lodash";
|
|
|
+import GoodsInfo from "./GoodsInfo";
|
|
|
+import { Goods } from "@/types";
|
|
|
+import { type1Arr1 } from "./data";
|
|
|
+
|
|
|
+function A3Goods() {
|
|
|
+ const dataTemp = useSelector(
|
|
|
+ (state: RootState) => state.A0Layout.dataAll.goods
|
|
|
+ );
|
|
|
+
|
|
|
+ const data = useMemo(() => {
|
|
|
+ if (dataTemp) return dataTemp;
|
|
|
+ else return [];
|
|
|
+ }, [dataTemp]);
|
|
|
+
|
|
|
+ // 左侧馆的筛选
|
|
|
+ const [type1, setType1] = useState("全部");
|
|
|
+
|
|
|
+ // 背景图
|
|
|
+ const imgBac = useMemo(() => {
|
|
|
+ const info = type1Arr1.find((v) => v.name === type1);
|
|
|
+ if (info) return `tab${info.id}Bac.jpg`;
|
|
|
+ else return "";
|
|
|
+ }, [type1]);
|
|
|
+
|
|
|
+ // 右侧类别的筛选
|
|
|
+ const [type2, setType2] = useState("全部类别");
|
|
|
+
|
|
|
+ // 右侧类别的下拉框
|
|
|
+ const type2Arr = useMemo(() => {
|
|
|
+ const arr = ["全部类别"];
|
|
|
+ data.forEach((v) => {
|
|
|
+ if (!arr.includes(v.type2)) arr.push(v.type2);
|
|
|
+ });
|
|
|
+ return arr;
|
|
|
+ }, [data]);
|
|
|
+
|
|
|
+ // 输入框
|
|
|
+ const inputRef = useRef<any>(null);
|
|
|
+ const [searchKey, setSearchKey] = useState(-1);
|
|
|
+
|
|
|
+ // 页码
|
|
|
+ const [page, setPage] = useState(1);
|
|
|
+
|
|
|
+ // 在页面渲染的数据
|
|
|
+ const dataRes = useMemo(() => {
|
|
|
+ console.log(searchKey);
|
|
|
+
|
|
|
+ // 所有数据
|
|
|
+ let arr = [...data];
|
|
|
+
|
|
|
+ // 筛选 左侧
|
|
|
+ if (type1 !== "全部") arr = arr.filter((v) => v.type1 === type1);
|
|
|
+
|
|
|
+ // 筛选 右侧
|
|
|
+ if (type2 !== "全部类别") arr = arr.filter((v) => v.type2 === type2);
|
|
|
+
|
|
|
+ if (inputRef.current) {
|
|
|
+ const val = inputRef.current.input.value.trim();
|
|
|
+ arr = arr.filter((v) => v.name.includes(val) || !val);
|
|
|
+ }
|
|
|
+ // 分页(8条一页)
|
|
|
+ const arrs = _.chunk(arr, 8);
|
|
|
+
|
|
|
+ return { arrs, total: arr.length };
|
|
|
+ }, [data, searchKey, type1, type2]);
|
|
|
+
|
|
|
+ // 筛选和输入框变化的时候,page变成1
|
|
|
+ useEffect(() => {
|
|
|
+ setPage(1);
|
|
|
+ }, [type1, type2, searchKey]);
|
|
|
+
|
|
|
+ // 分页器
|
|
|
+ const pageChangeFu = useCallback((pageNum: number) => {
|
|
|
+ setPage(pageNum);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // 查看文物详情
|
|
|
+ const [goodsInfo, setGoodsInfo] = useState({} as Goods);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ className={styles.A3Goods}
|
|
|
+ style={{
|
|
|
+ backgroundImage: `url(${baseURL}/3Goods/pc/${imgBac})`,
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {/* 顶部 */}
|
|
|
+ <div
|
|
|
+ className="A3top"
|
|
|
+ style={{ backgroundImage: `url(${baseURL}/3Goods/pc/top.png)` }}
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ onClick={() => history.push("/")}
|
|
|
+ className="A3Back"
|
|
|
+ src={backImg}
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+
|
|
|
+ {/* 左侧筛选 */}
|
|
|
+ <div className="A3leftBox">
|
|
|
+ {type1Arr1.map((v) => (
|
|
|
+ <div
|
|
|
+ onClick={() => setType1(v.name)}
|
|
|
+ className={classNames(v.name === type1 ? "active" : "")}
|
|
|
+ key={v.id}
|
|
|
+ >
|
|
|
+ {v.name}
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 右侧筛选 */}
|
|
|
+ <div className="A3RightBox">
|
|
|
+ <div className="A3RightBox1">
|
|
|
+ <Select
|
|
|
+ style={{ width: 200 }}
|
|
|
+ value={type2}
|
|
|
+ onChange={(e) => setType2(e)}
|
|
|
+ options={type2Arr.map((v) => ({ value: v, label: v }))}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ className="A3RightBox2"
|
|
|
+ onKeyUp={(e) => {
|
|
|
+ if (e.key === "Enter") setSearchKey(Date.now());
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Input ref={inputRef} placeholder="搜索文物" maxLength={15} />
|
|
|
+ {/* 搜索图标 */}
|
|
|
+ <div
|
|
|
+ className="A3searchIcon"
|
|
|
+ onClick={() => setSearchKey(Date.now())}
|
|
|
+ >
|
|
|
+ <SearchOutlined rev={undefined} />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {/* 主体 */}
|
|
|
+ {dataRes.arrs &&
|
|
|
+ dataRes.arrs[page - 1] &&
|
|
|
+ dataRes.arrs[page - 1].length ? (
|
|
|
+ <div className="A3Main">
|
|
|
+ {dataRes.arrs[page - 1].map((v) => (
|
|
|
+ <div className="A3Row" key={v.id}>
|
|
|
+ <ImageLazy
|
|
|
+ src={`${baseURL}/3Goods/${v.id}/main.jpg`}
|
|
|
+ width="100%"
|
|
|
+ height="100%"
|
|
|
+ noLook
|
|
|
+ offline
|
|
|
+ />
|
|
|
+ <div
|
|
|
+ className="A3RowHo"
|
|
|
+ title={v.name}
|
|
|
+ onClick={() => setGoodsInfo(v)}
|
|
|
+ >
|
|
|
+ {v.name}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ {/* 分页器 */}
|
|
|
+ <div className="A3page">
|
|
|
+ <Pagination
|
|
|
+ showQuickJumper
|
|
|
+ current={page}
|
|
|
+ total={dataRes.total}
|
|
|
+ pageSize={10}
|
|
|
+ hideOnSinglePage={true}
|
|
|
+ onChange={pageChangeFu}
|
|
|
+ showSizeChanger={false}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ ) : (
|
|
|
+ <div className="noRow">暂无数据</div>
|
|
|
+ )}
|
|
|
+
|
|
|
+ {/* 查看文物详情 */}
|
|
|
+ {goodsInfo.id ? (
|
|
|
+ <GoodsInfo
|
|
|
+ type={type1}
|
|
|
+ info={goodsInfo}
|
|
|
+ colseFu={() => setGoodsInfo({} as Goods)}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+const MemoA3Goods = React.memo(A3Goods);
|
|
|
+
|
|
|
+export default MemoA3Goods;
|