可視化 適配pc頁面

大佬們 點(diǎn)贊支持下?。。?!


// 混入代碼 
export default {
  data() {
    return {
      resizeData: {
        width: 1920, //設(shè)計(jì)稿寬
        height: 1080, //設(shè)計(jì)稿高
        ratio: 16 / 9 //比例
      }
    };
  },
  created() {
    this.refreshScale();
    window.addEventListener("resize", this.refreshScale, false);
    window.addEventListener(
      "pageshow",
      function(e) {
        if (e.persisted) {
          // 瀏覽器后退的時(shí)候重新計(jì)算
          this.refreshScale();
        }
      },
      false
    );
  },
  beforeDestroy() {
    window.removeEventListener("reisze", this.refreshScale());
  },
  methods: {
//zoom
setBodyZoom () {
      const t = window.screen.width
      let zoomNum = t / 1920 * 10
      zoomNum = Math.round(zoomNum) / 10
      document.body.style.zoom = zoomNum
    },
    //等比縮放高度鋪滿
    refreshScale() {
      const bodyStyle = document.createElement("style");
      bodyStyle.innerHTML = `body{width:${this.resizeData.width}px; height:${this.resizeData.height}px!important;background-image: none;background-color: #000517 !important;overflow: hidden;}`;
      document.documentElement.firstElementChild.appendChild(bodyStyle);
      let docWidth = document.documentElement.clientWidth;
      let docHeight = document.documentElement.clientHeight;
      const designWidth = this.resizeData.width,
        designHeight = this.resizeData.height,
        heightRatio = docHeight / designHeight;
      document.body.style =
        "transform:scale(" +
        heightRatio +
        ");transform-origin:left top;margin-left: " +
        (docWidth - designWidth * heightRatio) / 2 +
        "px";
    },
    //// 等比縮放寬度鋪滿
    refreshScaleWidth() {
      const bodyStyle = document.createElement("style");
      bodyStyle.innerHTML = `body{width:${this.resizeData.width}px; height:${this.resizeData.height}px!important;background-image: none;background-color: #000517 !important;overflow: hidden;}`;
      document.documentElement.firstElementChild.appendChild(bodyStyle);
      let docWidth = document.documentElement.clientWidth;
      const designWidth = this.resizeData.width,
        widthRatio = docWidth / designWidth;
      document.body.style =
        "transform:scale(" + widthRatio + ");transform-origin:left top;";
    },
    //// 全屏鋪滿    根據(jù)寬度100% 高度壓縮改變  或者高度100%  寬度壓縮改變
    refreshScaleFullh() {
      const bodyStyle = document.createElement("style");
      bodyStyle.innerHTML = `body{width:${this.resizeData.width}px; height:${this.resizeData.height}px!important;background-image: none;background-color: #000517 !important;overflow: hidden;}`;
      document.documentElement.firstElementChild.appendChild(bodyStyle);
      let docWidth = document.documentElement.clientWidth;
      let docHeight = document.documentElement.clientHeight;

      const designWidth = this.resizeData.width,
        designHeight = this.resizeData.height,
        widthRatio = docWidth / designWidth,
        heightRatio = docHeight / designHeight;
      document.body.style =
        "transform:scale(" +
        widthRatio +
        "," +
        heightRatio +
        ");transform-origin:left top;";
    },
    //根據(jù)寬度100% 高度不壓縮
    refreshScaleFull() {
      let baseWidth = document.documentElement.clientWidth;
      let baseHeight = document.documentElement.clientHeight;
      let appStyle = document.getElementById("app").style;
      let realRatio = baseWidth / baseHeight;
      let designRatio = this.resizeData.ratio;
      let scaleRate = baseWidth / this.resizeData.width;
      if (realRatio > designRatio) {
        scaleRate = baseHeight / this.resizeData.height;
      }
      appStyle.transformOrigin = "left top";
      appStyle.transform = `scale(${scaleRate}) translateX(0%)`;
      appStyle.width = `${baseWidth / scaleRate}px`;
      //然后高度 自適應(yīng)  里面內(nèi)容根據(jù)flex 跟百分比計(jì)算
    }
  }
};

//引入方式

import echartMixins from "@/utils/resizeMixins";
//使用mixins  
mixins: [echartMixins],
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容