Skip to content

Commit adf32e2

Browse files
authored
Feat/2.2.0 (#1758)
2 parents ace0f92 + 1fc2c5b commit adf32e2

File tree

3 files changed

+66
-26
lines changed

3 files changed

+66
-26
lines changed

src/frontend/client/src/components/Chat/Input/ChatForm.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ const ChatForm = ({ isLingsi, setShowCode, readOnly, index = 0 }) => {
137137
const disableInputs = useMemo(
138138
() => {
139139
if (readOnly) return true
140-
if (!isLingsi && bsConfig?.models.length === 0) return true
140+
if (isLingsi) return false
141+
if (!bsConfig?.models) return true
142+
if (bsConfig.models.length === 0) return true
141143
return !!((requiresKey ?? false) || invalidAssistant)
142144
},
143145
[requiresKey, invalidAssistant, isLingsi, readOnly, bsConfig],
@@ -213,6 +215,12 @@ const ChatForm = ({ isLingsi, setShowCode, readOnly, index = 0 }) => {
213215
const showVoice = modelData?.asr_model.id
214216

215217
const [audioOpening] = useRecordingAudioLoading()
218+
const noModel = useMemo(() => {
219+
if (isLingsi) return false
220+
if (!bsConfig?.models) return true
221+
if (bsConfig.models.length === 0) return true
222+
return false
223+
}, [isLingsi, bsConfig])
216224

217225
return (
218226
<form
@@ -313,7 +321,7 @@ const ChatForm = ({ isLingsi, setShowCode, readOnly, index = 0 }) => {
313321
</FileFormWrapper>
314322
{/* 发送和停止 */}
315323
<div className="absolute bottom-2 right-3 flex gap-2 items-center">
316-
{showVoice && <SpeechToTextComponent disabled={readOnly} onChange={(e) => {
324+
{showVoice && <SpeechToTextComponent disabled={readOnly || noModel} onChange={(e) => {
317325
const text = textAreaRef.current.value + e
318326
methods.setValue('text', text, { shouldValidate: true });
319327
}} />}

src/frontend/platform/src/pages/KnowledgePage/components/Paragraphs.tsx

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/>

src/frontend/platform/src/pages/KnowledgePage/components/PreviewFile.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,25 @@ export default function PreviewFile({
115115
});
116116
});
117117

118-
if (labelsMap.size) {
119-
setRePostion(!rePostion);
120-
setLabelsMap(labelsMap);
121-
labelsMapRef.current = labelsMap;
118+
if (labelsMap.size) {
119+
setRePostion(!rePostion);
120+
setLabelsMap(labelsMap);
121+
labelsMapRef.current = labelsMap;
122+
}
123+
}, [suffix, chunks, selectedChunkIndex, isUnsType, partitions]);
124+
useEffect(() => {
125+
// 当 chunks 变化且存在选中的 chunkIndex 时,检查该 chunk 是否仍存在
126+
if (selectedChunkIndex !== -1) {
127+
const chunkExists = chunks.some(c => c.chunkIndex === selectedChunkIndex);
128+
if (!chunkExists) {
129+
// 清除该 chunk 对应的标签
130+
setLabelsMap(new Map());
131+
labelsMapRef.current = new Map();
132+
delete labelsMapTempRef.current[selectedChunkIndex];
133+
setSelectedBbox([]);
122134
}
123-
}, [suffix, chunks, selectedChunkIndex, isUnsType, partitions]); // 增加partitions依赖
124-
135+
}
136+
}, [chunks, selectedChunkIndex, setLabelsMap, setSelectedBbox]);
125137
// 5. 页面滚动和定位逻辑(对齐ParagraphEdit的postion计算)
126138
useEffect(() => {
127139
setPostion(prev => [prev[0], prev[1] + selectedChunkDistanceFactor]);

0 commit comments

Comments
 (0)