index.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { baseURL, myData } from '@/utils/http'
  4. import classNames from 'classnames'
  5. import EndVideo from '@/components/EndVideo'
  6. import useLoding from '@/components/ownUse/useLoding'
  7. import BtnRight from '@/components/BtnRight'
  8. import history from '@/utils/history'
  9. import FloorBtn from '@/components/FloorBtn'
  10. import { renClickPageFu } from '../B1more/data'
  11. function A11base() {
  12. // 先加载背景图 序列帧等 在加载视频
  13. const { imgNow, imgNumFu } = useLoding(2)
  14. const [loding, setLoding] = useState(myData.isLdong ? 0 : 100)
  15. const timeRR = useRef(-1)
  16. useEffect(() => {
  17. if (imgNow) {
  18. clearInterval(timeRR.current)
  19. timeRR.current = window.setInterval(() => {
  20. if (loding >= 100) {
  21. clearInterval(timeRR.current)
  22. return
  23. }
  24. setLoding(loding + 2)
  25. }, 30)
  26. }
  27. }, [imgNow, loding])
  28. // 最后一个过长动画
  29. const [lastVideo, setLastVideo] = useState(false)
  30. // 名帖文字的显示和隐藏
  31. const [txtShow, setTxtShow] = useState(false)
  32. // 点击投名帖
  33. const btnStartFu = useCallback(() => {
  34. // 播放长视频
  35. setTxtShow(true)
  36. setTimeout(() => {
  37. setLastVideo(true)
  38. }, 2000)
  39. }, [])
  40. // 点击开始
  41. const btnSta = useCallback(() => {
  42. setTieShow(true)
  43. }, [])
  44. // 名帖信息展示
  45. const [tieShow, setTieShow] = useState(window.location.href.includes('r=ren') ? true : false)
  46. // 名帖1点击毛笔
  47. const [biShow, setBiShow] = useState(false)
  48. // 名帖2点击选中一个
  49. const [inptxt, setInpTxt] = useState({
  50. type: 0,
  51. txt1: '',
  52. txt2: '',
  53. txt3: ''
  54. })
  55. // 在页面显示的html格式文字
  56. const txtRes = useMemo(() => {
  57. let txt = `弟子 ${inptxt.txt1} 再拜 问起居 ${inptxt.txt3} 字${inptxt.txt2}`
  58. if (inptxt.type === 2) {
  59. txt = `中郎豫章 ${inptxt.txt3} ${inptxt.txt1} 七十三 字${inptxt.txt2}`
  60. }
  61. return txt
  62. }, [inptxt])
  63. // 输入框是否输入完整
  64. const isOk = useMemo(() => {
  65. let flag = false
  66. if (inptxt.txt1 && inptxt.txt2 && inptxt.txt3) flag = true
  67. return flag
  68. }, [inptxt])
  69. return (
  70. <div className={styles.A11base}>
  71. {/* 背景图页面 */}
  72. {!lastVideo ? (
  73. <div className={classNames('A11bg')} hidden={window.location.href.includes('r=ren')}>
  74. <img onLoad={imgNumFu} id='bgImgBox' src={baseURL + myData.base.bgImg} alt='' />
  75. <img onLoad={imgNumFu} className='A11Vlogo' src={`${baseURL}home/logo.png`} alt='' />
  76. {loding >= 100 ? (
  77. <div className='A11btn'>
  78. {/* 按钮 */}
  79. <div onClick={btnSta}>
  80. <div>点击开始{imgNow}</div>
  81. </div>
  82. </div>
  83. ) : (
  84. <div className='A11xian'>
  85. <div>
  86. <div style={{ width: loding + '%' }}></div>
  87. </div>
  88. </div>
  89. )}
  90. {/* 右下角按钮 */}
  91. {loding >= 100 ? <FloorBtn unityEnd={() => history.push('unend/end')} /> : null}
  92. </div>
  93. ) : null}
  94. {/* 名帖信息 */}
  95. {imgNow && !lastVideo ? (
  96. <div className={classNames('A11Tit', tieShow ? 'A11TitShow' : '')}>
  97. <div>
  98. <img className='t1Bg' src={`${baseURL}base/tieBg.jpg`} alt='' />
  99. <img
  100. onClick={() => setBiShow(true)}
  101. className='t1Bi1'
  102. src={`${baseURL}base/bi1.png`}
  103. alt=''
  104. />
  105. <BtnRight
  106. title='返回'
  107. clickSon={() => {
  108. const txt = renClickPageFu()
  109. if (txt) {
  110. txt === '1' ? history.replace('/more?r=ren1') : history.replace('/more?r=ren0')
  111. } else setTieShow(false)
  112. }}
  113. imgName='back'
  114. />
  115. </div>
  116. {/* 名帖2 */}
  117. <div
  118. className='A11TitSon'
  119. style={{ opacity: biShow ? '1' : '0', pointerEvents: biShow ? 'auto' : 'none' }}
  120. >
  121. <img className='A11TitSon1' src={`${baseURL}base/ban.png`} alt='' />
  122. <p className='A11TitSon2'>请选择内容</p>
  123. <div
  124. className='A11TitSonTxt'
  125. onClick={() => setInpTxt({ type: 1, txt1: '吴应', txt2: '子远', txt3: '南昌' })}
  126. >
  127. <img src={`${baseURL}base/txt2.png`} alt='' />
  128. <img
  129. style={{ opacity: inptxt.type === 1 ? '1' : '' }}
  130. src={`${baseURL}base/txt2Ac.png`}
  131. alt=''
  132. />
  133. </div>
  134. <div
  135. className='A11TitSonTxt2'
  136. onClick={() =>
  137. setInpTxt({
  138. type: 2,
  139. txt1: '吴应年',
  140. txt2: '子远',
  141. txt3: '南昌都乡吉阳里'
  142. })
  143. }
  144. >
  145. <img src={`${baseURL}base/txt1.png`} alt='' />
  146. <img
  147. style={{ opacity: inptxt.type === 2 ? '1' : '' }}
  148. src={`${baseURL}base/txt1Ac.png`}
  149. alt=''
  150. />
  151. </div>
  152. {txtShow ? null : (
  153. <BtnRight title='返回' clickSon={() => setBiShow(false)} imgName='back' />
  154. )}
  155. {/* 填完信息出来的文字盒子 */}
  156. <div
  157. className='A11txtBox'
  158. style={{ opacity: txtShow ? '1' : '0' }}
  159. dangerouslySetInnerHTML={{ __html: txtRes }}
  160. ></div>
  161. {/* 底部按钮 */}
  162. <div
  163. className='Tiebtn'
  164. onClick={btnStartFu}
  165. hidden={!inptxt.type || txtShow}
  166. style={{ opacity: isOk ? '1' : '0.5', pointerEvents: isOk ? 'auto' : 'none' }}
  167. >
  168. 投名帖
  169. </div>
  170. {/* 右侧自定义输入 */}
  171. <div className='TieRight' hidden={!inptxt.type}>
  172. <div className='TieRight1'>自定义内容</div>
  173. <div className='TieRight2'>
  174. <div>姓名</div>
  175. <div>
  176. <input
  177. maxLength={4}
  178. value={inptxt.txt1}
  179. onChange={e =>
  180. setInpTxt({ ...inptxt, txt1: e.target.value.replace(/\s+/g, '') })
  181. }
  182. />
  183. </div>
  184. </div>
  185. <div className='TieRight2'>
  186. <div>表字</div>
  187. <div>
  188. <input
  189. maxLength={4}
  190. value={inptxt.txt2}
  191. onChange={e =>
  192. setInpTxt({ ...inptxt, txt2: e.target.value.replace(/\s+/g, '') })
  193. }
  194. />
  195. </div>
  196. </div>
  197. <div className='TieRight2'>
  198. <div>籍贯</div>
  199. <div>
  200. <input
  201. maxLength={10}
  202. value={inptxt.txt3}
  203. onChange={e =>
  204. setInpTxt({ ...inptxt, txt3: e.target.value.replace(/\s+/g, '') })
  205. }
  206. />
  207. </div>
  208. </div>
  209. </div>
  210. </div>
  211. </div>
  212. ) : null}
  213. {/* 名帖动画 */}
  214. {/* 最后一个过长动画 */}
  215. {imgNow ? (
  216. <EndVideo lastVideo={lastVideo} src={baseURL + myData.base.lastVideo} path='/visit' />
  217. ) : null}
  218. </div>
  219. )
  220. }
  221. const MemoA11base = React.memo(A11base)
  222. export default MemoA11base