From f806aff5702fc6be9c9348d51964366cbf434bf7 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期四, 11 六月 2026 09:43:39 +0800
Subject: [PATCH] 维护
---
src/components/FilePreviewDialog/index.vue | 114 +++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 99 insertions(+), 15 deletions(-)
diff --git a/src/components/FilePreviewDialog/index.vue b/src/components/FilePreviewDialog/index.vue
index ff472c1..4bfff0a 100644
--- a/src/components/FilePreviewDialog/index.vue
+++ b/src/components/FilePreviewDialog/index.vue
@@ -11,7 +11,10 @@
>
<!-- 鍔犺浇鐘舵�� -->
<div v-if="loading" class="preview-loading">
- <i class="el-icon-loading" style="font-size: 40px; margin-bottom: 16px;"></i>
+ <i
+ class="el-icon-loading"
+ style="font-size: 40px; margin-bottom: 16px;"
+ ></i>
<span>鏂囦欢鍔犺浇涓�...</span>
</div>
@@ -19,11 +22,19 @@
<div v-else-if="fileType === 'image'" class="preview-container">
<div class="image-toolbar">
<el-button-group>
- <el-button size="mini" @click="zoomImageIn" :disabled="imageScale >= 300">
+ <el-button
+ size="mini"
+ @click="zoomImageIn"
+ :disabled="imageScale >= 300"
+ >
<i class="el-icon-zoom-in"></i> 鏀惧ぇ
</el-button>
<el-button size="mini" disabled>{{ imageScale }}%</el-button>
- <el-button size="mini" @click="zoomImageOut" :disabled="imageScale <= 50">
+ <el-button
+ size="mini"
+ @click="zoomImageOut"
+ :disabled="imageScale <= 50"
+ >
<i class="el-icon-zoom-out"></i> 缂╁皬
</el-button>
<el-button size="mini" @click="resetImageZoom">
@@ -83,11 +94,7 @@
</el-button>
</el-button-group>
- <el-button
- size="mini"
- type="success"
- @click="handleDownload"
- >
+ <el-button size="mini" type="success" @click="handleDownload">
<i class="el-icon-download"></i> 涓嬭浇
</el-button>
</div>
@@ -111,7 +118,10 @@
</div>
<!-- Office鏂囨。棰勮 -->
- <div v-else-if="fileType === 'office'" class="preview-container office-preview">
+ <div
+ v-else-if="fileType === 'office'"
+ class="preview-container office-preview"
+ >
<div class="office-toolbar">
<el-alert
title="Office鏂囨。棰勮鎻愮ず"
@@ -127,7 +137,11 @@
<div class="office-content">
<iframe
- :src="`https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(fileUrl)}`"
+ :src="
+ `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(
+ fileUrl
+ )}`
+ "
width="100%"
height="600px"
frameborder="0"
@@ -177,6 +191,11 @@
type: Object,
default: () => ({})
}
+ // 娣诲姞baseUrlHt浣滀负props浼犲叆
+ // baseUrlHt: {
+ // type: String,
+ // default: process.env.VUE_APP_BASE_API
+ // }
},
data() {
return {
@@ -185,6 +204,7 @@
// 鍔犺浇鐘舵��
loading: false,
pdfLoading: false,
+ baseUrlHt: "",
// 鏂囦欢淇℃伅
fileUrl: "",
fileName: "",
@@ -214,19 +234,75 @@
}
},
previewVisible(newVal) {
- this.$emit('update:visible', newVal);
+ this.$emit("update:visible", newVal);
if (!newVal) {
this.handleClose();
}
}
},
+ created() {
+ this.calculateBaseUrl();
+ },
methods: {
+ /** URL澶勭悊鍑芥暟 - 灏嗗畬鏁碪RL鏇挎崲涓篵aseUrlHt */
+ processFileUrl(url) {
+ if (!url) return "";
+
+ // 濡傛灉宸茬粡鏄畬鏁寸殑http鎴杊ttps閾炬帴
+ if (url.startsWith("http://") || url.startsWith("https://")) {
+ // 鎵惧埌绗笁涓枩鏉犲悗鐨勪綅缃紝鎻愬彇璺緞閮ㄥ垎
+ const thirdSlashIndex = url.indexOf("/", 8); // 浠巋ttp://鎴杊ttps://涔嬪悗寮�濮嬫壘
+ if (thirdSlashIndex !== -1) {
+ return `${this.baseUrlHt}${url.substring(thirdSlashIndex)}`;
+ }
+ return this.baseUrlHt; // 濡傛灉娌℃湁璺緞閮ㄥ垎锛屽彧杩斿洖baseUrlHt
+ }
+
+ // 鐩稿璺緞澶勭悊
+ if (url.startsWith("/")) {
+ return `${this.baseUrlHt}${url}`;
+ }
+
+ return `${this.baseUrlHt}/${url}`;
+ },
+ /** 璁$畻 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";
+ }
+ }
+ },
+
/** 鍒濆鍖栭瑙� */
initPreview() {
if (!this.file) return;
this.fileName = this.file.fileName || this.file.name || "鏈煡鏂囦欢";
- this.fileUrl = this.file.fileUrl || this.file.path || this.file.url;
+ const originalUrl = this.file.fileUrl || this.file.path || this.file.url;
+
+ // 澶勭悊URL锛屾浛鎹㈠煙鍚嶉儴鍒�
+ this.fileUrl = this.processFileUrl(originalUrl);
+
this.fileType = this.getFileType(this.fileName);
this.loading = true;
@@ -250,7 +326,10 @@
getFileType(fileName) {
if (!fileName) return "other";
- const extension = fileName.split('.').pop().toLowerCase();
+ const extension = fileName
+ .split(".")
+ .pop()
+ .toLowerCase();
const imageTypes = ["jpg", "jpeg", "png", "gif", "bmp", "webp"];
const pdfTypes = ["pdf"];
const officeTypes = ["doc", "docx", "xls", "xlsx", "ppt", "pptx"];
@@ -263,7 +342,12 @@
/** 鑾峰彇鏂囦欢鎵╁睍鍚� */
getFileExtension(filename) {
- return filename.split('.').pop().toLowerCase() || "鏈煡";
+ return (
+ filename
+ .split(".")
+ .pop()
+ .toLowerCase() || "鏈煡"
+ );
},
/** PDF鍔犺浇瀹屾垚 */
@@ -337,7 +421,7 @@
this.imageScale = 100;
},
- /** 涓嬭浇鏂囦欢 */
+ /** 涓嬭浇鏂囦欢 - 涔熼渶瑕佸鐞哢RL */
handleDownload() {
if (!this.fileUrl) {
this.$message.warning("鏂囦欢璺緞涓嶅瓨鍦紝鏃犳硶涓嬭浇");
--
Gitblit v1.9.3