|
@@ -1,6 +1,6 @@
|
|
|
import '@/assets/styles/base.css'
|
|
import '@/assets/styles/base.css'
|
|
|
// 关于路由
|
|
// 关于路由
|
|
|
-import React, { useCallback, useEffect } from 'react'
|
|
|
|
|
|
|
+import React, { useCallback, useEffect, useRef } from 'react'
|
|
|
import { Router, Route, Switch } from 'react-router-dom'
|
|
import { Router, Route, Switch } from 'react-router-dom'
|
|
|
import history, { isMobileFu } from './utils/history'
|
|
import history, { isMobileFu } from './utils/history'
|
|
|
import SpinLoding from './components/SpinLoding'
|
|
import SpinLoding from './components/SpinLoding'
|
|
@@ -14,22 +14,111 @@ import screenImg from '@/assets/img/landtip.png'
|
|
|
const A1home = React.lazy(() => import('./pages/A1home'))
|
|
const A1home = React.lazy(() => import('./pages/A1home'))
|
|
|
const A2layout = React.lazy(() => import('./pages/A2layout'))
|
|
const A2layout = React.lazy(() => import('./pages/A2layout'))
|
|
|
const A3scene = React.lazy(() => import('./pages/A3scene'))
|
|
const A3scene = React.lazy(() => import('./pages/A3scene'))
|
|
|
|
|
+const LookScene = React.lazy(() => import('./pages/A2layout/components/Look/LookScene'))
|
|
|
|
|
+
|
|
|
|
|
+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)))
|
|
|
|
|
+
|
|
|
|
|
+// 设计图按照 1920 X 960 来开发
|
|
|
|
|
+const planSize = {
|
|
|
|
|
+ width: 1920,
|
|
|
|
|
+ height: Math.round(Number((1920 / pageBi).toFixed(0)))
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
export default function App() {
|
|
export default function App() {
|
|
|
|
|
+ const rootRef = useRef<any>(null)
|
|
|
|
|
+
|
|
|
|
|
+ const timeRef = useRef(0)
|
|
|
// 从仓库中获取查看图片的信息
|
|
// 从仓库中获取查看图片的信息
|
|
|
// const lookBigImg = useSelector((state: RootState) => state.A0Layout.lookBigImg)
|
|
// const lookBigImg = useSelector((state: RootState) => state.A0Layout.lookBigImg)
|
|
|
|
|
|
|
|
- const rootDomFu = useCallback(() => {
|
|
|
|
|
- const rootDom: HTMLDivElement = document.querySelector('#root')!
|
|
|
|
|
- if (rootDom) {
|
|
|
|
|
- rootDom.style.height = window.innerHeight + 'px'
|
|
|
|
|
|
|
+ const getViewportSize = () => {
|
|
|
|
|
+ if (window.visualViewport) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ width: window.visualViewport.width,
|
|
|
|
|
+ height: window.visualViewport.height
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return {
|
|
|
|
|
+ width: window.innerWidth,
|
|
|
|
|
+ height: window.innerHeight
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const applyPageScale = useCallback(() => {
|
|
|
|
|
+ if (!rootRef.current || isMobileFu()) return
|
|
|
|
|
+
|
|
|
|
|
+ const run = () => {
|
|
|
|
|
+ const { width, height } = getViewportSize()
|
|
|
|
|
+
|
|
|
|
|
+ if (width >= height) {
|
|
|
|
|
+ document.body.style.overflow = 'hidden'
|
|
|
|
|
+
|
|
|
|
|
+ const sizeW = width / planSize.width
|
|
|
|
|
+ const sizeH = height / planSize.height
|
|
|
|
|
+
|
|
|
|
|
+ let moveX = (planSize.width - width) / 2
|
|
|
|
|
+ const moveY = (planSize.height - height) / 2
|
|
|
|
|
+ // if (width >= planSize.width) moveX = 0
|
|
|
|
|
+
|
|
|
|
|
+ rootRef.current.style.left = '0'
|
|
|
|
|
+ rootRef.current.style.transform = `translate3d(${-moveX}px,${-moveY}px,0px) scale(${sizeW},${sizeH}) rotate(0deg)`
|
|
|
|
|
+ rootRef.current.style.transformOrigin = 'center'
|
|
|
|
|
+ } else {
|
|
|
|
|
+ document.body.style.overflow = 'auto'
|
|
|
|
|
+ rootRef.current.style.transform = 'none'
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const { width, height } = getViewportSize()
|
|
|
|
|
+ if (width >= height) {
|
|
|
|
|
+ document.body.style.overflow = 'hidden'
|
|
|
|
|
+ requestAnimationFrame(run)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ run()
|
|
|
}
|
|
}
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
+ const pageFullChangeFu = useCallback(
|
|
|
|
|
+ (delay: number = 200) => {
|
|
|
|
|
+ if (isMobileFu()) return
|
|
|
|
|
+ clearTimeout(timeRef.current)
|
|
|
|
|
+ timeRef.current = window.setTimeout(applyPageScale, delay)
|
|
|
|
|
+ },
|
|
|
|
|
+ [applyPageScale]
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- window.addEventListener('resize', rootDomFu, true)
|
|
|
|
|
- rootDomFu()
|
|
|
|
|
- }, [rootDomFu])
|
|
|
|
|
|
|
+ rootRef.current = document.querySelector('#root')
|
|
|
|
|
+
|
|
|
|
|
+ // 移动端保持 CSS 默认 100vw/100vh 响应式布局,不做 PC 端缩放
|
|
|
|
|
+ if (isMobileFu()) return
|
|
|
|
|
+
|
|
|
|
|
+ rootRef.current.style.width = planSize.width + 'px'
|
|
|
|
|
+ rootRef.current.style.height = planSize.height + 'px'
|
|
|
|
|
+
|
|
|
|
|
+ const onResize = () => pageFullChangeFu()
|
|
|
|
|
+
|
|
|
|
|
+ applyPageScale()
|
|
|
|
|
+ requestAnimationFrame(() => {
|
|
|
|
|
+ requestAnimationFrame(applyPageScale)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ window.addEventListener('resize', onResize, false)
|
|
|
|
|
+ window.visualViewport?.addEventListener('resize', onResize)
|
|
|
|
|
+
|
|
|
|
|
+ return () => {
|
|
|
|
|
+ clearTimeout(timeRef.current)
|
|
|
|
|
+ window.removeEventListener('resize', onResize, false)
|
|
|
|
|
+ window.visualViewport?.removeEventListener('resize', onResize)
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [applyPageScale, pageFullChangeFu])
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
@@ -41,6 +130,7 @@ export default function App() {
|
|
|
<Route exact path='/' component={A1home} />
|
|
<Route exact path='/' component={A1home} />
|
|
|
<Route path='/layout' component={A2layout} />
|
|
<Route path='/layout' component={A2layout} />
|
|
|
<Route path='/scene' component={A3scene} />
|
|
<Route path='/scene' component={A3scene} />
|
|
|
|
|
+ <Route path='/look/:id' component={LookScene} />
|
|
|
</Switch>
|
|
</Switch>
|
|
|
</React.Suspense>
|
|
</React.Suspense>
|
|
|
</Router>
|
|
</Router>
|