index.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React, { useCallback, useEffect, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import classNames from 'classnames'
  4. import { baseURL, myData } from '@/utils/http'
  5. import { domDelOwnFu } from '@/utils/utilsSome'
  6. type Props = {
  7. isShow: boolean //是否显示
  8. imgSrc: string //标题图片的路径
  9. videoSrc: string //视频路径
  10. parentFu: () => void //点击继续的方法(调用父亲)
  11. }
  12. function BaseVideo({ isShow, imgSrc, videoSrc, parentFu }: Props) {
  13. const baseVideoRef = useRef<HTMLVideoElement>(null)
  14. useEffect(() => {
  15. setTimeout(() => {
  16. if (baseVideoRef.current) {
  17. baseVideoRef.current.play()
  18. }
  19. }, 100)
  20. }, [])
  21. const [loding, setLoding] = useState(myData.isLdong ? 0 : 100)
  22. const timeRR = useRef(-1)
  23. useEffect(() => {
  24. clearInterval(timeRR.current)
  25. timeRR.current = window.setInterval(() => {
  26. if (loding >= 100) {
  27. clearInterval(timeRR.current)
  28. return
  29. }
  30. setLoding(loding + 1)
  31. }, 30)
  32. }, [loding])
  33. const btnStartFu = useCallback(() => {
  34. if (loding >= 100) {
  35. parentFu()
  36. // 0.5s之后删除初始视频
  37. setTimeout(() => {
  38. domDelOwnFu('#BaseVideo')
  39. }, 500)
  40. }
  41. }, [loding, parentFu])
  42. return (
  43. <div
  44. id='BaseVideo'
  45. className={classNames(styles.BaseVideo, isShow ? '' : styles.BaseVideoHide)}
  46. >
  47. <img className='BaseVideoIcon' src={imgSrc} alt='' />
  48. <div className='BVbaseBtn' onClick={btnStartFu}>
  49. {/* anpg动图 */}
  50. <div className='BVBIcon'>
  51. <img src={`${baseURL}visit/arrow.png`} alt='' />
  52. </div>
  53. <img src={`${baseURL}visit/btn.png`} alt='' />
  54. <div className='BVBtxt'>{loding >= 100 ? '点击继续' : '加载中'}</div>
  55. {loding >= 100 ? null : (
  56. <div className='BVBxian'>
  57. <div>
  58. <div style={{ width: loding + '%' }}></div>
  59. </div>
  60. </div>
  61. )}
  62. </div>
  63. <video
  64. ref={baseVideoRef}
  65. src={videoSrc}
  66. playsInline
  67. muted
  68. webkit-playsinline='true'
  69. x5-video-player-type='h5'
  70. loop
  71. />
  72. </div>
  73. )
  74. }
  75. const MemoBaseVideo = React.memo(BaseVideo)
  76. export default MemoBaseVideo