index.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import React, { useCallback, useEffect, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import useDataUrl from '@/components/ownUse/useDataUrl'
  4. // import useMove from '@/components/ownUse/useMove'
  5. import { myData } from '@/utils/http'
  6. import classNames from 'classnames'
  7. import { domDelOwnFu } from '@/utils/utilsSome'
  8. import EndVideo from '@/components/EndVideo'
  9. function A1home() {
  10. const { dataUrlSame } = useDataUrl()
  11. // const { touchstart, touchmove, touchend } = useMove()
  12. // 动画视频的ref
  13. const videoRef = useRef<HTMLVideoElement>(null)
  14. const [loding, setLoding] = useState(myData.isLdong ? 0 : 100)
  15. const timeRR = useRef(-1)
  16. useEffect(() => {
  17. clearInterval(timeRR.current)
  18. timeRR.current = window.setInterval(() => {
  19. if (loding >= 100) {
  20. setMoveImgShow(false)
  21. setTimeout(() => {
  22. const ruDom = document.querySelector('#myStyle')
  23. if (ruDom) ruDom.remove()
  24. }, 3000)
  25. clearInterval(timeRR.current)
  26. return
  27. }
  28. setLoding(loding + 1)
  29. }, 50)
  30. }, [loding])
  31. // 点击开始
  32. const btnStartFu = useCallback(() => {
  33. setLoding(110)
  34. // 自动播放视频
  35. setTimeout(() => {
  36. if (videoRef.current) {
  37. videoRef.current.play()
  38. }
  39. }, 100)
  40. // 0.5s之后删除自己
  41. setTimeout(() => {
  42. domDelOwnFu('.A1base')
  43. }, 500)
  44. }, [])
  45. const [ind, setInd] = useState(0)
  46. // 向上滑动
  47. const videoEndFu = useCallback(
  48. (num: number) => {
  49. // 这个页面只能向上滑
  50. if (num === -1) return
  51. if (ind === myData.home.videos.length - 1 && num === 1) return
  52. setInd(ind + num)
  53. },
  54. [ind]
  55. )
  56. useEffect(() => {
  57. if (ind !== 0) {
  58. setTimeout(() => {
  59. const domAll: any = document.querySelectorAll('.A1videoBoxSon video')
  60. if (domAll && domAll.length) {
  61. domAll.forEach((v: HTMLVideoElement, i: number) => {
  62. if (ind === i) v.play()
  63. else v.pause()
  64. })
  65. }
  66. }, 100)
  67. }
  68. }, [ind])
  69. // 最后一个过长动画
  70. const [lastVideo, setLastVideo] = useState(false)
  71. // 有关序列帧
  72. const A1BfloorRef = useRef<HTMLImageElement>(null)
  73. const [moveImgShow, setMoveImgShow] = useState(true)
  74. useEffect(() => {
  75. // 看看是否已经插入的 script
  76. const ruDom = document.querySelector('#myStyle')
  77. if (ruDom) ruDom.remove()
  78. const styleStr = `.A1Bll {
  79. animation: A1BllMove1 8s infinite linear;
  80. }
  81. @keyframes A1BllMove1 {
  82. 100% {
  83. left: 0;
  84. }
  85. }
  86. .A1Brr {
  87. animation: A1BllMove2 8s infinite linear;
  88. }
  89. @keyframes A1BllMove2 {
  90. 100% {
  91. right: 0;
  92. }
  93. `
  94. const styletDom = document.createElement('style')
  95. styletDom.type = 'text/css'
  96. styletDom.id = 'myStyle'
  97. styletDom.innerHTML = styleStr
  98. document.querySelector('html')?.appendChild(styletDom)
  99. }, [])
  100. return (
  101. <div className={styles.A1home}>
  102. {/* 初始加载画面 */}
  103. <div
  104. className={classNames('A1base', loding === 110 ? 'A1baseHide' : '')}
  105. style={{ backgroundImage: `url(${dataUrlSame}${myData.home.bgImg})` }}
  106. >
  107. <img className='A1Vlogo' src={`${dataUrlSame}home/logo.png`} alt='' />
  108. {loding >= 100 ? (
  109. <div className='A1loding A1lodingBtn' onClick={btnStartFu}>
  110. <img src={`${dataUrlSame}visit/btn.png`} alt='' />
  111. <div>开始</div>
  112. </div>
  113. ) : (
  114. <div className='A1loding sizeNo'>{loding}%</div>
  115. )}
  116. {/* 序列帧动画 */}
  117. {/* 底部颜色条 */}
  118. <img ref={A1BfloorRef} className='A1Bfloor' src={`${dataUrlSame}home/floor.png`} alt='' />
  119. {/* 底部房子 */}
  120. <img className='A1Broom' src={`${dataUrlSame}home/home.png`} alt='' />
  121. {/* 左右小人 */}
  122. <img
  123. className={classNames('A1Bll', moveImgShow ? '' : 'A1BMoveHide')}
  124. src={`${dataUrlSame}home/left.png`}
  125. alt=''
  126. />
  127. <img
  128. className={classNames('A1Brr', moveImgShow ? '' : 'A1BMoveHide')}
  129. src={`${dataUrlSame}home/right.png`}
  130. alt=''
  131. />
  132. </div>
  133. {/* 5个动画视频 */}
  134. <div
  135. className={classNames('A1videoBox', lastVideo || loding !== 110 ? 'A1videoBoxHide' : '')}
  136. style={{
  137. transform: `translateY(-${(100 / myData.home.videos.length) * ind}%)`,
  138. height: `${100 * myData.home.videos.length}%`
  139. }}
  140. >
  141. {myData.home.videos.map((url, index) => (
  142. <div
  143. key={index}
  144. style={{ height: 100 / myData.home.videos.length + '%' }}
  145. className='A1videoBoxSon'
  146. >
  147. <video
  148. ref={ind === index ? videoRef : null}
  149. playsInline
  150. muted
  151. webkit-playsinline='true'
  152. x5-video-player-type='h5'
  153. src={dataUrlSame + url}
  154. >
  155. <source type='video/mp4' />
  156. Your browser does not support the video tag.
  157. </video>
  158. </div>
  159. ))}
  160. </div>
  161. {/* 操作按钮 */}
  162. {loding !== 110 || lastVideo ? null : (
  163. <div
  164. className='A1btnBox'
  165. // onTouchStart={e => touchstart(e.touches[0].pageY)}
  166. // onTouchMove={e => touchmove(e.touches[0].pageY)}
  167. // onTouchEnd={() => touchend(val => videoEndFu(val), 'mobile')}
  168. // onMouseDown={e => touchstart(e.pageY)}
  169. // onMouseMove={e => touchmove(e.pageY)}
  170. // onMouseUp={() => touchend(val => videoEndFu(val), 'pc')}
  171. >
  172. <img
  173. hidden={ind === myData.home.videos.length - 1}
  174. className='A1videoBtn'
  175. onClick={() => videoEndFu(1)}
  176. src={`${dataUrlSame}home/next.png`}
  177. alt=''
  178. />
  179. <div className={ind === myData.home.videos.length - 1 ? 'A1videoBtnBoxShow' : ''}>
  180. <img className='A1videoBtnLogo' src={`${dataUrlSame}home/logo.png`} alt='' />
  181. <div className='A1videoBtnNext' onClick={() => setLastVideo(true)}>
  182. <img src={`${dataUrlSame}home/nextLast.png`} alt='' />
  183. <p>点击开始</p>
  184. </div>
  185. </div>
  186. </div>
  187. )}
  188. {/* 最后一个过长动画 */}
  189. <EndVideo
  190. lastVideo={lastVideo}
  191. delDom='.A1videoBox'
  192. src={dataUrlSame + myData.home.lastVideo}
  193. path='/visit'
  194. />
  195. </div>
  196. )
  197. }
  198. const MemoA1home = React.memo(A1home)
  199. export default MemoA1home