123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import '@/assets/styles/base.css'
- // 关于路由
- import React, { useCallback, useEffect, useRef } from 'react'
- import { Router, Route, Switch } from 'react-router-dom'
- import history from './utils/history'
- import SpinLoding from './components/SpinLoding'
- import NotFound from '@/components/NotFound'
- import store from './store'
- // import { isLoc, myData } from './utils/http'
- const A1home = React.lazy(() => import('./pages/A1home'))
- const A1_1base = React.lazy(() => import('./pages/A1_1base'))
- const A2visit = React.lazy(() => import('./pages/A2visit'))
- const A3banquet = React.lazy(() => import('./pages/A3banquet'))
- const A4dance = React.lazy(() => import('./pages/A4dance'))
- const A5chef = React.lazy(() => import('./pages/A5chef'))
- const A6plow = React.lazy(() => import('./pages/A6plow'))
- const B1more = React.lazy(() => import('./pages/B1more'))
- // 云起图仙居 等热点集合页面
- const B2hots = React.lazy(() => import('./pages/B2hots'))
- // 云气图
- const B3yun = React.lazy(() => import('./pages/B3yun'))
- // 仙居
- const B4xian = React.lazy(() => import('./pages/B4xian'))
- // unity页面
- const C1unity = React.lazy(() => import('./pages/C1unity'))
- const Text = React.lazy(() => import('./pages/Text'))
- declare global {
- //设置全局属性
- interface Window {
- //window对象属性
- isHH: boolean //加入对象
- unityOpenHot: (index: number) => void
- unityBack: () => void
- }
- }
- let tempW = document.documentElement.clientWidth
- let tempH = document.documentElement.clientHeight
- let tempMax = tempW >= tempH ? tempW : tempH
- let tempMin = tempW >= tempH ? tempH : tempW
- const pageBi = Math.round(Number((tempMax / tempMin).toFixed(2)))
- // 设计图按照 844 X 390 来开发
- const planSize = {
- width: 844,
- height: Math.round(Number((844 / pageBi).toFixed(0)))
- }
- export default function App() {
- useEffect(() => {
- // 打包环境 刷新页面从 首页 开始
- // if (!isLoc && myData.isLdong) {
- // if (window.location.hash !== '#/') {
- // window.location.href = window.location.origin
- // }
- // }
- }, [])
- // 根元素
- const rootRef = useRef<any>(null)
- const pageFullChangeFu = useCallback(() => {
- let width = document.documentElement.clientWidth
- let height = document.documentElement.clientHeight
- let isHHTemp = false
- if (width >= height) {
- //横屏
- isHHTemp = true
- const sizeW = width / planSize.width
- let sizeH = height / planSize.height
- let moveX = (planSize.width - width) / 2
- let moveY = (planSize.height - height) / 2
- if (width >= planSize.width) moveX = 0
- rootRef.current.style.left = '0'
- rootRef.current.style.transform = `translate(${-moveX}px,${-moveY}px) scale(${sizeW},${sizeH}) rotate(0deg)`
- rootRef.current.style.transformOrigin = 'center'
- } else {
- // 竖屏
- isHHTemp = false
- const temp = width
- width = height
- height = temp
- const sizeW = width / planSize.width
- let sizeH = height / planSize.height
- rootRef.current.style.left = '100%'
- rootRef.current.style.transform = `rotate(90deg) scale(${sizeW},${sizeH})`
- rootRef.current.style.transformOrigin = 'left top'
- }
- // 横竖屏变化的时候 刷新页面
- // if (window.isHH !== isHHTemp) {
- // window.location.reload()
- // }
- store.dispatch({ type: 'layout/isHH', payload: isHHTemp })
- }, [])
- useEffect(() => {
- rootRef.current = document.querySelector('#root')
- rootRef.current.style.width = planSize.width + 'px'
- rootRef.current.style.height = planSize.height + 'px'
- pageFullChangeFu()
- window.addEventListener('resize', pageFullChangeFu, false)
- }, [pageFullChangeFu])
- return (
- <>
- {/* 关于路由 */}
- <Router history={history}>
- <React.Suspense fallback={<SpinLoding />}>
- <Switch>
- <Route path='/' component={A1home} exact />
- <Route path='/base' component={A1_1base} exact />
- <Route path='/visit' component={A2visit} exact />
- <Route path='/banquet' component={A3banquet} exact />
- <Route path='/dance' component={A4dance} exact />
- <Route path='/chef' component={A5chef} exact />
- <Route path='/plow' component={A6plow} exact />
- <Route path='/more' component={B1more} exact />
- <Route path='/hots' component={B2hots} exact />
- <Route path='/yun' component={B3yun} exact />
- <Route path='/xian' component={B4xian} exact />
- <Route path='/unity/:id' component={C1unity} exact />
- <Route path='/text' component={Text} exact />
- <Route path='*' component={NotFound} />
- </Switch>
- </React.Suspense>
- </Router>
- </>
- )
- }
|