From 94e0abbf193f9e1fc953716ca7868d74cd14a2cd Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期一, 21 九月 2026 11:06:25 +0800
Subject: [PATCH] fix(inspectionTask): 修复连接实验室功能并更新字段标签

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

diff --git a/src/components/Preview/filePreview.vue b/src/components/Preview/filePreview.vue
index 0381a79..5e15828 100644
--- a/src/components/Preview/filePreview.vue
+++ b/src/components/Preview/filePreview.vue
@@ -3,10 +3,11 @@
     <div v-if="isImage">
       <img :src="imgUrl" alt="Image Preview" />
     </div>
-    <div v-if="isPdf">
-      <object :data="fileUrl" type="application/pdf" width="100%" height="750px">
-        <p>鎮ㄧ殑娴忚鍣ㄤ笉鏀寔 PDF 棰勮銆�<a :href="fileUrl">涓嬭浇 PDF 鏂囦欢</a></p>
-      </object>
+    <div v-if="isPdf" style="height: 80vh;">
+      <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>
@@ -52,14 +53,17 @@
 </template>
 
 <script>
+import axios from 'axios'
 import VueOfficeDocx from '@vue-office/docx'
 //寮曞叆鐩稿叧鏍峰紡
 import '@vue-office/docx/lib/index.css'
 import VueOfficeExcel from '@vue-office/excel'
 //寮曞叆鐩稿叧鏍峰紡
 import '@vue-office/excel/lib/index.css'
+import onlyoffice from "@/components/Onlyoffice/onlyoffice.vue";
 export default {
   components: {
+    onlyoffice,
     VueOfficeDocx,
     VueOfficeExcel,
   },
@@ -71,6 +75,9 @@
     currentFile: {
       type: Object,
       required: true
+    },
+    option: {
+      type: Object,
     },
   },
   data() {
@@ -86,7 +93,9 @@
         transformData: (workbookData) => { return workbookData }, //灏嗚幏鍙栧埌鐨別xcel鏁版嵁杩涜澶勭悊涔嬪悗涓旀覆鏌撳埌椤甸潰涔嬪墠锛屽彲閫氳繃transformData瀵瑰嵆灏嗘覆鏌撶殑鏁版嵁鍙婃牱寮忚繘琛屼慨鏀癸紝姝ゆ椂姣忎釜鍗曞厓鏍肩殑text鍊煎氨鏄嵆灏嗘覆鏌撳埌椤甸潰涓婄殑鍐呭
       },
       csvList: [],//csv鏂囦欢鏁版嵁
-      imgUrl: ''
+      imgUrl: '',
+      pdfUrl: '',       //pdf鏈湴棰勮鍦板潃
+      pdfError: false,
     }
   },
   computed: {
@@ -128,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