feat(文档管理): 添加文档状态更新和向量生成功能

refactor(话术管理): 重构话术列表和编辑界面,调整API路径

fix(请求拦截器): 移除调试日志并优化错误处理

style(分页组件): 格式化代码并添加初始化标记

feat(知识库): 实现文档状态切换和向量生成功能
This commit is contained in:
2026-04-11 16:11:00 +08:00
parent c80f67d2ab
commit 4c91dd6fd5
8 changed files with 1199 additions and 563 deletions

View File

@@ -127,32 +127,37 @@
</div>
<div class="file-table" v-loading="fileLoading">
<el-table :data="fileList" style="width: 100%" row-key="id" border>
<el-table-column prop="Title" label="名称" min-width="200">
<el-table-column prop="title" label="名称" min-width="200">
<template #default="scope">
<span class="file-link" @click="onViewDocumentDetail(scope.row)" style="cursor: pointer; color: #409eff">{{
scope.row.Title
scope.row.title
}}</span>
</template>
</el-table-column>
<el-table-column prop="chunkCount" label="分块数" width="80" align="center" />
<el-table-column prop="status" label="状态" width="90" align="center">
<template #default="scope">
<el-tag :type="scope.row.status === 1 ? 'success' : 'info'" size="small">
{{ scope.row.status === 1 ? '正常' : '禁用' }}
</el-tag>
<el-switch
v-model="scope.row.statusEnabled"
inline-prompt
active-text=""
inactive-text=""
@change="onFileStatusChange(scope.row)"
/>
</template>
</el-table-column>
<el-table-column prop="vectorStatus" label="向量化" width="100" align="center">
<template #default="scope">
<el-tag :type="scope.row.vectorStatus === 'done' ? 'success' : 'warning'" size="small">
{{ scope.row.vectorStatus || '未处理' }}
<el-tag :type="scope.row.vectorStatus === 2 ? 'success' : 'warning'" size="small">
{{ scope.row.vectorStatus === 2 ? '已完成' : '未完成' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="createdAt" label="上传日期" width="180" />
<el-table-column label="动作" width="120" align="center">
<el-table-column label="动作" width="180" align="center">
<template #default="scope">
<el-button text size="small" @click="onPreviewFile(scope.row)">预览</el-button>
<el-button text size="small" type="primary" @click="onGenerateVector(scope.row)">生成向量</el-button>
<el-button text size="small" type="danger" @click="onDeleteFile(scope.row)">删除</el-button>
</template>
</el-table-column>
@@ -286,7 +291,7 @@ import { ElMessage, ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules, UploadFile } from 'element-plus';
import DocumentDetailDialog from './component/documentDetailDialog.vue';
import { listknowledges, createknowledge, updateknowledge, deleteknowledge } from '/@/api/knowledge/dataset';
import { listDocuments, uploadFile, createDocument, deleteDocument } from '/@/api/knowledge/document';
import { listDocuments, uploadFile, createDocument, deleteDocument, updateDocument, generateVector, getDocument } from '/@/api/knowledge/document';
// 数据集相关
const knowledgeLoading = ref(false);
@@ -497,7 +502,10 @@ const getFileList = async () => {
pageNum: 1,
pageSize: 100,
});
fileList.value = response.data?.list || [];
fileList.value = (response.data?.list || []).map((item: any) => ({
...item,
statusEnabled: item.status === 1,
}));
} catch (_error) {
ElMessage.error('获取文件列表失败');
} finally {
@@ -578,14 +586,47 @@ const onConfirmUpload = async () => {
};
// 文件状态变化
const _onFileStatusChange = (row: any) => {
ElMessage.success(row.enabled ? '已启用' : '已禁用');
const onFileStatusChange = async (row: any) => {
const newStatus = row.statusEnabled ? 1 : 0;
try {
// 调用后端API来更新文件状态
await updateDocument({
id: row.id,
status: newStatus,
});
ElMessage.success(row.statusEnabled ? '已启用' : '已禁用');
} catch (error) {
// 失败时恢复原状态
row.statusEnabled = !row.statusEnabled;
ElMessage.error('状态更新失败');
}
};
// 生成向量
const onGenerateVector = async (row: any) => {
try {
// 调用后端API来生成向量传递id和datasetId
await generateVector(row.id, currentknowledge.value.id);
ElMessage.success('生成向量任务已提交');
// 模拟更新状态
setTimeout(() => {
getFileList();
}, 1000);
} catch (error) {
ElMessage.error('生成向量失败');
}
};
// 查看文档详情
const onViewDocumentDetail = (row: any) => {
currentDocument.value = row;
showDocumentDetailDialog.value = true;
const onViewDocumentDetail = async (row: any) => {
try {
// 调用getDocument接口获取最新的文件详情
const response = await getDocument(row.id);
currentDocument.value = response.data;
showDocumentDetailDialog.value = true;
} catch (error) {
ElMessage.error('获取文件详情失败');
}
};
// 预览文件