From 3df460667d74868d0a54fce12d5e881bbd6c0c1a Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期四, 17 九月 2026 17:11:18 +0800
Subject: [PATCH] 青岛维护统计
---
src/components/FilePreviewDialog/index.vue | 63 +++++++++++++++++--------------
1 files changed, 34 insertions(+), 29 deletions(-)
diff --git a/src/components/FilePreviewDialog/index.vue b/src/components/FilePreviewDialog/index.vue
index 4bfff0a..357c237 100644
--- a/src/components/FilePreviewDialog/index.vue
+++ b/src/components/FilePreviewDialog/index.vue
@@ -61,7 +61,7 @@
<!-- PDF棰勮 -->
<div v-else-if="fileType === 'pdf'" class="preview-container pdf-preview">
<div class="pdf-toolbar">
- <el-button-group>
+ <el-button-group v-if="!useNativePdf">
<el-button
size="mini"
@click="changePage(currentPage - 1)"
@@ -81,7 +81,7 @@
</el-button>
</el-button-group>
- <el-button-group class="zoom-controls">
+ <el-button-group v-if="!useNativePdf" class="zoom-controls">
<el-button size="mini" @click="zoomOut" :disabled="scale <= 50">
<i class="el-icon-zoom-out"></i> 缂╁皬
</el-button>
@@ -99,7 +99,15 @@
</el-button>
</div>
- <div class="pdf-content" v-loading="pdfLoading">
+ <!-- pdf.js 鍥犺法鍩�(CORS)鍔犺浇澶辫触鏃讹紝闄嶇骇涓烘祻瑙堝櫒鍘熺敓 PDF 棰勮锛坕frame 瀵艰埅涓嶅彈鍚屾簮绛栫暐闄愬埗锛� -->
+ <iframe
+ v-if="useNativePdf"
+ :src="fileUrl"
+ class="pdf-native-iframe"
+ frameborder="0"
+ ></iframe>
+
+ <div class="pdf-content" v-else v-loading="pdfLoading">
<pdf
ref="pdf"
:src="pdfUrl"
@@ -214,6 +222,8 @@
pageCount: 0,
scale: 100,
pageRotate: 0,
+ // pdf.js 鍔犺浇澶辫触锛堝 CORS锛夋椂闄嶇骇涓烘祻瑙堝櫒鍘熺敓棰勮
+ useNativePdf: false,
// 鍥剧墖鐩稿叧
imageScale: 100
};
@@ -267,30 +277,11 @@
},
/** 璁$畻 baseUrlHt */
calculateBaseUrl() {
- // 鑾峰彇褰撳墠娴忚鍣ㄥ湴鍧�
- const currentUrl = window.location.href;
- console.log("褰撳墠娴忚鍣ㄥ湴鍧�:", currentUrl);
-
- try {
- // 浣跨敤 URL 瀵硅薄瑙f瀽
- const urlObj = new URL(currentUrl);
- // 鑾峰彇涓绘満鍚嶏紙IP 鎴栧煙鍚嶏級
- const hostname = urlObj.hostname;
- // 鎷兼帴绔彛 :9095
- this.baseUrlHt = `http://${hostname}:9095`;
- console.log("璁$畻寰楀埌鐨� baseUrlHt:", this.baseUrlHt);
- } catch (error) {
- console.error("瑙f瀽URL澶辫触:", error);
- // 澶囩敤鏂规锛氫娇鐢ㄦ鍒欐彁鍙�
- const match = currentUrl.match(/https?:\/\/([^:\/]+)/);
- if (match) {
- this.baseUrlHt = `http://${match[1]}:9095`;
- } else {
- // 鏈�鍚庣殑澶囩敤鏂规
- this.baseUrlHt =
- process.env.VUE_APP_BASE_API || "http://localhost:9095";
- }
- }
+ // 璧板綋鍓嶅煙鍚嶏紙鍚屽煙鐩稿璺緞锛夛紝鐢� nginx 鐨� /profile/ 浠g悊杞彂鍒板悗绔� 9095銆�
+ // 鐩磋繛 9095 绔彛浼氬洜绔彛涓嶅悓浜х敓璺ㄥ煙(CORS)锛岃�屽悗绔瓨鍦ㄥ弻閲� CORS 鍝嶅簲澶撮棶棰橈紝
+ // 鍚屽煙璇锋眰涓嶈Е鍙� CORS 妫�鏌ワ紝鍙粠鏍规簮涓婄粫寮�璇ラ棶棰橈紙鍥剧墖/PDF/涓嬭浇鍏ㄩ儴鐢熸晥锛夈��
+ this.baseUrlHt = "";
+ console.log("鏂囦欢璁块棶璧板悓鍩熶唬鐞�: /profile/");
},
/** 鍒濆鍖栭瑙� */
@@ -302,6 +293,7 @@
// 澶勭悊URL锛屾浛鎹㈠煙鍚嶉儴鍒�
this.fileUrl = this.processFileUrl(originalUrl);
+ console.log(this.fileUrl,'this.fileUrl');
this.fileType = this.getFileType(this.fileName);
@@ -312,6 +304,7 @@
this.scale = 100;
this.imageScale = 100;
this.pageCount = 0;
+ this.useNativePdf = false;
// 妯℃嫙鍔犺浇寤惰繜
setTimeout(() => {
@@ -360,8 +353,13 @@
pdfErrorHandler(error) {
console.error("PDF鍔犺浇澶辫触:", error);
this.pdfLoading = false;
- this.$message.error("PDF鏂囦欢鍔犺浇澶辫触锛岃灏濊瘯涓嬭浇鍚庢煡鐪�");
- this.previewVisible = false;
+ // pdf.js 閫氳繃 fetch 鍔犺浇璺ㄥ煙 PDF 鍙� CORS 闄愬埗锛屽け璐ユ椂闄嶇骇涓烘祻瑙堝櫒鍘熺敓棰勮
+ // 锛坕frame 灞炰簬瀵艰埅璇锋眰锛屼笉鍙楀悓婧愮瓥鐣ラ檺鍒讹紝鍙互姝e父鍔犺浇璺ㄥ煙 PDF锛�
+ this.useNativePdf = true;
+ this.$message({
+ type: "info",
+ message: "宸插垏鎹负娴忚鍣ㄥ師鐢熼瑙堟ā寮�"
+ });
},
/** 鍥剧墖鍔犺浇瀹屾垚 */
@@ -513,6 +511,13 @@
align-items: flex-start;
}
+ /* 鍘熺敓 PDF 棰勮锛圕ORS 闄嶇骇鏂规锛� */
+ .pdf-native-iframe {
+ flex: 1;
+ border: none;
+ background: #f8f9fa;
+ }
+
/* Office棰勮鏍峰紡 */
.office-content {
flex: 1;
--
Gitblit v1.9.3