index.tsx 2.3 KB

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