Sfoglia il codice sorgente

预览基本完成

谢杰标 2 anni fa
parent
commit
e0969a2b16

+ 28 - 0
common/navTo.js

@@ -31,4 +31,32 @@ export function getQueryString(name) {
   return theRequest;
 }
 
+// webview打开缩放
+export function metaSetScalable(type = "yes") {
+  let setContent = "";
+  let meta = document.querySelector("meta[name='viewport']");
+  const content = meta.getAttribute("content");
+  if (type == "yes") {
+    if (!content.includes("user-scalable=no")) {
+      return;
+    }
+    setContent = "width=device-width, initial-scale=1.0, minimum-scale=1.0";
+  } else {
+    if (
+      content.includes("user-scalable") &&
+      content.includes("user-scalable=no")
+    ) {
+      return;
+    }
+    var coverSupport =
+      "CSS" in window &&
+      typeof CSS.supports === "function" &&
+      (CSS.supports("top: env(a)") || CSS.supports("top: constant(a)"));
+    setContent = `width=device-width, initial-scale=1.0, user-scalable=no, initial-scale=1.0, maximum-scale=1.0${
+      coverSupport ? ", viewport-fit=cover" : ""
+    }`;
+  }
+  meta.content = setContent;
+}
+
 export { togo };

+ 1 - 2
components/course/handoutsTree.vue

@@ -83,9 +83,8 @@ export default {
     openDocument() {
       let url = this.$method.splitImgHost(this.fileInfo.url);
       // #ifdef H5
-      // window.location.href = url;
       uni.navigateTo({
-        url: `/pages/webview/sdlink?url=http://192.168.1.57:8080/?src=https%3A%2F%2Ffile-dev.xyyxt.net%2Foss%2Fimages%2F16825677098141789605970.pdf`,
+        url: `/pages/webview/sdlink?url=http://192.168.1.57:8080/?src=${url}`,
       });
       // #endif
       // #ifdef MP-WEIXIN

+ 1 - 1
index.html

@@ -15,7 +15,7 @@
         typeof CSS.supports === "function" &&
         (CSS.supports("top: env(a)") || CSS.supports("top: constant(a)"));
       document.write(
-        '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
+        '<meta name="viewport" content="width=device-width,  initial-scale=1.0,  user-scalable=no, initial-scale=1.0, maximum-scale=1.0' +
           (coverSupport ? ", viewport-fit=cover" : "") +
           '" />'
       );

+ 4 - 1
pages/webview/sdlink.vue

@@ -5,6 +5,7 @@
 </template>
 
 <script>
+import { metaSetScalable } from "../../common/navTo";
 export default {
   data() {
     return {
@@ -18,7 +19,9 @@ export default {
   },
   onLoad(option) {
     this.url = option.url;
-    console.log(this.url, "123");
+    // #ifdef H5
+    metaSetScalable();
+    // #endif
   },
 };
 </script>

+ 15 - 1
pages3/course/jydetail.vue

@@ -13,6 +13,7 @@
 
 <script>
 import handoutsBox from "@/components/course/handoutsBox.vue";
+import { metaSetScalable } from "../../common/navTo";
 export default {
   name: "SaasMiniprogramJydetail",
 
@@ -22,7 +23,11 @@ export default {
       goodsDetail: {},
     };
   },
-
+  onShow() {
+    // #ifdef H5
+    metaSetScalable("no");
+    // #endif
+  },
   async onLoad(options) {
     this.options = options;
     if (this.options.skipPort) {
@@ -40,6 +45,15 @@ export default {
         this.goodsDetail = res.data.data;
       });
     },
+    metaSetScalable1() {
+      let meta = document.querySelector(".meta_scalable_yes");
+      console.log("🚀 ~ file: jydetail.vue:47 ~ metaSetScalable ~ meta:", meta);
+      if (meta) {
+        meta.remove();
+      }
+      document.querySelector(".meta_scalable_yes");
+      console.log("12321321", meta);
+    },
   },
   components: {
     handoutsBox,