App.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import '@/assets/styles/base.css'
  2. // 关于路由
  3. import React, { useCallback, useEffect, useRef } from 'react'
  4. import { Router, Route, Switch } from 'react-router-dom'
  5. import history, { callIframeFu } from './utils/history'
  6. import SpinLoding from './components/SpinLoding'
  7. import store, { RootState } from './store'
  8. import { useSelector } from 'react-redux'
  9. import NotFound from '@/components/NotFound'
  10. import { baseURL, isLoc, myData } from './utils/http'
  11. import AsyncSpinLoding from './components/AsyncSpinLoding'
  12. import { Image } from 'antd'
  13. // import Vconsole from 'vconsole'
  14. // new Vconsole()
  15. // import { isLoc, myData } from './utils/http'
  16. const A1home = React.lazy(() => import('./pages/A1home'))
  17. const A1_1base = React.lazy(() => import('./pages/A0base'))
  18. const A2yblm = React.lazy(() => import('./pages/A2yblm'))
  19. const A3beie = React.lazy(() => import('./pages/A3beie'))
  20. const A4quanwen = React.lazy(() => import('./pages/A4quanwen'))
  21. const A5wenwu = React.lazy(() => import('./pages/A5wenwu'))
  22. const A6ybwx = React.lazy(() => import('./pages/A6ybwx'))
  23. const A7Wjwj = React.lazy(() => import('./pages/A7wjwj'))
  24. const A6_1_zxys = React.lazy(() => import('./pages/A6ybwx/A6_1_zxys'))
  25. const A6_2_zxzgh = React.lazy(() => import('./pages/A6ybwx/A6_2_zxzgh'))
  26. declare global {
  27. //设置全局属性
  28. interface Window {
  29. //window对象属性
  30. isHH: boolean //加入对象
  31. unityOpenHot: (name: string) => void
  32. unityBack: () => void
  33. }
  34. }
  35. let tempW = document.documentElement.clientWidth
  36. let tempH = document.documentElement.clientHeight
  37. let tempMax = tempW >= tempH ? tempW : tempH
  38. let tempMin = tempW >= tempH ? tempH : tempW
  39. const pageBi = Math.round(Number((tempMax / tempMin).toFixed(2)))
  40. // 设计图按照 844 X 390 来开发
  41. const planSize = {
  42. width: 844,
  43. height: Math.round(Number((844 / pageBi).toFixed(0)))
  44. }
  45. export default function App() {
  46. useEffect(() => {
  47. // 打包环境 刷新页面从 首页 开始
  48. if (!isLoc && myData.isLdong) {
  49. if (window.location.hash !== '#/') {
  50. window.location.href = window.location.href.split('#')[0] + '#/'
  51. }
  52. }
  53. }, [])
  54. const lookBigImg = useSelector((state: RootState) => state.A0Layout.lookBigImg)
  55. // 根元素
  56. const rootRef = useRef<any>(null)
  57. const pageFullChangeFu = useCallback(() => {
  58. let width = document.documentElement.clientWidth
  59. let height = document.documentElement.clientHeight
  60. let isHHTemp = false
  61. if (width >= height) {
  62. if (tempMax - width > 100) return
  63. //横屏
  64. isHHTemp = true
  65. const sizeW = width / planSize.width
  66. let sizeH = height / planSize.height
  67. let moveX = (planSize.width - width) / 2
  68. let moveY = (planSize.height - height) / 2
  69. if (width >= planSize.width) moveX = 0
  70. rootRef.current.style.left = '0'
  71. rootRef.current.style.transform = `translate(${-moveX}px,${-moveY}px) scale(${sizeW},${sizeH}) rotate(0deg)`
  72. rootRef.current.style.transformOrigin = 'center'
  73. store.dispatch({
  74. type: 'layout/style',
  75. payload: {
  76. width: planSize.width,
  77. moveX: -moveX,
  78. moveY: -moveY,
  79. sizeW,
  80. sizeH
  81. }
  82. })
  83. } else {
  84. if (tempMax - height > 100) return
  85. // 竖屏
  86. isHHTemp = false
  87. const temp = width
  88. const wjwjScene = document.getElementById('wjwjScene') as HTMLIFrameElement
  89. const panoramic = document.getElementById('panoramic') as HTMLIFrameElement
  90. const A7Poem = document.getElementById('A7Poem') as HTMLIFrameElement
  91. wjwjScene.style.width = height + 'px'
  92. wjwjScene.style.height = temp + 'px'
  93. wjwjScene.style.transform = 'rotate(90deg) translate(-50%, -50%)'
  94. wjwjScene.style.transformOrigin = 'left top'
  95. panoramic.style.width = height + 'px'
  96. panoramic.style.height = temp + 'px'
  97. panoramic.style.transform = 'rotate(90deg) translate(-50%, -50%)'
  98. panoramic.style.transformOrigin = 'left top'
  99. A7Poem.style.width = height + 'px'
  100. A7Poem.style.height = temp + 'px'
  101. A7Poem.style.transform = 'rotate(90deg) translate(-50%, -50%)'
  102. A7Poem.style.transformOrigin = 'left top'
  103. width = height
  104. height = temp
  105. const sizeW = width / planSize.width
  106. let sizeH = height / planSize.height
  107. rootRef.current.style.left = '100%'
  108. rootRef.current.style.transform = `rotate(90deg) scale(${sizeW},${sizeH})`
  109. rootRef.current.style.transformOrigin = 'left top'
  110. }
  111. // 横竖屏变化的时候 刷新页面
  112. // if (window.isHH !== isHHTemp) {
  113. // window.location.reload()
  114. // }
  115. store.dispatch({ type: 'layout/isHH', payload: isHHTemp })
  116. }, [])
  117. // const audioPlayFu = useCallback(() => {
  118. // 播放背景音乐
  119. // const audioDom: HTMLAudioElement = document.querySelector('#bgMp3')!
  120. // if (audioDom) {
  121. // if (audioDom.paused) audioDom.play()
  122. // else rootRef.current.removeEventListener('click', audioPlayFu)
  123. // }
  124. // }, [])
  125. useEffect(() => {
  126. rootRef.current = document.querySelector('#root')
  127. rootRef.current.style.width = planSize.width + 'px'
  128. rootRef.current.style.height = planSize.height + 'px'
  129. pageFullChangeFu()
  130. window.addEventListener('resize', pageFullChangeFu, false)
  131. // 全局点击都播放背景音乐
  132. // if (myData.isLdong && !isLoc) rootRef.current.addEventListener('click', audioPlayFu)
  133. }, [pageFullChangeFu])
  134. // 动态根据路由更改背景图
  135. const handleHashChange = () => {
  136. if (window.location.hash === '#/base') {
  137. callIframeFu('changePanel', 0)
  138. callIframeFu('showInscription', -1)
  139. callIframeFu('showHotspot', -1)
  140. };
  141. if (window.location.hash === '#/yblm') {
  142. callIframeFu('changePanel', 1)
  143. callIframeFu('showInscription', -1)
  144. callIframeFu('showHotspot', -1)
  145. };
  146. if (window.location.hash === '#/beie') { callIframeFu('changePanel', 3); callIframeFu('showInscription', 0) }
  147. if (window.location.hash === '#/quanwen') {
  148. callIframeFu('changePanel', 3);
  149. callIframeFu('showInscription', -1)
  150. }
  151. if (window.location.hash === '#/wenwu') {
  152. callIframeFu('changePanel', 4)
  153. callIframeFu('showInscription', -1)
  154. callIframeFu('showHotspot', -1)
  155. };
  156. };
  157. useEffect(() => {
  158. window.addEventListener('hashchange', handleHashChange);
  159. return () => {
  160. window.removeEventListener('hashchange', handleHashChange);
  161. };
  162. }, []);
  163. return (
  164. <>
  165. {/* 关于路由 */}
  166. <Router history={history}>
  167. <React.Suspense fallback={<SpinLoding />}>
  168. <Switch>
  169. <Route path='/' component={A1home} exact />
  170. <Route path='/base' component={A1_1base} exact />
  171. <Route path='/yblm' component={A2yblm} exact />
  172. <Route path='/beie' component={A3beie} exact />
  173. <Route path='/quanwen' component={A4quanwen} exact />
  174. <Route path='/wenwu' component={A5wenwu} exact />
  175. <Route path='/ybwx' component={A6ybwx} exact />
  176. <Route path='/wjwj' component={A7Wjwj} exact />
  177. <Route path='/zxys' component={A6_1_zxys} exact />
  178. <Route path='/sinicize' component={A6_2_zxzgh} exact />
  179. <Route path='*' component={NotFound} />
  180. </Switch>
  181. </React.Suspense>
  182. </Router>
  183. <iframe style={{ display: 'none' }} id='modalIframe' title='modal' src=''></iframe>
  184. {/* 背景音乐 */}
  185. <audio id='bgMp3' loop style={{ display: 'none' }} src={baseURL + 'home/bg.mp3'}></audio>
  186. {/* 发送请求的加载组件 */}
  187. <AsyncSpinLoding />
  188. {/* 所有图片点击预览查看大图 */}
  189. {lookBigImg.show ? (
  190. <Image
  191. preview={{
  192. visible: lookBigImg.show,
  193. src: lookBigImg.url,
  194. onVisibleChange: value => {
  195. // 清除仓库信息
  196. store.dispatch({
  197. type: 'layout/lookBigImg',
  198. payload: { url: '', show: false }
  199. })
  200. }
  201. }}
  202. />
  203. ) : null}
  204. </>
  205. )
  206. }