|
@@ -0,0 +1,230 @@
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
+import styles from "./index.module.scss";
|
|
|
+import { baseURL } from "@/utils/http";
|
|
|
+import { type1Arr1M } from "./data";
|
|
|
+import { Input, Select } from "antd";
|
|
|
+import { SearchOutlined } from "@ant-design/icons";
|
|
|
+import backImg from "@/assets/img/back.png";
|
|
|
+import history from "@/utils/history";
|
|
|
+import { useSelector } from "react-redux";
|
|
|
+import { RootState } from "@/store";
|
|
|
+import ImageLazy from "@/components/ImageLazy";
|
|
|
+import { Goods } from "@/types";
|
|
|
+// import lookImg from "@/assets/img/look.png";
|
|
|
+import { UpOutlined } from "@ant-design/icons";
|
|
|
+import GoodsInfoM from "./GoodsInfoM";
|
|
|
+
|
|
|
+function A3GoodsM() {
|
|
|
+ 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 = type1Arr1M.find((v) => v.name === type1);
|
|
|
+ if (info) return `tab${info.id}Bac.jpg`;
|
|
|
+ else return "";
|
|
|
+ }, [type1]);
|
|
|
+
|
|
|
+ // 输入框
|
|
|
+ const inputRef = useRef<any>(null);
|
|
|
+ const [searchKey, setSearchKey] = useState(-1);
|
|
|
+
|
|
|
+ // 右侧类别的筛选
|
|
|
+ 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 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ return arr;
|
|
|
+ }, [data, searchKey, type1, type2]);
|
|
|
+
|
|
|
+ // 每次变化的时候 滚动到顶部
|
|
|
+ const fullTopFu = useCallback(() => {
|
|
|
+ if (scrollRef.current) {
|
|
|
+ scrollRef.current.scrollTop = 0;
|
|
|
+ window.setTimeout(() => {
|
|
|
+ if (scrollRef.current) scrollRef.current.scrollTop = 1;
|
|
|
+ }, 100);
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ fullTopFu();
|
|
|
+ }, [fullTopFu, searchKey, type1, type2]);
|
|
|
+
|
|
|
+ // 查看文物详情
|
|
|
+ const [goodsInfo, setGoodsInfo] = useState({} as Goods);
|
|
|
+
|
|
|
+ // 手机打开输入框的时候 下面主体变形
|
|
|
+ useEffect(() => {
|
|
|
+ const num = document.documentElement.clientHeight;
|
|
|
+ const dom: HTMLDivElement | null = document.querySelector("#A3GoodsM");
|
|
|
+ if (dom) dom.style.height = num + "px";
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // 滚动距离
|
|
|
+
|
|
|
+ const [scrollShow, setScrollShow] = useState(false);
|
|
|
+
|
|
|
+ const scrollRef = useRef<HTMLDivElement>(null);
|
|
|
+
|
|
|
+ const scrollFu = useCallback(() => {
|
|
|
+ if (scrollRef.current) {
|
|
|
+ const num = scrollRef.current.scrollTop;
|
|
|
+ setScrollShow(num >= 400);
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ window.addEventListener("scroll", scrollFu, true);
|
|
|
+
|
|
|
+ return () => {
|
|
|
+ window.removeEventListener("scroll", scrollFu);
|
|
|
+ };
|
|
|
+ }, [scrollFu]);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ id="A3GoodsM"
|
|
|
+ className={styles.A3GoodsM}
|
|
|
+ style={{
|
|
|
+ backgroundImage: `url(${baseURL}/3Goods/mobile/${imgBac})`,
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <div
|
|
|
+ className="A3Gtop"
|
|
|
+ style={{ backgroundImage: `url(${baseURL}/3Goods/mobile/top.png)` }}
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ onClick={() => history.push("/")}
|
|
|
+ className="A3Back"
|
|
|
+ src={backImg}
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+
|
|
|
+ {/* 输入框 */}
|
|
|
+ <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 className="A3Gtop1">
|
|
|
+ <div className="A3Gtop1_1">
|
|
|
+ <Select
|
|
|
+ style={{ width: "100%" }}
|
|
|
+ value={type1}
|
|
|
+ onChange={(e) => setType1(e)}
|
|
|
+ options={type1Arr1M.map((v) => ({
|
|
|
+ value: v.name,
|
|
|
+ label: v.name,
|
|
|
+ }))}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div className="A3Gtop1_1">
|
|
|
+ <Select
|
|
|
+ style={{ width: "100%" }}
|
|
|
+ value={type2}
|
|
|
+ onChange={(e) => setType2(e)}
|
|
|
+ options={type2Arr.map((v) => ({ value: v, label: v }))}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 主体 */}
|
|
|
+ {dataRes && dataRes.length ? (
|
|
|
+ <div className="A3Main" ref={scrollRef}>
|
|
|
+ {dataRes.map((v) => (
|
|
|
+ <div className="A3Row" key={v.id} onClick={() => setGoodsInfo(v)}>
|
|
|
+ <ImageLazy
|
|
|
+ src={`${baseURL}/3Goods/${v.id}/main.jpg`}
|
|
|
+ width="100%"
|
|
|
+ height={160}
|
|
|
+ noLook
|
|
|
+ offline
|
|
|
+ />
|
|
|
+ <div className="A3RowHo">{v.name}</div>
|
|
|
+ {/* 查看的小图片 */}
|
|
|
+ {/* <div className="lookImg">
|
|
|
+ <img src={lookImg} alt="" />
|
|
|
+ </div> */}
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ ) : (
|
|
|
+ <div className="noRow">暂无数据</div>
|
|
|
+ )}
|
|
|
+
|
|
|
+ {/* 返回顶部 */}
|
|
|
+ <div className="A3ToTop" hidden={!scrollShow} onClick={fullTopFu}>
|
|
|
+ <div className="A3ToTop1">
|
|
|
+ <UpOutlined rev={undefined} />
|
|
|
+ </div>
|
|
|
+ <div className="A3ToTop2">回到顶部</div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 查看文物详情 */}
|
|
|
+ {goodsInfo.id ? (
|
|
|
+ <GoodsInfoM
|
|
|
+ type={type1}
|
|
|
+ info={goodsInfo}
|
|
|
+ colseFu={() => setGoodsInfo({} as Goods)}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+const MemoA3GoodsM = React.memo(A3GoodsM);
|
|
|
+
|
|
|
+export default MemoA3GoodsM;
|