@@ -64,16 +64,17 @@ export default function Paragraphs({ fileId, onBack }) {
6464 const latestFileUrlRef = useRef ( '' ) ;
6565 const latestPreviewUrlRef = useRef ( '' ) ;
6666 const latestOriginalUrlRef = useRef ( '' ) ;
67-
68- const [ selectedChunkIndex , setSelectedBbox ] = useKnowledgeStore ( ( state ) => [ state . selectedChunkIndex , state . setSelectedBbox ] ) ;
67+ const selectedChunkIndex = useKnowledgeStore ( ( state ) => state . selectedChunkIndex ) ;
68+ const setSelectedBbox = useKnowledgeStore ( ( state ) => state . setSelectedBbox ) ;
6969 useEffect ( ( ) => {
7070 // 切换chunk清空选中的高亮标注bbox
7171 setSelectedBbox ( [ ] )
7272 } , [ selectedChunkIndex ] )
7373
7474 // 表格配置(完全保留原始逻辑)
7575 const tableConfig = useMemo ( ( ) => ( {
76- file_ids : selectedFileId ? [ selectedFileId ] : [ ]
76+ file_ids : selectedFileId ? [ selectedFileId ] : [ ] ,
77+ knowledge_id : id
7778 } ) , [ selectedFileId ] ) ;
7879
7980 const {
@@ -236,7 +237,7 @@ export default function Paragraphs({ fileId, onBack }) {
236237 text : item . text || '' ,
237238 bbox : item . metadata ?. bbox || { } ,
238239 activeLabels : { } ,
239- chunkIndex : item . metadata ?. chunk_index || index ,
240+ chunkIndex : item . metadata ?. chunk_index ,
240241 page : item . metadata ?. page || 0 ,
241242 metadata : item . metadata || { }
242243 } ) ) ;
@@ -352,7 +353,7 @@ export default function Paragraphs({ fileId, onBack }) {
352353 }
353354 } , [ rawFiles , isInitReady , fileId , handleFileChange , selectedFileId , hasInited ] ) ;
354355
355- // 处理分段修改(完全保留原始逻辑)
356+ // 处理分段修改
356357 const handleChunkChange = useCallback ( ( chunkIndex , text ) => {
357358 let chunkIndexPage = chunkIndex % pageSize ;
358359 console . log ( '转换后的localIndex:' , chunkIndexPage ) ;
@@ -363,7 +364,8 @@ export default function Paragraphs({ fileId, onBack }) {
363364 const bbox = { chunk_bboxes : selectedBbox } ;
364365
365366 // selectedBbox空数组时,使用safeChunks的bbox
366- const bboxStr = selectedBbox . length ? JSON . stringify ( bbox ) : safeChunks [ chunkIndexPage ] . bbox ;
367+ const targetChunk = chunks . find ( chunk => chunk . chunkIndex === chunkIndex ) ;
368+ const bboxStr = selectedBbox . length ? JSON . stringify ( bbox ) : targetChunk ?. bbox ;
367369 captureAndAlertRequestErrorHoc ( updateChunkApi ( {
368370 knowledge_id : Number ( id ) ,
369371 file_id : selectedFileId || currentFile ?. id || '' ,
@@ -380,7 +382,7 @@ export default function Paragraphs({ fileId, onBack }) {
380382 ( item ) => item ?. metadata ?. chunk_index === chunkIndex ,
381383 ( item ) => ( { text, metadata : { ...item . metadata , bbox : bboxStr } } )
382384 ) ;
383- } , [ id , currentFile , refreshData , selectedBbox ] ) ;
385+ } , [ id , currentFile , refreshData , selectedBbox , chunks ] ) ;
384386
385387 // 格式化文件列表(完全保留原始逻辑)
386388 const files = useMemo ( ( ) => {
@@ -486,16 +488,34 @@ export default function Paragraphs({ fileId, onBack }) {
486488 } , [ ] ) ;
487489
488490
489- // 删除分段(完全保留原始逻辑)
490- const handleDeleteChunk = useCallback ( ( data ) => {
491- captureAndAlertRequestErrorHoc ( delChunkApi ( {
492- knowledge_id : Number ( id ) ,
493- file_id : selectedFileId || currentFile ?. id || '' ,
494- chunk_index : data || 0
495- } ) ) ;
496- reload ( ) ;
497- } , [ id , reload ] ) ;
491+ const handleDeleteChunk = useCallback ( ( data ) => {
492+
493+ const updatedChunks = chunks . filter ( chunk => chunk . chunkIndex !== data ) ;
494+ setChunks ( updatedChunks ) ;
495+
496+ // 清除选中的bbox(如果选中的是被删除的chunk)
497+ if ( selectedChunkIndex === data ) {
498+ setSelectedBbox ( [ ] ) ;
499+ }
500+
501+ captureAndAlertRequestErrorHoc ( delChunkApi ( {
502+ knowledge_id : Number ( id ) ,
503+ file_id : selectedFileId || currentFile ?. id || '' ,
504+ chunk_index : data || 0
505+ } ) ) ;
506+
507+ reload ( ) ;
498508
509+ } , [
510+ id ,
511+ reload ,
512+ chunks ,
513+ selectedFileId ,
514+ currentFile ?. id ,
515+ setChunks ,
516+ selectedChunkIndex , // 从store获取的选中chunkIndex
517+ setSelectedBbox // 从store获取的set方法
518+ ] ) ;
499519 // 格式化文件大小(完全保留原始逻辑)
500520 const formatFileSize = useCallback ( ( bytes ) => {
501521 if ( bytes === 0 ) return '0 Bytes' ;
@@ -721,7 +741,7 @@ export default function Paragraphs({ fileId, onBack }) {
721741 previewUrl = { previewUrl }
722742 urlState = { { load : ! isFetchingUrl , url : previewUrl || fileUrl } }
723743 file = { currentFile }
724- chunks = { safeChunks }
744+ chunks = { chunks }
725745 setChunks = { setChunks }
726746 rules = { previewRules }
727747 edit
@@ -747,7 +767,7 @@ export default function Paragraphs({ fileId, onBack }) {
747767 className = "h-[calc(100vh-206px)] pb-6"
748768 fileSuffix = { currentFile ?. suffix || '' }
749769 loading = { loading }
750- chunks = { safeChunks }
770+ chunks = { chunks }
751771 onDel = { handleDeleteChunk }
752772 onChange = { handleChunkChange }
753773 />
0 commit comments