123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- import React from "react";
- import { connect } from "dva";
- import styles from "./index.less";
- import PanelBlock from "./components/PanelBlock";
- import HeaderContent from "./components/HeadContent";
- import OverView from "./components/Overview";
- import PortalTraffic from "./components/PortalTraffic";
- import Enquire from "./components/Enquire";
- import OverseasEnquireLocation from "./components/OverseasEnquireLocation";
- import DistributorEnquireLocation from "./components/DistributorEnquireLocation";
- import AddMemberTrend from "./components/addMemberTrend";
- import AddProductTrend from "./components/addProductTrend";
- import SearchRankCloud from "./components/SearchRankCloud";
- import MemberLocation from "./components/MemberLocation";
- import StoreTraffic from "./components/StoreTraffic";
- import MapContainer from "./components/MapContainer";
- import OrderBasic from "./components/Order";
- @connect(({ bigscreen }) => ({
- bigscreen,
- }))
- class BigScreen extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- isFullScreen: false,
- startTime: performance.now(),
- };
- this.resizeHandler = null;
- this.timer = null;
- this.htmlOverflow = null;
- this.bodyOverflow = null;
- }
- componentDidMount() {
- const { dispatch } = this.props;
- dispatch({
- type: "bigscreen/load_data",
- });
- this.setScale();
- window.addEventListener("resize", this.debounceSetScale);
- this.showRenderTime();
- this.htmlOverflow = document.documentElement.style.overflow;
- this.bodyOverflow = document.body.style.overflow;
- document.documentElement.style.overflow = "hidden";
- document.body.style.overflow = "hidden";
- // 全屏事件监听
- [
- "fullscreenchange",
- "webkitfullscreenchange",
- "mozfullscreenchange",
- "MSFullscreenChange",
- ].forEach((event) =>
- document.addEventListener(event, this.onFullScreenChange)
- );
- }
- componentWillUnmount() {
- window.removeEventListener("resize", this.debounceSetScale);
- document.documentElement.style.overflow = this.htmlOverflow || "";
- document.body.style.overflow = this.bodyOverflow || "";
- [
- "fullscreenchange",
- "webkitfullscreenchange",
- "mozfullscreenchange",
- "MSFullscreenChange",
- ].forEach((event) =>
- document.removeEventListener(event, this.onFullScreenChange)
- );
- }
- // 全屏切换
- toggleFullScreen = () => {
- const elem = document.querySelector(`.${styles.screenWrapper}`);
- if (!this.state.isFullScreen) {
- if (elem.requestFullscreen) elem.requestFullscreen();
- else if (elem.webkitRequestFullscreen) elem.webkitRequestFullscreen();
- else if (elem.mozRequestFullScreen) elem.mozRequestFullScreen();
- else if (elem.msRequestFullscreen) elem.msRequestFullscreen();
- } else {
- if (document.exitFullscreen) document.exitFullscreen();
- else if (document.webkitExitFullscreen) document.webkitExitFullscreen();
- else if (document.mozCancelFullScreen) document.mozCancelFullScreen();
- else if (document.msExitFullscreen) document.msExitFullscreen();
- }
- };
- onFullScreenChange = () => {
- this.setState({
- isFullScreen: !!(
- document.fullscreenElement ||
- document.webkitFullscreenElement ||
- document.mozFullScreenElement ||
- document.msFullscreenElement
- ),
- renderKey: Date.now() // 用时间戳保证唯一
- });
- };
- debounceSetScale = () => {
- clearTimeout(this.resizeHandler);
- this.resizeHandler = setTimeout(() => {
- this.setScale();
- }, 200);
- };
- setScale = () => {
- const baseWidth = 3840;
- const baseHeight = 2160;
- const wrapper = document.querySelector(`.${styles.screenWrapper}`);
- const ww = wrapper ? wrapper.clientWidth : window.innerWidth;
- const wh = wrapper ? wrapper.clientHeight : window.innerHeight;
- const scale = Math.min(ww / baseWidth, wh / baseHeight);
- const screenContainer = document.querySelector(
- `.${styles.screenContainer}`
- );
- // const mapContainer = document.querySelector(`.${styles.mapContainer}`);
- if (screenContainer) {
- screenContainer.style.transform = `scale(${scale}) translate(-50%, -50%)`;
- screenContainer.style.transformOrigin = "0 0";
- screenContainer.style.left = "50%";
- screenContainer.style.top = "50%";
- screenContainer.style.margin = "0";
- }
- // if (mapContainer) {
- // mapContainer.style.transform = `scale(${scale}) translate(-50%, -50%)`;
- // mapContainer.style.transformOrigin = "0 0";
- // mapContainer.style.left = "50%";
- // mapContainer.style.top = "50%";
- // mapContainer.style.margin = "0";
- // }
- };
- showRenderTime = () => {
- const timeUsed = (performance.now() - this.state.startTime).toFixed(2);
- console.log(`页面渲染完成耗时:${timeUsed} ms`);
- };
- render() {
- const { isFullScreen, renderKey } = this.state;
- return (
- <div className={styles.screenWrapper}>
- {isFullScreen ? null : (
- <button
- className={styles.fullscreenBtn}
- onClick={this.toggleFullScreen}
- >
- {"全屏"}
- </button>
- )}
- <div className={styles.screenContainer}>
- {/* 顶部 */}
- <div className={styles.headPanel}>
- <HeaderContent key={renderKey}/>
- </div>
- <div className={styles.contentPanel} key={renderKey}>
- {/* 左侧 */}
- <div className={styles.contentPanelLeft}>
- <PanelBlock
- styleObj={{
- width: "699px",
- height: "420px",
- marginBottom: "36px",
- backgroundImage: `url(${require("../../../assets/bigscreen/box-1.png")})`,
- }}
- >
- <PortalTraffic />
- </PanelBlock>
- <PanelBlock
- width="699px"
- height="420px"
- marginBottom="36px"
- styleObj={{
- backgroundImage: `url(${require("../../../assets/bigscreen/box-1.png")})`,
- }}
- >
- <Enquire />
- </PanelBlock>
- <PanelBlock
- styleObj={{
- width: "699px",
- height: "420px",
- marginBottom: "36px",
- backgroundImage: `url(${require("../../../assets/bigscreen/box-1.png")})`,
- }}
- >
- <OrderBasic />
- </PanelBlock>
- <PanelBlock
- flexDirection="row"
- height="420px"
- styleObj={{ padding: 0 }}
- >
- <PanelBlock
- styleObj={{
- width: "326px",
- marginRight: "47px",
- backgroundImage: `url(${require("../../../assets/bigscreen/box-2.png")})`,
- }}
- >
- <OverseasEnquireLocation />
- </PanelBlock>
- <PanelBlock
- styleObj={{
- width: "326px",
- backgroundImage: `url(${require("../../../assets/bigscreen/box-2.png")})`,
- }}
- >
- <DistributorEnquireLocation />
- </PanelBlock>
- </PanelBlock>
- </div>
- {/* 中间 */}
- <div className={styles.contentPanelCenter}>
- <PanelBlock justifyContent="flex-start" height="496px">
- <OverView />
- </PanelBlock>
- <PanelBlock />
- {/* <PanelBlock flexDirection="row" height="608px">
- <PanelBlock
- width="822px"
- marginRight="64px"
- styleObj={{
- backgroundImage: `url(${require("../../../assets/bigscreen/box-3.png")})`,
- }}
- >
- <AddMemberTrend />
- </PanelBlock>
- <PanelBlock
- width="822px"
- styleObj={{
- backgroundImage: `url(${require("../../../assets/bigscreen/box-3.png")})`,
- }}
- >
- <AddProductTrend />
- </PanelBlock>
- </PanelBlock> */}
- </div>
- {/* 右侧 */}
- <div className={styles.contentPanelRight}>
- <PanelBlock
- height="648px"
- width="699px"
- marginBottom="36px"
- styleObj={{
- backgroundImage: `url(${require("../../../assets/bigscreen/box-4.png")})`,
- }}
- >
- <SearchRankCloud />
- </PanelBlock>
- <PanelBlock
- height="648px"
- width="699px"
- marginBottom="36px"
- styleObj={{
- backgroundImage: `url(${require("../../../assets/bigscreen/box-4.png")})`,
- }}
- >
- <StoreTraffic />
- </PanelBlock>
- <PanelBlock
- height="420px"
- width="699px"
- styleObj={{
- backgroundImage: `url(${require("../../../assets/bigscreen/box-5.png")})`,
- }}
- >
- <AddMemberTrend />
- </PanelBlock>
- </div>
- <div className={styles.mapContainer}>
- <PanelBlock isRotateFade={true}>
- <MapContainer />
- </PanelBlock>
- </div>
- </div>
- </div>
- </div>
- );
- }
- }
- export default BigScreen;
|