App.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 from './utils/history'
  6. import SpinLoding from './components/SpinLoding'
  7. import NotFound from '@/components/NotFound'
  8. import store from './store'
  9. // import { isLoc, myData } from './utils/http'
  10. const A1home = React.lazy(() => import('./pages/A1home'))
  11. const A1_1base = React.lazy(() => import('./pages/A1_1base'))
  12. const A2visit = React.lazy(() => import('./pages/A2visit'))
  13. const A3banquet = React.lazy(() => import('./pages/A3banquet'))
  14. const A4dance = React.lazy(() => import('./pages/A4dance'))
  15. const A5chef = React.lazy(() => import('./pages/A5chef'))
  16. const A6plow = React.lazy(() => import('./pages/A6plow'))
  17. const B1more = React.lazy(() => import('./pages/B1more'))
  18. // 云起图仙居 等热点集合页面
  19. const B2hots = React.lazy(() => import('./pages/B2hots'))
  20. // 云气图
  21. const B3yun = React.lazy(() => import('./pages/B3yun'))
  22. // 仙居
  23. const B4xian = React.lazy(() => import('./pages/B4xian'))
  24. // unity页面
  25. const C1unity = React.lazy(() => import('./pages/C1unity'))
  26. const Text = React.lazy(() => import('./pages/Text'))
  27. declare global {
  28. //设置全局属性
  29. interface Window {
  30. //window对象属性
  31. isHH: boolean //加入对象
  32. unityOpenHot: (index: number) => void
  33. unityBack: () => void
  34. }
  35. }
  36. let tempW = document.documentElement.clientWidth
  37. let tempH = document.documentElement.clientHeight
  38. let tempMax = tempW >= tempH ? tempW : tempH
  39. let tempMin = tempW >= tempH ? tempH : tempW
  40. const pageBi = Math.round(Number((tempMax / tempMin).toFixed(2)))
  41. // 设计图按照 844 X 390 来开发
  42. const planSize = {
  43. width: 844,
  44. height: Math.round(Number((844 / pageBi).toFixed(0)))
  45. }
  46. export default function App() {
  47. useEffect(() => {
  48. // 打包环境 刷新页面从 首页 开始
  49. // if (!isLoc && myData.isLdong) {
  50. // if (window.location.hash !== '#/') {
  51. // window.location.href = window.location.origin
  52. // }
  53. // }
  54. }, [])
  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. //横屏
  63. isHHTemp = true
  64. const sizeW = width / planSize.width
  65. let sizeH = height / planSize.height
  66. let moveX = (planSize.width - width) / 2
  67. let moveY = (planSize.height - height) / 2
  68. if (width >= planSize.width) moveX = 0
  69. rootRef.current.style.left = '0'
  70. rootRef.current.style.transform = `translate(${-moveX}px,${-moveY}px) scale(${sizeW},${sizeH}) rotate(0deg)`
  71. rootRef.current.style.transformOrigin = 'center'
  72. } else {
  73. // 竖屏
  74. isHHTemp = false
  75. const temp = width
  76. width = height
  77. height = temp
  78. const sizeW = width / planSize.width
  79. let sizeH = height / planSize.height
  80. rootRef.current.style.left = '100%'
  81. rootRef.current.style.transform = `rotate(90deg) scale(${sizeW},${sizeH})`
  82. rootRef.current.style.transformOrigin = 'left top'
  83. }
  84. // 横竖屏变化的时候 刷新页面
  85. // if (window.isHH !== isHHTemp) {
  86. // window.location.reload()
  87. // }
  88. store.dispatch({ type: 'layout/isHH', payload: isHHTemp })
  89. }, [])
  90. useEffect(() => {
  91. rootRef.current = document.querySelector('#root')
  92. rootRef.current.style.width = planSize.width + 'px'
  93. rootRef.current.style.height = planSize.height + 'px'
  94. pageFullChangeFu()
  95. window.addEventListener('resize', pageFullChangeFu, false)
  96. }, [pageFullChangeFu])
  97. return (
  98. <>
  99. {/* 关于路由 */}
  100. <Router history={history}>
  101. <React.Suspense fallback={<SpinLoding />}>
  102. <Switch>
  103. <Route path='/' component={A1home} exact />
  104. <Route path='/base' component={A1_1base} exact />
  105. <Route path='/visit' component={A2visit} exact />
  106. <Route path='/banquet' component={A3banquet} exact />
  107. <Route path='/dance' component={A4dance} exact />
  108. <Route path='/chef' component={A5chef} exact />
  109. <Route path='/plow' component={A6plow} exact />
  110. <Route path='/more' component={B1more} exact />
  111. <Route path='/hots' component={B2hots} exact />
  112. <Route path='/yun' component={B3yun} exact />
  113. <Route path='/xian' component={B4xian} exact />
  114. <Route path='/unity/:id' component={C1unity} exact />
  115. <Route path='/text' component={Text} exact />
  116. <Route path='*' component={NotFound} />
  117. </Switch>
  118. </React.Suspense>
  119. </Router>
  120. </>
  121. )
  122. }