|
@@ -0,0 +1,208 @@
|
|
|
+/* eslint-disable jsx-a11y/iframe-has-title */
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
+import styles from "./index.module.scss";
|
|
|
+import backImg from "@/assets/img/goods/toBack.png";
|
|
|
+import { PcTab5ListType } from "@/pages/A2Main/Tab5Info";
|
|
|
+import { A2_APItab5Info } from "@/store/action/A2Main";
|
|
|
+import { envUrl, isEnvFlag } from "@/utils/env";
|
|
|
+import { Spin } from "antd";
|
|
|
+import classNmaes from "classnames";
|
|
|
+import Menu from "../Menu";
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ sId: string;
|
|
|
+ closeFu: () => void;
|
|
|
+ isOpen?: boolean;
|
|
|
+ title?: string;
|
|
|
+};
|
|
|
+
|
|
|
+function Info({ sId, closeFu, isOpen, title }: Props) {
|
|
|
+ // 顶部的标题
|
|
|
+ const [titleTxt, setTitleTxt] = useState("");
|
|
|
+
|
|
|
+ const [data, setData] = useState([] as PcTab5ListType[]);
|
|
|
+
|
|
|
+ const getInfoFu = useCallback(async () => {
|
|
|
+ const res = await A2_APItab5Info(sId);
|
|
|
+ if (res.code === 0) {
|
|
|
+ let tempArr: any[] = [];
|
|
|
+
|
|
|
+ if (res.data && res.data[0]) {
|
|
|
+ // 顶部的标题
|
|
|
+ setTitleTxt(res.data[0].text);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (res.data && res.data[0] && res.data[0].channelChildren)
|
|
|
+ tempArr = res.data[0].channelChildren;
|
|
|
+
|
|
|
+ const arrRes: PcTab5ListType[] = [];
|
|
|
+ tempArr.forEach((v) => {
|
|
|
+ const obj: PcTab5ListType = {
|
|
|
+ id: v.id,
|
|
|
+ name: v.text,
|
|
|
+ flag: v.flag,
|
|
|
+ children: [],
|
|
|
+ };
|
|
|
+ if (v.children && v.children.length) {
|
|
|
+ v.children.forEach((v2: any) => {
|
|
|
+ obj.children!.push({
|
|
|
+ id: v2.id,
|
|
|
+ name: v2.text,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ arrRes.push(obj);
|
|
|
+ });
|
|
|
+ setData(arrRes);
|
|
|
+ }
|
|
|
+ }, [sId]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getInfoFu();
|
|
|
+ }, [getInfoFu]);
|
|
|
+
|
|
|
+ // 右边嵌套页面的加载loding
|
|
|
+ const [isLoding, setIsLoding] = useState(true);
|
|
|
+
|
|
|
+ // 选中的id
|
|
|
+ const [acId, setAcId] = useState("");
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (data[0]) {
|
|
|
+ if (data[0].flag) {
|
|
|
+ setAcId(data[0].id);
|
|
|
+ } else if (data[0].children && data[0].children[0]) {
|
|
|
+ setAcId(data[0].children[0].id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, [data]);
|
|
|
+
|
|
|
+ // 动态获取标题的 高度
|
|
|
+ const tab5ItitleRef = useRef<HTMLDivElement>(null);
|
|
|
+
|
|
|
+ // 动态设置 iframe 外层盒子的高度
|
|
|
+ const [ifrHeight, setIfrHeight] = useState(0);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ const dom = tab5ItitleRef.current;
|
|
|
+ if (dom) {
|
|
|
+ const num = dom.offsetHeight + 30;
|
|
|
+ const numRes =
|
|
|
+ document.documentElement.clientHeight - (isOpen ? 40 : 100) - num;
|
|
|
+ setIfrHeight(numRes);
|
|
|
+ }
|
|
|
+ }, [isOpen]);
|
|
|
+
|
|
|
+ // 过滤出有详情的 数据
|
|
|
+ const dataFilter = useMemo(() => {
|
|
|
+ const arr = [] as PcTab5ListType[];
|
|
|
+ data.forEach((v) => {
|
|
|
+ if (v.flag) arr.push(v);
|
|
|
+ if (v.children) {
|
|
|
+ v.children.forEach((v2) => {
|
|
|
+ arr.push(v2);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return arr;
|
|
|
+ }, [data]);
|
|
|
+
|
|
|
+ // 通过 当前 详情 页面的 id 拿到 索引
|
|
|
+ const acIndex = useMemo(() => {
|
|
|
+ let index = 0;
|
|
|
+
|
|
|
+ if (acId && dataFilter.length) {
|
|
|
+ index = dataFilter.findIndex((v) => v.id === acId);
|
|
|
+ }
|
|
|
+ return index;
|
|
|
+ }, [acId, dataFilter]);
|
|
|
+
|
|
|
+ // 点击 上一页 和 下一页
|
|
|
+ const cutAcIdFu = useCallback(
|
|
|
+ (num: number, index: number) => {
|
|
|
+ const cutId = dataFilter[index + num].id;
|
|
|
+ setAcId(cutId);
|
|
|
+ },
|
|
|
+ [dataFilter]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 点击目录
|
|
|
+ const [menuFlag, setMenuFlag] = useState(false);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className={styles.Info}>
|
|
|
+ {/* 返回按钮 */}
|
|
|
+ <img
|
|
|
+ className="tab5Iback"
|
|
|
+ hidden={isOpen}
|
|
|
+ onClick={closeFu}
|
|
|
+ src={backImg}
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+
|
|
|
+ <div className="tab5Ititle" ref={tab5ItitleRef}>
|
|
|
+ {title ? title : titleTxt}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="tab5ILoding" hidden={!isLoding}>
|
|
|
+ <Spin size="large" />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="iframeBox" style={{ height: ifrHeight }}>
|
|
|
+ {acId ? (
|
|
|
+ <iframe
|
|
|
+ onLoad={() => setIsLoding(false)}
|
|
|
+ key={acId}
|
|
|
+ src={`${isEnvFlag ? "" : "/pc"}/knowInfo.html?sId=${acId}`}
|
|
|
+ frameBorder="0"
|
|
|
+ ></iframe>
|
|
|
+ ) : null}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 底部固定的 操作按钮 */}
|
|
|
+ <div className="tab5Ibtn" style={{ bottom: isOpen ? 10 : 100 }}>
|
|
|
+ <div
|
|
|
+ onClick={() => cutAcIdFu(-1, acIndex)}
|
|
|
+ className={classNmaes("tab5Ibtn1", acIndex === 0 ? "tab5IbtnNo" : "")}
|
|
|
+ >
|
|
|
+ <img src={`${envUrl}/App/main5/left.png`} alt="" />
|
|
|
+ <span>上一页</span>
|
|
|
+ </div>
|
|
|
+ <div className="tab5Ibtn2" onClick={() => setMenuFlag(true)}>
|
|
|
+ <img src={`${envUrl}/App/main5/menu.png`} alt="" />
|
|
|
+ <span>目录</span>
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ onClick={() => cutAcIdFu(1, acIndex)}
|
|
|
+ className={classNmaes(
|
|
|
+ "tab5Ibtn1 tab5Ibtn3",
|
|
|
+ acIndex >= dataFilter.length - 1 ? "tab5IbtnNo" : ""
|
|
|
+ )}
|
|
|
+ >
|
|
|
+ <span>下一页</span>
|
|
|
+ <img src={`${envUrl}/App/main5/right.png`} alt="" />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 点击目录出来的页面 */}
|
|
|
+ {menuFlag ? (
|
|
|
+ <Menu
|
|
|
+ data={data}
|
|
|
+ acId={acId}
|
|
|
+ closeFu={() => setMenuFlag(false)}
|
|
|
+ cutAcIdFuToSon={(id) => setAcId(id)}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+const MemoInfo = React.memo(Info);
|
|
|
+
|
|
|
+export default MemoInfo;
|