知识库历史文件
This commit is contained in:
@@ -50,16 +50,22 @@
|
||||
</el-table-column>
|
||||
<el-table-column prop="uploader" label="上传人员" width="120" />
|
||||
<el-table-column prop="uploadTime" label="上传时间" width="180" />
|
||||
<el-table-column prop="wordCount" label="字数" width="100" />
|
||||
<el-table-column label="状态" width="100">
|
||||
<!-- <el-table-column prop="wordCount" label="字数" width="100" /> -->
|
||||
<!-- <el-table-column label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.enabled ? 'success' : 'info'" size="small">
|
||||
{{ row.enabled ? '已启用' : '已禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="180" align="center">
|
||||
</el-table-column> -->
|
||||
<el-table-column label="操作" width="280" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link size="small" @click="openSegmentDialog(row)">
|
||||
<el-icon><Edit /></el-icon>编辑
|
||||
</el-button>
|
||||
<el-button type="warning" link size="small" @click="openHistoryDialog(row)">
|
||||
<el-icon><Clock /></el-icon>历史
|
||||
</el-button>
|
||||
<el-button type="primary" link size="small" @click="previewFile(row)">
|
||||
<el-icon><View /></el-icon>预览
|
||||
</el-button>
|
||||
@@ -75,16 +81,35 @@
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
<!-- 分段编辑弹窗(包含版本更新功能) -->
|
||||
<DocumentSegment
|
||||
v-model="showSegmentDialog"
|
||||
:dataset-id="currentDatasetId"
|
||||
:document-id="currentDifyDocId"
|
||||
:knowledge-id="currentKnowledgeId"
|
||||
:file-root-id="currentFileRootId"
|
||||
@file-updated="handleFileUpdated"
|
||||
/>
|
||||
|
||||
<!-- 历史版本弹窗 -->
|
||||
<FileHistory
|
||||
v-model="showHistoryDialog"
|
||||
:data="historyList"
|
||||
:loading="historyLoading"
|
||||
@preview="previewHistoryFile"
|
||||
@download="downloadHistoryFile"
|
||||
/>
|
||||
</AdminLayout>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, watch } from 'vue'
|
||||
import AdminLayout from '@/views/admin/AdminLayout.vue'
|
||||
import { Upload, Search, Document, View, Download, Delete } from '@element-plus/icons-vue'
|
||||
import { Upload, Search, FileText as Document, Eye as View, Download, Trash2 as Delete, Pencil as Edit, Clock } from 'lucide-vue-next'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { aiKnowledgeAPI } from 'shared/api/ai'
|
||||
import { FileUpload } from 'shared/components'
|
||||
import { FileUpload, FileHistory } from 'shared/components'
|
||||
import DocumentSegment from 'shared/components/ai/knowledge/DocumentSegment.vue'
|
||||
import { FILE_DOWNLOAD_URL } from '@/config/index'
|
||||
import type { TbKnowledge } from 'shared/types'
|
||||
|
||||
@@ -184,7 +209,7 @@ const fetchDocuments = async (knowledgeId: string) => {
|
||||
documents.value = (result.pageDomain.dataList || []).map((file: any) => ({
|
||||
id: file.fileId,
|
||||
name: file.fileName || '-',
|
||||
uploader: file.creator || '-',
|
||||
uploader: file.uploaderName || '-',
|
||||
uploadTime: file.createTime ? new Date(file.createTime).toLocaleString() : '-',
|
||||
fileId: file.fileId,
|
||||
fileRootId: file.fileRootId,
|
||||
@@ -303,6 +328,89 @@ const handleUploadError = (error: string) => {
|
||||
ElMessage.error(error)
|
||||
}
|
||||
|
||||
// ====================== 分段编辑功能 ======================
|
||||
const showSegmentDialog = ref(false)
|
||||
const currentDatasetId = ref('')
|
||||
const currentDifyDocId = ref('')
|
||||
const currentKnowledgeId = ref('')
|
||||
const currentFileRootId = ref('')
|
||||
|
||||
const openSegmentDialog = (row: DocumentItem) => {
|
||||
if (!row.difyFileId) {
|
||||
ElMessage.warning('该文件暂无分段信息')
|
||||
return
|
||||
}
|
||||
// 获取当前知识库的 difyDatasetId
|
||||
const kb = knowledges.value.find((k: TbKnowledge) => k.knowledgeId === activeKnowledgeId.value)
|
||||
if (!kb?.difyDatasetId) {
|
||||
ElMessage.warning('知识库信息不完整')
|
||||
return
|
||||
}
|
||||
currentDatasetId.value = kb.difyDatasetId
|
||||
currentDifyDocId.value = row.difyFileId
|
||||
currentKnowledgeId.value = row.knowledgeId || ''
|
||||
currentFileRootId.value = row.fileRootId || ''
|
||||
showSegmentDialog.value = true
|
||||
}
|
||||
|
||||
// 文件更新后刷新列表
|
||||
const handleFileUpdated = () => {
|
||||
fetchDocuments(activeKnowledgeId.value)
|
||||
}
|
||||
|
||||
// ====================== 历史版本功能 ======================
|
||||
const showHistoryDialog = ref(false)
|
||||
const historyLoading = ref(false)
|
||||
const historyList = ref<any[]>([])
|
||||
|
||||
const openHistoryDialog = async (row: DocumentItem) => {
|
||||
if (!row.fileRootId) {
|
||||
ElMessage.warning('文件信息不完整')
|
||||
return
|
||||
}
|
||||
showHistoryDialog.value = true
|
||||
historyLoading.value = true
|
||||
try {
|
||||
const result = await aiKnowledgeAPI.getFileHistory(row.fileRootId)
|
||||
console.log('历史版本响应:', result)
|
||||
if (result.success) {
|
||||
// 兼容 data 和 dataList 两种返回格式
|
||||
historyList.value = result.data || result.dataList || []
|
||||
} else {
|
||||
ElMessage.error(result.message || '获取历史版本失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取历史版本失败:', error)
|
||||
ElMessage.error('获取历史版本失败')
|
||||
} finally {
|
||||
historyLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const previewHistoryFile = (row: any) => {
|
||||
if (!row.fileId) {
|
||||
ElMessage.warning('文件信息不完整')
|
||||
return
|
||||
}
|
||||
const fileUrl = `${FILE_DOWNLOAD_URL}${row.fileId}`
|
||||
window.open(fileUrl, '_blank')
|
||||
}
|
||||
|
||||
const downloadHistoryFile = (row: any) => {
|
||||
if (!row.fileId) {
|
||||
ElMessage.warning('文件信息不完整')
|
||||
return
|
||||
}
|
||||
const fileUrl = `${FILE_DOWNLOAD_URL}${row.fileId}`
|
||||
const link = document.createElement('a')
|
||||
link.href = fileUrl
|
||||
link.download = row.fileName || 'file'
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
ElMessage.success('开始下载')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchKnowledges()
|
||||
})
|
||||
@@ -310,16 +418,4 @@ onMounted(() => {
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import url("./KnowLedgeView.scss");
|
||||
|
||||
.knowledge-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.tab-desc {
|
||||
color: #909399;
|
||||
font-size: 13px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user