index.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import React, { useEffect, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { baseURL, myData } from '@/utils/http'
  4. import history from '@/utils/history'
  5. import classNames from 'classnames'
  6. import BaseImg from '@/components/BaseImg'
  7. import S1manor from './S1manor'
  8. import S2mien from './S2mien'
  9. import S3goods from './S3goods'
  10. import BtnRight from '@/components/BtnRight'
  11. import useLoding from '@/components/ownUse/useLoding'
  12. import { domDelOwnFu } from '@/utils/utilsSome'
  13. import VideoModel from '@/components/VideoModel'
  14. import { renClickPageFu } from './data'
  15. const videoObj = {
  16. 探索庄园: {
  17. 汉代百科: 'more/1.mp4',
  18. 文物欣赏: 'more/2.mp4'
  19. },
  20. 汉代百科: {
  21. 探索庄园: 'more/3.mp4',
  22. 文物欣赏: 'more/4.mp4'
  23. },
  24. 文物欣赏: {
  25. 探索庄园: 'more/5.mp4',
  26. 汉代百科: 'more/6.mp4'
  27. }
  28. }
  29. type TxtType = '探索庄园' | '汉代百科' | '文物欣赏'
  30. const floorArr: TxtType[] = ['探索庄园', '汉代百科', '文物欣赏']
  31. function B1more() {
  32. const [floorTxt, setFloorTxt] = useState<TxtType>(
  33. renClickPageFu() === '1' ? '汉代百科' : '探索庄园'
  34. )
  35. const floorRef = useRef<TxtType>(renClickPageFu() === '1' ? '汉代百科' : '探索庄园')
  36. // 需要播放的视频路径
  37. const [videoSrc, setVideoSrc] = useState('')
  38. useEffect(() => {
  39. if (videoSrc) {
  40. setTimeout(() => {
  41. const domAll: any = document.querySelectorAll('.A6videoBox video')
  42. if (domAll && domAll.length) {
  43. domAll.forEach((v: HTMLVideoElement) => {
  44. if (baseURL + videoSrc === v.src) v.play()
  45. else {
  46. v.pause()
  47. v.currentTime = 0
  48. }
  49. })
  50. }
  51. }, 100)
  52. }
  53. }, [videoSrc])
  54. useEffect(() => {
  55. const tempObj = Reflect.get(videoObj, floorRef.current)
  56. const temp = Reflect.get(tempObj, floorTxt)
  57. floorRef.current = floorTxt
  58. setVideoSrc(temp)
  59. }, [floorTxt])
  60. // 初始加载中动画
  61. const [isLoding, setIsLoding] = useState(window.location.href.includes('r=ren') ? false : true)
  62. // 先加载背景图 序列帧等 在加载视频
  63. const { imgNow, imgNumFu } = useLoding(1)
  64. // 点击左下角按钮
  65. const [leftVideo, setLeftVideo] = useState(false)
  66. // 汉代百科点击人 离开前先播放视频
  67. const [lastVideo, setLastVideo] = useState({ src: '', path: '' })
  68. const videoRef = useRef<HTMLVideoElement>(null)
  69. useEffect(() => {
  70. if (lastVideo.src) {
  71. setTimeout(() => {
  72. if (videoRef.current) videoRef.current.play()
  73. }, 100)
  74. }
  75. }, [lastVideo.src])
  76. return (
  77. <div className={styles.B1more}>
  78. {/* 三个主要页面 */}
  79. <img
  80. style={{ opacity: 0 }}
  81. onLoad={imgNumFu}
  82. id='bgImgBox'
  83. src={baseURL + myData.more['探索庄园'].bg}
  84. alt=''
  85. />
  86. {imgNow ? (
  87. <>
  88. <S1manor
  89. hidden={!!videoSrc || floorTxt !== '探索庄园'}
  90. setLastVideo={info => setLastVideo(info)}
  91. />
  92. <S2mien hidden={!!videoSrc || floorTxt !== '汉代百科'} />
  93. <S3goods hidden={!!videoSrc || floorTxt !== '文物欣赏'} />
  94. </>
  95. ) : null}
  96. {/* 初始静态图 */}
  97. <BaseImg
  98. isShow={!isLoding}
  99. iconSrc={``}
  100. parentFu={() => setIsLoding(false)}
  101. moreSta={true}
  102. imgNow={imgNow}
  103. imgNumFu={imgNumFu}
  104. />
  105. {/* 6个视频 */}
  106. {imgNow
  107. ? myData.more.videos.map((src, index) => (
  108. <div
  109. className={classNames('A6videoBox', videoSrc === src ? 'A6videoBoxShow' : '')}
  110. key={index}
  111. >
  112. <video
  113. playsInline
  114. muted
  115. webkit-playsinline='true'
  116. x5-video-player-type='h5'
  117. onEnded={() => setVideoSrc('')}
  118. src={baseURL + src}
  119. >
  120. <source type='video/mp4' src={baseURL + src} />
  121. Your browser does not support the video tag.
  122. </video>
  123. {/* 右下角的跳过按钮 */}
  124. <BtnRight imgName='skip' clickSon={() => setVideoSrc('')} title='跳过' />
  125. {/* {myData.isLdong ? null : (
  126. )} */}
  127. </div>
  128. ))
  129. : null}
  130. {/* 底部三个按钮 */}
  131. {imgNow ? (
  132. <div className='A6floorBox' style={{ opacity: isLoding ? 0 : 1 }}>
  133. {floorArr.map(v => (
  134. <div
  135. onClick={() => {
  136. domDelOwnFu('#bgImgBox')
  137. setFloorTxt(v)
  138. }}
  139. className={classNames(v === floorTxt ? 'A6FrowAc' : '')}
  140. key={v}
  141. >
  142. {v}
  143. </div>
  144. ))}
  145. </div>
  146. ) : null}
  147. {/* 右下角的图标 */}
  148. {imgNow ? (
  149. <div
  150. hidden={leftVideo}
  151. className='A6rBtn'
  152. style={{ opacity: isLoding ? 0 : 1, zIndex: videoSrc ? 10 : 30 }}
  153. >
  154. <div className='A6rBtn1' title='陶庄园' onClick={() => history.push('/unend/end')}></div>
  155. <div className='A6rBtn2' title='仙居世界' onClick={() => history.push('/hots')}></div>
  156. </div>
  157. ) : null}
  158. {/* 左下角播放按钮 */}
  159. <div onClick={() => setLeftVideo(true)} className={classNames('A1LeftVideoBtn hoverD')}>
  160. <img src={`${baseURL}home/icon-play.png`} alt='' />
  161. </div>
  162. {/* 左下角视频 */}
  163. {imgNow ? (
  164. <VideoModel
  165. isShow={leftVideo}
  166. src={baseURL + myData.home.leftVideo}
  167. closeFu={() => setLeftVideo(false)}
  168. />
  169. ) : null}
  170. {/* 点击人 播放视频 然后跳转 */}
  171. {lastVideo.src ? (
  172. <div className='lastVideo' id='HotOpCss'>
  173. <video
  174. ref={videoRef}
  175. playsInline
  176. muted
  177. webkit-playsinline='true'
  178. x5-video-player-type='h5'
  179. onEnded={() => history.push(lastVideo.path)}
  180. >
  181. <source type='video/mp4' src={baseURL + lastVideo.src} />
  182. Your browser does not support the video tag.
  183. </video>
  184. {/* 右下角的跳过按钮 */}
  185. <BtnRight imgName='skip' clickSon={() => history.push(lastVideo.path)} title='跳过' />
  186. </div>
  187. ) : null}
  188. </div>
  189. )
  190. }
  191. const MemoB1more = React.memo(B1more)
  192. export default MemoB1more