From 0204d3e40681c2a4f50df373012d8cb226d98966 Mon Sep 17 00:00:00 2001
From: 董国庆 <364620639@qq.com>
Date: 星期五, 20 六月 2025 16:03:12 +0800
Subject: [PATCH] 修改bug

---
 laboratory/src/utils/utils.js |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/laboratory/src/utils/utils.js b/laboratory/src/utils/utils.js
index a1019e4..25dc81a 100644
--- a/laboratory/src/utils/utils.js
+++ b/laboratory/src/utils/utils.js
@@ -1,3 +1,6 @@
+import axios from 'axios';
+import apiConfig from './baseurl';
+
 export const customRequest = (params) => {
   const { file, onSuccess, onError } = params;
   uploadObs(file)
@@ -7,4 +10,30 @@
     .catch((ret) => {
       onError();
     });
-};
\ No newline at end of file
+};
+
+export const customUploadRequest = ({ file, onSuccess, onError, action, headers }) => {
+  // 默认 action 为 apiConfig.imgUrl
+  const uploadUrl = action || apiConfig.imgUrl;
+  // 默认 headers 带上 Authorization
+  const uploadHeaders = {
+    Authorization: sessionStorage.getItem('token') || '',
+    ...headers
+  };
+  const formData = new FormData();
+  formData.append('file', file);
+
+  axios.post(uploadUrl, formData, { headers: uploadHeaders })
+    .then(res => {
+      onSuccess(res.data);
+    })
+    .catch(err => {
+      onError(err);
+    });
+};
+
+export function getFullUrl(url) {
+  if (!url) return '';
+  if (/^https?:\/\//.test(url)) return url;
+  return apiConfig.showImgUrl + url;
+}
\ No newline at end of file

--
Gitblit v1.7.1