Kaynağa Gözat

feat(云机分辨率): 初始化分辨率与差异上报

zengzhixiang 2 yıl önce
ebeveyn
işleme
e0a271038d

+ 55 - 14
static/screenAndroid/WXdraw.js

@@ -255,22 +255,63 @@ function doConnectDirectives() {
     }
     if (result.type === 'getPhoneSize' || result.type === 'setPhoneSize') {
       // console.log(result);
-      const data = window.phoneSizeList.find(function (v) {
-        return (
-          v.width === Math.min(result.data.width, result.data.height) &&
-          v.height === Math.max(result.data.width, result.data.height) &&
-          v.dpi === result.data.dpi
-        );
-      });
-      window.currentPhoneSize = data || {
-        width: Math.min(result.data.width, result.data.height),
-        height: Math.max(result.data.width, result.data.height),
-        dpi: result.data.dpi,
-      };
+      if (
+        window.currentPhoneSize &&
+        (window.currentPhoneSize.width !==
+          Math.min(result.data.width, result.data.height) ||
+          window.currentPhoneSize.height !==
+            Math.max(result.data.width, result.data.height) ||
+          window.currentPhoneSize.dpi !== result.data.dpi)
+      ) {
+        // 获取到的分辨率与当前分辨率不符
+
+        const data = window.phoneSizeList.find(function (v) {
+          return (
+            v.width === Math.min(result.data.width, result.data.height) &&
+            v.height === Math.max(result.data.width, result.data.height) &&
+            v.dpi === result.data.dpi
+          );
+        });
+        window.currentPhoneSize = data || {
+          width: Math.min(result.data.width, result.data.height),
+          height: Math.max(result.data.width, result.data.height),
+          dpi: result.data.dpi,
+        };
 
-      if (result.type === 'setPhoneSize') {
-        lastSetPhone = Date.now();
+        if (result.type === 'setPhoneSize') {
+          lastSetPhone = Date.now();
+        }
+        // if (result.type === 'getPhoneSize') {
+        // 上报给后端
+        $.ajax({
+          url:
+            baseUrl +
+            '/api/resources/v5/machine/resolution/operationResolvingPower',
+          headers: {
+            Authorization: token,
+          },
+          type: 'post',
+          dataType: 'json',
+          contentType: 'application/json; charset=UTF-8',
+          data: JSON.stringify({
+            userCardId: window.userCardId,
+            resolvingPowerId: window.currentPhoneSize.id,
+          }),
+        });
       }
+      // }
+
+      updateDB(db, storeName, {
+        id: userCardId,
+        socketURL: socketURL,
+        cUrl: cUrl,
+        cardToken: cardToken,
+        resolvingPower: resolvingPower,
+        width: window.currentPhoneSize.width,
+        height: window.currentPhoneSize.height,
+        dpi: window.currentPhoneSize.dpi,
+      });
+
       return;
     }
   };

+ 31 - 29
static/screenAndroid/WXtrialInterface.html

@@ -359,6 +359,13 @@
             cUrl = request.result.cUrl;
             cardToken = request.result.cardToken;
             resolvingPower = request.result.resolvingPower;
+
+            window.currentPhoneSize = {
+              width: request.result.width,
+              height: request.result.height,
+              dpi: request.result.dpi,
+            };
+
             doConnectBusiness();
             doConnectDirectives();
           } else {
@@ -494,6 +501,9 @@
                     cUrl: cUrl,
                     cardToken: res.data.cardToken,
                     resolvingPower: res.data.resolvingPower,
+                    width: res.data.width,
+                    height: res.data.high,
+                    dpi: res.data.dpi,
                   });
                 } else {
                   updateDB(db, storeName, {
@@ -502,8 +512,23 @@
                     cUrl: cUrl,
                     cardToken: res.data.cardToken,
                     resolvingPower: res.data.resolvingPower,
+                    width: res.data.width,
+                    height: res.data.high,
+                    dpi: res.data.dpi,
                   });
                 }
