文件上传下载修正
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
<template>
|
||||
<AdminLayout title="知识库管理" info="管理外部和内部知识库文档">
|
||||
<template #action>
|
||||
<el-button type="primary" @click="openUploadDialog">
|
||||
<el-icon><Upload /></el-icon>
|
||||
上传文档
|
||||
</el-button>
|
||||
<!-- 上传文档组件 -->
|
||||
<FileUpload
|
||||
ref="fileUploadRef"
|
||||
mode="dialog"
|
||||
:title="'上传文档到:' + currentKnowledgeName"
|
||||
button-text="上传文档"
|
||||
accept=".pdf,.doc,.docx,.txt,.md"
|
||||
:max-size="50 * 1024 * 1024"
|
||||
:max-count="10"
|
||||
:custom-upload="customKnowledgeUpload"
|
||||
@upload-error="handleUploadError"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<div class="knowledge-container">
|
||||
@@ -67,19 +75,6 @@
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
|
||||
<!-- 上传文档组件 -->
|
||||
<FileUpload
|
||||
ref="fileUploadRef"
|
||||
mode="dialog"
|
||||
:title="'上传文档到:' + currentKnowledgeName"
|
||||
button-text="上传文档"
|
||||
accept=".pdf,.doc,.docx,.txt,.md"
|
||||
:max-size="50 * 1024 * 1024"
|
||||
:max-count="10"
|
||||
:custom-upload="customKnowledgeUpload"
|
||||
@upload-error="handleUploadError"
|
||||
/>
|
||||
</AdminLayout>
|
||||
</template>
|
||||
|
||||
@@ -90,6 +85,7 @@ import { Upload, Search, Document, View, Download, Delete } from '@element-plus/
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { aiKnowledgeAPI } from 'shared/api/ai'
|
||||
import { FileUpload } from 'shared/components'
|
||||
import { FILE_DOWNLOAD_URL } from '@/config/index'
|
||||
import type { TbKnowledge } from 'shared/types'
|
||||
|
||||
// Tab 配置
|
||||
@@ -113,12 +109,11 @@ interface DocumentItem {
|
||||
name: string
|
||||
uploader: string
|
||||
uploadTime: string
|
||||
position: number
|
||||
dataSourceType: string
|
||||
wordCount: number
|
||||
hitCount: number
|
||||
indexingStatus: string
|
||||
enabled: boolean
|
||||
fileId?: string
|
||||
fileRootId?: string
|
||||
knowledgeId?: string
|
||||
difyFileId?: string
|
||||
version?: number
|
||||
}
|
||||
const documents = ref<DocumentItem[]>([])
|
||||
|
||||
@@ -185,18 +180,17 @@ const fetchDocuments = async (knowledgeId: string) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await aiKnowledgeAPI.getDocumentList(knowledgeId, 1, 100)
|
||||
if (result.success && result.data) {
|
||||
documents.value = (result.data.data || []).map((doc: any) => ({
|
||||
id: doc.id,
|
||||
name: doc.name,
|
||||
uploader: doc.created_by || '-',
|
||||
uploadTime: doc.created_at ? new Date(doc.created_at * 1000).toLocaleString() : '-',
|
||||
position: doc.position,
|
||||
dataSourceType: doc.data_source_type,
|
||||
wordCount: doc.word_count || 0,
|
||||
hitCount: doc.hit_count || 0,
|
||||
indexingStatus: doc.indexing_status,
|
||||
enabled: doc.enabled
|
||||
if (result.success && result.pageDomain) {
|
||||
documents.value = (result.pageDomain.dataList || []).map((file: any) => ({
|
||||
id: file.fileId,
|
||||
name: file.fileName || '-',
|
||||
uploader: file.creator || '-',
|
||||
uploadTime: file.createTime ? new Date(file.createTime).toLocaleString() : '-',
|
||||
fileId: file.fileId,
|
||||
fileRootId: file.fileRootId,
|
||||
knowledgeId: file.knowledgeId,
|
||||
difyFileId: file.difyFileId,
|
||||
version: file.version
|
||||
}))
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -226,12 +220,30 @@ watch(activeKnowledgeId, (newVal) => {
|
||||
if (newVal) fetchDocuments(newVal)
|
||||
})
|
||||
|
||||
const previewFile = (row: DocumentItem) => {
|
||||
ElMessage.info(`预览文件: ${row.name}`)
|
||||
const previewFile = async (row: DocumentItem) => {
|
||||
if (!row.fileId) {
|
||||
ElMessage.warning('文件信息不完整')
|
||||
return
|
||||
}
|
||||
// 使用 FILE_DOWNLOAD_URL 构建文件 URL 并在新窗口打开
|
||||
const fileUrl = `${FILE_DOWNLOAD_URL}${row.fileId}`
|
||||
window.open(fileUrl, '_blank')
|
||||
}
|
||||
|
||||
const downloadFile = (row: DocumentItem) => {
|
||||
ElMessage.success(`下载文件: ${row.name}`)
|
||||
if (!row.fileId) {
|
||||
ElMessage.warning('文件信息不完整')
|
||||
return
|
||||
}
|
||||
// 创建隐藏的下载链接并触发下载
|
||||
const fileUrl = `${FILE_DOWNLOAD_URL}${row.fileId}`
|
||||
const link = document.createElement('a')
|
||||
link.href = fileUrl
|
||||
link.download = row.name || 'file'
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
ElMessage.success('开始下载')
|
||||
}
|
||||
|
||||
const deleteFile = async (row: DocumentItem) => {
|
||||
@@ -291,15 +303,6 @@ const handleUploadError = (error: string) => {
|
||||
ElMessage.error(error)
|
||||
}
|
||||
|
||||
// 打开上传弹窗
|
||||
const openUploadDialog = () => {
|
||||
if (!activeKnowledgeId.value) {
|
||||
ElMessage.warning('请先选择一个知识库')
|
||||
return
|
||||
}
|
||||
fileUploadRef.value?.openDialog()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchKnowledges()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user