diff --git a/chat-client/src/api/Segment.ts b/chat-client/src/api/Segment.ts index 1eb1fa2..be0ec6c 100644 --- a/chat-client/src/api/Segment.ts +++ b/chat-client/src/api/Segment.ts @@ -1,6 +1,6 @@ import request from '@/utils/request' -export function getSegmentList(params: { datasetId: string; documentId: string }) { +export function getSegmentList(params: { datasetId: string; documentId: string; page: number; pageSize: number }) { return request({ url: '/brichat-service/documentSegment/selectSegments', method: 'get', diff --git a/chat-client/src/views/datasets/components/DocumentList.vue b/chat-client/src/views/datasets/components/DocumentList.vue index d4341dc..84d909a 100644 --- a/chat-client/src/views/datasets/components/DocumentList.vue +++ b/chat-client/src/views/datasets/components/DocumentList.vue @@ -88,7 +88,6 @@ :header-row-style="{ height: '50px' }" @selection-change="handleSelectionChange" @row-dblclick="handleRowDoubleClick" - @sort-change="handleSortChange" > - + -- - - + + {{ formatFileSize(row.charCount) }} -- - + @@ -167,15 +166,6 @@ > {{t('vabI18n.knowledge.document.buttons.download')}} - - 替换 - @@ -244,44 +234,7 @@ @success="handleUploadSuccess" /> - - - - - - 将要替换的文件: - - - - {{ replaceTargetFile.fileName }} - - 大小:{{ formatFileSize(replaceTargetFile.charCount) }} - 创建时间:{{ replaceTargetFile.createDate }} - - - - - - - - + - + 分段数据 分段{{segment.position}}: {{segment.content}} + + 暂无分段数据 @@ -351,6 +310,23 @@ + + + + 分段{{previewSegment.position}}: + {{previewSegment.content}} + + + + (null) // 重命名相关 const renameDialogVisible = ref(false) @@ -578,6 +557,7 @@ y: 0 // 面包屑导航相关 const currentParentId = ref(undefined) const breadcrumbPath = ref>([]) +const isScroll = ref(true) // 面包屑导航项接口 interface BreadcrumbItem { @@ -597,8 +577,6 @@ const handleClose = () => { onUnmounted(() => { // 清理右键菜单事件监听器 document.removeEventListener('click', hideContextMenu) -// 停止自动刷新定时器 -stopAutoRefresh() }) const getFileTypeIcon = (fileType: string) => { @@ -680,12 +658,6 @@ size: 20, total: 0 }) -// 排序数据 -const sortConfig = reactive({ -orderBy: 'name', -orderDirection: 'ASC' -}) - // 文件列表数据 const fileList = ref([]) @@ -857,12 +829,6 @@ const triggerFileInput = () => { uploadDialogVisible.value = true } -// 文件替换处理 - 从行操作触发 -const handleFileReplaceFromRow = (row: FileItem) => { - replaceTargetFile.value = row - replaceDialogVisible.value = true -} - const indexMethod = (index: number) => { return (pagination.current - 1) * pagination.size + index + 1 } @@ -873,22 +839,9 @@ return (pagination.current - 1) * pagination.size + index + 1 const handleUploadSuccess = async () => { uploadDialogVisible.value = false await fetchDocuments() -// ElNotification({ -// title: t('vabI18n.knowledge.document.messages.uploadSuccess'), -// message: t('vabI18n.knowledge.document.messages.uploadSuccessEnd'), -// type: 'success' -// }) -} - -// 处理文件替换成功回调 -const handleReplaceSuccess = async () => { -replaceDialogVisible.value = false -replaceTargetFile.value = null -selectedRows.value = [] // 清空选择 -await fetchDocuments() ElNotification({ - title: '替换成功', - message: '文件替换成功', + title: t('vabI18n.knowledge.document.messages.uploadSuccess'), + message: t('vabI18n.knowledge.document.messages.uploadSuccessEnd'), type: 'success' }) } @@ -990,12 +943,17 @@ const handlePreview = async (row: FileItem) => { console.log("previewFileUrl (from API)", previewFileUrl.value) } } + segmentdocId.value = row.difyDocId const resp = await getSegmentList({ datasetId:datasetId.value, - documentId: row.difyDocId + documentId: row.difyDocId, + page: 1, + pageSize: 10 }) - if (resp.data?.length) { - segmentList.value = resp.data + console.log("resp.data",resp) + console.log(segmentdocId) + if (resp.data.list?.length) { + segmentList.value = resp.data.list } } catch (error) { ElNotification({ @@ -1013,28 +971,6 @@ const handlePreview = async (row: FileItem) => { // 在script setup部分添加loading状态 const tableLoading = ref(false) -// 定时器相关 -const refreshTimer = ref(null) - -// 启动定时器 -const startAutoRefresh = () => { - stopAutoRefresh() // 先清除可能存在的定时器 - refreshTimer.value = setInterval(() => { - // 只有在非加载状态下才自动刷新 - if (!tableLoading.value) { - fetchDocuments() - } - }, 30000) // 5秒刷新一次 -} - -// 停止定时器 -const stopAutoRefresh = () => { - if (refreshTimer.value) { - clearInterval(refreshTimer.value) - refreshTimer.value = null - } -} - // 修改fetchDocuments函数 const fetchDocuments = async () => { tableLoading.value = true @@ -1043,8 +979,8 @@ try { difyDatasetId: datasetId.value, parentId: currentParentId.value, // 使用当前文件夹ID fileName: searchKeyword.value || undefined, - orderBy: sortConfig.orderBy, - orderDirection: sortConfig.orderDirection, + orderBy: 'name', + orderDirection: 'ASC', pageNo: pagination.current, pageSize: pagination.size } @@ -1127,7 +1063,7 @@ const typeMap: Record { - if (sortInfo.prop && sortInfo.order) { - // 映射前端字段到后端字段 - const fieldMapping: Record = { - 'fileName': 'name', - 'createDate': 'created_at', - 'charCount': 'size' - } - - sortConfig.orderBy = fieldMapping[sortInfo.prop] || sortInfo.prop - sortConfig.orderDirection = sortInfo.order === 'ascending' ? 'ASC' : 'DESC' - - // 重置到第一页并刷新数据 - pagination.current = 1 - fetchDocuments() - } -} - // 处理文件夹打开 const handleOpenFolder = (row: FileItem) => { // 设置当前文件夹ID并更新面包屑路径 @@ -1332,6 +1247,62 @@ try { createFolderLoading.value = false } } + +// 分页滚动加载 +const handleScroll = async (event: Event) => { + const container = event.target as HTMLElement; + if(segmentList.value.length %10 !== 0 || segmentList.value.length<10) { + isScroll.value = false + return + } + // 判断是否已经滚动到底部 + if (container.scrollHeight - container.scrollTop - container.clientHeight < 10) { + // 如果没有在加载状态,则加载更多 + if (!segmentIsLoading.value && isScroll.value) { + loadMoreSegments(); + } + } +} + +// 加载更多分段数据 +const loadMoreSegments = async () => { + segmentIsLoading.value = true; // 设置为正在加载状态 + try { + // 获取当前选择的文件数据(请根据你的代码适配) + const resp = await getSegmentList({ + datasetId: datasetId.value, + documentId: segmentdocId.value, + page: segmentPage.value, + pageSize: segmentPageSize.value + }); + + // 如果获取到数据 + if (resp.data.list?.length) { + segmentList.value.push(...resp.data.list); // 将新数据追加到原来的列表中 + segmentPage.value += 1; // 页数加 1,准备加载下一页 + } + } catch (error) { + ElNotification({ + title: t('vabI18n.knowledge.document.errors.previewFailed'), + message: error instanceof Error ? error.message : t('vabI18n.knowledge.document.messages.getFileContentFailed'), + type: 'error' + }); + } finally { + segmentIsLoading.value = false; // 设置为加载完成状态 + } +} + +// 处理分段预览 +const handlePreviewSegment = (segment) => { +previewSegment.value = segment +previewDialogVisible.value = true +} + +// 关闭预览对话框 +const handleClosePreviewDialog = () => { +previewDialogVisible.value = false +} + diff --git a/chat-server/src/main/java/com/bjtds/brichat/controller/DocumentSegmentController.java b/chat-server/src/main/java/com/bjtds/brichat/controller/DocumentSegmentController.java index 34b91f4..3091a3c 100644 --- a/chat-server/src/main/java/com/bjtds/brichat/controller/DocumentSegmentController.java +++ b/chat-server/src/main/java/com/bjtds/brichat/controller/DocumentSegmentController.java @@ -2,6 +2,7 @@ package com.bjtds.brichat.controller; import com.bjtds.brichat.entity.dto.SegmentDto; import com.bjtds.brichat.service.dify.DocumentSegmentService; +import com.bjtds.brichat.util.PageInfoResult; import com.bjtds.brichat.util.ResultUtils; import lombok.extern.slf4j.Slf4j; import org.checkerframework.checker.units.qual.C; @@ -21,9 +22,11 @@ public class DocumentSegmentController { private DocumentSegmentService documentSegmentService; @GetMapping("/selectSegments") - public ResultUtils SelectSegments(@RequestParam("documentId") String documentId, @RequestParam("datasetId") String datasetId) { - List segments = documentSegmentService.SelectSegments(documentId, datasetId); - segments.sort(Comparator.comparing(SegmentDto::getPosition)); - return ResultUtils.success(segments); + public ResultUtils SelectSegments(@RequestParam("documentId") String documentId, + @RequestParam("datasetId") String datasetId, + @RequestParam(value = "page",required = false,defaultValue = "1") int page, + @RequestParam(value = "pageSize",required = false,defaultValue = "10") int pageSize) { + PageInfoResult pageInfoResult = documentSegmentService.SelectSegments(documentId, datasetId, page, pageSize); + return ResultUtils.pageInfo(pageInfoResult); } } diff --git a/chat-server/src/main/java/com/bjtds/brichat/mapper/postgresql/DifyDocumentSegmentMapper.java b/chat-server/src/main/java/com/bjtds/brichat/mapper/postgresql/DifyDocumentSegmentMapper.java index 3691b78..093d6a4 100644 --- a/chat-server/src/main/java/com/bjtds/brichat/mapper/postgresql/DifyDocumentSegmentMapper.java +++ b/chat-server/src/main/java/com/bjtds/brichat/mapper/postgresql/DifyDocumentSegmentMapper.java @@ -9,5 +9,5 @@ import java.util.List; @Mapper public interface DifyDocumentSegmentMapper { - List SelectSegmentsByDocumentIdAndDatasetId(String documentId, String datasetId); + List SelectSegmentsByDocumentIdAndDatasetId(String documentId, String datasetId, int offset, int pageSize); } diff --git a/chat-server/src/main/java/com/bjtds/brichat/service/dify/DocumentSegmentService.java b/chat-server/src/main/java/com/bjtds/brichat/service/dify/DocumentSegmentService.java index 46f6f45..553b817 100644 --- a/chat-server/src/main/java/com/bjtds/brichat/service/dify/DocumentSegmentService.java +++ b/chat-server/src/main/java/com/bjtds/brichat/service/dify/DocumentSegmentService.java @@ -1,10 +1,11 @@ package com.bjtds.brichat.service.dify; import com.bjtds.brichat.entity.dto.SegmentDto; +import com.bjtds.brichat.util.PageInfoResult; import java.util.List; public interface DocumentSegmentService { - List SelectSegments(String documentId, String datasetId); + PageInfoResult SelectSegments(String documentId, String datasetId, int page, int pageSize); } diff --git a/chat-server/src/main/java/com/bjtds/brichat/service/dify/impl/DocumentSegmentServiceImpl.java b/chat-server/src/main/java/com/bjtds/brichat/service/dify/impl/DocumentSegmentServiceImpl.java index 39a5035..54bca30 100644 --- a/chat-server/src/main/java/com/bjtds/brichat/service/dify/impl/DocumentSegmentServiceImpl.java +++ b/chat-server/src/main/java/com/bjtds/brichat/service/dify/impl/DocumentSegmentServiceImpl.java @@ -3,6 +3,7 @@ package com.bjtds.brichat.service.dify.impl; import com.bjtds.brichat.entity.dto.SegmentDto; import com.bjtds.brichat.mapper.postgresql.DifyDocumentSegmentMapper; import com.bjtds.brichat.service.dify.DocumentSegmentService; +import com.bjtds.brichat.util.PageInfoResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -15,8 +16,16 @@ public class DocumentSegmentServiceImpl implements DocumentSegmentService { @Autowired private DifyDocumentSegmentMapper difyDocumentSegmentMapper; +// @Override +// public List SelectSegments(String documentId, String datasetId) { +// return difyDocumentSegmentMapper.SelectSegmentsByDocumentIdAndDatasetId(documentId, datasetId); +// } + + @Override - public List SelectSegments(String documentId, String datasetId) { - return difyDocumentSegmentMapper.SelectSegmentsByDocumentIdAndDatasetId(documentId, datasetId); + public PageInfoResult SelectSegments(String documentId, String datasetId, int page, int pageSize) { + int offset = (page - 1) * pageSize; + List segmentDtos = difyDocumentSegmentMapper.SelectSegmentsByDocumentIdAndDatasetId(documentId, datasetId, offset, pageSize); + return new PageInfoResult<>(segmentDtos, 0); } } diff --git a/chat-server/src/main/resources/com/bjtds/brichat/mapper/postgresql/DifyDocumentSegmentMapper.xml b/chat-server/src/main/resources/com/bjtds/brichat/mapper/postgresql/DifyDocumentSegmentMapper.xml index b6b0efa..58a0c52 100644 --- a/chat-server/src/main/resources/com/bjtds/brichat/mapper/postgresql/DifyDocumentSegmentMapper.xml +++ b/chat-server/src/main/resources/com/bjtds/brichat/mapper/postgresql/DifyDocumentSegmentMapper.xml @@ -11,5 +11,7 @@ dataset_id = CAST(#{datasetId} as uuid) + order by position asc + limit #{pageSize} offset #{offset}