index.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 classNames from 'classnames'
  5. import { myData } from '@/utils/http'
  6. import { domDelOwnFu } from '@/utils/utilsSome'
  7. import history from '@/utils/history'
  8. import { ArrowRightOutlined } from '@ant-design/icons'
  9. function A5chef() {
  10. const { dataUrlSame } = useDataUrl()
  11. const [loding, setLoding] = useState(myData.isLdong ? 0 : 100)
  12. const timeRR = useRef(-1)
  13. useEffect(() => {
  14. clearInterval(timeRR.current)
  15. timeRR.current = window.setInterval(() => {
  16. if (loding >= 100) {
  17. clearInterval(timeRR.current)
  18. return
  19. }
  20. setLoding(loding + 1)
  21. }, 30)
  22. }, [loding])
  23. // 点击继续
  24. const [baseFlag, setBaseFlag] = useState(true)
  25. const btnStart = useCallback(() => {
  26. if (loding >= 100) {
  27. setBaseFlag(false)
  28. // 0.5s之后删除初始盒子
  29. setTimeout(() => {
  30. domDelOwnFu('.A5base')
  31. }, 500)
  32. }
  33. }, [loding])
  34. // 点击 跳下一个章节
  35. const [lastVideo, setLastVideo] = useState(false)
  36. const videoRefLast = useRef<HTMLVideoElement>(null)
  37. const lastVideoFu = useCallback(() => {
  38. setLastVideo(true)
  39. setTimeout(() => {
  40. if (videoRefLast.current) {
  41. videoRefLast.current.play()
  42. }
  43. }, 100)
  44. }, [])
  45. // 点击后厨群像
  46. const [chuShow, setChuShow] = useState(false)
  47. // 点击热点
  48. const [hotInd, setHotInd] = useState(-1)
  49. const hotTime = useRef(-1)
  50. const hotIndFu = useCallback((index: number) => {
  51. setBgMove(myData.chef.hot[index].change)
  52. clearTimeout(hotTime.current)
  53. hotTime.current = window.setTimeout(() => {
  54. setHotInd(index)
  55. }, 500)
  56. }, [])
  57. useEffect(() => {
  58. if (hotInd === -1) setBgMove('')
  59. setTimeout(() => {
  60. const videoDomAll: any = document.querySelectorAll('.A5video video')
  61. videoDomAll.forEach((v: HTMLVideoElement, index: number) => {
  62. if (hotInd === index) {
  63. v.currentTime = 0
  64. v.play()
  65. } else v.pause()
  66. })
  67. }, 100)
  68. }, [hotInd])
  69. const hotAcRef = useRef<HTMLVideoElement>(null)
  70. // 热点位移
  71. const [bgMove, setBgMove] = useState('')
  72. return (
  73. <div className={styles.A5chef}>
  74. {/* 整体盒子 */}
  75. <div
  76. className='A5main'
  77. style={{ backgroundImage: `url(${dataUrlSame + myData.chef.baseImg})`, transform: bgMove }}
  78. >
  79. {/* 加载页面 */}
  80. <div className={classNames('A5base', baseFlag ? '' : 'A5baseHide')}>
  81. <img src={`${dataUrlSame}chef/mulu.png`} alt='' />
  82. <div className='A5baseBtn' onClick={btnStart}>
  83. {/* anpg动图 */}
  84. <div className='A5BIcon'>
  85. <img src={`${dataUrlSame}visit/arrow.png`} alt='' />
  86. </div>
  87. <img src={`${dataUrlSame}visit/btn.png`} alt='' />
  88. <div className='A5Btxt'>{loding >= 100 ? '点击继续' : '加载中'}</div>
  89. {loding >= 100 ? null : (
  90. <div className='A5Bxian'>
  91. <div>
  92. <div style={{ width: loding + '%' }}></div>
  93. </div>
  94. </div>
  95. )}
  96. </div>
  97. </div>
  98. {/* 热点按钮页面 */}
  99. <div className={classNames('A5hotBox', baseFlag ? '' : 'A5hotBoxAc')}>
  100. {/* 循环渲染热点 */}
  101. {myData.chef.hot.map((item, index) => (
  102. <div
  103. onClick={() => hotIndFu(index)}
  104. key={index}
  105. className='pvHot'
  106. style={{
  107. top: item.loc.top,
  108. left: item.loc.left
  109. }}
  110. >
  111. <img className='pvHotBase' src={`${dataUrlSame}visit/hot/hotBase.png`} alt='' />
  112. <img className='pvHotHover' src={dataUrlSame + item.imgSrc} alt='' />
  113. </div>
  114. ))}
  115. {/* 后厨群像 */}
  116. <div
  117. style={{ backgroundImage: `url(${dataUrlSame}chef/houChu.jpg)` }}
  118. className={classNames('A5chu', chuShow ? 'A5chuShow' : '')}
  119. >
  120. {/* 返回按钮 */}
  121. <div
  122. style={{ backgroundImage: `url(${dataUrlSame}chef/back23.png)` }}
  123. className='A5hotBoxBack hoverD'
  124. title='返回'
  125. onClick={() => setChuShow(false)}
  126. ></div>
  127. </div>
  128. <div
  129. onClick={() => setChuShow(true)}
  130. className='A5chuBtn'
  131. style={{ backgroundImage: `url(${dataUrlSame}chef/chuBtn.png)` }}
  132. >
  133. 后厨群像
  134. </div>
  135. {/* 跳到下一章 */}
  136. <div className='pvBtn'>
  137. <img src={`${dataUrlSame}visit/btn.png`} alt='' />
  138. <div onClick={lastVideoFu}>
  139. 田间耕作
  140. <ArrowRightOutlined />
  141. </div>
  142. </div>
  143. <div className='pvRRbtn'>
  144. {/* 更多 跳新页面 */}
  145. <div title='更多' className='pvRRbtn2' onClick={() => history.push('/more')}></div>
  146. </div>
  147. </div>
  148. </div>
  149. {/* 点击热点之后出来的视频 */}
  150. {myData.chef.hot.map((item, index) => (
  151. <div key={index} className={classNames('A5video', hotInd === index ? 'A5videoAc' : '')}>
  152. <video
  153. ref={hotInd === index ? hotAcRef : null}
  154. playsInline
  155. muted
  156. webkit-playsinline='true'
  157. x5-video-player-type='h5'
  158. src={dataUrlSame + item.videoSrc}
  159. loop
  160. >
  161. <source type='video/mp4' />
  162. Your browser does not support the video tag.
  163. </video>
  164. {/* 热点右侧图文信息 */}
  165. <div className='A5vTxt' style={{ backgroundImage: `url(${dataUrlSame}chef/hotBg.png)` }}>
  166. <img src={dataUrlSame + item.showImg} alt='' />
  167. <div dangerouslySetInnerHTML={{ __html: item.txt }}></div>
  168. </div>
  169. {/* 返回按钮 */}
  170. <div
  171. style={{ backgroundImage: `url(${dataUrlSame}chef/back22.png)` }}
  172. className='A5vBack hoverD'
  173. title='返回'
  174. onClick={() => setHotInd(-1)}
  175. ></div>
  176. </div>
  177. ))}
  178. {/* 最后一个过长动画 */}
  179. <div className={classNames('A5last', lastVideo ? 'A5lastAc' : '')}>
  180. <video
  181. ref={videoRefLast}
  182. playsInline
  183. muted
  184. webkit-playsinline='true'
  185. x5-video-player-type='h5'
  186. src={dataUrlSame + myData.visit.lastVideo}
  187. onEnded={() => history.push('/plow')}
  188. >
  189. <source type='video/mp4' />
  190. Your browser does not support the video tag.
  191. </video>
  192. </div>
  193. </div>
  194. )
  195. }
  196. const MemoA5chef = React.memo(A5chef)
  197. export default MemoA5chef