From 0c9660562a03191d44fc779a889d3da0dc624b6d Mon Sep 17 00:00:00 2001
From: 董国庆 <364620639@qq.com>
Date: 星期五, 25 七月 2025 10:47:19 +0800
Subject: [PATCH] 修改弹窗ui和客户反馈
---
laboratory/src/utils/utils.js | 36 ++++++++++++++++++++++++++++++++++--
1 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/laboratory/src/utils/utils.js b/laboratory/src/utils/utils.js
index c408da7..ee15529 100644
--- a/laboratory/src/utils/utils.js
+++ b/laboratory/src/utils/utils.js
@@ -25,11 +25,9 @@
axios.post(uploadUrl, formData, { headers: uploadHeaders })
.then(res => {
- console.log('22222',res)
onSuccess(res.data);
})
.catch(err => {
- console.log('222222222222',err)
onError(err);
});
};
@@ -38,4 +36,38 @@
if (!url) return '';
if (/^https?:\/\//.test(url)) return url;
return apiConfig.showImgUrl + url;
+}
+
+/**
+ * 通用文件下载方法
+ * @param {string} url 文件的下载地址(支持相对和绝对路径)
+ * @param {string} name 下载保存的文件名(可选)
+ */
+export function downloadFileByUrl(url, name) {
+ console.log('22222222222222222222',url)
+ if (!url) return;
+ // 处理相对路径
+ const fullUrl = getFullUrl(url);
+ console.log('fullUrl fullUrl',fullUrl)
+ const a = document.createElement('a');
+ a.href = fullUrl;
+ if (name) {
+ a.download = name;
+ } else {
+ a.download = '';
+ }
+ a.style.display = 'none';
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+}
+
+/**
+ * 在新标签页打开文件(预览或下载)
+ * @param {string} url 文件地址(支持相对和绝对路径)
+ */
+export function openFileInNewTab(url) {
+ if (!url) return;
+ const fullUrl = getFullUrl(url);
+ window.open(fullUrl, '_blank');
}
\ No newline at end of file
--
Gitblit v1.7.1