From 39bc5ec7aaaa414415734412e4da2aa18ec5a81f Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期三, 16 九月 2026 10:13:00 +0800
Subject: [PATCH] fix: 修改文件上传功能,调整接口调用和数据处理逻辑以支持多文件上传

---
 src/views/personnelManagement/contractManagement/filesDia.vue |  101 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 60 insertions(+), 41 deletions(-)

diff --git a/src/views/personnelManagement/contractManagement/filesDia.vue b/src/views/personnelManagement/contractManagement/filesDia.vue
index 02f9cef..7c0bbf1 100644
--- a/src/views/personnelManagement/contractManagement/filesDia.vue
+++ b/src/views/personnelManagement/contractManagement/filesDia.vue
@@ -13,7 +13,7 @@
             :action="uploadUrl"
             :on-success="handleUploadSuccess"
             :on-error="handleUploadError"
-            name="file"
+            name="files"
             :show-file-list="false"
             :headers="headers"
             style="display: inline;margin-right: 10px"
@@ -23,16 +23,15 @@
         <el-button type="danger" plain @click="handleDelete">鍒犻櫎</el-button>
       </div>
       <PIMTable
-          rowKey="id"
+          rowKey="storageAttachmentId"
           :column="tableColumn"
           :tableData="tableData"
+          :page="page"
           :tableLoading="tableLoading"
           :isSelection="true"
-          :page="page"
           @selection-change="handleSelectionChange"
-          height="500"
           @pagination="paginationSearch"
-          :total="page.total"
+          height="500"
       >
       </PIMTable>
       <template #footer>
@@ -47,22 +46,20 @@
 
 <script setup>
 import {ref} from "vue";
+import filePreview from '@/components/filePreview/index.vue'
 import {ElMessageBox} from "element-plus";
 import {getToken} from "@/utils/auth.js";
-import filePreview from '@/components/filePreview/index.vue'
 import {
-  fileAdd,
-  fileDel,
-  fileListPage
-} from "@/api/financialManagement/revenueManagement.js";
-import Pagination from "@/components/PIMTable/Pagination.vue";
+  createAttachment,
+  deleteAttachment,
+  attachmentList
+} from "@/api/basicData/storageAttachment.js";
 const { proxy } = getCurrentInstance()
 const emit = defineEmits(['close'])
 
 const dialogFormVisible = ref(false);
 const currentId = ref('')
 const selectedRows = ref([]);
-const filePreviewRef = ref()
 const tableColumn = ref([
   {
     label: "鏂囦欢鍚嶇О",
@@ -91,35 +88,40 @@
   },
 ]);
 const page = reactive({
-	current: 1,
-	size: 100,
+  current: 1,
+  size: 100,
+  total: 0,
 });
-const total = ref(0);
 const tableData = ref([]);
 const fileList = ref([]);
 const tableLoading = ref(false);
-const accountType = ref('')
+const filePreviewRef = ref()
 const headers = ref({
   Authorization: "Bearer " + getToken(),
 });
-const uploadUrl = ref(import.meta.env.VITE_APP_BASE_API + "/file/upload"); // 涓婁紶鐨勫浘鐗囨湇鍔″櫒鍦板潃
+const uploadUrl = ref(import.meta.env.VITE_APP_BASE_API + "/common/upload"); // 涓婁紶鐨勬湇鍔″櫒鍦板潃
 
 // 鎵撳紑寮规
-const openDialog = (row,type) => {
-  accountType.value = type;
+const openDialog = (row) => {
   dialogFormVisible.value = true;
   currentId.value = row.id;
   getList()
 }
 const paginationSearch = (obj) => {
-	page.current = obj.page;
-	page.size = obj.limit;
-	getList();
+  page.current = obj.page;
+  page.size = obj.limit;
+  getList();
 };
 const getList = () => {
-  fileListPage({accountId: currentId.value,accountType:accountType.value, ...page}).then(res => {
-    tableData.value = res.data.records;
-    page.total = res.data.total;
+  tableLoading.value = true;
+  attachmentList({recordId: currentId.value, recordType: 'staff_contract'}).then(res => {
+    tableData.value = (res.data || []).map(item => ({
+      ...item,
+      name: item.originalFilename || item.name
+    }));
+    page.total = res.data ? res.data.length : 0;
+  }).finally(() => {
+    tableLoading.value = false;
   })
 }
 // 琛ㄦ牸閫夋嫨鏁版嵁
@@ -132,25 +134,42 @@
   dialogFormVisible.value = false;
   emit('close')
 };
+let pendingFiles = [];
+let uploadTimer = null;
+
 // 涓婁紶鎴愬姛澶勭悊
 function handleUploadSuccess(res, file) {
   // 濡傛灉涓婁紶鎴愬姛
-  if (res.code == 200) {
-    const fileRow = {}
-    fileRow.name = res.data.originalName
-    fileRow.url = res.data.tempPath
-    uploadFile(fileRow)
+  if (res.code == 200 && res.data && res.data.length > 0) {
+    const newFiles = res.data.map(item => ({
+      ...item,
+      name: item.originalFilename || item.name
+    }));
+
+    pendingFiles = [...pendingFiles, ...newFiles];
+
+    // 闃叉姈澶勭悊锛岄伩鍏嶅鏂囦欢鍚屾椂涓婁紶瀵艰嚧鍒楄〃琚鐩�
+    if (uploadTimer) clearTimeout(uploadTimer);
+    uploadTimer = setTimeout(() => {
+      const mergedFiles = [...(tableData.value || []), ...pendingFiles];
+      const storageAttachmentDTO = {
+        recordType: 'staff_contract',
+        recordId: currentId.value,
+        application: "file",
+        storageBlobDTOs: mergedFiles
+      };
+      createAttachment(storageAttachmentDTO).then(r => {
+        proxy.$modal.msgSuccess("鏂囦欢涓婁紶鎴愬姛");
+        getList()
+      }).catch(() => {
+        proxy.$modal.msgError("鏂囦欢涓婁紶澶辫触");
+      }).finally(() => {
+        pendingFiles = []; // 閲嶇疆
+      });
+    }, 500);
   } else {
     proxy.$modal.msgError("鏂囦欢涓婁紶澶辫触");
   }
-}
-function uploadFile(file) {
-  file.accountId = currentId.value;
-  file.accountType = accountType.value;
-  fileAdd(file).then(res => {
-    proxy.$modal.msgSuccess("鏂囦欢涓婁紶鎴愬姛");
-    getList()
-  })
 }
 // 涓婁紶澶辫触澶勭悊
 function handleUploadError() {
@@ -164,7 +183,7 @@
 const handleDelete = () => {
   let ids = [];
   if (selectedRows.value.length > 0) {
-    ids = selectedRows.value.map((item) => item.id);
+    ids = selectedRows.value.map((item) => item.storageAttachmentId);
   } else {
     proxy.$modal.msgWarning("璇烽�夋嫨鏁版嵁");
     return;
@@ -174,7 +193,7 @@
     cancelButtonText: "鍙栨秷",
     type: "warning",
   }).then(() => {
-    fileDel(ids).then((res) => {
+    deleteAttachment(ids).then((res) => {
       proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛");
       getList();
     });
@@ -194,4 +213,4 @@
 
 <style scoped>
 
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.9.3