From ff5b4a4202405b26393c5f71999e43f3e2746499 Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期三, 08 四月 2026 15:13:12 +0800
Subject: [PATCH] feat(知识库): 添加批量操作和文件删除功能

---
 src/pages/cooperativeOffice/collaborativeApproval/knowledgeBase/detail.vue |   78 +++++++++++++++++++++++++++++---------
 1 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/src/pages/cooperativeOffice/collaborativeApproval/knowledgeBase/detail.vue b/src/pages/cooperativeOffice/collaborativeApproval/knowledgeBase/detail.vue
index 88af8c9..a8f708a 100644
--- a/src/pages/cooperativeOffice/collaborativeApproval/knowledgeBase/detail.vue
+++ b/src/pages/cooperativeOffice/collaborativeApproval/knowledgeBase/detail.vue
@@ -108,10 +108,10 @@
             <view class="upload-tip" v-if="!readonly">
               鏀寔鏂囨。锛坉oc, docx, xls, xlsx, pdf, txt锛夊拰鍥剧墖锛坖pg, jpeg, png, gif锛夋牸寮�
             </view>
-            <view class="file-list" v-if="form.commonFileList && form.commonFileList.length > 0">
-              <view v-for="(file, index) in form.commonFileList" :key="index" class="file-item">
+            <view class="file-list" v-if="form.files && form.files.length > 0">
+              <view v-for="(file, index) in form.files" :key="index" class="file-item">
                 <up-icon name="file-text" size="20" color="#667eea"></up-icon>
-                <text class="file-name" @click="previewFile(file)">{{ file.name || file.fileName }}</text>
+                <text class="file-name">{{ file.name || file.fileName }}</text>
                 <up-icon v-if="!readonly" name="close-circle-fill" size="18" color="#ff4d4f" @click="handleRemoveFile(index)"></up-icon>
               </view>
             </view>
@@ -172,9 +172,12 @@
   import {
     addKnowledgeBase,
     updateKnowledgeBase,
+    delKnowledgeBaseFile,
   } from "@/api/managementMeetings/knowledgeBase";
   import { userListNoPageByTenantId } from "@/api/system/user";
   import upload from "@/utils/upload";
+  import { getToken } from "@/utils/auth";
+  import config from "@/config";
 
   defineOptions({ name: "knowledge-base-detail" });
 
@@ -206,7 +209,7 @@
     creator: userStore.nickName || "",
     usageCount: 0,
     tempFileIds: [],
-    commonFileList: []
+    files: []
   });
 
   // 閫夋嫨鍣ㄧ姸鎬�
@@ -300,11 +303,11 @@
           if (!form.value.tempFileIds) form.value.tempFileIds = [];
           form.value.tempFileIds.push(res.data.tempId);
           
-          if (!form.value.commonFileList) form.value.commonFileList = [];
-          form.value.commonFileList.push({
-            id: res.data.tempId,
+          if (!form.value.files) form.value.files = [];
+          form.value.files.push({
+            tempId: res.data.tempId,
             name: item.name || '鏈懡鍚嶆枃浠�',
-            url: res.data.url
+            url: res.data.url || res.data.tempPath
           });
           
           showToast('涓婁紶鎴愬姛');
@@ -321,20 +324,48 @@
 
   const deleteFile = (event) => {
     const { index } = event;
-    form.value.commonFileList.splice(index, 1);
-    if (form.value.tempFileIds) {
-      form.value.tempFileIds.splice(index, 1);
-    }
+    handleRemoveFile(index);
   };
 
-  const handleRemoveFile = (index) => {
-    form.value.commonFileList.splice(index, 1);
-    if (form.value.tempFileIds) {
-      form.value.tempFileIds.splice(index, 1);
+  const handleRemoveFile = async (index) => {
+    const list = Array.isArray(form.value.files)
+      ? form.value.files
+      : [];
+    const file = list[index];
+    if (!file) return;
+
+    const fileId = file.id;
+    const tempId = file.tempId || file.tempFileId;
+    const isEditMode = detailType.value === 2;
+    const canDeleteRemote = isEditMode && !!fileId;
+
+    try {
+      if (canDeleteRemote) {
+        uni.showLoading({ title: "鍒犻櫎涓�...", mask: true });
+        const res = await delKnowledgeBaseFile([fileId]);
+        uni.hideLoading();
+        if (res.code !== 200) {
+          showToast(res.msg || "鍒犻櫎澶辫触");
+          return;
+        }
+      }
+
+      form.value.files.splice(index, 1);
+      if (form.value.tempFileIds) {
+        const idx = form.value.tempFileIds.findIndex(
+          v => String(v) === String(tempId || fileId)
+        );
+        if (idx > -1) form.value.tempFileIds.splice(idx, 1);
+      }
+    } catch (e) {
+      uni.hideLoading();
+      console.error("鍒犻櫎闄勪欢澶辫触:", e);
+      showToast("鍒犻櫎澶辫触");
     }
   };
 
   const previewFile = (file) => {
+    console.log("previewFile", file);
     if (file.url) {
       // 濡傛灉鏄浘鐗囷紝棰勮鍥剧墖
       const isImage = /\.(jpg|jpeg|png|gif)$/i.test(file.name || file.fileName || file.url);
@@ -345,7 +376,10 @@
       } else {
         // 鍏朵粬鏂囦欢灏濊瘯鎵撳紑
         uni.downloadFile({
-          url: file.url,
+          url: file.url.startsWith("http") ? file.url : (config.baseUrl + file.url),
+          header: {
+            Authorization: "Bearer " + getToken(),
+          },
           success: (res) => {
             if (res.statusCode === 200) {
               uni.openDocument({
@@ -401,8 +435,14 @@
           if (!knowledgeId.value || String(data.id) === String(knowledgeId.value)) {
             form.value = JSON.parse(JSON.stringify(data));
             // 鍏煎澶勭悊鏂囦欢鍒楄〃
-            if (form.value.commonFileList) {
-              form.value.tempFileIds = form.value.commonFileList.map(f => f.id || f.tempId);
+            if (form.value.files) {
+              const ids = (form.value.files || [])
+                .map(f => f?.tempId || f?.tempFileId || f?.id)
+                .filter(v => v !== undefined && v !== null && v !== "");
+              form.value.tempFileIds = ids;
+            }
+            if (!Array.isArray(form.value.files)) {
+              form.value.files = [];
             }
           }
         }

--
Gitblit v1.9.3