Browse Source

Merge branch 'iterationApp' into dev

lex 3 years ago
parent
commit
764ad46611
1 changed files with 43 additions and 10 deletions
  1. 43 10
      src/views/message/modal/filePreview.vue

+ 43 - 10
src/views/message/modal/filePreview.vue

@@ -38,14 +38,15 @@
       </template>
     </van-field>
 
-    <van-popup position="bottom" v-model="filePreview" style="height: 100%">
+    <van-popup
+      position="bottom"
+      id="filePreview"
+      v-model="filePreview"
+      style="height: 100%"
+    >
       <van-sticky>
-        <m-header
-          :backUrl="backUrl"
-          :isFixed="false"
-          :appHide="true"
-          name="预览"
-        />
+        <!-- :backUrl="backUrl" -->
+        <m-header :isFixed="false" :appHide="true" name="预览" />
       </van-sticky>
       <div
         id="previewIframe"
@@ -81,9 +82,35 @@ export default {
     };
   },
   mounted() {
-    console.log(this.dataModel);
+    // console.log(this.dataModel);
+    window.addEventListener("hashchange", this.onHash, false);
   },
   methods: {
+    onHash() {
+      this.filePreview = false;
+    },
+    onPopupClose() {
+      this.filePreview = !this.filePreview;
+      // 打开弹窗
+      if (this.filePreview) {
+        const route = this.$route;
+        let times = 0;
+        /* eslint-disable */
+        for (let i in route.query) {
+          times += 1;
+        }
+        let fullPath = route.fullPath;
+        const origin = window.location.origin;
+        const url = times > 0 ? "&pto=1" : "?pto=1";
+        history.pushState("", "", `${origin}/#${fullPath}${url}`);
+      } else {
+        window.history.go(-1);
+      }
+      let popup = document.querySelector("#filePreview");
+      if (popup) {
+        popup.scrollTop = 0;
+      }
+    },
     checkFileSuffix(url) {
       let urlArr = url.split(".");
       let suffix = urlArr[urlArr.length - 1];
@@ -128,9 +155,9 @@ export default {
     },
     downLoadFile(file) {
       // this.previewUrl = 'https://view.officeapps.live.com/op/view.aspx?src=' + file
-      this.filePreview = true;
+      // this.filePreview = true;
       this.fileType = this.getFileSuffix(file);
-
+      this.onPopupClose();
       if (this.fileType == "xls" || this.fileType == "pdf") {
         this.$toast.loading({
           duration: 0, // 持续展示 toast
@@ -181,6 +208,9 @@ export default {
       }
     },
   },
+  destroyed() {
+    window.removeEventListener("hashchange", this.onHash);
+  },
 };
 </script>
 
@@ -191,6 +221,9 @@ export default {
     display: flex;
     flex-direction: column;
   }
+  /deep/.van-popup--bottom {
+    border-radius: 0;
+  }
 }
 .preview_file {
   width: 100%;