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(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 ( <> {/* 关于路由 */} }> ) }