import React, { useCallback, useEffect, useState } from "react"; import styles from "./index.module.scss"; import { Swiper, SwiperSlide } from "swiper/react"; import classNames from "classnames"; // Import Swiper styles import "swiper/css"; import { envUrl } from "@/utils/history"; import { A2SwType } from "@/types"; import store from "@/store"; type Props = { data: A2SwType[]; type: number; }; function SwiperCom({ data, type }: Props) { useEffect(() => { setActive(0); }, [type]); // 选中状态 const [active, setActive] = useState(0); const cutAcFu = useCallback( (item: A2SwType) => { setActive(item.id); if (type === 1) { // 如果是历史,打开视频弹窗 store.dispatch({ type: "main/lookVideo", payload: { id: item.id, title: item.info?.title!, txt: item.info?.txt!, }, }); } else { window.open(item.path); } }, [type] ); // swiper实例 // const mySwiperRef = useRef(null); return (
(mySwiperRef.current = swiper)} > {data.map((v) => (
cutAcFu(v)} className={classNames( "SwiperComRow", active === v.id ? "SwiperComRowAc" : "" )} >

{v.name}

{v.name}
))}
); } const MemoSwiperCom = React.memo(SwiperCom); export default MemoSwiperCom;