index.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import React, { useCallback, useMemo, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import BaseImg from '@/components/BaseImg'
  4. import { baseURL, myData } from '@/utils/http'
  5. import EndVideo from '@/components/EndVideo'
  6. import NextPage from '@/components/NextPage'
  7. import classNames from 'classnames'
  8. import FloorBtn from '@/components/FloorBtn'
  9. import HotIcon from '@/components/HotIcon'
  10. import Hot2 from '../A2visit/PanoVideo/Hot2'
  11. import { PlowHotType } from '@/types'
  12. import useLoding from '@/components/ownUse/useLoding'
  13. function A6plow() {
  14. // 初始显示和隐藏
  15. const [cutVideoShow, setCutVideoShow] = useState(false)
  16. // 控制视频播放的方法
  17. const videoPlayFu = useCallback((index: number) => {
  18. setTimeout(() => {
  19. const domAll: any = document.querySelectorAll('.A6video')
  20. if (domAll && domAll.length) {
  21. domAll.forEach((v: HTMLVideoElement, i: number) => {
  22. if (index === i) v.play()
  23. else {
  24. v.pause()
  25. v.currentTime = 0
  26. }
  27. })
  28. }
  29. }, 100)
  30. }, [])
  31. // 点击继续
  32. const btnStart = useCallback(() => {
  33. setCutVideoShow(true)
  34. // 播放第一个整地的视频
  35. videoPlayFu(0)
  36. }, [videoPlayFu])
  37. // 点击 跳下一个章节
  38. const [lastVideo, setLastVideo] = useState(false)
  39. // 左侧按钮的选中
  40. const [leftAc, setLeftAc] = useState(0)
  41. const leftAcFu = useCallback(
  42. (index: number) => {
  43. videoPlayFu(index)
  44. setLeftAc(index)
  45. },
  46. [videoPlayFu]
  47. )
  48. // 底部文字
  49. const floorTxt = useMemo(() => {
  50. return myData.plow.info[leftAc].txt
  51. }, [leftAc])
  52. // 打开热点
  53. const [hotInd, setHotInd] = useState(-1)
  54. const hotInfo = useMemo(() => {
  55. let info = {} as PlowHotType
  56. const temp = myData.plow.info[leftAc].hot
  57. if (temp && temp[hotInd]) {
  58. info = temp[hotInd]
  59. }
  60. return info
  61. }, [hotInd, leftAc])
  62. // 先加载背景图 序列帧等 在加载视频
  63. const { imgNow, imgNumFu } = useLoding(3)
  64. return (
  65. <div className={styles.A6plow}>
  66. {/* 初始静态图 */}
  67. <BaseImg
  68. isShow={cutVideoShow}
  69. iconSrc={`${baseURL}plow/mulu.png`}
  70. parentFu={() => btnStart()}
  71. bgImg={`${baseURL}${myData.plow.baseImg}`}
  72. imgNow={imgNow}
  73. imgNumFu={imgNumFu}
  74. />
  75. {/* 主要内容 */}
  76. {imgNow ? (
  77. <div className={classNames('A6main', cutVideoShow ? 'A6mainShow' : '')}>
  78. {/* 左侧title */}
  79. <div className='A6Lbtn' style={{ backgroundImage: `url(${baseURL}plow/leftBg.png)` }}>
  80. {myData.plow.info.map((item, index) => (
  81. <div
  82. key={index}
  83. className='A6LbtnRow'
  84. onClick={() => leftAcFu(index)}
  85. style={{
  86. backgroundImage: `url(${baseURL}plow/left${leftAc === index ? 'Ac' : ''}.png)`,
  87. color: leftAc === index ? '#BD7656' : '#DACB8B'
  88. }}
  89. >
  90. {item.name}
  91. </div>
  92. ))}
  93. </div>
  94. {/* 底部文字 */}
  95. <div
  96. className='A6txt'
  97. style={{ backgroundImage: `url(${baseURL}plow/txtBg.png)` }}
  98. dangerouslySetInnerHTML={{ __html: floorTxt }}
  99. ></div>
  100. {/* 视频加热点 */}
  101. <div className='A6videoBox'>
  102. {myData.plow.info.map((item, index) => (
  103. <div className={classNames(leftAc === index ? 'A6vShow' : '')} key={index}>
  104. <video
  105. className='A6video'
  106. playsInline
  107. muted
  108. webkit-playsinline='true'
  109. x5-video-player-type='h5'
  110. loop
  111. >
  112. <source type='video/mp4' src={baseURL + item.videoSrc} />
  113. Your browser does not support the video tag.
  114. </video>
  115. {/* 热点 */}
  116. {item.hot.map((v: PlowHotType, i) => (
  117. <HotIcon
  118. style={{
  119. top: v.locPage.top,
  120. left: v.locPage.left
  121. }}
  122. key={i}
  123. index={i}
  124. clickSon={val => setHotInd(val)}
  125. hoverSrc={v.hoverSrc}
  126. />
  127. ))}
  128. </div>
  129. ))}
  130. </div>
  131. {/* 跳到下一章 */}
  132. <NextPage clickSon={() => setLastVideo(true)} txt='结束宴饮' />
  133. {/* 右下角按钮 */}
  134. <FloorBtn />
  135. </div>
  136. ) : null}
  137. {hotInd >= 0 && hotInfo.name ? (
  138. <Hot2 data={hotInfo.data} closeFu={() => setHotInd(-1)} name={hotInfo.name} />
  139. ) : null}
  140. {/* 结尾动画 */}
  141. {imgNow ? (
  142. <EndVideo
  143. lastVideo={lastVideo}
  144. delDom='.A6main'
  145. src={baseURL + myData.plow.lastVideo}
  146. path='/end'
  147. noBtn={true}
  148. />
  149. ) : null}
  150. </div>
  151. )
  152. }
  153. const MemoA6plow = React.memo(A6plow)
  154. export default MemoA6plow