|
@@ -1,12 +1,126 @@
|
|
-import React from "react";
|
|
|
|
|
|
+import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
import styles from "./index.module.scss";
|
|
import styles from "./index.module.scss";
|
|
- function A2_Goods() {
|
|
|
|
-
|
|
|
|
|
|
+import logoImg from "@/assets/img/goods/logo.png";
|
|
|
|
+import { GoodsType, goodsArr } from "@/utils/data";
|
|
|
|
+import history, { envUrl } from "@/utils/history";
|
|
|
|
+import { CloseOutlined } from "@ant-design/icons";
|
|
|
|
+import curImg from "@/assets/img/goods/cur.png";
|
|
|
|
+import curAcImg from "@/assets/img/goods/curAc.png";
|
|
|
|
+import GoodsInfo from "./GoodsInfo";
|
|
|
|
+
|
|
|
|
+function A2_Goods() {
|
|
|
|
+ // 一个藏品的宽度
|
|
|
|
+ const goodsWidth = useMemo(() => {
|
|
|
|
+ const fullWidth = window.innerWidth <= 1600 ? 1600 : window.innerWidth;
|
|
|
|
+ const oneWidth = fullWidth / 3.4;
|
|
|
|
+ return oneWidth;
|
|
|
|
+ }, []);
|
|
|
|
+
|
|
|
|
+ // 滚轮提示
|
|
|
|
+ const [curTit, setCurTit] = useState(true);
|
|
|
|
+ const curTimeRef = useRef(0);
|
|
|
|
+ const [curCut, setCurCut] = useState(true);
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (!curTit) {
|
|
|
|
+ localStorage.setItem("WCBWG_CUR", "1");
|
|
|
|
+ clearInterval(curTimeRef.current);
|
|
|
|
+ }
|
|
|
|
+ }, [curTit]);
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ // 开启滚轮提示 图片更换 定时器
|
|
|
|
+ clearInterval(curTimeRef.current);
|
|
|
|
+ curTimeRef.current = window.setInterval(() => {
|
|
|
|
+ setCurCut(!curCut);
|
|
|
|
+ }, 2000);
|
|
|
|
+ }, [curCut]);
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ const isFlag = localStorage.getItem("WCBWG_CUR");
|
|
|
|
+ if (isFlag) setCurTit(false);
|
|
|
|
+ return () => {
|
|
|
|
+ clearInterval(curTimeRef.current);
|
|
|
|
+ };
|
|
|
|
+ }, []);
|
|
|
|
+
|
|
|
|
+ // 滚轮滑动事件
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ const dom = document.querySelector("#goddsSwBox") as HTMLDivElement;
|
|
|
|
+ dom.onwheel = (e) => {
|
|
|
|
+ // 使用过滚轮
|
|
|
|
+ setCurTit(false);
|
|
|
|
+ const num = dom.scrollLeft;
|
|
|
|
+ dom.scrollLeft = num + e.deltaY;
|
|
|
|
+ };
|
|
|
|
+ }, []);
|
|
|
|
+
|
|
|
|
+ // 查看文物详情
|
|
|
|
+ const [info, setInfo] = useState({} as GoodsType);
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div className={styles.A2_Goods}>
|
|
<div className={styles.A2_Goods}>
|
|
- <h1>A2_Goods</h1>
|
|
|
|
|
|
+ {/* 馆藏鉴赏图片 */}
|
|
|
|
+ <div className="logo">
|
|
|
|
+ <img src={logoImg} alt="" />
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+ {/* 回到首页 */}
|
|
|
|
+ <div className="toHomeBox" onClick={() => history.push("/")}></div>
|
|
|
|
+ {/* 文物主体 */}
|
|
|
|
+ <div className="goodsMain" id="goddsSwBox">
|
|
|
|
+ <div
|
|
|
|
+ className="goodsBox"
|
|
|
|
+ style={{ width: goodsWidth * goodsArr.length + "px" }}
|
|
|
|
+ >
|
|
|
|
+ {goodsArr.map((v) => (
|
|
|
|
+ <div
|
|
|
|
+ style={{ width: goodsWidth + "px" }}
|
|
|
|
+ className="goodsRow"
|
|
|
|
+ key={v.id}
|
|
|
|
+ >
|
|
|
|
+ {/* 正常显示的 */}
|
|
|
|
+ <div className="rowShow">
|
|
|
|
+ <div className="rowName">{v.name}</div>
|
|
|
|
+ <div className="rowImg">
|
|
|
|
+ <img src={`${envUrl}/${v.id}.png`} alt="" />
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ {/* 鼠标移入的 */}
|
|
|
|
+ <div className="rowHover">
|
|
|
|
+ <div className="rowName">{v.name}</div>
|
|
|
|
+ <div className="rowImg" onClick={() => setInfo(v)}>
|
|
|
|
+ <img src={`${envUrl}/${v.id}-wenwu.png`} alt="" />
|
|
|
|
+ </div>
|
|
|
|
+ <div className="rowTxt">
|
|
|
|
+ <div className="rowTxtRow">年代:{v.age}</div>
|
|
|
|
+ <div className="rowTxtRow">类别:{v.sort}</div>
|
|
|
|
+ <div className="rowTxtRow">尺寸:{v.size}</div>
|
|
|
|
+ <div className="rowTxtRowZ">{v.intro}</div>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ ))}
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ {/* 滚轮提示 */}
|
|
|
|
+ {curTit ? (
|
|
|
|
+ <div className="curTitBox" hidden={!!info.id}>
|
|
|
|
+ <div className="curClose" onClick={() => setCurTit(false)}>
|
|
|
|
+ <CloseOutlined />
|
|
|
|
+ </div>
|
|
|
|
+ <div className="curImg">
|
|
|
|
+ <img src={curImg} alt="" style={{ opacity: curCut ? 1 : 0 }} />
|
|
|
|
+ <img src={curAcImg} alt="" style={{ opacity: curCut ? 0 : 1 }} />
|
|
|
|
+ </div>
|
|
|
|
+ <p>鼠标滚轮可控制图片滚动</p>
|
|
|
|
+ </div>
|
|
|
|
+ ) : null}
|
|
|
|
+
|
|
|
|
+ {/* 查看文物详情 */}
|
|
|
|
+ <GoodsInfo data={info} closePageFu={() => setInfo({} as GoodsType)} />
|
|
</div>
|
|
</div>
|
|
- )
|
|
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
const MemoA2_Goods = React.memo(A2_Goods);
|
|
const MemoA2_Goods = React.memo(A2_Goods);
|