/* eslint-disable jsx-a11y/iframe-has-title */ import React, { useCallback, useEffect, useMemo, useState } from "react"; import styles from "./index.module.scss"; import { A2FileObjType, A2FileType } from "@/types"; import { baseURL } from "@/utils/http"; import classNames from "classnames"; import ImageLazy from "@/ImageLazy"; import R_leftImg from "@/assets/img/goods/R_left.png"; import R_rightImg from "@/assets/img/goods/R_right.png"; import icon1 from "@/assets/img/goods/icon1.png"; import icon1Ac from "@/assets/img/goods/icon1Ac.png"; type Props = { listObj: A2FileObjType; audioInfo: A2FileType; isOpen: boolean; }; function RightFile({ listObj, audioInfo, isOpen }: Props) { useEffect(() => { // 如果有音频信息 if (audioInfo.id) { // 显示音频图标 setRight1({ show: true, done: false }); window.setTimeout(() => { const dom: HTMLAudioElement = document.querySelector("#myAudio")!; dom.onended = () => { // console.log("-------音频播放结束"); // 音频播放结束 setRight1({ show: true, done: false }); }; // 音频的状态 if (!isOpen) { dom.play(); setRight1({ show: true, done: true }); } }, 100); } }, [audioInfo, isOpen]); // 文件类型 type const [type, setType] = useState<"model" | "video" | "img">("model"); // 音频的显示和隐藏 const [right1, setRight1] = useState({ show: false, done: false }); // 当前显示的 索引 const [showInd, setShowInd] = useState(0); const cutIndFu = useCallback( (num: number) => { setShowInd(showInd + num); }, [showInd] ); // 打开和关闭音频 const audioCutFu = useCallback((val: boolean) => { const dom: HTMLAudioElement = document.querySelector("#myAudio")!; if (val) dom.play(); else dom.pause(); setRight1({ show: true, done: val }); }, []); // 在页面展示的数组 const list = useMemo(() => { return listObj[type]; }, [listObj, type]); // 是否只有单独的音频上传 const isOneAudio = useMemo(() => { if ( audioInfo.id && listObj.img.length === 0 && listObj.model.length === 0 && listObj.video.length === 0 ) return true; else return false; }, [audioInfo, listObj]); // 切换不同文件(模型/视频/图片的数组) const typeArr = useMemo(() => { const arr: { name: "模型" | "视频" | "图片"; type: "model" | "video" | "img"; }[] = []; if (listObj.model.length) arr.push({ name: "模型", type: "model" }); if (listObj.video.length) arr.push({ name: "视频", type: "video" }); if (listObj.img.length) arr.push({ name: "图片", type: "img" }); return arr; }, [listObj]); // 当前默认展示什么模块(优先级按照 模型-视频-图片) useEffect(() => { if (listObj.model.length) setType("model"); else if (listObj.video.length) setType("video"); else setType("img"); }, [listObj]); // 每次变化type的时候把 索引变成0 useEffect(() => { setShowInd(0); }, [type]); return (