import React, { useCallback, useEffect, useRef, useState } from 'react' import styles from './index.module.scss' import classNames from 'classnames' import { baseURL, myData } from '@/utils/http' import { domDelOwnFu } from '@/utils/utilsSome' type Props = { isShow: boolean //是否显示 imgSrc: string //标题图片的路径 videoSrc: string //视频路径 parentFu: () => void //点击继续的方法(调用父亲) } function BaseVideo({ isShow, imgSrc, videoSrc, parentFu }: Props) { const baseVideoRef = useRef(null) useEffect(() => { setTimeout(() => { if (baseVideoRef.current) { baseVideoRef.current.play() } }, 100) }, []) const [loding, setLoding] = useState(myData.isLdong ? 0 : 100) const timeRR = useRef(-1) useEffect(() => { clearInterval(timeRR.current) timeRR.current = window.setInterval(() => { if (loding >= 100) { clearInterval(timeRR.current) return } setLoding(loding + 1) }, 30) }, [loding]) const btnStartFu = useCallback(() => { if (loding >= 100) { parentFu() // 0.5s之后删除初始视频 setTimeout(() => { domDelOwnFu('#BaseVideo') }, 500) } }, [loding, parentFu]) return (
{/* anpg动图 */}
{loding >= 100 ? '点击继续' : '加载中'}
{loding >= 100 ? null : (
)}
) } const MemoBaseVideo = React.memo(BaseVideo) export default MemoBaseVideo