From 1bef1efdcb25897244b6060f5a80dbc7ee99f737 Mon Sep 17 00:00:00 2001 From: lmr <350416710@qq.com> Date: Tue, 16 Sep 2025 10:31:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/KnowledgePage/AdjustFilesUpload.tsx | 2 +- .../components/DocxFileViewer.tsx | 32 ++++++-- .../KnowledgePage/components/Paragraphs.tsx | 75 +++++++++++++++++-- .../components/PreviewResult.tsx | 7 +- .../src/pages/KnowledgePage/filesUpload.tsx | 2 +- 5 files changed, 101 insertions(+), 17 deletions(-) diff --git a/src/frontend/platform/src/pages/KnowledgePage/AdjustFilesUpload.tsx b/src/frontend/platform/src/pages/KnowledgePage/AdjustFilesUpload.tsx index 71b75361b..aa9842062 100644 --- a/src/frontend/platform/src/pages/KnowledgePage/AdjustFilesUpload.tsx +++ b/src/frontend/platform/src/pages/KnowledgePage/AdjustFilesUpload.tsx @@ -286,7 +286,7 @@ export default function AdjustFilesUpload() { variant="outline" size="icon" className="bg-[#fff] size-8" - onClick={handleBack} + onClick={() => navigate(-1)} > diff --git a/src/frontend/platform/src/pages/KnowledgePage/components/DocxFileViewer.tsx b/src/frontend/platform/src/pages/KnowledgePage/components/DocxFileViewer.tsx index 6585e6c1b..81c1722db 100644 --- a/src/frontend/platform/src/pages/KnowledgePage/components/DocxFileViewer.tsx +++ b/src/frontend/platform/src/pages/KnowledgePage/components/DocxFileViewer.tsx @@ -3,13 +3,32 @@ import * as mammoth from "mammoth"; import { LoadingIcon } from "@/components/bs-icons/loading"; const DocxPreview = ({ filePath }) => { - console.log(filePath,445); + console.log(filePath, 445); + + // 检查文件路径是否以.doc结尾(不区分大小写) + const isDocFile = filePath.toLowerCase().endsWith('.doc'); const [htmlContent, setHtmlContent] = useState(""); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const previewRef = useRef(null); + // 如果是.doc文件,直接返回不支持预览提示,不执行后续逻辑 + if (isDocFile) { + return ( +
+
+ 文件不支持预览 +

此文件类型不支持预览

+
+
+ ); + } + useEffect(() => { const fetchAndConvertDocx = async () => { try { @@ -64,9 +83,11 @@ const DocxPreview = ({ filePath }) => { `; if (loading) { - return
- -
+ return ( +
+ +
+ ); } return ( @@ -91,4 +112,5 @@ const DocxPreview = ({ filePath }) => { ); }; -export default DocxPreview; \ No newline at end of file +export default DocxPreview; + \ No newline at end of file diff --git a/src/frontend/platform/src/pages/KnowledgePage/components/Paragraphs.tsx b/src/frontend/platform/src/pages/KnowledgePage/components/Paragraphs.tsx index e7d2300e7..c1cce9fd9 100644 --- a/src/frontend/platform/src/pages/KnowledgePage/components/Paragraphs.tsx +++ b/src/frontend/platform/src/pages/KnowledgePage/components/Paragraphs.tsx @@ -88,10 +88,19 @@ const latestPreviewUrlRef = useRef(''); let chunkBboxes = []; try { const firstChunk = response.data?.[0]; - if (firstChunk?.metadata?.bbox) { + if (firstChunk?.metadata?.bbox) { + console.log(JSON.parse(firstChunk?.metadata?.bbox).chunk_bboxes,6666666666666); + + // 先判断bbox是否为空字符串 + if (typeof firstChunk.metadata.bbox === 'string' && JSON.parse(firstChunk?.metadata?.bbox).chunk_bboxes === '') { + console.log('bbox为空字符串'); + chunkBboxes = []; + } else { + // 解析JSON const bboxObj = JSON.parse(firstChunk.metadata.bbox); chunkBboxes = bboxObj.chunk_bboxes || []; } + } } catch (e) { console.error('解析 chunk_bboxes 失败:', e); chunkBboxes = []; @@ -115,19 +124,69 @@ const fetchFileUrl = useCallback(async (fileId) => { const pares = await getFileBboxApi(fileId); setPartitions(pares || []); - // 严格判断URL有效性 + // 获取当前选中的文件信息 + const currentFile = rawFiles.find(f => String(f.id) === String(fileId)); let finalUrl = ''; - if (typeof res.preview_url === 'string' && res.preview_url.trim() !== '') { - finalUrl = res.preview_url.trim(); - } else if (typeof res.original_url === 'string' && res.original_url.trim() !== '') { - finalUrl = res.original_url.trim(); + let finalPreviewUrl = ''; + + // 检查是否有有效的preview_url和original_url + const hasPreviewUrl = typeof res.preview_url === 'string' && res.preview_url.trim() !== ''; + const hasOriginalUrl = typeof res.original_url === 'string' && res.original_url.trim() !== ''; + + if (currentFile) { + console.log(currentFile,3); + + // 判断是否为UNS或LOCAL类型 + const isUnsOrLocal = currentFile.parse_type === "uns" || currentFile.parse_type === "local"; + console.log(isUnsOrLocal,currentFile,4444444); + + + if (isUnsOrLocal) { + // UNS或LOCAL类型:根据bbox是否有效选择URL + const isBboxesValid = hasChunkBboxes; + const isBboxesEmpty = !hasChunkBboxes || chunkBboxes.length === 0; + if (!isBboxesEmpty && hasPreviewUrl) { + // 有有效bbox且有preview_url → 使用preview_url + console.log(1111); + + finalUrl = res.preview_url.trim(); + finalPreviewUrl = res.preview_url.trim(); + console.log('UNS/LOCAL类型(有有效bbox):使用preview_url'); + } else { + // 无有效bbox(为空数组/字符串)或无preview_url → 强制使用original_url + console.log(2222); + + finalUrl = hasOriginalUrl ? res.original_url.trim() : ''; + finalPreviewUrl = finalUrl; + console.log('UNS/LOCAL类型(无有效bbox或无preview_url):使用original_url'); + } + } else { + // 其他类型:优先使用preview_url,无则使用original_url + if (hasPreviewUrl) { + // 有preview_url → 优先使用 + finalUrl = res.preview_url.trim(); + finalPreviewUrl = res.preview_url.trim(); + console.log('其他类型:使用preview_url'); + } else { + // 无preview_url → 使用original_url或备选URL + finalUrl = hasOriginalUrl ? res.original_url.trim() : ''; + finalPreviewUrl = finalUrl; + console.log('其他类型(无preview_url):使用original_url'); + } + } + } else { + // 如果没有找到当前文件,使用默认策略 + finalUrl = hasPreviewUrl ? res.preview_url.trim() : (hasOriginalUrl ? res.original_url.trim() : ''); + finalPreviewUrl = finalUrl; + console.log('未找到文件信息,使用默认URL策略'); } if (finalUrl) { finalUrl = decodeURIComponent(finalUrl); + finalPreviewUrl = decodeURIComponent(finalPreviewUrl); // 同时更新状态和ref(ref会同步生效) setFileUrl(finalUrl); - setPreviewUrl(finalUrl); + setPreviewUrl(finalPreviewUrl); return finalUrl; } else { setFileUrl(''); @@ -143,7 +202,7 @@ const fetchFileUrl = useCallback(async (fileId) => { } finally { setIsFetchingUrl(false); } -}, []); +}, [rawFiles, hasChunkBboxes]); diff --git a/src/frontend/platform/src/pages/KnowledgePage/components/PreviewResult.tsx b/src/frontend/platform/src/pages/KnowledgePage/components/PreviewResult.tsx index 4dc669f24..c1ab4c2e9 100644 --- a/src/frontend/platform/src/pages/KnowledgePage/components/PreviewResult.tsx +++ b/src/frontend/platform/src/pages/KnowledgePage/components/PreviewResult.tsx @@ -32,7 +32,7 @@ export default function PreviewResult({ showPreview, previewCount, rules, step, const { id } = useParams() const [chunks, setChunks] = useState([]) // 当前文件分块 - const [partitions, setPartitions] = useState({}) // 当前文件分区 + const [partitions, setPartitions] = useState(null) // 当前文件分区 const [selectId, setSelectId] = useState(''); // 当前选择文件id const [syncChunksSelectId, setSelectIdSyncChunks] = useState(''); // 当前选择文件id(与chunk更新保持同步) useEffect(() => { @@ -73,6 +73,8 @@ export default function PreviewResult({ showPreview, previewCount, rules, step, const currentFile = fileList.find(file => file.id === selectId) let preview_url + console.log(currentFile,789); + if (showPreview) { preview_url = currentFile.previewUrl || currentFile?.filePath } else { @@ -151,7 +153,8 @@ export default function PreviewResult({ showPreview, previewCount, rules, step, } return (
- {(step === 3 || step === 2 && !previewCount) && currentFile && navigate(-1)} >