Forráskód Böngészése

refactor: 修改文件上传逻辑,重命名上传API为addImageApi,更新上传参数以支持不同类型的附件路径

laiqi 5 hónapja
szülő
commit
3dbb0cedce
1 módosított fájl, 9 hozzáadás és 5 törlés
  1. 9 5
      apps/web-ele/src/views/order-manage/detail.vue

+ 9 - 5
apps/web-ele/src/views/order-manage/detail.vue

@@ -19,7 +19,7 @@ import {
 
 import { getDictListApi } from '#/api/dict';
 import {
-  addAttachmentApi,
+  addImageApi,
   deleteAttachmentApi,
   getAttachmentListApi,
 } from '#/api/file';
@@ -256,8 +256,7 @@ const beforeUpload = (file: File) => {
 };
 
 // 处理文件上传
-const handleFileUpload = async (options: any) => {
-  const { file } = options;
+const handleFileUpload = async (file: any, _fileList: any[]) => {
   uploadLoading.value = true;
 
   try {
@@ -304,35 +303,40 @@ const handleFileUpload = async (options: any) => {
     }
 
     const formData = new FormData();
-    formData.append('file', file);
+    formData.append('file', file.raw);
 
     // 根据上传类型设置不同的参数
     let attlsh = '';
     let attmodel = '';
+    let attpath = '';
 
     switch (currentUploadType.value) {
       case 'buyer': {
         attlsh = coupon2sid.value;
         attmodel = 'coupon_buyer';
+        attpath = '/coupon_buyer/';
         break;
       }
       case 'certificate': {
         attlsh = coupon2sid.value;
         attmodel = 'coupon_identity';
+        attpath = '/coupon_identity/';
         break;
       }
       case 'invoice': {
         attlsh = data.value.row.ordersid;
         attmodel = 'coupon_invoice';
+        attpath = '/coupon_invoice/';
         break;
       }
     }
 
     formData.append('attlsh', attlsh);
     formData.append('attmodel', attmodel);
+    formData.append('attpath', attpath);
 
     // 调用上传API
-    await addAttachmentApi(formData);
+    await addImageApi(formData);
 
     ElMessage.success('上传成功!');
     uploadDialogVisible.value = false;