+                const data = window.phoneSizeList.find(function (v) {
+                  return (
+                    v.width === res.data.width &&
+                    v.height === res.data.height &&
+                    v.dpi === res.data.dpi
+                  );
+                });
+                window.currentPhoneSize = data || {
+                  width: res.data.width,
+                  height: res.data.height,
+                  dpi: res.data.dpi,
+                };
               } else {
                 $.toast('网络异常,请稍后重试', 'text');
                 setTimeout(() => {
@@ -907,7 +932,7 @@
         if (!isControl) {
           return;
         }
-        stopManyClick(() => {
+        stopManyClick(function () {
           new Promise((resolve, reject) => {
             if (window.navigator.clipboard) {
               window.navigator.clipboard
@@ -937,7 +962,7 @@
             }
           }).then(function () {
             $('.box-shear-plate').empty();
-            $.ajax({
+            return $.ajax({
               url: baseUrl + '/api/public/v5/shear/content',
               headers: {
                 Authorization: token,
@@ -1741,11 +1766,6 @@
       // 分辨率列表
       window.phoneSizeList = [];
       // 当前生效的分辨率
-      window.currentPhoneSize = {
-        // id: 1,
-        width: 720,
-        height: 1280,
-      };
       // 选中的分辨率
       // window.activePhoneSize = window.currentPhoneSize;
 
@@ -1778,13 +1798,13 @@
         // window.phoneSizeListBack = phoneSizeList; // 备份下数据,用户横竖切换时。
         const currentPhoneSize = window.phoneSizeList.find(function (v) {
           return (
-            v.width ===
-              window.currentPhoneSize[resolving ? 'width' : 'height'] &&
-            v.height ===
-              window.currentPhoneSize[resolving ? 'height' : 'width'] &&
+            window.currentPhoneSize &&
+            v.width === window.currentPhoneSize.width &&
+            v.height === window.currentPhoneSize.height &&
             v.dpi === window.currentPhoneSize.dpi
           );
         });
+
         window.currentPhoneSize = currentPhoneSize || window.currentPhoneSize;
         // return updatePhoneSizeListHtml();
       });
@@ -1836,24 +1856,6 @@
         //   }),
         // );
         // 上报分辨率
-        $.ajax({
-          url:
-            baseUrl +
-            '/api/resources/v5/machine/resolution/operationResolvingPower',
-          headers: {
-            Authorization: token,
-          },
-          type: 'post',
-          dataType: 'json',
-          contentType: 'application/json; charset=UTF-8',
-          data: JSON.stringify({
-            userCardId: window.userCardId,
-            resolvingPowerId: config.id,
-            // width: config.width,
-            // height: config.height,
-            // dpi: config.dpi,
-          }),
-        });
         window.currentPhoneSize = config;
       }
       // wsss.addEventListener('message', function (event) {

+ 55 - 14
static/screenIos/WXdraw.js

@@ -263,22 +263,63 @@ function doConnectDirectives() {
     }
     if (result.type === 'getPhoneSize' || result.type === 'setPhoneSize') {
       // console.log(result);
-      const data = window.phoneSizeList.find(function (v) {
-        return (
-          v.width === Math.min(result.data.width, result.data.height) &&
-          v.height === Math.max(result.data.width, result.data.height) &&
-          v.dpi === result.data.dpi
-        );
-      });
-      window.currentPhoneSize = data || {
-        width: Math.min(result.data.width, result.data.height),
-        height: Math.max(result.data.width, result.data.height),
-        dpi: result.data.dpi,
-      };
+      if (
+        window.currentPhoneSize &&
+        (window.currentPhoneSize.width !==
+          Math.min(result.data.width, result.data.height) ||
+          window.currentPhoneSize.height !==
+            Math.max(result.data.width, result.data.height) ||
+          window.currentPhoneSize.dpi !== result.data.dpi)
+      ) {
+        // 获取到的分辨率与当前分辨率不符
+
+        const data = window.phoneSizeList.find(function (v) {
+          return (
+            v.width === Math.min(result.data.width, result.data.height) &&
+            v.height === Math.max(result.data.width, result.data.height) &&
+            v.dpi === result.data.dpi
+          );
+        });
+        window.currentPhoneSize = data || {
+          width: Math.min(result.data.width, result.data.height),
+          height: Math.max(result.data.width, result.data.height),
+          dpi: result.data.dpi,
+        };
 
-      if (result.type === 'setPhoneSize') {
-        lastSetPhone = Date.now();
+        if (result.type === 'setPhoneSize') {
+          lastSetPhone = Date.now();
+        }
+        // if (result.type === 'getPhoneSize') {
+        // 上报给后端
+        $.ajax({
+          url:
+            baseUrl +
+            '/api/resources/v5/machine/resolution/operationResolvingPower',
+          headers: {
+            Authorization: token,
+          },
+          type: 'post',
+          dataType: 'json',
+          contentType: 'application/json; charset=UTF-8',
+          data: JSON.stringify({
+            userCardId: window.userCardId,
+            resolvingPowerId: window.currentPhoneSize.id,
+          }),
+        });
       }
+      // }
+
+      updateDB(db, storeName, {
+        id: userCardId,
+        socketURL: socketURL,
+        cUrl: cUrl,
+        cardToken: cardToken,
+        resolvingPower: resolvingPower,
+        width: window.currentPhoneSize.width,
+        height: window.currentPhoneSize.height,
+        dpi: window.currentPhoneSize.dpi,
+      });
+
       return;
     }
   };

+ 33 - 29
static/screenIos/WXtrialInterface.html

@@ -64,7 +64,7 @@
       {{~}}
     </template>
     <template id="template-shear">
-      {{? it.length}}
+      {{? it.length }}
       <div class="title">
         剪贴板
         <div class="btn-clear">清空</div>
@@ -436,6 +436,13 @@
             cUrl = request.result.cUrl;
             cardToken = request.result.cardToken;
             resolvingPower = request.result.resolvingPower;
+
+            window.currentPhoneSize = {
+              width: request.result.width,
+              height: request.result.height,
+              dpi: request.result.dpi,
+            };
+
             doConnectBusiness();
             doConnectDirectives();
           } else {
@@ -513,6 +520,9 @@
                     cUrl: cUrl,
                     cardToken: res.data.cardToken,
                     resolvingPower: res.data.resolvingPower,
+                    width: res.data.width,
+                    height: res.data.high,
+                    dpi: res.data.dpi,
                   });
                 } else {
                   updateDB(db, storeName, {
@@ -521,8 +531,23 @@
                     cUrl: cUrl,
                     cardToken: res.data.cardToken,
                     resolvingPower: res.data.resolvingPower,
+                    width: res.data.width,
+                    height: res.data.high,
+                    dpi: res.data.dpi,
                   });
                 }
+                const data = window.phoneSizeList.find(function (v) {
+                  return (
+                    v.width === res.data.width &&
+                    v.height === res.data.height &&
+                    v.dpi === res.data.dpi
+                  );
+                });
+                window.currentPhoneSize = data || {
+                  width: res.data.width,
+                  height: res.data.height,
+                  dpi: res.data.dpi,
+                };
               } else {
                 $.toast('网络异常,请稍后重试', 'text');
                 setTimeout(() => {
@@ -624,6 +649,9 @@
       });
 
       function showShearPlate() {
+        if (!isControl) {
+          return;
+        }
         stopManyClick(function () {
           new Promise((resolve, reject) => {
             if (window.navigator.clipboard) {
@@ -1543,11 +1571,6 @@
       // 分辨率列表
       window.phoneSizeList = [];
       // 当前生效的分辨率
-      window.currentPhoneSize = {
-        // id: 1,
-        width: 720,
-        height: 1280,
-      };
       // 选中的分辨率
       // window.activePhoneSize = window.currentPhoneSize;
 
@@ -1580,13 +1603,13 @@
         // window.phoneSizeListBack = phoneSizeList; // 备份下数据,用户横竖切换时。
         const currentPhoneSize = window.phoneSizeList.find(function (v) {
           return (
-            v.width ===
-              window.currentPhoneSize[resolving ? 'width' : 'height'] &&
-            v.height ===
-              window.currentPhoneSize[resolving ? 'height' : 'width'] &&
+            window.currentPhoneSize &&
+            v.width === window.currentPhoneSize.width &&
+            v.height === window.currentPhoneSize.height &&
             v.dpi === window.currentPhoneSize.dpi
           );
         });
+
         window.currentPhoneSize = currentPhoneSize || window.currentPhoneSize;
         // return updatePhoneSizeListHtml();
       });
@@ -1639,25 +1662,6 @@
         //   }),
         // );
         // 上报分辨率
-        $.ajax({
-          url:
-            baseUrl +
-            '/api/resources/v5/machine/resolution/operationResolvingPower',
-          headers: {
-            Authorization: token,
-          },
-          type: 'post',
-          dataType: 'json',
-          contentType: 'application/json; charset=UTF-8',
-          data: JSON.stringify({
-            userCardId: window.userCardId,
-            resolvingPowerId: config.id,
-            // width: config.width,
-            // height: config.height,
-            // dpi: config.dpi,
-          }),
-        });
-
         window.currentPhoneSize = config;
       }
       // wsss.addEventListener('message', function (event) {