From b871888a4ee32d15adfd52fdfabc44c7c674db0e Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 17 九月 2026 16:36:45 +0800
Subject: [PATCH] 新疆——新聚lims 1.标准维护预览附件问题

---
 src/components/Preview/filePreview.vue |   52 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/src/components/Preview/filePreview.vue b/src/components/Preview/filePreview.vue
index aedb375..5e15828 100644
--- a/src/components/Preview/filePreview.vue
+++ b/src/components/Preview/filePreview.vue
@@ -4,10 +4,10 @@
       <img :src="imgUrl" alt="Image Preview" />
     </div>
     <div v-if="isPdf" style="height: 80vh;">
-<!--      <object :data="fileUrl" type="application/pdf" width="100%" height="750px">-->
-<!--        <p>鎮ㄧ殑娴忚鍣ㄤ笉鏀寔 PDF 棰勮銆�<a :href="fileUrl" style="color: #3a7bfa;" target="_blank">涓嬭浇 PDF 鏂囦欢</a></p>-->
-<!--      </object>-->
-      <onlyoffice ref="onlyoffice" :options="option" style="width: 100%;height: 100%;" />
+      <onlyoffice v-if="useOnlyOffice" ref="onlyoffice" :options="option" style="width: 100%;height: 100%;" />
+      <iframe v-else-if="pdfUrl" :src="pdfUrl" title="PDF 棰勮" style="width: 100%;height: 100%;border: none;"></iframe>
+      <p v-else-if="pdfError">PDF 棰勮澶辫触锛�<a :href="fileUrl" style="color: #3a7bfa;" target="_blank">鐐规涓嬭浇鏌ョ湅</a></p>
+      <p v-else>姝e湪鍔犺浇 PDF鈥�</p>
     </div>
     <div v-if="isDoc">
       <p v-if="!isDocShow">鏂囨。鏃犳硶鐩存帴棰勮锛岃涓嬭浇鏌ョ湅銆�</p>
@@ -53,6 +53,7 @@
 </template>
 
 <script>
+import axios from 'axios'
 import VueOfficeDocx from '@vue-office/docx'
 //寮曞叆鐩稿叧鏍峰紡
 import '@vue-office/docx/lib/index.css'
@@ -92,7 +93,9 @@
         transformData: (workbookData) => { return workbookData }, //灏嗚幏鍙栧埌鐨別xcel鏁版嵁杩涜澶勭悊涔嬪悗涓旀覆鏌撳埌椤甸潰涔嬪墠锛屽彲閫氳繃transformData瀵瑰嵆灏嗘覆鏌撶殑鏁版嵁鍙婃牱寮忚繘琛屼慨鏀癸紝姝ゆ椂姣忎釜鍗曞厓鏍肩殑text鍊煎氨鏄嵆灏嗘覆鏌撳埌椤甸潰涓婄殑鍐呭
       },
       csvList: [],//csv鏂囦欢鏁版嵁
-      imgUrl: ''
+      imgUrl: '',
+      pdfUrl: '',       //pdf鏈湴棰勮鍦板潃
+      pdfError: false,
     }
   },
   computed: {
@@ -134,9 +137,46 @@
     },
     isSupported() {
       return this.isImage || this.isPdf || this.isDoc || this.isZipOrRar || this.isCsv || this.isXls;
-    }
+    },
+    // 璋冪敤鏂逛紶浜� OnlyOffice 鐨勯厤缃墠璧版枃妗f湇鍔★紝鍚﹀垯鐢ㄦ祻瑙堝櫒鍐呯疆闃呰鍣�
+    useOnlyOffice() {
+      return !!(this.option && this.option.url);
+    },
+  },
+  watch: {
+    fileUrl: {
+      handler() {
+        this.loadPdf();
+      },
+      immediate: true,
+    },
+  },
+  beforeDestroy() {
+    this.releasePdfUrl();
   },
   methods: {
+    releasePdfUrl() {
+      if (this.pdfUrl) {
+        URL.revokeObjectURL(this.pdfUrl);
+        this.pdfUrl = "";
+      }
+    },
+    async loadPdf() {
+      this.releasePdfUrl();
+      this.pdfError = false;
+      if (!this.isPdf || this.useOnlyOffice) {
+        return;
+      }
+      try {
+        const { data } = await axios.get(this.fileUrl, { responseType: "blob" });
+        // 鍚庣杩斿洖鐨� Content-Type 涓嶄竴瀹氬甫 application/pdf锛岃繖閲屽己鍒舵寚瀹氾紝
+        // 娴忚鍣ㄦ墠浼氱敤鍐呯疆闃呰鍣ㄦ墦寮�鑰屼笉鏄洿鎺ヤ笅杞�
+        this.pdfUrl = URL.createObjectURL(new Blob([data], { type: "application/pdf" }));
+      } catch (error) {
+        console.error(error);
+        this.pdfError = true;
+      }
+    },
     renderedHandler() {
       console.log("娓叉煋瀹屾垚")
       this.isDocShow = true

--
Gitblit v1.9.3