From 679ede97899d73d5a7619091b6ee3b7c881d1627 Mon Sep 17 00:00:00 2001
From: 董国庆 <364620639@qq.com>
Date: 星期六, 28 六月 2025 10:04:27 +0800
Subject: [PATCH] 修改bug

---
 laboratory/src/views/dataManagement/originalRecordTest/components/addDialog.vue |   89 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 68 insertions(+), 21 deletions(-)

diff --git a/laboratory/src/views/dataManagement/originalRecordTest/components/addDialog.vue b/laboratory/src/views/dataManagement/originalRecordTest/components/addDialog.vue
index 65d10cd..764b8be 100644
--- a/laboratory/src/views/dataManagement/originalRecordTest/components/addDialog.vue
+++ b/laboratory/src/views/dataManagement/originalRecordTest/components/addDialog.vue
@@ -59,7 +59,8 @@
                     :file-list="photoList"
                     :auto-upload="false"
                     list-type="picture-card"
-                    :on-change="handlePhotoChange"
+                    :http-request="handlePhotoUpload"
+                    :on-remove="handlePhotoRemove"
                   >
                     <i class="el-icon-plus"></i>
                   </el-upload>
@@ -79,7 +80,7 @@
                     action="#"
                     :file-list="spectrumList"
                     :auto-upload="false"
-                    :on-change="handleSpectrumChange"
+                    :http-request="handleSpectrumUpload"
                     :on-remove="handleSpectrumRemove"
                   >
                     <el-button type="primary">
@@ -102,6 +103,7 @@
 </template>
 
 <script>
+import { customUploadRequest, getFullUrl } from '@/utils/utils'
 export default {
   name: "AddDialog",
   props: {
@@ -266,28 +268,73 @@
         }
       });
     },
-    handlePhotoChange(file, fileList) {
-      // 模拟上传成功
-      const mockFile = {
-        name: file.name || '测试图片.jpg',
-        url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
-        status: 'success'
-      };
-      this.photoList = [...this.photoList, mockFile];
-      this.$refs.form.validateField('photos');
+    // 真实图片上传
+    handlePhotoUpload(options) {
+      const { file, onSuccess, onError } = options;
+      customUploadRequest({
+        file,
+        onSuccess: (res) => {
+          if (res.code === 200) {
+            const fileObj = {
+              name: file.name,
+              url: getFullUrl(res.msg || res.data || ''),
+              status: 'success'
+            };
+            this.photoList.push(fileObj);
+            this.$refs.form.validateField('photos');
+            this.$message.success('图片上传成功');
+            onSuccess(res);
+          } else {
+            this.$message.error(res.message || '图片上传失败');
+            onError();
+          }
+        },
+        onError: (err) => {
+          this.$message.error('图片上传失败');
+          onError(err);
+        }
+      });
     },
-    handleSpectrumChange(file, fileList) {
-      // 模拟上传成功
-      const mockFile = {
-        name: file.name || '测试图谱.pdf',
-        url: 'https://example.com/test.pdf',
-        status: 'success'
-      };
-      this.spectrumList = [...this.spectrumList, mockFile];
-      this.$refs.form.validateField('spectrums');
+    handlePhotoRemove(file) {
+      const index = this.photoList.findIndex(item => item.name === file.name);
+      if (index !== -1) {
+        this.photoList.splice(index, 1);
+        this.$refs.form.validateField('photos');
+      }
+    },
+    // 真实图谱上传
+    handleSpectrumUpload(options) {
+      const { file, onSuccess, onError } = options;
+      customUploadRequest({
+        file,
+        onSuccess: (res) => {
+          if (res.code === 200) {
+            const fileObj = {
+              name: file.name,
+              url: getFullUrl(res.msg || res.data || ''),
+              status: 'success'
+            };
+            this.spectrumList.push(fileObj);
+            this.$refs.form.validateField('spectrums');
+            this.$message.success('文件上传成功');
+            onSuccess(res);
+          } else {
+            this.$message.error(res.message || '文件上传失败');
+            onError();
+          }
+        },
+        onError: (err) => {
+          this.$message.error('文件上传失败');
+          onError(err);
+        }
+      });
     },
     handleSpectrumRemove(file) {
-      // 处理文件移除逻辑
+      const index = this.spectrumList.findIndex(item => item.name === file.name);
+      if (index !== -1) {
+        this.spectrumList.splice(index, 1);
+        this.$refs.form.validateField('spectrums');
+      }
     },
     // iPad 相关方法
     handleIPadPhoto() {

--
Gitblit v1.7.1