Ver código fonte

更新 预览逻辑

王智慧 2 anos atrás
pai
commit
39c3511fbc
1 arquivos alterados com 23 adições e 9 exclusões
  1. 23 9
      src/views/marineManage/marineNotice.vue

+ 23 - 9
src/views/marineManage/marineNotice.vue

@@ -18,7 +18,7 @@
             <el-button
               link
               type="primary"
-              @click="openFile(scope.row.downloadUrl)"
+              @click="openFile(scope.row.downloadUrl, scope.row.suffixName)"
             >
               {{ scope.row.fileName }}
             </el-button>
@@ -92,20 +92,34 @@ function pageChange(e) {
   currentPage.value = e;
   getShippingNoticeList();
 }
-
-function openFile(baseURL) {
+let types = [
+  { type: "doc", application: "application/msword" },
+  {
+    type: "docx",
+    application:
+      "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+  },
+  { type: "pdf", application: "application/pdf" },
+];
+function openFile(baseURL, suffixName) {
   axios({
     baseURL,
     withCredentials: true,
     timeout: 36000,
     responseType: "blob",
   }).then((res) => {
-    const blob = new window.Blob([res.data], {
-      type: "application/pdf",
-    });
-    const href = URL.createObjectURL(blob);
-    pdfUrl.value = href;
-    pdfModal.value = true;
+    if (suffixName.toLowerCase() == "pdf") {
+      const blob = new window.Blob([res.data], {
+        type: "application/pdf",
+      });
+      const href = URL.createObjectURL(blob);
+      pdfUrl.value = href;
+      pdfModal.value = true;
+    } else {
+      let a = document.createElement("a");
+      a.setAttribute("href", baseURL);
+      a.click();
+    }
   });
 }