更新开发环境API服务地址至192.168.3.30,调整ESLint配置以忽略特定变量,添加数据集和文档相关的创建与更新接口,优化错误处理和用户反馈,移除模拟数据,增强代码可读性。
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
|
||||
<div
|
||||
class="chunk-item"
|
||||
v-for="(chunk, index) in filteredChunks"
|
||||
v-for="chunk in filteredChunks"
|
||||
:key="chunk.id"
|
||||
>
|
||||
<div class="chunk-checkbox">
|
||||
@@ -115,6 +115,7 @@ export default {
|
||||
import { ref, reactive, computed, onMounted } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { getDocument, listDocumentChunks, previewDocument } from '/@/api/knowledge/document';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@@ -150,8 +151,8 @@ const selectAll = ref(false);
|
||||
// 过滤后的切片列表
|
||||
const filteredChunks = computed(() => {
|
||||
if (!chunkSearch.value) return chunkList.value;
|
||||
return chunkList.value.filter(chunk =>
|
||||
chunk.content.toLowerCase().includes(chunkSearch.value.toLowerCase())
|
||||
return chunkList.value.filter((chunk) =>
|
||||
(chunk.content || '').toLowerCase().includes(chunkSearch.value.toLowerCase())
|
||||
);
|
||||
});
|
||||
|
||||
@@ -171,14 +172,14 @@ const truncateText = (text: string, maxLength: number) => {
|
||||
|
||||
// 返回知识库列表
|
||||
const onBackToKnowledge = () => {
|
||||
router.push('/knowledge');
|
||||
router.push('/knowledge/dataset');
|
||||
};
|
||||
|
||||
// 返回数据集详情
|
||||
const onBackToDataset = () => {
|
||||
router.push({
|
||||
path: '/knowledge',
|
||||
query: { datasetId: datasetId.value, datasetName: datasetName.value }
|
||||
path: '/knowledge/document',
|
||||
query: { datasetId: datasetId.value, datasetName: datasetName.value },
|
||||
});
|
||||
};
|
||||
|
||||
@@ -186,17 +187,19 @@ const onBackToDataset = () => {
|
||||
const getDocumentDetail = async () => {
|
||||
contentLoading.value = true;
|
||||
try {
|
||||
// 模拟数据
|
||||
documentInfo.id = documentId.value;
|
||||
documentInfo.name = route.query.docName as string || '456_product(1).txt';
|
||||
documentInfo.fileType = 'txt';
|
||||
documentInfo.fileSize = 10;
|
||||
documentInfo.createdAt = '22/01/2026 00:53:32';
|
||||
|
||||
// 模拟文档内容
|
||||
documentContent.value = '<p>123</p>';
|
||||
} catch (error) {
|
||||
console.error('获取文档详情失败:', error);
|
||||
const [detailRes, contentRes] = await Promise.all([getDocument(documentId.value), previewDocument(documentId.value)]);
|
||||
const detail = detailRes.data || {};
|
||||
documentInfo.id = detail.id || documentId.value;
|
||||
documentInfo.name = detail.name || (route.query.docName as string) || '';
|
||||
documentInfo.fileType = detail.fileType || '';
|
||||
documentInfo.fileSize = detail.fileSize || 0;
|
||||
documentInfo.createdAt = detail.createdAt || '';
|
||||
const contentData = contentRes.data;
|
||||
documentContent.value =
|
||||
typeof contentData === 'string' ? contentData : contentData?.content || contentData?.text || '';
|
||||
} catch (_error) {
|
||||
ElMessage.error('获取文档详情失败');
|
||||
documentContent.value = '';
|
||||
} finally {
|
||||
contentLoading.value = false;
|
||||
}
|
||||
@@ -206,18 +209,21 @@ const getDocumentDetail = async () => {
|
||||
const getChunkList = async () => {
|
||||
chunkLoading.value = true;
|
||||
try {
|
||||
// 模拟数据
|
||||
chunkList.value = [
|
||||
{
|
||||
id: '1',
|
||||
content: '123',
|
||||
enabled: true,
|
||||
selected: false,
|
||||
},
|
||||
];
|
||||
chunkTotal.value = 1;
|
||||
} catch (error) {
|
||||
console.error('获取切片列表失败:', error);
|
||||
const res: any = await listDocumentChunks({
|
||||
documentId: documentId.value,
|
||||
pageNum: chunkPage.value,
|
||||
pageSize: chunkPageSize.value,
|
||||
});
|
||||
chunkList.value = (res.data?.list || []).map((item: any) => ({
|
||||
...item,
|
||||
enabled: true,
|
||||
selected: false,
|
||||
}));
|
||||
chunkTotal.value = res.data?.total || 0;
|
||||
} catch (_error) {
|
||||
chunkList.value = [];
|
||||
chunkTotal.value = 0;
|
||||
ElMessage.error('获取切片列表失败');
|
||||
} finally {
|
||||
chunkLoading.value = false;
|
||||
}
|
||||
@@ -225,14 +231,14 @@ const getChunkList = async () => {
|
||||
|
||||
// 全选变化
|
||||
const onSelectAllChange = (val: boolean) => {
|
||||
chunkList.value.forEach(chunk => {
|
||||
chunkList.value.forEach((chunk) => {
|
||||
chunk.selected = val;
|
||||
});
|
||||
};
|
||||
|
||||
// 切片状态变化
|
||||
const onChunkStatusChange = (chunk: any) => {
|
||||
ElMessage.success(chunk.enabled ? '已启用' : '已禁用');
|
||||
const onChunkStatusChange = (_chunk: any) => {
|
||||
ElMessage.info('切片启停功能暂未开放');
|
||||
};
|
||||
|
||||
// 添加切片
|
||||
@@ -242,10 +248,14 @@ const onAddChunk = () => {
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
datasetId.value = route.query.datasetId as string || '';
|
||||
datasetName.value = route.query.datasetName as string || 'dataset_tenant_1';
|
||||
documentId.value = route.query.docId as string || '';
|
||||
|
||||
datasetId.value = (route.query.datasetId as string) || '';
|
||||
datasetName.value = (route.query.datasetName as string) || '';
|
||||
documentId.value = (route.query.docId as string) || '';
|
||||
if (!documentId.value) {
|
||||
ElMessage.warning('缺少文档ID,无法查看详情');
|
||||
onBackToDataset();
|
||||
return;
|
||||
}
|
||||
getDocumentDetail();
|
||||
getChunkList();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user