index.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import React from "react";
  2. import { connect } from "dva";
  3. import styles from "./index.less";
  4. import PanelBlock from "./components/PanelBlock";
  5. import HeaderContent from "./components/HeadContent";
  6. import OverView from "./components/Overview";
  7. import PortalTraffic from "./components/PortalTraffic";
  8. import Enquire from "./components/Enquire";
  9. import OverseasEnquireLocation from "./components/OverseasEnquireLocation";
  10. import DistributorEnquireLocation from "./components/DistributorEnquireLocation";
  11. import AddMemberTrend from "./components/addMemberTrend";
  12. import AddProductTrend from "./components/addProductTrend";
  13. import SearchRankCloud from "./components/SearchRankCloud";
  14. import MemberLocation from "./components/MemberLocation";
  15. import StoreTraffic from "./components/StoreTraffic";
  16. import MapContainer from "./components/MapContainer";
  17. import OrderBasic from "./components/Order";
  18. @connect(({ bigscreen }) => ({
  19. bigscreen,
  20. }))
  21. class BigScreen extends React.Component {
  22. constructor(props) {
  23. super(props);
  24. this.state = {
  25. isFullScreen: false,
  26. startTime: performance.now(),
  27. };
  28. this.resizeHandler = null;
  29. this.timer = null;
  30. this.htmlOverflow = null;
  31. this.bodyOverflow = null;
  32. }
  33. componentDidMount() {
  34. const { dispatch } = this.props;
  35. dispatch({
  36. type: "bigscreen/load_data",
  37. });
  38. this.setScale();
  39. window.addEventListener("resize", this.debounceSetScale);
  40. this.showRenderTime();
  41. this.htmlOverflow = document.documentElement.style.overflow;
  42. this.bodyOverflow = document.body.style.overflow;
  43. document.documentElement.style.overflow = "hidden";
  44. document.body.style.overflow = "hidden";
  45. // 全屏事件监听
  46. [
  47. "fullscreenchange",
  48. "webkitfullscreenchange",
  49. "mozfullscreenchange",
  50. "MSFullscreenChange",
  51. ].forEach((event) =>
  52. document.addEventListener(event, this.onFullScreenChange)
  53. );
  54. }
  55. componentWillUnmount() {
  56. window.removeEventListener("resize", this.debounceSetScale);
  57. document.documentElement.style.overflow = this.htmlOverflow || "";
  58. document.body.style.overflow = this.bodyOverflow || "";
  59. [
  60. "fullscreenchange",
  61. "webkitfullscreenchange",
  62. "mozfullscreenchange",
  63. "MSFullscreenChange",
  64. ].forEach((event) =>
  65. document.removeEventListener(event, this.onFullScreenChange)
  66. );
  67. }
  68. // 全屏切换
  69. toggleFullScreen = () => {
  70. const elem = document.querySelector(`.${styles.screenWrapper}`);
  71. if (!this.state.isFullScreen) {
  72. if (elem.requestFullscreen) elem.requestFullscreen();
  73. else if (elem.webkitRequestFullscreen) elem.webkitRequestFullscreen();
  74. else if (elem.mozRequestFullScreen) elem.mozRequestFullScreen();
  75. else if (elem.msRequestFullscreen) elem.msRequestFullscreen();
  76. } else {
  77. if (document.exitFullscreen) document.exitFullscreen();
  78. else if (document.webkitExitFullscreen) document.webkitExitFullscreen();
  79. else if (document.mozCancelFullScreen) document.mozCancelFullScreen();
  80. else if (document.msExitFullscreen) document.msExitFullscreen();
  81. }
  82. };
  83. onFullScreenChange = () => {
  84. this.setState({
  85. isFullScreen: !!(
  86. document.fullscreenElement ||
  87. document.webkitFullscreenElement ||
  88. document.mozFullScreenElement ||
  89. document.msFullscreenElement
  90. ),
  91. renderKey: Date.now() // 用时间戳保证唯一
  92. });
  93. };
  94. debounceSetScale = () => {
  95. clearTimeout(this.resizeHandler);
  96. this.resizeHandler = setTimeout(() => {
  97. this.setScale();
  98. }, 200);
  99. };
  100. setScale = () => {
  101. const baseWidth = 3840;
  102. const baseHeight = 2160;
  103. const wrapper = document.querySelector(`.${styles.screenWrapper}`);
  104. const ww = wrapper ? wrapper.clientWidth : window.innerWidth;
  105. const wh = wrapper ? wrapper.clientHeight : window.innerHeight;
  106. const scale = Math.min(ww / baseWidth, wh / baseHeight);
  107. const screenContainer = document.querySelector(
  108. `.${styles.screenContainer}`
  109. );
  110. // const mapContainer = document.querySelector(`.${styles.mapContainer}`);
  111. if (screenContainer) {
  112. screenContainer.style.transform = `scale(${scale}) translate(-50%, -50%)`;
  113. screenContainer.style.transformOrigin = "0 0";
  114. screenContainer.style.left = "50%";
  115. screenContainer.style.top = "50%";
  116. screenContainer.style.margin = "0";
  117. }
  118. // if (mapContainer) {
  119. // mapContainer.style.transform = `scale(${scale}) translate(-50%, -50%)`;
  120. // mapContainer.style.transformOrigin = "0 0";
  121. // mapContainer.style.left = "50%";
  122. // mapContainer.style.top = "50%";
  123. // mapContainer.style.margin = "0";
  124. // }
  125. };
  126. showRenderTime = () => {
  127. const timeUsed = (performance.now() - this.state.startTime).toFixed(2);
  128. console.log(`页面渲染完成耗时:${timeUsed} ms`);
  129. };
  130. render() {
  131. const { isFullScreen, renderKey } = this.state;
  132. return (
  133. <div className={styles.screenWrapper}>
  134. {isFullScreen ? null : (
  135. <button
  136. className={styles.fullscreenBtn}
  137. onClick={this.toggleFullScreen}
  138. >
  139. {"全屏"}
  140. </button>
  141. )}
  142. <div className={styles.screenContainer}>
  143. {/* 顶部 */}
  144. <div className={styles.headPanel}>
  145. <HeaderContent key={renderKey}/>
  146. </div>
  147. <div className={styles.contentPanel} key={renderKey}>
  148. {/* 左侧 */}
  149. <div className={styles.contentPanelLeft}>
  150. <PanelBlock
  151. styleObj={{
  152. width: "699px",
  153. height: "420px",
  154. marginBottom: "36px",
  155. backgroundImage: `url(${require("../../../assets/bigscreen/box-1.png")})`,
  156. }}
  157. >
  158. <PortalTraffic />
  159. </PanelBlock>
  160. <PanelBlock
  161. width="699px"
  162. height="420px"
  163. marginBottom="36px"
  164. styleObj={{
  165. backgroundImage: `url(${require("../../../assets/bigscreen/box-1.png")})`,
  166. }}
  167. >
  168. <Enquire />
  169. </PanelBlock>
  170. <PanelBlock
  171. styleObj={{
  172. width: "699px",
  173. height: "420px",
  174. marginBottom: "36px",
  175. backgroundImage: `url(${require("../../../assets/bigscreen/box-1.png")})`,
  176. }}
  177. >
  178. <OrderBasic />
  179. </PanelBlock>
  180. <PanelBlock
  181. flexDirection="row"
  182. height="420px"
  183. styleObj={{ padding: 0 }}
  184. >
  185. <PanelBlock
  186. styleObj={{
  187. width: "326px",
  188. marginRight: "47px",
  189. backgroundImage: `url(${require("../../../assets/bigscreen/box-2.png")})`,
  190. }}
  191. >
  192. <OverseasEnquireLocation />
  193. </PanelBlock>
  194. <PanelBlock
  195. styleObj={{
  196. width: "326px",
  197. backgroundImage: `url(${require("../../../assets/bigscreen/box-2.png")})`,
  198. }}
  199. >
  200. <DistributorEnquireLocation />
  201. </PanelBlock>
  202. </PanelBlock>
  203. </div>
  204. {/* 中间 */}
  205. <div className={styles.contentPanelCenter}>
  206. <PanelBlock justifyContent="flex-start" height="496px">
  207. <OverView />
  208. </PanelBlock>
  209. <PanelBlock />
  210. {/* <PanelBlock flexDirection="row" height="608px">
  211. <PanelBlock
  212. width="822px"
  213. marginRight="64px"
  214. styleObj={{
  215. backgroundImage: `url(${require("../../../assets/bigscreen/box-3.png")})`,
  216. }}
  217. >
  218. <AddMemberTrend />
  219. </PanelBlock>
  220. <PanelBlock
  221. width="822px"
  222. styleObj={{
  223. backgroundImage: `url(${require("../../../assets/bigscreen/box-3.png")})`,
  224. }}
  225. >
  226. <AddProductTrend />
  227. </PanelBlock>
  228. </PanelBlock> */}
  229. </div>
  230. {/* 右侧 */}
  231. <div className={styles.contentPanelRight}>
  232. <PanelBlock
  233. height="648px"
  234. width="699px"
  235. marginBottom="36px"
  236. styleObj={{
  237. backgroundImage: `url(${require("../../../assets/bigscreen/box-4.png")})`,
  238. }}
  239. >
  240. <SearchRankCloud />
  241. </PanelBlock>
  242. <PanelBlock
  243. height="648px"
  244. width="699px"
  245. marginBottom="36px"
  246. styleObj={{
  247. backgroundImage: `url(${require("../../../assets/bigscreen/box-4.png")})`,
  248. }}
  249. >
  250. <StoreTraffic />
  251. </PanelBlock>
  252. <PanelBlock
  253. height="420px"
  254. width="699px"
  255. styleObj={{
  256. backgroundImage: `url(${require("../../../assets/bigscreen/box-5.png")})`,
  257. }}
  258. >
  259. <AddMemberTrend />
  260. </PanelBlock>
  261. </div>
  262. <div className={styles.mapContainer}>
  263. <PanelBlock isRotateFade={true}>
  264. <MapContainer />
  265. </PanelBlock>
  266. </div>
  267. </div>
  268. </div>
  269. </div>
  270. );
  271. }
  272. }
  273. export default BigScreen;