AppTemp.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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, { isMobiileFu } from './utils/history'
  6. import SpinLoding from './components/SpinLoding'
  7. // import { Image } from 'antd'
  8. // import { useSelector } from 'react-redux'
  9. // import store, { RootState } from './store'
  10. // import MessageCom from './components/Message'
  11. // import LookDom from './components/LookDom'
  12. import NotFound from '@/components/NotFound'
  13. const A1home = React.lazy(() => import('./pages/A1home'))
  14. // 设计图按照 1920 X 919 来开发
  15. const planSize = {
  16. width: isMobiileFu() ? 414 : 1920,
  17. height: isMobiileFu() ? 736 : 919
  18. }
  19. export default function App() {
  20. // 从仓库中获取查看图片的信息
  21. // const lookBigImg = useSelector((state: RootState) => state.A0Layout.lookBigImg)
  22. const rootRef = useRef<any>(null)
  23. // 移动端存下来 最小屏幕数据 防止打开输入框的时候压缩高度
  24. const moBaseObj = useRef({
  25. num: 0,
  26. scaleH: 0,
  27. moveY: 0
  28. })
  29. const pageFullChangeFu = useCallback(() => {
  30. let width = document.documentElement.clientWidth
  31. let height = document.documentElement.clientHeight
  32. // 屏幕改变的时候改变字体大小,这个项目暂时用不上
  33. // // 1920 = 16px
  34. // const bei = 1920 / 16;
  35. // let res = Math.round(width / bei);
  36. // if (res <= 10) res = 10;
  37. // rootRef.current.style.setProperty("--fontNum", res + "px");
  38. // 移动端开发 宽度限制最大500px
  39. if (planSize.width <= 500) {
  40. width = width >= 500 ? 500 : width
  41. rootRef.current.style.margin = '0 auto'
  42. }
  43. const sizeW = width / planSize.width
  44. let sizeH = height / planSize.height
  45. const moveX = (planSize.width - width) / 2
  46. let moveY = (planSize.height - height) / 2
  47. // 移动端
  48. if (height < moBaseObj.current.num) {
  49. // 打开了键盘
  50. document.querySelector('body')!.style.overflow = 'auto'
  51. sizeH = moBaseObj.current.scaleH
  52. moveY = moBaseObj.current.moveY
  53. } else document.querySelector('body')!.style.overflow = 'hidden'
  54. // console.log("-------", width, moveX);
  55. rootRef.current.style.transform = `translate(${-moveX}px,${-moveY}px) scale(${sizeW},${sizeH})`
  56. }, [])
  57. useEffect(() => {
  58. rootRef.current = document.querySelector('#root')
  59. rootRef.current.style.width = planSize.width + 'px'
  60. rootRef.current.style.height = planSize.height + 'px'
  61. // 移动端
  62. if (planSize.width <= 500) {
  63. const height = document.documentElement.clientHeight
  64. moBaseObj.current = {
  65. num: height,
  66. scaleH: height / planSize.height,
  67. moveY: (planSize.height - height) / 2
  68. }
  69. }
  70. pageFullChangeFu()
  71. window.addEventListener('resize', pageFullChangeFu, false)
  72. }, [pageFullChangeFu])
  73. return (
  74. <>
  75. {/* 关于路由 */}
  76. <Router history={history}>
  77. <React.Suspense fallback={<SpinLoding />}>
  78. <Switch>
  79. <Route path='/' component={A1home} exact />
  80. <Route path='*' component={NotFound} />
  81. </Switch>
  82. </React.Suspense>
  83. </Router>
  84. {/* 所有图片点击预览查看大图 */}
  85. {/* <Image
  86. preview={{
  87. visible: lookBigImg.show,
  88. src: lookBigImg.url,
  89. onVisibleChange: value => {
  90. // 清除仓库信息
  91. store.dispatch({
  92. type: 'layout/lookBigImg',
  93. payload: { url: '', show: false }
  94. })
  95. }
  96. }}
  97. /> */}
  98. {/* 查看视频音频 */}
  99. {/* <LookDom /> */}
  100. {/* antd 轻提示 ---兼容360浏览器 */}
  101. {/* <MessageCom /> */}
  102. </>
  103. )
  104. }