张诺
13 小时以前 231334ac73df257d0f2a2d59f3697273b769070d
src/views/collaborativeApproval/knowledgeBase/index.vue
@@ -145,6 +145,8 @@
            :on-error="handleUploadError"
            :on-success="handleUploadSuccess"
            :on-remove="handleRemove"
            :on-preview="handlePreview"
            :show-file-list="true"
          >
            <el-button type="primary">上传</el-button>
            <template #tip>
@@ -222,9 +224,10 @@
        <div class="detail-section" v-if="currentKnowledge.commonFileList && currentKnowledge.commonFileList.length > 0">
          <h4>附件材料</h4>
          <div class="file-list">
            <div v-for="file in currentKnowledge.commonFileList" :key="file.id" class="file-item" style="margin-bottom: 8px;">
              <el-icon><Document /></el-icon>
              <el-link type="primary" :href="file.url" target="_blank" style="margin-left: 8px;">{{ file.name }}</el-link>
            <div v-for="file in currentKnowledge.commonFileList" :key="file.id" class="file-item">
              <div class="file-info">
                <el-link :href="file.url" target="_blank" :download="file.name">{{ file.name }}</el-link>
              </div>
            </div>
          </div>
        </div>
@@ -260,13 +263,12 @@
</template>
<script setup>
import { Search, Document } from "@element-plus/icons-vue";
import { Search } from "@element-plus/icons-vue";
import { onMounted, ref, reactive, toRefs, getCurrentInstance, computed, watch } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import PIMTable from "@/components/PIMTable/PIMTable.vue";
import FormDialog from '@/components/Dialog/FormDialog.vue';
import { listKnowledgeBase, delKnowledgeBase,addKnowledgeBase,updateKnowledgeBase } from "@/api/collaborativeApproval/knowledgeBase.js";
import { delLedgerFile } from "@/api/salesManagement/salesLedger.js";
import { listKnowledgeBase, delKnowledgeBase,addKnowledgeBase,updateKnowledgeBase, delKnowledgeBaseFile } from "@/api/collaborativeApproval/knowledgeBase.js";
import useUserStore from '@/store/modules/user';
import { userListNoPageByTenantId } from '@/api/system/user.js';
import { getToken } from "@/utils/auth";
@@ -520,7 +522,7 @@
    });
  } else if (type === "edit" && row) {
    dialogTitle.value = "编辑知识";
    fileList.value = row.commonFileList || [];
    fileList.value = row.files || [];
    Object.assign(form.value, {
      id: row.id,
      title: row.title,
@@ -532,7 +534,8 @@
      keyPoints: row.keyPoints,
      creator: row.creator,
      usageCount: row.usageCount,
      files: row.commonFileList || []
      files: row.files || [],
    });
  }
  dialogVisible.value = true;
@@ -681,14 +684,40 @@
  }
}
// 移除文件
function handleRemove(file) {
  if (dialogType.value === "edit") {
    let ids = [];
    ids.push(file.id);
    delLedgerFile(ids).then((res) => {
      proxy.$modal.msgSuccess("删除成功");
function handleRemove(file, fileList) {
  // 如果是编辑模式且文件有id,调用API删除
  if (dialogType.value === "edit" && file.id) {
    delKnowledgeBaseFile([file.id]).then((res) => {
      if (res.code === 200) {
        proxy.$modal.msgSuccess("删除成功");
        // 从form.value.files中移除
        const index = form.value.files.findIndex(f => f.id === file.id);
        if (index > -1) {
          form.value.files.splice(index, 1);
        }
      } else {
        proxy.$modal.msgError(res.msg || "删除失败");
        // 如果删除失败,重新添加回文件列表
        fileList.push(file);
      }
    }).catch((error) => {
      proxy.$modal.msgError("删除失败");
      // 如果删除失败,重新添加回文件列表
      fileList.push(file);
    });
  } else {
    // 新上传的文件,直接从form.value.files中移除
    const index = form.value.files.findIndex(f => f.name === file.name && f.url === file.url);
    if (index > -1) {
      form.value.files.splice(index, 1);
    }
  }
}
// 文件预览/下载
function handlePreview(file) {
  // 创建一个隐藏的a标签来触发下载
  proxy.$download.name(file.url);
}
// 提交知识表单
@@ -803,12 +832,12 @@
}
.detail-content {
  background: #f8f9fa;
  padding: 16px;
  border-radius: 6px;
  line-height: 1.6;
  color: #606266;
  white-space: pre-wrap;
}
.detail-section {
  margin-top: 24px;
}
.key-points {