From c5351e5f1d21b848bbaaa403726115d220443074 Mon Sep 17 00:00:00 2001
From: qinxianzhangyao <11053546+qinxianzhangyao@user.noreply.gitee.com>
Date: 星期二, 31 十月 2023 15:36:24 +0800
Subject: [PATCH] qxtj

---
 src/utils/devicePixelRatio.js |   61 +++++++++---------------------
 1 files changed, 19 insertions(+), 42 deletions(-)

diff --git a/src/utils/devicePixelRatio.js b/src/utils/devicePixelRatio.js
index 73788f3..d1bba32 100644
--- a/src/utils/devicePixelRatio.js
+++ b/src/utils/devicePixelRatio.js
@@ -1,44 +1,21 @@
-class devicePixelRatio {
-    /* 鑾峰彇绯荤粺绫诲瀷 */
-    getSystem() {
-      const agent = navigator.userAgent.toLowerCase();
-      const isMac = /macintosh|mac os x/i.test(navigator.userAgent);
-      if (isMac) return false;
-      // 鐩墠鍙拡瀵� win 澶勭悊锛屽叾瀹冪郴缁熸殏鏃犺鎯呭喌锛岄渶瑕佸垯缁х画鍦ㄦ娣诲姞鍗冲彲
-      if (agent.indexOf("windows") >= 0) return true;
+export const monitorZoom = () => {
+  let ratio = 0,
+    screen = window.screen,
+    ua = navigator.userAgent.toLowerCase();
+  if (window.devicePixelRatio !== undefined) {
+    ratio = window.devicePixelRatio;
+  } else if (~ua.indexOf("msie")) {
+    if (screen.deviceXDPI && screen.logicalXDPI) {
+      ratio = screen.deviceXDPI / screen.logicalXDPI;
     }
-    /* 鐩戝惉鏂规硶鍏煎鍐欐硶 */
-    addHandler(element, type, handler) {
-      if (element.addEventListener) {
-        element.addEventListener(type, handler, false);
-      } else if (element.attachEvent) {
-        element.attachEvent("on" + type, handler);
-      } else {
-        element["on" + type] = handler;
-      }
-    }
-    /* 鏍℃娴忚鍣ㄧ缉鏀炬瘮渚� */
-    correct() {
-      // 椤甸潰devicePixelRatio锛堣澶囧儚绱犳瘮渚嬶級鍙樺寲鍚庯紝璁$畻椤甸潰body鏍囩zoom淇敼鍏跺ぇ灏忥紝鏉ユ姷娑坉evicePixelRatio甯︽潵鐨勫彉鍖�
-      document.getElementsByTagName("body")[0].style.zoom =
-        1 / window.devicePixelRatio;
-    }
-    /* 鐩戝惉椤甸潰缂╂斁 */
-    watch() {
-      const that = this;
-      // 娉ㄦ剰: 杩欎釜鏂规硶鏄В鍐冲叏灞�鏈変袱涓獁indow.resize
-      that.addHandler(window, "resize", function () {
-        that.correct(); // 閲嶆柊鏍℃娴忚鍣ㄧ缉鏀炬瘮渚�
-      });
-    }
-    /* 鍒濆鍖栭〉闈㈡瘮渚� */
-    init() {
-      const that = this;
-      // 鍒ゆ柇璁惧锛屽彧鍦� win 绯荤粺涓嬫牎姝f祻瑙堝櫒缂╂斁姣斾緥
-      if (that.getSystem()) {
-        that.correct(); // 鏍℃娴忚鍣ㄧ缉鏀炬瘮渚�
-        that.watch(); // 鐩戝惉椤甸潰缂╂斁
-      }
-    }
+  } else if (
+    window.outerWidth !== undefined &&
+    window.innerWidth !== undefined
+  ) {
+    ratio = window.outerWidth / window.innerWidth;
   }
-  export default devicePixelRatio;
\ No newline at end of file
+  if (ratio) {
+    ratio = Math.round(ratio * 100);
+  }
+  return ratio;
+};
\ No newline at end of file

--
Gitblit v1.8.0