@gientech/modual 2.2.3-fix.5 → 2.2.3-fix.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +38 -0
- package/.prettierignore +16 -0
- package/.prettierrc +17 -0
- package/CHANGELOG.md +162 -0
- package/Dockerfile +15 -0
- package/README.md +761 -761
- package/USAGE.md +247 -0
- package/bash.exe.stackdump +40 -0
- package/components.json +21 -0
- package/default.conf +19 -0
- package/dist/README.md +761 -0
- package/{assets/GientechStreamReader-r5ZTSZk2.js → dist/assets/GientechStreamReader-Bae2-4f7.js} +1 -1
- package/{assets/LeftOutlined-DZMeGbKk.js → dist/assets/LeftOutlined-COk0w5nY.js} +1 -1
- package/{assets/circle-plus-B73z_SUN.js → dist/assets/circle-plus-DOKqXUMk.js} +1 -1
- package/{assets → dist/assets}/database.svg +11 -11
- package/{assets → dist/assets}/database_add.svg +53 -53
- package/{assets → dist/assets}/database_connect.svg +66 -66
- package/{assets → dist/assets}/database_upload.svg +29 -29
- package/{assets → dist/assets}/databse.svg +6 -6
- package/{assets → dist/assets}/defaultWeLogo.svg +14 -14
- package/{assets → dist/assets}/graph.svg +4 -4
- package/{assets → dist/assets}/iconAi.svg +9 -9
- package/dist/assets/index-1PwCuRjv.js +1061 -0
- package/dist/assets/index-7QvYA6eT.js +1 -0
- package/{assets/index-97Oe7YBe.js → dist/assets/index-BKbpfN9S.js} +1 -1
- package/{assets/index-B4k3tK0f.js → dist/assets/index-BXdyn2W3.js} +1 -1
- package/dist/assets/index-BhUNGJOe.js +27 -0
- package/{assets/index-BDc2zBbG.js → dist/assets/index-Bin0NZwF.js} +3 -7
- package/{assets/index-DHK_n74G.js → dist/assets/index-CpSzj-Sx.js} +73 -58
- package/{assets/index-usBlUHOb.js → dist/assets/index-Ct_k24Ar.js} +1 -1
- package/dist/assets/index-DT3qkjJ3.js +750 -0
- package/dist/assets/index-lFBFf_0k.js +1890 -0
- package/{assets/index-iOuQJ8vu.js → dist/assets/index-vfI1_Qg0.js} +1 -1
- package/{assets → dist/assets}/knowledge.svg +4 -4
- package/{assets → dist/assets}/mysql.svg +14 -14
- package/{assets → dist/assets}/sensitive.svg +5 -5
- package/{assets/style-6bvhg-jh.js → dist/assets/style-CfNUqKAA.js} +7 -7
- package/dist/assets/style2.css +1 -0
- package/dist/assets/style5.css +1 -0
- package/{assets/triangle-alert-C4Z1AkGW.js → dist/assets/triangle-alert-CaJaaCaZ.js} +1 -1
- package/{assets/x-DWGzNb9c.js → dist/assets/x-B65AntWN.js} +1 -1
- package/{assistantConfig.js → dist/assistantConfig.js} +9 -14
- package/dist/chat.js +1 -0
- package/dist/chatCompare.js +1 -0
- package/dist/database.js +20 -0
- package/{databaseId.js → dist/databaseId.js} +1 -1
- package/{databaseTable.js → dist/databaseTable.js} +1 -1
- package/dist/index.js +1 -0
- package/dist/modelManage.js +1 -0
- package/dist/package.json +73 -0
- package/{sensitive.js → dist/sensitive.js} +6 -6
- package/dist/streamFilesReader.js +1 -0
- package/{worker → dist/worker}/pdf.worker.min.js +21 -21
- package/doc_assets/images/1.png +0 -0
- package/doc_assets/images/3.png +0 -0
- package/doc_assets/images/component-screenshot.png +1 -0
- package/doc_assets//346/226/271/346/241/210/v2.0.7/345/217/230/346/233/264/346/200/273/347/273/223.md +115 -0
- package/doc_assets//346/226/271/346/241/210//344/274/230/345/214/226/346/226/271/346/241/210-/345/244/232/344/274/232/350/257/235SSE/350/277/236/346/216/245/347/256/241/347/220/206.md +504 -0
- package/doc_assets//346/226/271/346/241/210//346/215/242/350/241/214/346/240/274/345/274/217/344/277/235/346/214/201/344/274/230/345/214/226/346/226/271/346/241/210.md +359 -0
- package/eslint.config.js +92 -0
- package/index.html +13 -0
- package/package.json +125 -44
- package/package.json.demo-backup +109 -0
- package/postcss.config.cjs +19 -0
- package/public/icons/answerAwartar.png +0 -0
- package/public/icons/docx-file.png +0 -0
- package/public/icons/folder.png +0 -0
- package/public/icons/html.png +0 -0
- package/public/icons/image.png +0 -0
- package/public/icons/jpg-file.png +0 -0
- package/public/icons/json.png +0 -0
- package/public/icons/md.png +0 -0
- package/public/icons/pdf.png +0 -0
- package/public/icons/pptx.png +0 -0
- package/public/icons/questionAwartar.png +0 -0
- package/public/icons/sheets.png +0 -0
- package/public/icons/txt.png +0 -0
- package/public/icons/xlsx.png +0 -0
- package/public/vite.svg +1 -0
- package/public/worker/pdf.worker.min.js +22 -0
- package/rag/assets/index.Bd0tNzw0.js +2797 -0
- package/rag/assets/index.D6t67hlu.css +1 -0
- package/rag/assets/left.KBHV5h7q.jpg +0 -0
- package/rag/assets/worker-BbpylX7l.DptbXke_.js +13 -0
- package/release-it.json +21 -0
- package/scripts/README.md +133 -0
- package/scripts/build-demo.js +88 -0
- package/scripts/check-changelog.cjs +124 -0
- package/scripts/check-version.cjs +49 -0
- package/scripts/decrypt-api-key.js +95 -0
- package/scripts/demo-selector.js +216 -0
- package/scripts/dev-demo.js +85 -0
- package/scripts/open-file.cjs +61 -0
- package/scripts/preview-demo.js +130 -0
- package/scripts/run-demo.bat +34 -0
- package/src/assets/img/close.png +0 -0
- package/src/assets/img/database.png +0 -0
- package/src/assets/img/downArrow.png +0 -0
- package/src/assets/img/downLoad.png +0 -0
- package/src/assets/img/excel.png +0 -0
- package/src/assets/img/graphIcon.png +0 -0
- package/src/assets/img/iconAi.svg +9 -0
- package/src/assets/img/img.png +0 -0
- package/src/assets/img/pdf.png +0 -0
- package/src/assets/img/ppt.png +0 -0
- package/src/assets/img/search.svg +3 -0
- package/src/assets/img/selected.svg +4 -0
- package/src/assets/img/singleQa.png +0 -0
- package/src/assets/img/txt.png +0 -0
- package/src/assets/img/webSearch.png +0 -0
- package/src/assets/img/word.png +0 -0
- package/src/assets/login/homeBg.png +0 -0
- package/src/assets/login/left.jpg +0 -0
- package/src/assets/login/logoImg.png +0 -0
- package/src/examples/ConversationAssistantPage/index.tsx +42 -0
- package/src/examples/LoginPage/index.tsx +20 -0
- package/src/examples/chat/components/DrawerGraphPreview.tsx +78 -0
- package/src/examples/chat/index.tsx +171 -0
- package/src/examples/chat/logo03.png +0 -0
- package/src/examples/chatCompare/icons/rag_think.svg +8 -0
- package/src/examples/chatCompare/icons/wenda_lianwangsousuo.svg +9 -0
- package/src/examples/chatCompare/index.tsx +154 -0
- package/src/examples/gientechStreamFilesReader/index.tsx +979 -0
- package/src/examples/headlessChat/assets/mind.svg +6 -0
- package/src/examples/headlessChat/assets/net.svg +7 -0
- package/src/examples/headlessChat/index.tsx +298 -0
- package/src/examples/knowledgebaseDetails/index.tsx +119 -0
- package/src/examples/ragDatabaseDataPage/index.tsx +40 -0
- package/src/examples/ragDatabaseIdPage/index.tsx +126 -0
- package/src/examples/ragDatabasePage/index.tsx +36 -0
- package/src/examples/ragModelManagePage/index.tsx +107 -0
- package/src/examples/ragModelManagePage/style.css +7 -0
- package/src/examples/ragSearchPage/index.tsx +0 -0
- package/src/examples/ragSensitiveWordsPage/index.tsx +117 -0
- package/src/examples/ragSensitiveWordsPage/style.css +16 -0
- package/src/examples/sensitiveId/index.tsx +41 -0
- package/src/examples/streamFiles/index.tsx +417 -0
- package/src/examples/utils/demo_setting_pannel.ts +0 -0
- package/src/lib_enter.ts +44 -0
- package/src/main.tsx +5 -0
- package/src/main.tsx.backup +5 -0
- package/src/modules/CHAT_UNIFICATION_PLAN.md +324 -0
- package/src/modules/assistantConfig/assets/databse.svg +6 -0
- package/src/modules/assistantConfig/assets/empty.png +0 -0
- package/src/modules/assistantConfig/assets/graph.svg +4 -0
- package/src/modules/assistantConfig/assets/knowledge.svg +4 -0
- package/src/modules/assistantConfig/assets/sensitive.svg +5 -0
- package/src/modules/assistantConfig/components/Database.tsx +171 -0
- package/src/modules/assistantConfig/components/Graph.tsx +177 -0
- package/src/modules/assistantConfig/components/Knowledge.tsx +276 -0
- package/src/modules/assistantConfig/components/NotFoundContent.tsx +21 -0
- package/src/modules/assistantConfig/components/Paragraph.tsx +51 -0
- package/src/modules/assistantConfig/components/ParamsItem.tsx +40 -0
- package/src/modules/assistantConfig/components/ResourceBinderItem.tsx +133 -0
- package/src/modules/assistantConfig/components/SearchableSelector.tsx +500 -0
- package/src/modules/assistantConfig/components/Sensitive.tsx +221 -0
- package/src/modules/assistantConfig/components/SliderInput.tsx +66 -0
- package/src/modules/assistantConfig/constants.tsx +75 -0
- package/src/modules/assistantConfig/index.tsx +785 -0
- package/src/modules/assistantConfig/server.ts +262 -0
- package/src/modules/chat/AllFiles.tsx +158 -0
- package/src/modules/chat/Conversations/Item.tsx +169 -0
- package/src/modules/chat/Conversations/List.tsx +210 -0
- package/src/modules/chat/Conversations/groupByTime.ts +39 -0
- package/src/modules/chat/Conversations/index.tsx +255 -0
- package/src/modules/chat/ReferenceBar.tsx +659 -0
- package/src/modules/chat/constants.tsx +66 -0
- package/src/modules/chat/i18n.ts +151 -0
- package/src/modules/chat/i18n.tsx +151 -0
- package/src/modules/chat/icons/rag_think.svg +8 -0
- package/src/modules/chat/icons/wenda_lianwangsousuo.svg +9 -0
- package/src/modules/chat/index.tsx +2400 -0
- package/src/modules/chat/referenceCom/DeleteModal.tsx +75 -0
- package/src/modules/chat/referenceCom/DrawerContent.tsx +136 -0
- package/src/modules/chat/referenceCom/DrawerDatabase.tsx +102 -0
- package/src/modules/chat/referenceCom/DrawerGraphPreview.tsx +86 -0
- package/src/modules/chat/referenceCom/DrawerPreview.tsx +73 -0
- package/src/modules/chat/referenceCom/DrawerTitle.tsx +26 -0
- package/src/modules/chat/referenceCom/RenameModal.tsx +86 -0
- package/src/modules/chat/referenceCom/TagCom.tsx +30 -0
- package/src/modules/chat/style.css +6 -0
- package/src/modules/chat/style.less +7 -0
- package/src/modules/chat/types.ts +17 -0
- package/src/modules/chat/utils/index.ts +348 -0
- package/src/modules/chatCompare/UseChatCompareHooks.ts +103 -0
- package/src/modules/chatCompare/components/AichatCompareUseController.tsx +754 -0
- package/src/modules/chatCompare/components/AssistantSelector.tsx +127 -0
- package/src/modules/chatCompare/components/ChatInputer.tsx +67 -0
- package/src/modules/chatCompare/components/ChatInstance.tsx +426 -0
- package/src/modules/chatCompare/components/ChatItem.tsx +556 -0
- package/src/modules/chatCompare/components/Sender/FileCardCommon.tsx +97 -0
- package/src/modules/chatCompare/components/Sender/FileUpload.tsx +89 -0
- package/src/modules/chatCompare/components/Sender/FilesDisplay.tsx +309 -0
- package/src/modules/chatCompare/components/Sender/VoiceInput.tsx +80 -0
- package/src/modules/chatCompare/components/Sender/contexts/BadgeContext.tsx +36 -0
- package/src/modules/chatCompare/components/Sender/fileIcon.tsx +100 -0
- package/src/modules/chatCompare/components/Sender/index.tsx +850 -0
- package/src/modules/chatCompare/components/UseChatInstanceHooks.ts +406 -0
- package/src/modules/chatCompare/components/UseScrollHooks.ts +36 -0
- package/src/modules/chatCompare/components/components/AllFiles.tsx +156 -0
- package/src/modules/chatCompare/components/components/DeleteModal.tsx +75 -0
- package/src/modules/chatCompare/components/components/DrawerContent.tsx +138 -0
- package/src/modules/chatCompare/components/components/DrawerDatabase.tsx +110 -0
- package/src/modules/chatCompare/components/components/DrawerGraphPreview.tsx +95 -0
- package/src/modules/chatCompare/components/components/DrawerPreview.tsx +75 -0
- package/src/modules/chatCompare/components/components/DrawerTitle.tsx +26 -0
- package/src/modules/chatCompare/components/components/DrawerVideo.tsx +85 -0
- package/src/modules/chatCompare/components/components/ReferenceBar.tsx +659 -0
- package/src/modules/chatCompare/components/components/RenameModal.tsx +86 -0
- package/src/modules/chatCompare/components/components/TagCom.tsx +30 -0
- package/src/modules/chatCompare/components/defaultStyleSet.tsx +148 -0
- package/src/modules/chatCompare/components/server.ts +208 -0
- package/src/modules/chatCompare/components/serverFn.ts +172 -0
- package/src/modules/chatCompare/components/style.less +97 -0
- package/src/modules/chatCompare/components/useFileManager.ts +173 -0
- package/src/modules/chatCompare/components/utils.ts +31 -0
- package/src/modules/chatCompare/data.ts +842 -0
- package/src/modules/chatCompare/index.tsx +537 -0
- package/src/modules/chatCompare/utils/AiChat.types.tsx +110 -0
- package/src/modules/chatCompare/utils/constants.tsx +70 -0
- package/src/modules/chatCompare/utils/fileUploadValidator.ts +183 -0
- package/src/modules/chatCompare/utils/icons/rag_think.svg +8 -0
- package/src/modules/chatCompare/utils/icons/wenda_lianwangsousuo.svg +9 -0
- package/src/modules/chatCompare/utils/index.ts +46 -0
- package/src/modules/database/CreateModal.tsx +402 -0
- package/src/modules/database/assets/Doris.png +0 -0
- package/src/modules/database/assets/PostgreSQL.png +0 -0
- package/src/modules/database/assets/SQLServer.png +0 -0
- package/src/modules/database/assets/database.svg +11 -0
- package/src/modules/database/assets/database_add.svg +53 -0
- package/src/modules/database/assets/database_connect.svg +66 -0
- package/src/modules/database/assets/database_upload.svg +29 -0
- package/src/modules/database/assets/empty.png +0 -0
- package/src/modules/database/assets/mysql.svg +14 -0
- package/src/modules/database/index.tsx +477 -0
- package/src/modules/database/server.ts +196 -0
- package/src/modules/databaseId/CustomCom.tsx +156 -0
- package/src/modules/databaseId/EditConfig.tsx +280 -0
- package/src/modules/databaseId/UploadDrawer.tsx +535 -0
- package/src/modules/databaseId/assets/aiOptimize.svg +10 -0
- package/src/modules/databaseId/assets/empty.png +0 -0
- package/src/modules/databaseId/assets/template.svg +6 -0
- package/src/modules/databaseId/assets/upload.svg +9 -0
- package/src/modules/databaseId/assets/useTemp.svg +6 -0
- package/src/modules/databaseId/i18n.ts +360 -0
- package/src/modules/databaseId/index.tsx +855 -0
- package/src/modules/databaseId/server.ts +286 -0
- package/src/modules/databaseId/style.css +5 -0
- package/src/modules/databaseTable/EditRowDrawer.tsx +124 -0
- package/src/modules/databaseTable/index.tsx +359 -0
- package/src/modules/databaseTable/server.ts +180 -0
- package/src/modules/headlessChat/ReferenceBar.tsx +783 -0
- package/src/modules/headlessChat/constants.tsx +54 -0
- package/src/modules/headlessChat/index.tsx +1903 -0
- package/src/modules/headlessChat/referenceCom/DeleteModal.tsx +75 -0
- package/src/modules/headlessChat/referenceCom/DrawerContent.tsx +136 -0
- package/src/modules/headlessChat/referenceCom/DrawerDatabase.tsx +102 -0
- package/src/modules/headlessChat/referenceCom/DrawerGraphPreview.tsx +86 -0
- package/src/modules/headlessChat/referenceCom/DrawerPreview.tsx +73 -0
- package/src/modules/headlessChat/referenceCom/DrawerTitle.tsx +26 -0
- package/src/modules/headlessChat/referenceCom/RenameModal.tsx +86 -0
- package/src/modules/headlessChat/referenceCom/TagCom.tsx +30 -0
- package/src/modules/headlessChat/style.less +3 -0
- package/src/modules/headlessChat/types.ts +23 -0
- package/src/modules/headlessChat/utils/index.ts +348 -0
- package/src/modules/knowledgeBase/index.tsx +58 -0
- package/src/modules/knowledgeBase/server.ts +196 -0
- package/src/modules/knowledgebaseDetails/KnowledgeBaseDetails.tsx +169 -0
- package/src/modules/knowledgebaseDetails/components/KnowledgeBaseSummaryCard.tsx +193 -0
- package/src/modules/knowledgebaseDetails/components/fileManagementParts.tsx +534 -0
- package/src/modules/knowledgebaseDetails/components/index.ts +3 -0
- package/src/modules/knowledgebaseDetails/index.ts +3 -0
- package/src/modules/knowledgebaseDetails/modules/ConfigModule.tsx +49 -0
- package/src/modules/knowledgebaseDetails/modules/FaqModule.tsx +47 -0
- package/src/modules/knowledgebaseDetails/modules/KnowledgeParseModule.tsx +771 -0
- package/src/modules/knowledgebaseDetails/modules/RetrievalTestModule.tsx +49 -0
- package/src/modules/knowledgebaseDetails/modules/UploadManagementModule.tsx +49 -0
- package/src/modules/knowledgebaseDetails/modules/types.ts +44 -0
- package/src/modules/knowledgebaseDetails/modules-shim.d.ts +14 -0
- package/src/modules/knowledgebaseDetails/servers/analysis.ts +5 -0
- package/src/modules/knowledgebaseDetails/servers/index.ts +318 -0
- package/src/modules/login/components/Login/LoginBox/index.tsx +105 -0
- package/src/modules/login/components/Login/RegisterBox/index.tsx +181 -0
- package/src/modules/login/components/Login/index.tsx +100 -0
- package/src/modules/login/i18n.ts +217 -0
- package/src/modules/login/index.tsx +113 -0
- package/src/modules/login/style.css +3 -0
- package/src/modules/login/useServices.ts +53 -0
- package/src/modules/login/utils.ts +42 -0
- package/src/modules/modelManage/ConfigDrawer.tsx +267 -0
- package/src/modules/modelManage/ReplaceModal.tsx +113 -0
- package/src/modules/modelManage/assets/empty.png +0 -0
- package/src/modules/modelManage/const.ts +51 -0
- package/src/modules/modelManage/i18n.ts +407 -0
- package/src/modules/modelManage/index.tsx +668 -0
- package/src/modules/modelManage/server.ts +231 -0
- package/src/modules/nodegraph/index.tsx +1 -0
- package/src/modules/search/assets/Icon-history.svg +8 -0
- package/src/modules/search/assets/answerAwartar.png +0 -0
- package/src/modules/search/assets/doc.png +0 -0
- package/src/modules/search/assets/genera.gif +0 -0
- package/src/modules/search/assets/icon-robot.svg +9 -0
- package/src/modules/search/assets/icon-search-bar.svg +14 -0
- package/src/modules/search/assets/icon-sub-title.svg +3 -0
- package/src/modules/search/assets/icon-title.svg +9 -0
- package/src/modules/search/assets/icon-zoomOut.svg +9 -0
- package/src/modules/search/assets/iconAi.svg +9 -0
- package/src/modules/search/assets/pdf.png +0 -0
- package/src/modules/search/assets/ppt.png +0 -0
- package/src/modules/search/assets/search.svg +3 -0
- package/src/modules/search/assets/selected.svg +4 -0
- package/src/modules/search/assets/txt.png +0 -0
- package/src/modules/search/assets/xls.png +0 -0
- package/src/modules/search/components/AssisSelect.tsx +137 -0
- package/src/modules/search/components/Editor/ChatViewEditor.tsx +261 -0
- package/src/modules/search/components/Editor/aichat.css +1 -0
- package/src/modules/search/components/Editor/constant.ts +13 -0
- package/src/modules/search/components/Editor/index.tsx +113 -0
- package/src/modules/search/components/Editor/plugins/autofomatRules.ts +332 -0
- package/src/modules/search/components/Editor/plugins/convertImgPlugins.tsx +20 -0
- package/src/modules/search/components/Editor/plugins/createIndexes.tsx +38 -0
- package/src/modules/search/components/Editor/plugins/displayer.ts +298 -0
- package/src/modules/search/components/Editor/plugins/imageClick.tsx +32 -0
- package/src/modules/search/components/Editor/plugins/myplugin.tsx +98 -0
- package/src/modules/search/components/Editor/ui/avatar.tsx +19 -0
- package/src/modules/search/components/Editor/ui/blockquote-element.tsx +21 -0
- package/src/modules/search/components/Editor/ui/button.tsx +58 -0
- package/src/modules/search/components/Editor/ui/calendar.tsx +68 -0
- package/src/modules/search/components/Editor/ui/caption.tsx +46 -0
- package/src/modules/search/components/Editor/ui/checkbox.tsx +27 -0
- package/src/modules/search/components/Editor/ui/code-block-combobox.tsx +188 -0
- package/src/modules/search/components/Editor/ui/code-block-element.css +434 -0
- package/src/modules/search/components/Editor/ui/code-block-element.tsx +39 -0
- package/src/modules/search/components/Editor/ui/code-leaf.tsx +24 -0
- package/src/modules/search/components/Editor/ui/code-line-element.tsx +10 -0
- package/src/modules/search/components/Editor/ui/code-syntax-leaf.tsx +21 -0
- package/src/modules/search/components/Editor/ui/column-element.tsx +30 -0
- package/src/modules/search/components/Editor/ui/column-group-element.tsx +94 -0
- package/src/modules/search/components/Editor/ui/command.tsx +75 -0
- package/src/modules/search/components/Editor/ui/comment-avatar.tsx +22 -0
- package/src/modules/search/components/Editor/ui/comment-create-form.tsx +37 -0
- package/src/modules/search/components/Editor/ui/comment-item.tsx +74 -0
- package/src/modules/search/components/Editor/ui/comment-leaf.tsx +49 -0
- package/src/modules/search/components/Editor/ui/comment-more-dropdown.tsx +42 -0
- package/src/modules/search/components/Editor/ui/comment-reply-items.tsx +22 -0
- package/src/modules/search/components/Editor/ui/comment-resolve-button.tsx +32 -0
- package/src/modules/search/components/Editor/ui/comment-value.tsx +34 -0
- package/src/modules/search/components/Editor/ui/comments-popover.tsx +63 -0
- package/src/modules/search/components/Editor/ui/date-element.tsx +83 -0
- package/src/modules/search/components/Editor/ui/dialog.tsx +63 -0
- package/src/modules/search/components/Editor/ui/draggable.tsx +177 -0
- package/src/modules/search/components/Editor/ui/dropdown-menu.tsx +180 -0
- package/src/modules/search/components/Editor/ui/emoji-input-element.tsx +85 -0
- package/src/modules/search/components/Editor/ui/excalidraw-element.tsx +28 -0
- package/src/modules/search/components/Editor/ui/fixed-toolbar-buttons.tsx +76 -0
- package/src/modules/search/components/Editor/ui/fixed-toolbar.tsx +8 -0
- package/src/modules/search/components/Editor/ui/floating-toolbar-buttons.tsx +51 -0
- package/src/modules/search/components/Editor/ui/floating-toolbar.tsx +77 -0
- package/src/modules/search/components/Editor/ui/heading-element.tsx +48 -0
- package/src/modules/search/components/Editor/ui/highlight-leaf.tsx +17 -0
- package/src/modules/search/components/Editor/ui/hr-element.tsx +30 -0
- package/src/modules/search/components/Editor/ui/icons.tsx +267 -0
- package/src/modules/search/components/Editor/ui/image-element.tsx +74 -0
- package/src/modules/search/components/Editor/ui/inline-combobox.tsx +368 -0
- package/src/modules/search/components/Editor/ui/input.tsx +25 -0
- package/src/modules/search/components/Editor/ui/insert-dropdown-menu.tsx +218 -0
- package/src/modules/search/components/Editor/ui/kbd-leaf.tsx +20 -0
- package/src/modules/search/components/Editor/ui/link-element.tsx +29 -0
- package/src/modules/search/components/Editor/ui/link-floating-toolbar.tsx +161 -0
- package/src/modules/search/components/Editor/ui/list-element.tsx +30 -0
- package/src/modules/search/components/Editor/ui/mark-toolbar-button.tsx +24 -0
- package/src/modules/search/components/Editor/ui/media-embed-element.tsx +133 -0
- package/src/modules/search/components/Editor/ui/media-popover.tsx +97 -0
- package/src/modules/search/components/Editor/ui/mention-element.tsx +43 -0
- package/src/modules/search/components/Editor/ui/mention-input-element.tsx +141 -0
- package/src/modules/search/components/Editor/ui/mode-dropdown-menu.tsx +93 -0
- package/src/modules/search/components/Editor/ui/more-dropdown-menu.tsx +67 -0
- package/src/modules/search/components/Editor/ui/paragraph-element.tsx +4 -0
- package/src/modules/search/components/Editor/ui/placeholder.tsx +52 -0
- package/src/modules/search/components/Editor/ui/popover.tsx +32 -0
- package/src/modules/search/components/Editor/ui/resizable.tsx +66 -0
- package/src/modules/search/components/Editor/ui/separator.tsx +25 -0
- package/src/modules/search/components/Editor/ui/style.less +12 -0
- package/src/modules/search/components/Editor/ui/table-cell-element.tsx +143 -0
- package/src/modules/search/components/Editor/ui/table-element.tsx +243 -0
- package/src/modules/search/components/Editor/ui/table-row-element.tsx +22 -0
- package/src/modules/search/components/Editor/ui/tableValue.tsx +135 -0
- package/src/modules/search/components/Editor/ui/todo-list-element.tsx +43 -0
- package/src/modules/search/components/Editor/ui/toggle-element.tsx +31 -0
- package/src/modules/search/components/Editor/ui/toolbar.tsx +157 -0
- package/src/modules/search/components/Editor/ui/tooltip.tsx +65 -0
- package/src/modules/search/components/Editor/ui/turn-into-dropdown-menu.tsx +160 -0
- package/src/modules/search/components/Editor/ui/with-draggables.tsx +175 -0
- package/src/modules/search/components/FileList.tsx +287 -0
- package/src/modules/search/components/ImageGroupView/index.tsx +85 -0
- package/src/modules/search/components/ResultContent.tsx +232 -0
- package/src/modules/search/components/SearchInput.tsx +232 -0
- package/src/modules/search/components/SearchLanding.tsx +74 -0
- package/src/modules/search/components/SearchView.tsx +563 -0
- package/src/modules/search/components/SimpleEditor.tsx +158 -0
- package/src/modules/search/components/SimpleFileList.tsx +215 -0
- package/src/modules/search/index.tsx +10 -0
- package/src/modules/search/reademe.md +1 -0
- package/src/modules/search/servers/apis.tsx +19 -0
- package/src/modules/search/servers/index.ts +184 -0
- package/src/modules/search/style.less +503 -0
- package/src/modules/search/type.ts +22 -0
- package/src/modules/search/utils.ts +34 -0
- package/src/modules/sensitive/i18n.ts +391 -0
- package/src/modules/sensitive/index.tsx +604 -0
- package/src/modules/sensitive/sensitiveEditor.tsx +543 -0
- package/src/modules/sensitive/server.ts +197 -0
- package/src/modules/sensitiveId/AutoTag.tsx +311 -0
- package/src/modules/sensitiveId/UploadModal.tsx +181 -0
- package/src/modules/sensitiveId/VirtualWrap.tsx +125 -0
- package/src/modules/sensitiveId/index.tsx +253 -0
- package/src/modules/sensitiveId/server.ts +142 -0
- package/src/modules/streamFilesReader/GientechStreamReader.tsx +1658 -0
- package/src/modules/streamFilesReader/components/Header/Toolbar.tsx +0 -0
- package/src/modules/streamFilesReader/components/Header/index.tsx +297 -0
- package/src/modules/streamFilesReader/index.tsx +3 -0
- package/src/style.css +6 -0
- package/src/type.d.ts +0 -0
- package/src/utils/commonFn.tsx +153 -0
- package/src/utils/decryptApiKey.ts +40 -0
- package/src/utils/gientechCommon/components/AppError.tsx +32 -0
- package/src/utils/gientechCommon/components/AppLoading.tsx +75 -0
- package/src/utils/gientechCommon/components/DeleteModal.tsx +75 -0
- package/src/utils/gientechCommon/components/DisplayError.tsx +33 -0
- package/src/utils/gientechCommon/components/DisplayLoading.tsx +38 -0
- package/src/utils/gientechCommon/components/FeedBackModal.tsx +319 -0
- package/src/utils/gientechCommon/components/FileCardCommon.tsx +82 -0
- package/src/utils/gientechCommon/components/FileManager/index.tsx +418 -0
- package/src/utils/gientechCommon/components/FileManager/style.css +5 -0
- package/src/utils/gientechCommon/components/Messages/GientechNewChatWelcome.tsx +583 -0
- package/src/utils/gientechCommon/components/Messages/ReferenceCard.tsx +359 -0
- package/src/utils/gientechCommon/components/Messages/RetriveItem.tsx +245 -0
- package/src/utils/gientechCommon/components/Messages/WebRetriveItem.tsx +209 -0
- package/src/utils/gientechCommon/components/Messages/defaultBot.png +0 -0
- package/src/utils/gientechCommon/components/Messages/defaultStyleSet.tsx +148 -0
- package/src/utils/gientechCommon/components/Messages/defaultWeLogo.svg +14 -0
- package/src/utils/gientechCommon/components/RenameModal.tsx +86 -0
- package/src/utils/gientechCommon/components/style.less +11 -0
- package/src/utils/gientechCommon/configs/commonConfig.ts +2 -0
- package/src/utils/gientechCommon/configs/senderConfig.ts +0 -0
- package/src/utils/gientechCommon/configs/stylesConfig.ts +142 -0
- package/src/utils/gientechCommon/hooks/AichatUseController.tsx +761 -0
- package/src/utils/gientechCommon/hooks/style.less +8 -0
- package/src/utils/gientechCommon/hooks/useFileDisplayTools.tsx +352 -0
- package/src/utils/gientechCommon/hooks/useFileManager.ts +169 -0
- package/src/utils/gientechCommon/slate/converters/deserializers.ts +763 -0
- package/src/utils/gientechCommon/slate/converters/mockData.ts +232 -0
- package/src/utils/gientechCommon/slate/converters/slateConverters.ts +258 -0
- package/src/utils/gientechCommon/slate/richElements/index.tsx +499 -0
- package/src/utils/gientechCommon/utils/fileUtils.ts +86 -0
- package/src/utils/gientechCommon/utils/index.ts +386 -0
- package/src/utils/gientechCommon/utils/request.ts +37 -0
- package/src/utils/gientechCommon/utils/serverFn.ts +172 -0
- package/src/utils/index.tsx +186 -0
- package/src/utils/testconfigs/demologin/index.tsx +32 -0
- package/src/utils/testconfigs/index.ts +66 -0
- package/src/vite-env.d.ts +49 -0
- package/stats.html +4949 -0
- package/tailwind.config.js +170 -0
- package/tsconfig.app.json +31 -0
- package/tsconfig.app.tsbuildinfo +11 -0
- package/tsconfig.json +17 -0
- package/tsconfig.node.json +23 -0
- package/tsconfig.node.tsbuildinfo +1 -0
- package/vite.config.app.ts +91 -0
- package/vite.config.ts +238 -0
- package/assets/index-BIEKgWu0.js +0 -27
- package/assets/index-C1tyXsqQ.js +0 -943
- package/assets/index-CzZQWA2P.js +0 -1
- package/assets/index-DPA1HCWQ.js +0 -1372
- package/assets/index-DPyRygOA.js +0 -745
- package/assets/plus-BICgMvz9.js +0 -6
- package/assets/search-CD5YKija.js +0 -6
- package/assets/style2.css +0 -1
- package/assets/style5.css +0 -1
- package/chat.js +0 -1
- package/chatCompare.js +0 -1
- package/database.js +0 -20
- package/index.js +0 -1
- package/modelManage.js +0 -1
- package/streamFilesReader.js +0 -1
- /package/{assets → dist/assets}/Doris.png +0 -0
- /package/{assets → dist/assets}/PostgreSQL.png +0 -0
- /package/{assets → dist/assets}/SQLServer.png +0 -0
- /package/{assets → dist/assets}/empty.png +0 -0
- /package/{assets → dist/assets}/homeBg.png +0 -0
- /package/{assets → dist/assets}/index-CpW6Dhpp.js +0 -0
- /package/{assets → dist/assets}/left.jpg +0 -0
- /package/{assets → dist/assets}/logoImg.png +0 -0
- /package/{assets → dist/assets}/style.css +0 -0
- /package/{assets → dist/assets}/style3.css +0 -0
- /package/{assets → dist/assets}/style4.css +0 -0
- /package/{assets → dist/assets}/worker-BbpylX7l.js +0 -0
- /package/{assistantConfig.d.ts → dist/assistantConfig.d.ts} +0 -0
- /package/{chat.d.ts → dist/chat.d.ts} +0 -0
- /package/{chatCompare.d.ts → dist/chatCompare.d.ts} +0 -0
- /package/{database.d.ts → dist/database.d.ts} +0 -0
- /package/{databaseId.d.ts → dist/databaseId.d.ts} +0 -0
- /package/{databaseTable.d.ts → dist/databaseTable.d.ts} +0 -0
- /package/{icons → dist/icons}/answerAwartar.png +0 -0
- /package/{icons → dist/icons}/docx-file.png +0 -0
- /package/{icons → dist/icons}/folder.png +0 -0
- /package/{icons → dist/icons}/html.png +0 -0
- /package/{icons → dist/icons}/image.png +0 -0
- /package/{icons → dist/icons}/jpg-file.png +0 -0
- /package/{icons → dist/icons}/json.png +0 -0
- /package/{icons → dist/icons}/md.png +0 -0
- /package/{icons → dist/icons}/pdf.png +0 -0
- /package/{icons → dist/icons}/pptx.png +0 -0
- /package/{icons → dist/icons}/questionAwartar.png +0 -0
- /package/{icons → dist/icons}/sheets.png +0 -0
- /package/{icons → dist/icons}/txt.png +0 -0
- /package/{icons → dist/icons}/xlsx.png +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{modelManage.d.ts → dist/modelManage.d.ts} +0 -0
- /package/{sensitive.d.ts → dist/sensitive.d.ts} +0 -0
- /package/{streamFilesReader.d.ts → dist/streamFilesReader.d.ts} +0 -0
- /package/{vite.svg → dist/vite.svg} +0 -0
|
@@ -0,0 +1,1658 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect, useRef, useMemo } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import { Fviewer, parseFile, registerPDFWorker } from '@mxmweb/fviewer';
|
|
5
|
+
import type { ParseResult } from '@mxmweb/fviewer';
|
|
6
|
+
import Header from './components/Header';
|
|
7
|
+
export { registerPDFWorker };
|
|
8
|
+
import type { Annotation, ToolsConfig } from '@mxmweb/fviewer';
|
|
9
|
+
|
|
10
|
+
import { Styles } from '@mxmweb/zui';
|
|
11
|
+
// Stream接口参数类型
|
|
12
|
+
interface StreamRequestParams {
|
|
13
|
+
convertedFilePath: string;
|
|
14
|
+
pageNo: number;
|
|
15
|
+
pageSize: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Markdown完整内容缓存类型
|
|
19
|
+
interface MarkdownContentCache {
|
|
20
|
+
data: string; // markdown完整内容
|
|
21
|
+
timestamp: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// GientechStreamReader组件属性接口
|
|
25
|
+
export interface GientechStreamReaderProps {
|
|
26
|
+
// 文件相关
|
|
27
|
+
convertedFilePath: string;
|
|
28
|
+
csrfToken?: string;
|
|
29
|
+
fileName?: string;
|
|
30
|
+
fileType: string;
|
|
31
|
+
initialPage?: number;
|
|
32
|
+
initialZoom?: number; // 初始缩放比例
|
|
33
|
+
totalPages?: number; // 添加总页数参数
|
|
34
|
+
annotations?: (Annotation | any)[]; // 统一的标注数据
|
|
35
|
+
|
|
36
|
+
// 用户信息
|
|
37
|
+
userName?: string;
|
|
38
|
+
userId?: string;
|
|
39
|
+
pageSize?: number;
|
|
40
|
+
|
|
41
|
+
// API配置
|
|
42
|
+
streamApiUrl?: string;
|
|
43
|
+
authorization?: string;
|
|
44
|
+
|
|
45
|
+
// 事件回调
|
|
46
|
+
eventsEmit?: (name: string, data?: any, innerFn?: any) => void;
|
|
47
|
+
|
|
48
|
+
// 工具配置 - 用户可自定义,与默认配置合并
|
|
49
|
+
tools?: Partial<ToolsConfig>;
|
|
50
|
+
|
|
51
|
+
// 样式配置
|
|
52
|
+
styles?: Styles;
|
|
53
|
+
|
|
54
|
+
// 自定义组件
|
|
55
|
+
customComponents?: {
|
|
56
|
+
LoadingComponent?: React.ComponentType<{
|
|
57
|
+
status: string;
|
|
58
|
+
theme: Styles;
|
|
59
|
+
}>;
|
|
60
|
+
ErrorComponent?: React.ComponentType<{
|
|
61
|
+
error: string;
|
|
62
|
+
theme: Styles;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// 自定义类名
|
|
67
|
+
className?: string;
|
|
68
|
+
headerClass?: string;
|
|
69
|
+
contentClass?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 页面缓存类型 - 重新设计支持分页chunk缓存
|
|
73
|
+
interface PageChunkCache {
|
|
74
|
+
[chunkKey: string]: {
|
|
75
|
+
data: ArrayBuffer;
|
|
76
|
+
pages: number[]; // 这个chunk包含的页面范围
|
|
77
|
+
timestamp: number;
|
|
78
|
+
totalPages?: number; // 从响应头获取的总页数
|
|
79
|
+
pdfDocument?: any; // 缓存解析后的PDF文档
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 单个页面缓存类型
|
|
84
|
+
interface PageCache {
|
|
85
|
+
[pageNo: number]: {
|
|
86
|
+
data: ArrayBuffer;
|
|
87
|
+
timestamp: number;
|
|
88
|
+
pdfDocument?: any; // 缓存解析后的PDF文档
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 样式组件
|
|
93
|
+
const ReaderContainer = styled.div<{ $theme: Styles }>`
|
|
94
|
+
display: flex;
|
|
95
|
+
flex-direction: column;
|
|
96
|
+
height: 100%;
|
|
97
|
+
width: 100%;
|
|
98
|
+
background: ${props => props.$theme.colors.background};
|
|
99
|
+
border: 1px solid ${props => props.$theme.colors.border};
|
|
100
|
+
border-radius: ${props => props.$theme.space.radius};
|
|
101
|
+
overflow: hidden;
|
|
102
|
+
min-height: 0;
|
|
103
|
+
position: relative; // 添加相对定位,用于loading遮罩的绝对定位
|
|
104
|
+
|
|
105
|
+
/* 添加动画样式 */
|
|
106
|
+
@keyframes spin {
|
|
107
|
+
0% {
|
|
108
|
+
transform: rotate(0deg);
|
|
109
|
+
}
|
|
110
|
+
100% {
|
|
111
|
+
transform: rotate(360deg);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
`;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 默认文件加载动画组件
|
|
118
|
+
* 提供美观的文件加载动画效果,支持状态文本显示
|
|
119
|
+
*/
|
|
120
|
+
const DefaultLoadingComponent: React.FC<{
|
|
121
|
+
status: string;
|
|
122
|
+
theme: Styles;
|
|
123
|
+
}> = ({ status, theme }) => {
|
|
124
|
+
return (
|
|
125
|
+
<div
|
|
126
|
+
style={{
|
|
127
|
+
display: 'flex',
|
|
128
|
+
flexDirection: 'column',
|
|
129
|
+
alignItems: 'center',
|
|
130
|
+
justifyContent: 'center',
|
|
131
|
+
height: '100%',
|
|
132
|
+
padding: '40px',
|
|
133
|
+
background: theme.colors.background,
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
{/* 文件图标动画 */}
|
|
137
|
+
<div
|
|
138
|
+
style={{
|
|
139
|
+
position: 'relative',
|
|
140
|
+
width: '80px',
|
|
141
|
+
height: '80px',
|
|
142
|
+
marginBottom: '24px',
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
{/* 文件图标背景 */}
|
|
146
|
+
<div
|
|
147
|
+
style={{
|
|
148
|
+
width: '60px',
|
|
149
|
+
height: '80px',
|
|
150
|
+
background: theme.colors.primary,
|
|
151
|
+
borderRadius: '8px 8px 0 0',
|
|
152
|
+
position: 'relative',
|
|
153
|
+
margin: '0 auto',
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
{/* 文件折角 */}
|
|
157
|
+
<div
|
|
158
|
+
style={{
|
|
159
|
+
position: 'absolute',
|
|
160
|
+
top: '0',
|
|
161
|
+
right: '0',
|
|
162
|
+
width: '0',
|
|
163
|
+
height: '0',
|
|
164
|
+
borderStyle: 'solid',
|
|
165
|
+
borderWidth: '0 20px 20px 0',
|
|
166
|
+
borderColor: `transparent ${theme.colors.background} transparent transparent`,
|
|
167
|
+
}}
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
{/* 加载动画圆点 */}
|
|
172
|
+
<div
|
|
173
|
+
style={{
|
|
174
|
+
position: 'absolute',
|
|
175
|
+
top: '50%',
|
|
176
|
+
left: '50%',
|
|
177
|
+
transform: 'translate(-50%, -50%)',
|
|
178
|
+
width: '20px',
|
|
179
|
+
height: '20px',
|
|
180
|
+
borderRadius: '50%',
|
|
181
|
+
background: theme.colors.background,
|
|
182
|
+
animation: 'pulse 1.5s ease-in-out infinite',
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
{/* 状态文本 */}
|
|
188
|
+
<div
|
|
189
|
+
style={{
|
|
190
|
+
fontSize: '16px',
|
|
191
|
+
fontWeight: '500',
|
|
192
|
+
color: theme.colors.text,
|
|
193
|
+
marginBottom: '8px',
|
|
194
|
+
textAlign: 'center',
|
|
195
|
+
}}
|
|
196
|
+
>
|
|
197
|
+
{status}
|
|
198
|
+
</div>
|
|
199
|
+
|
|
200
|
+
{/* 进度指示器 */}
|
|
201
|
+
<div
|
|
202
|
+
style={{
|
|
203
|
+
width: '200px',
|
|
204
|
+
height: '4px',
|
|
205
|
+
background: theme.colors.border,
|
|
206
|
+
borderRadius: '2px',
|
|
207
|
+
overflow: 'hidden',
|
|
208
|
+
position: 'relative',
|
|
209
|
+
}}
|
|
210
|
+
>
|
|
211
|
+
<div
|
|
212
|
+
style={{
|
|
213
|
+
width: '30%',
|
|
214
|
+
height: '100%',
|
|
215
|
+
background: theme.colors.primary,
|
|
216
|
+
borderRadius: '2px',
|
|
217
|
+
animation: 'loading-progress 2s ease-in-out infinite',
|
|
218
|
+
}}
|
|
219
|
+
/>
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
{/* 动画样式 */}
|
|
223
|
+
<style>{`
|
|
224
|
+
@keyframes pulse {
|
|
225
|
+
0%, 100% {
|
|
226
|
+
opacity: 1;
|
|
227
|
+
transform: translate(-50%, -50%) scale(1);
|
|
228
|
+
}
|
|
229
|
+
50% {
|
|
230
|
+
opacity: 0.5;
|
|
231
|
+
transform: translate(-50%, -50%) scale(1.1);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
@keyframes loading-progress {
|
|
236
|
+
0% {
|
|
237
|
+
transform: translateX(-100%);
|
|
238
|
+
}
|
|
239
|
+
50% {
|
|
240
|
+
transform: translateX(0%);
|
|
241
|
+
}
|
|
242
|
+
100% {
|
|
243
|
+
transform: translateX(100%);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
`}</style>
|
|
247
|
+
</div>
|
|
248
|
+
);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// 移除未使用的 LoadingContainer
|
|
252
|
+
|
|
253
|
+
const ErrorContainer = styled.div<{ $theme: Styles }>`
|
|
254
|
+
display: flex;
|
|
255
|
+
flex-direction: column;
|
|
256
|
+
align-items: center;
|
|
257
|
+
justify-content: center;
|
|
258
|
+
height: 100%;
|
|
259
|
+
color: ${props => props.$theme.colors.error};
|
|
260
|
+
text-align: center;
|
|
261
|
+
padding: 20px;
|
|
262
|
+
`;
|
|
263
|
+
|
|
264
|
+
// 默认配置
|
|
265
|
+
const DEFAULT_STREAM_API_URL = 'http://10.15.12.13:9005/proxy/index/knowledgeBase/file/stream';
|
|
266
|
+
const CACHE_EXPIRY_TIME = 5 * 60 * 1000; // 5分钟缓存过期
|
|
267
|
+
|
|
268
|
+
// 默认主题
|
|
269
|
+
const defaultTheme: Styles = {
|
|
270
|
+
colors: {
|
|
271
|
+
primary: '#007bff',
|
|
272
|
+
secondary: '#6c757d',
|
|
273
|
+
success: '#008000',
|
|
274
|
+
warning: '#FFA500',
|
|
275
|
+
error: '#FF0000',
|
|
276
|
+
info: '#0000FF',
|
|
277
|
+
background: '#f8f9fa',
|
|
278
|
+
text: '#343a40',
|
|
279
|
+
border: '#dee2e6',
|
|
280
|
+
disabled: '#808080',
|
|
281
|
+
disabledBackground: '#F5F5F5',
|
|
282
|
+
disabledText: '#808080',
|
|
283
|
+
},
|
|
284
|
+
space: {
|
|
285
|
+
sidebar: '12px',
|
|
286
|
+
size: '12px',
|
|
287
|
+
radius: '4px',
|
|
288
|
+
padding: '8px 12px',
|
|
289
|
+
margin: '4px',
|
|
290
|
+
shadow: '0 2px 4px rgba(0,0,0,0.1)',
|
|
291
|
+
lineHeight: '1.5',
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* 将 ArrayBuffer 按文本解码:优先 UTF-8,若出现大量替换字符则尝试 GB18030(常见中文编码),避免中文 txt 显示乱码
|
|
297
|
+
*/
|
|
298
|
+
function decodeArrayBufferAsText(buffer: ArrayBuffer): string {
|
|
299
|
+
const utf8 = new TextDecoder('utf-8', { fatal: false }).decode(buffer);
|
|
300
|
+
const replacementCount = (utf8.match(/\uFFFD/g) || []).length;
|
|
301
|
+
if (replacementCount === 0 || utf8.length < 20) return utf8;
|
|
302
|
+
try {
|
|
303
|
+
const gb = new TextDecoder('gb18030', { fatal: false }).decode(buffer);
|
|
304
|
+
const gbReplacement = (gb.match(/\uFFFD/g) || []).length;
|
|
305
|
+
return gbReplacement < replacementCount ? gb : utf8;
|
|
306
|
+
} catch {
|
|
307
|
+
return utf8;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* GientechStreamReader组件
|
|
313
|
+
* 基于stream接口的文件读取器,支持分页获取PDF数据并渲染
|
|
314
|
+
* 遵循adopter_develop规范,使用HOC模式封装core组件
|
|
315
|
+
*
|
|
316
|
+
* @param props - 组件属性
|
|
317
|
+
* @returns GientechStreamReader组件
|
|
318
|
+
*/
|
|
319
|
+
const GientechStreamReader: React.FC<GientechStreamReaderProps> = ({
|
|
320
|
+
convertedFilePath,
|
|
321
|
+
fileName,
|
|
322
|
+
fileType,
|
|
323
|
+
csrfToken,
|
|
324
|
+
initialPage = 1,
|
|
325
|
+
initialZoom = 1, // 默认初始缩放比例为1
|
|
326
|
+
totalPages: userTotalPages, // 接收用户传入的总页数
|
|
327
|
+
annotations = [],
|
|
328
|
+
pageSize = 5, // 更新默认值为5,与StreamPreview一致
|
|
329
|
+
streamApiUrl = DEFAULT_STREAM_API_URL,
|
|
330
|
+
authorization,
|
|
331
|
+
eventsEmit = () => {},
|
|
332
|
+
tools: userTools, // 接收用户传入的工具配置
|
|
333
|
+
styles,
|
|
334
|
+
customComponents,
|
|
335
|
+
className,
|
|
336
|
+
headerClass,
|
|
337
|
+
contentClass,
|
|
338
|
+
}) => {
|
|
339
|
+
// 状态管理
|
|
340
|
+
const [isLoading, setIsLoading] = useState(true); // 初始为loading状态
|
|
341
|
+
const [loadingStatus, setLoadingStatus] = useState<string>('正在加载文档...'); // 加载提示文本
|
|
342
|
+
const [error, setError] = useState<string | null>(null);
|
|
343
|
+
const [currentPage, setCurrentPage] = useState(initialPage);
|
|
344
|
+
const [totalPages, setTotalPages] = useState(userTotalPages || 0); // 使用用户传入的总页数,不自动覆盖
|
|
345
|
+
const [scale, setScale] = useState(initialZoom);
|
|
346
|
+
const [rotation, setRotation] = useState(0);
|
|
347
|
+
const [pdfDocument, setPdfDocument] = useState<any>(null);
|
|
348
|
+
const [imageContent, setImageContent] = useState<any>(null);
|
|
349
|
+
|
|
350
|
+
// Markdown相关状态
|
|
351
|
+
const [markdownContent, setMarkdownContent] = useState<string>('');
|
|
352
|
+
|
|
353
|
+
// 通用文件内容状态
|
|
354
|
+
const [textContent, setTextContent] = useState<any>(null);
|
|
355
|
+
const [htmlContent, setHtmlContent] = useState<any>(null);
|
|
356
|
+
|
|
357
|
+
// 通用文件缓存状态
|
|
358
|
+
const [genericContentCache, setGenericContentCache] = useState<{
|
|
359
|
+
[key: string]: { content: any; timestamp: number };
|
|
360
|
+
}>({});
|
|
361
|
+
|
|
362
|
+
// 防抖状态 - 防止重复请求
|
|
363
|
+
const isGenericLoadingRef = useRef(false);
|
|
364
|
+
const hasLoadedGenericRef = useRef(false);
|
|
365
|
+
|
|
366
|
+
// 引用
|
|
367
|
+
const pageCache = useRef<PageCache>({});
|
|
368
|
+
const chunkCache = useRef<PageChunkCache>({});
|
|
369
|
+
const markdownContentCache = useRef<MarkdownContentCache | null>(null);
|
|
370
|
+
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
|
371
|
+
const currentPageRef = useRef<number>(initialPage); // 添加ref来跟踪当前页面
|
|
372
|
+
// 调试:跟踪每次渲染计数(必须放在任何条件 return 之前,避免 Hook 次数不一致)
|
|
373
|
+
const renderCountRef = useRef(0);
|
|
374
|
+
renderCountRef.current += 1;
|
|
375
|
+
console.log('[GientechStreamReader] render count:', renderCountRef.current);
|
|
376
|
+
console.log('[GientechStreamReader] props snapshot (early):', {
|
|
377
|
+
fileType,
|
|
378
|
+
currentPage,
|
|
379
|
+
totalPages,
|
|
380
|
+
hasMarkdown: !!markdownContent,
|
|
381
|
+
hasImage: !!imageContent,
|
|
382
|
+
hasText: !!textContent,
|
|
383
|
+
hasHtml: !!htmlContent,
|
|
384
|
+
isLoading,
|
|
385
|
+
error,
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// 使用主题
|
|
389
|
+
const mergedTheme = styles?.theme || defaultTheme;
|
|
390
|
+
|
|
391
|
+
// 当文件类型或文件路径改变时,重置通用加载的防抖/已加载标记,避免影响其它文件类型
|
|
392
|
+
useEffect(() => {
|
|
393
|
+
isGenericLoadingRef.current = false;
|
|
394
|
+
hasLoadedGenericRef.current = false;
|
|
395
|
+
}, [fileType, convertedFilePath]);
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 根据文件类型动态配置工具,并合并用户自定义配置
|
|
399
|
+
*/
|
|
400
|
+
const getToolsConfig = useCallback((): ToolsConfig => {
|
|
401
|
+
const baseTools = {
|
|
402
|
+
annotation: true,
|
|
403
|
+
download: true,
|
|
404
|
+
zoom: true,
|
|
405
|
+
close: true,
|
|
406
|
+
navigation: true,
|
|
407
|
+
rotate: false,
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
let defaultTools: ToolsConfig;
|
|
411
|
+
|
|
412
|
+
switch (fileType) {
|
|
413
|
+
case 'pdf':
|
|
414
|
+
case 'pdf_slides':
|
|
415
|
+
defaultTools = {
|
|
416
|
+
...baseTools,
|
|
417
|
+
annotation: false, // PDF模式关闭标注功能
|
|
418
|
+
download: false, // PDF模式关闭下载功能
|
|
419
|
+
navigation: true, // PDF模式开启翻页导航
|
|
420
|
+
rotate: false, // PDF模式关闭旋转功能
|
|
421
|
+
};
|
|
422
|
+
break;
|
|
423
|
+
case 'image':
|
|
424
|
+
defaultTools = {
|
|
425
|
+
...baseTools,
|
|
426
|
+
annotation: false, // 图片模式关闭标注功能
|
|
427
|
+
download: false, // 图片模式关闭下载功能
|
|
428
|
+
navigation: false, // 图片模式关闭翻页导航
|
|
429
|
+
rotate: true, // 图片模式开启旋转功能
|
|
430
|
+
zoom: true,
|
|
431
|
+
};
|
|
432
|
+
break;
|
|
433
|
+
case 'markdown':
|
|
434
|
+
case 'markdown_table':
|
|
435
|
+
defaultTools = {
|
|
436
|
+
...baseTools,
|
|
437
|
+
annotation: false, // Markdown模式开启标注功能
|
|
438
|
+
download: false, // Markdown模式关闭下载功能
|
|
439
|
+
navigation: false, // Markdown模式关闭翻页导航
|
|
440
|
+
rotate: false, // Markdown模式关闭旋转功能
|
|
441
|
+
zoom: false, // Markdown模式关闭缩放功能
|
|
442
|
+
};
|
|
443
|
+
break;
|
|
444
|
+
case 'text':
|
|
445
|
+
case 'html':
|
|
446
|
+
case 'unknown':
|
|
447
|
+
defaultTools = {
|
|
448
|
+
...baseTools,
|
|
449
|
+
annotation: false, // 其他模式关闭标注功能
|
|
450
|
+
download: false, // 其他模式关闭下载功能
|
|
451
|
+
navigation: false, // 其他模式关闭翻页导航
|
|
452
|
+
rotate: false, // 其他模式关闭旋转功能
|
|
453
|
+
zoom: false, // 其他模式关闭缩放功能
|
|
454
|
+
};
|
|
455
|
+
break;
|
|
456
|
+
default:
|
|
457
|
+
defaultTools = baseTools;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// 合并用户自定义配置,用户配置优先
|
|
461
|
+
if (userTools) {
|
|
462
|
+
return {
|
|
463
|
+
...defaultTools,
|
|
464
|
+
...userTools,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return defaultTools;
|
|
469
|
+
}, [fileType, userTools]);
|
|
470
|
+
|
|
471
|
+
// 获取当前文件类型的工具配置
|
|
472
|
+
const tools = getToolsConfig();
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* 计算chunk的key
|
|
476
|
+
* @param pageNo 页码
|
|
477
|
+
* @param pageSize 页面大小
|
|
478
|
+
* @returns chunk key
|
|
479
|
+
*/
|
|
480
|
+
const getChunkKey = useCallback((pageNo: number, pageSize: number): string => {
|
|
481
|
+
const chunkStart = Math.floor((pageNo - 1) / pageSize) * pageSize + 1;
|
|
482
|
+
return `${chunkStart}-${chunkStart + pageSize - 1}`;
|
|
483
|
+
}, []);
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* 检查页面是否在缓存中,并返回解析后的PDF文档
|
|
487
|
+
* @param pageNo 页码
|
|
488
|
+
* @returns 缓存的PDF文档或null
|
|
489
|
+
*/
|
|
490
|
+
const getCachedPage = useCallback(
|
|
491
|
+
async (pageNo: number): Promise<any | null> => {
|
|
492
|
+
// 根据文件类型决定处理方式
|
|
493
|
+
const isPDF = fileType === 'pdf' || fileType === 'pdf_slides';
|
|
494
|
+
|
|
495
|
+
if (!isPDF) {
|
|
496
|
+
console.log(`文件类型 ${fileType} 不是PDF,跳过缓存检查`);
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
console.log(`检查页面 ${pageNo} 是否在缓存中`);
|
|
501
|
+
|
|
502
|
+
// 先检查单个页面缓存
|
|
503
|
+
const pageCached = pageCache.current[pageNo];
|
|
504
|
+
if (pageCached && Date.now() - pageCached.timestamp < CACHE_EXPIRY_TIME) {
|
|
505
|
+
console.log(`使用单个页面缓存: ${pageNo}`);
|
|
506
|
+
if (pageCached.pdfDocument) {
|
|
507
|
+
console.log(`直接返回缓存的PDF文档: ${pageNo}`);
|
|
508
|
+
return pageCached.pdfDocument;
|
|
509
|
+
}
|
|
510
|
+
// 如果没有缓存的PDF文档,需要重新解析
|
|
511
|
+
return null;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// 检查chunk缓存
|
|
515
|
+
const chunkKey = getChunkKey(pageNo, pageSize);
|
|
516
|
+
const chunkCached = chunkCache.current[chunkKey];
|
|
517
|
+
console.log(
|
|
518
|
+
`检查chunk缓存: ${chunkKey}, 存在: ${!!chunkCached}, 包含页面: ${chunkCached?.pages?.join(', ') || '无'}`
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
if (chunkCached && Date.now() - chunkCached.timestamp < CACHE_EXPIRY_TIME) {
|
|
522
|
+
// 验证页面是否真的在这个chunk中
|
|
523
|
+
if (chunkCached.pages.includes(pageNo)) {
|
|
524
|
+
console.log(`使用chunk缓存: ${pageNo} (chunk: ${chunkKey})`);
|
|
525
|
+
if (chunkCached.pdfDocument) {
|
|
526
|
+
console.log(`直接返回缓存的PDF文档: ${pageNo}`);
|
|
527
|
+
return chunkCached.pdfDocument;
|
|
528
|
+
}
|
|
529
|
+
// 如果没有缓存的PDF文档,需要重新解析
|
|
530
|
+
return null;
|
|
531
|
+
} else {
|
|
532
|
+
console.log(
|
|
533
|
+
`页面 ${pageNo} 不在chunk ${chunkKey} 中,chunk包含: ${chunkCached.pages.join(', ')}`
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
console.log(`页面 ${pageNo} 不在任何缓存中,需要重新请求`);
|
|
539
|
+
return null;
|
|
540
|
+
},
|
|
541
|
+
[pageSize, getChunkKey, fileType]
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* 获取stream数据(仅用于PDF文件)
|
|
546
|
+
* @param pageNo 页码
|
|
547
|
+
* @returns Promise<ArrayBuffer>
|
|
548
|
+
*/
|
|
549
|
+
const fetchStreamData = useCallback(
|
|
550
|
+
async (pageNo: number): Promise<ArrayBuffer> => {
|
|
551
|
+
try {
|
|
552
|
+
// 根据文件类型决定是否传递分页参数
|
|
553
|
+
const isPDF = fileType === 'pdf' || fileType === 'pdf_slides';
|
|
554
|
+
|
|
555
|
+
if (!isPDF) {
|
|
556
|
+
console.log(`文件类型 ${fileType} 不需要分页参数,获取完整内容`);
|
|
557
|
+
throw new Error(`文件类型 ${fileType} 不支持分页加载`);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// 计算需要请求的chunk
|
|
561
|
+
const chunkStart = Math.floor((pageNo - 1) / pageSize) * pageSize + 1;
|
|
562
|
+
const chunkKey = getChunkKey(pageNo, pageSize);
|
|
563
|
+
|
|
564
|
+
console.log(
|
|
565
|
+
`请求PDF chunk数据: ${chunkStart} (包含页面 ${chunkStart}-${chunkStart + pageSize - 1})`
|
|
566
|
+
);
|
|
567
|
+
|
|
568
|
+
const headers: Record<string, string> = {
|
|
569
|
+
'Content-Type': 'application/json',
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
if (authorization) {
|
|
573
|
+
headers['Authorization'] = authorization;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if (csrfToken) {
|
|
577
|
+
headers['X-CSRF-TOKEN-IN'] = csrfToken;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// PDF文件类型传递分页参数
|
|
581
|
+
const requestData = {
|
|
582
|
+
convertedFilePath,
|
|
583
|
+
pageNo: chunkStart, // 使用chunk的起始页
|
|
584
|
+
pageSize,
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
const response = await axios.post<ArrayBuffer>(streamApiUrl, requestData, {
|
|
588
|
+
headers,
|
|
589
|
+
responseType: 'arraybuffer',
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
// 获取响应头中的CSRF Token并触发事件
|
|
593
|
+
const responseCsrfToken =
|
|
594
|
+
response.headers['x-csrf-token-out'] || response.headers['X-CSRF-TOKEN-OUT'];
|
|
595
|
+
if (responseCsrfToken) {
|
|
596
|
+
console.log('获取到响应头中的CSRF Token:', responseCsrfToken);
|
|
597
|
+
eventsEmit('request_finish', responseCsrfToken);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// 缓存chunk数据
|
|
601
|
+
const chunkPages = Array.from({ length: pageSize }, (_, i) => chunkStart + i);
|
|
602
|
+
chunkCache.current[chunkKey] = {
|
|
603
|
+
data: response.data,
|
|
604
|
+
pages: chunkPages,
|
|
605
|
+
timestamp: Date.now(),
|
|
606
|
+
totalPages: userTotalPages, // 始终使用用户传入的总页数,不覆盖
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
console.log(
|
|
610
|
+
`缓存PDF chunk数据: ${chunkKey}, 包含页面: ${chunkPages.join(', ')}, 请求的页面: ${pageNo}`
|
|
611
|
+
);
|
|
612
|
+
console.log(`当前所有缓存:`, Object.keys(chunkCache.current));
|
|
613
|
+
|
|
614
|
+
return response.data;
|
|
615
|
+
} catch (error: any) {
|
|
616
|
+
console.error('获取PDF stream数据失败:', error);
|
|
617
|
+
throw new Error(`PDF请求失败: ${error.response?.status || '网络错误'}`);
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
[
|
|
621
|
+
streamApiUrl,
|
|
622
|
+
convertedFilePath,
|
|
623
|
+
pageSize,
|
|
624
|
+
authorization,
|
|
625
|
+
getChunkKey,
|
|
626
|
+
userTotalPages,
|
|
627
|
+
totalPages,
|
|
628
|
+
fileType,
|
|
629
|
+
eventsEmit,
|
|
630
|
+
]
|
|
631
|
+
);
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* 加载PDF文档(仅用于PDF文件类型)
|
|
635
|
+
* @param pageNo 页码
|
|
636
|
+
* @param isInitialLoad 是否为初始加载
|
|
637
|
+
*/
|
|
638
|
+
const loadPDFDocument = useCallback(
|
|
639
|
+
async (pageNo: number, isInitialLoad: boolean = false) => {
|
|
640
|
+
if (!pageNo) return;
|
|
641
|
+
|
|
642
|
+
// 根据文件类型决定处理方式
|
|
643
|
+
const isPDF = fileType === 'pdf' || fileType === 'pdf_slides';
|
|
644
|
+
|
|
645
|
+
if (!isPDF) {
|
|
646
|
+
console.log(`文件类型 ${fileType} 不是PDF,跳过PDF加载逻辑`);
|
|
647
|
+
return null; // 直接返回,不进行任何操作
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
try {
|
|
651
|
+
if (isInitialLoad) {
|
|
652
|
+
setIsLoading(true);
|
|
653
|
+
setLoadingStatus('正在加载PDF文档...');
|
|
654
|
+
} else {
|
|
655
|
+
setIsLoading(true);
|
|
656
|
+
setLoadingStatus(`正在加载第 ${pageNo} 页...`);
|
|
657
|
+
}
|
|
658
|
+
setError(null);
|
|
659
|
+
|
|
660
|
+
console.log(`开始加载PDF页面: ${pageNo}, 初始加载: ${isInitialLoad}`);
|
|
661
|
+
|
|
662
|
+
// 先检查缓存
|
|
663
|
+
const cachedPdf = await getCachedPage(pageNo);
|
|
664
|
+
if (cachedPdf) {
|
|
665
|
+
// 如果缓存中有PDF文档,直接使用,无需重新解析
|
|
666
|
+
console.log(`使用缓存的PDF文档: ${pageNo}`);
|
|
667
|
+
setPdfDocument(cachedPdf);
|
|
668
|
+
setIsLoading(false);
|
|
669
|
+
setLoadingStatus('');
|
|
670
|
+
console.log(`页面 ${pageNo} 加载完成(使用缓存)`);
|
|
671
|
+
return cachedPdf;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// 获取stream数据
|
|
675
|
+
const streamData = await fetchStreamData(pageNo);
|
|
676
|
+
|
|
677
|
+
// 使用fileParser解析数据
|
|
678
|
+
const parseResult: ParseResult = await parseFile(streamData, {
|
|
679
|
+
fileName: fileName || 'Stream文档',
|
|
680
|
+
fileType: 'pdf',
|
|
681
|
+
token: authorization,
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
if (parseResult.error) {
|
|
685
|
+
throw new Error(parseResult.error);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
if (parseResult.type !== 'pdf' || !parseResult.content?.document) {
|
|
689
|
+
throw new Error('解析结果不是有效的PDF文档');
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
const pdf = parseResult.content.document;
|
|
693
|
+
console.log('设置PDF文档:', pdf);
|
|
694
|
+
console.log('PDF文档类型:', typeof pdf);
|
|
695
|
+
console.log(
|
|
696
|
+
'PDF文档方法:',
|
|
697
|
+
pdf ? Object.getOwnPropertyNames(Object.getPrototypeOf(pdf)) : '无文档'
|
|
698
|
+
);
|
|
699
|
+
console.log('PDF文档页数:', pdf ? pdf.numPages : '无页数');
|
|
700
|
+
console.log('当前请求的页面:', pageNo);
|
|
701
|
+
console.log('PDF文档包含的页面范围:', pdf ? `1-${pdf.numPages}` : '无页数');
|
|
702
|
+
setPdfDocument(pdf);
|
|
703
|
+
|
|
704
|
+
// 缓存解析后的PDF文档
|
|
705
|
+
const chunkKey = getChunkKey(pageNo, pageSize);
|
|
706
|
+
if (chunkCache.current[chunkKey]) {
|
|
707
|
+
chunkCache.current[chunkKey].pdfDocument = pdf;
|
|
708
|
+
console.log(`缓存PDF文档到chunk: ${chunkKey}`);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// 设置总页数 - 优先使用用户传入的总页数,如果没有传入则使用PDF文档的实际页数
|
|
712
|
+
if (userTotalPages) {
|
|
713
|
+
console.log(`使用用户传入的总页数: ${userTotalPages}`);
|
|
714
|
+
setTotalPages(userTotalPages);
|
|
715
|
+
} else if (pdf && pdf.numPages) {
|
|
716
|
+
const actualTotalPages = pdf.numPages;
|
|
717
|
+
console.log(`用户未传入总页数,从PDF文档获取实际总页数: ${actualTotalPages}`);
|
|
718
|
+
setTotalPages(actualTotalPages);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
setIsLoading(false);
|
|
722
|
+
setLoadingStatus('');
|
|
723
|
+
|
|
724
|
+
console.log(`页面 ${pageNo} 加载完成`);
|
|
725
|
+
return pdf;
|
|
726
|
+
} catch (error: any) {
|
|
727
|
+
console.error('PDF加载失败:', error);
|
|
728
|
+
setError(error.message || 'PDF加载失败,请稍后重试');
|
|
729
|
+
setIsLoading(false);
|
|
730
|
+
setLoadingStatus('');
|
|
731
|
+
throw error;
|
|
732
|
+
}
|
|
733
|
+
},
|
|
734
|
+
[
|
|
735
|
+
fetchStreamData,
|
|
736
|
+
fileName,
|
|
737
|
+
authorization,
|
|
738
|
+
totalPages,
|
|
739
|
+
getCachedPage,
|
|
740
|
+
getChunkKey,
|
|
741
|
+
pageSize,
|
|
742
|
+
fileType,
|
|
743
|
+
]
|
|
744
|
+
);
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* 检查页面是否在缓存中(用于调试)
|
|
748
|
+
*/
|
|
749
|
+
const isPageInCache = useCallback(
|
|
750
|
+
(pageNo: number): boolean => {
|
|
751
|
+
// 根据文件类型决定处理方式
|
|
752
|
+
const isPDF = fileType === 'pdf' || fileType === 'pdf_slides';
|
|
753
|
+
|
|
754
|
+
if (!isPDF) {
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// 先检查单个页面缓存
|
|
759
|
+
const pageCached = pageCache.current[pageNo];
|
|
760
|
+
if (pageCached && Date.now() - pageCached.timestamp < CACHE_EXPIRY_TIME) {
|
|
761
|
+
return !!pageCached.pdfDocument;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// 检查chunk缓存
|
|
765
|
+
const chunkKey = getChunkKey(pageNo, pageSize);
|
|
766
|
+
const chunkCached = chunkCache.current[chunkKey];
|
|
767
|
+
if (chunkCached && Date.now() - chunkCached.timestamp < CACHE_EXPIRY_TIME) {
|
|
768
|
+
return chunkCached.pages.includes(pageNo) && !!chunkCached.pdfDocument;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
return false;
|
|
772
|
+
},
|
|
773
|
+
[pageSize, getChunkKey, fileType]
|
|
774
|
+
);
|
|
775
|
+
|
|
776
|
+
// ========== Markdown相关工具函数 ==========
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* 检查markdown内容是否在缓存中
|
|
780
|
+
* @returns 缓存的内容或null
|
|
781
|
+
*/
|
|
782
|
+
const getCachedMarkdownContent = useCallback((): string | null => {
|
|
783
|
+
console.log('检查markdown内容是否在缓存中');
|
|
784
|
+
|
|
785
|
+
const cached = markdownContentCache.current;
|
|
786
|
+
if (cached && Date.now() - cached.timestamp < CACHE_EXPIRY_TIME) {
|
|
787
|
+
console.log('使用markdown内容缓存');
|
|
788
|
+
return cached.data;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
console.log('markdown内容不在缓存中,需要重新请求');
|
|
792
|
+
return null;
|
|
793
|
+
}, []);
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* 获取完整markdown数据
|
|
797
|
+
* @returns Promise<string>
|
|
798
|
+
*/
|
|
799
|
+
const fetchMarkdownData = useCallback(async (): Promise<string> => {
|
|
800
|
+
try {
|
|
801
|
+
console.log('请求完整markdown数据');
|
|
802
|
+
|
|
803
|
+
const headers: Record<string, string> = {
|
|
804
|
+
'Content-Type': 'application/json',
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
if (authorization) {
|
|
808
|
+
headers['Authorization'] = authorization;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
if (csrfToken) {
|
|
812
|
+
headers['X-CSRF-TOKEN-IN'] = csrfToken;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
const requestData = {
|
|
816
|
+
convertedFilePath,
|
|
817
|
+
// 不传pageNo和pageSize,获取完整文章
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
console.log('发送markdown请求:', requestData);
|
|
821
|
+
|
|
822
|
+
const response = await axios.post(streamApiUrl, requestData, {
|
|
823
|
+
headers,
|
|
824
|
+
responseType: 'text', // markdown返回文本
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
// 获取响应头中的CSRF Token并触发事件
|
|
828
|
+
const responseCsrfToken =
|
|
829
|
+
response.headers['x-csrf-token-out'] || response.headers['X-CSRF-TOKEN-OUT'];
|
|
830
|
+
if (responseCsrfToken) {
|
|
831
|
+
console.log('获取到响应头中的CSRF Token:', responseCsrfToken);
|
|
832
|
+
eventsEmit('request_finish', responseCsrfToken);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
console.log('markdown响应状态:', response.status);
|
|
836
|
+
console.log('markdown响应数据长度:', response.data?.length || 0);
|
|
837
|
+
|
|
838
|
+
return response.data;
|
|
839
|
+
} catch (error: any) {
|
|
840
|
+
console.error('获取markdown数据失败:', error);
|
|
841
|
+
throw new Error(`获取markdown数据失败: ${error.message}`);
|
|
842
|
+
}
|
|
843
|
+
}, [convertedFilePath, authorization, streamApiUrl, eventsEmit]);
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* 加载完整markdown文档
|
|
847
|
+
* @returns Promise<string>
|
|
848
|
+
*/
|
|
849
|
+
const loadMarkdownDocument = useCallback(async () => {
|
|
850
|
+
try {
|
|
851
|
+
setIsLoading(true);
|
|
852
|
+
setLoadingStatus('正在加载markdown文档...');
|
|
853
|
+
setError(null);
|
|
854
|
+
|
|
855
|
+
console.log('开始加载完整markdown文档');
|
|
856
|
+
|
|
857
|
+
// 先检查缓存
|
|
858
|
+
const cachedContent = getCachedMarkdownContent();
|
|
859
|
+
if (cachedContent) {
|
|
860
|
+
console.log('使用缓存的markdown内容');
|
|
861
|
+
setMarkdownContent(cachedContent);
|
|
862
|
+
setIsLoading(false);
|
|
863
|
+
setLoadingStatus('');
|
|
864
|
+
return cachedContent;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// 获取完整数据
|
|
868
|
+
const streamData = await fetchMarkdownData();
|
|
869
|
+
|
|
870
|
+
// 缓存markdown内容
|
|
871
|
+
markdownContentCache.current = {
|
|
872
|
+
data: streamData,
|
|
873
|
+
timestamp: Date.now(),
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
setMarkdownContent(streamData);
|
|
877
|
+
setIsLoading(false);
|
|
878
|
+
setLoadingStatus('');
|
|
879
|
+
console.log('完整markdown文档加载完成');
|
|
880
|
+
return streamData;
|
|
881
|
+
} catch (error: any) {
|
|
882
|
+
console.error('markdown加载失败:', error);
|
|
883
|
+
setError(error.message || 'markdown加载失败,请稍后重试');
|
|
884
|
+
setIsLoading(false);
|
|
885
|
+
setLoadingStatus('');
|
|
886
|
+
throw error;
|
|
887
|
+
}
|
|
888
|
+
}, [fetchMarkdownData, getCachedMarkdownContent]);
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* 获取完整图片数据(以与PDF/Markdown一致的请求方式)
|
|
892
|
+
*/
|
|
893
|
+
const fetchImageData = useCallback(async (): Promise<ArrayBuffer> => {
|
|
894
|
+
try {
|
|
895
|
+
const headers: Record<string, string> = {
|
|
896
|
+
'Content-Type': 'application/json',
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
if (authorization) {
|
|
900
|
+
headers['Authorization'] = authorization;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
if (csrfToken) {
|
|
904
|
+
headers['X-CSRF-TOKEN-IN'] = csrfToken;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
const requestData = {
|
|
908
|
+
convertedFilePath,
|
|
909
|
+
// 不传 pageNo/pageSize,获取完整图片二进制
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
const response = await axios.post<ArrayBuffer>(streamApiUrl, requestData, {
|
|
913
|
+
headers,
|
|
914
|
+
responseType: 'arraybuffer',
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
// 获取响应头中的CSRF Token并触发事件
|
|
918
|
+
const responseCsrfToken =
|
|
919
|
+
response.headers['x-csrf-token-out'] || response.headers['X-CSRF-TOKEN-OUT'];
|
|
920
|
+
if (responseCsrfToken) {
|
|
921
|
+
console.log('获取到响应头中的CSRF Token:', responseCsrfToken);
|
|
922
|
+
eventsEmit('request_finish', responseCsrfToken);
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
return response.data;
|
|
926
|
+
} catch (error: any) {
|
|
927
|
+
console.error('获取图片数据失败:', error);
|
|
928
|
+
throw new Error(`获取图片数据失败: ${error.message}`);
|
|
929
|
+
}
|
|
930
|
+
}, [convertedFilePath, authorization, streamApiUrl, eventsEmit]);
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* 加载图片文档
|
|
934
|
+
*/
|
|
935
|
+
const loadImageDocument = useCallback(async () => {
|
|
936
|
+
try {
|
|
937
|
+
setIsLoading(true);
|
|
938
|
+
setLoadingStatus('正在加载图片...');
|
|
939
|
+
setError(null);
|
|
940
|
+
|
|
941
|
+
const imgBuffer = await fetchImageData();
|
|
942
|
+
|
|
943
|
+
const parseResult: ParseResult = await parseFile(imgBuffer, {
|
|
944
|
+
fileName: fileName || '图片',
|
|
945
|
+
fileType: 'image',
|
|
946
|
+
token: authorization,
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
if (parseResult.error) {
|
|
950
|
+
throw new Error(parseResult.error);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
if (parseResult.type !== 'image' || !parseResult.content) {
|
|
954
|
+
throw new Error('解析结果不是有效的图片');
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
setImageContent(parseResult.content); // { type: 'image', url }
|
|
958
|
+
setIsLoading(false);
|
|
959
|
+
setLoadingStatus('');
|
|
960
|
+
return parseResult.content;
|
|
961
|
+
} catch (error: any) {
|
|
962
|
+
console.error('图片加载失败:', error);
|
|
963
|
+
setError(error.message || '图片加载失败,请稍后重试');
|
|
964
|
+
setIsLoading(false);
|
|
965
|
+
setLoadingStatus('');
|
|
966
|
+
throw error;
|
|
967
|
+
}
|
|
968
|
+
}, [authorization, fileName, fetchImageData]);
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
* 获取通用文件数据(用于html、text、unknown等文件类型)
|
|
972
|
+
* 所有文件类型都使用同样的接口,只是非PDF类型不传分页参数
|
|
973
|
+
* @returns Promise<ArrayBuffer>
|
|
974
|
+
*/
|
|
975
|
+
const fetchGenericData = useCallback(async (): Promise<ArrayBuffer> => {
|
|
976
|
+
try {
|
|
977
|
+
console.log(`请求通用文件数据,文件类型: ${fileType}`);
|
|
978
|
+
|
|
979
|
+
const headers: Record<string, string> = {
|
|
980
|
+
'Content-Type': 'application/json',
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
if (authorization) {
|
|
984
|
+
headers['Authorization'] = authorization;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
if (csrfToken) {
|
|
988
|
+
headers['X-CSRF-TOKEN-IN'] = csrfToken;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
const requestData = {
|
|
992
|
+
convertedFilePath,
|
|
993
|
+
// 非PDF文件类型不传pageNo和pageSize,获取完整文件内容
|
|
994
|
+
};
|
|
995
|
+
|
|
996
|
+
console.log('发送通用文件请求:', requestData);
|
|
997
|
+
|
|
998
|
+
const response = await axios.post<ArrayBuffer>(streamApiUrl, requestData, {
|
|
999
|
+
headers,
|
|
1000
|
+
responseType: 'arraybuffer',
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
// 获取响应头中的CSRF Token并触发事件
|
|
1004
|
+
const responseCsrfToken =
|
|
1005
|
+
response.headers['x-csrf-token-out'] || response.headers['X-CSRF-TOKEN-OUT'];
|
|
1006
|
+
if (responseCsrfToken) {
|
|
1007
|
+
console.log('获取到响应头中的CSRF Token:', responseCsrfToken);
|
|
1008
|
+
eventsEmit('request_finish', responseCsrfToken);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
console.log('通用文件响应状态:', response.status);
|
|
1012
|
+
console.log('通用文件响应数据长度:', response.data?.byteLength || 0);
|
|
1013
|
+
|
|
1014
|
+
return response.data;
|
|
1015
|
+
} catch (error: any) {
|
|
1016
|
+
console.error('获取通用文件数据失败:', error);
|
|
1017
|
+
throw new Error(`获取通用文件数据失败: ${error.message}`);
|
|
1018
|
+
}
|
|
1019
|
+
}, [convertedFilePath, authorization, streamApiUrl, eventsEmit]);
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* 加载通用文件文档(用于html、text、unknown等文件类型)
|
|
1023
|
+
*/
|
|
1024
|
+
const loadGenericDocument = useCallback(async () => {
|
|
1025
|
+
try {
|
|
1026
|
+
console.log(`=== loadGenericDocument 被调用 ===`);
|
|
1027
|
+
console.log(`调用栈:`, new Error().stack);
|
|
1028
|
+
console.log(`当前时间:`, new Date().toISOString());
|
|
1029
|
+
|
|
1030
|
+
// 防抖检查 - 如果正在加载中,直接返回
|
|
1031
|
+
if (isGenericLoadingRef.current) {
|
|
1032
|
+
console.log(`通用文档正在加载中,忽略重复请求,文件类型: ${fileType}`);
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
// 如果已经加载过,直接返回
|
|
1037
|
+
if (hasLoadedGenericRef.current) {
|
|
1038
|
+
console.log(`通用文档已经加载过,忽略重复请求,文件类型: ${fileType}`);
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// 检查缓存
|
|
1043
|
+
const cacheKey = `${fileType}_${convertedFilePath}`;
|
|
1044
|
+
const cached = genericContentCache[cacheKey];
|
|
1045
|
+
console.log(
|
|
1046
|
+
`检查通用文档缓存,key: ${cacheKey}, 缓存存在: ${!!cached}, 缓存时间: ${cached ? Date.now() - cached.timestamp : 'N/A'}ms`
|
|
1047
|
+
);
|
|
1048
|
+
|
|
1049
|
+
if (cached && Date.now() - cached.timestamp < CACHE_EXPIRY_TIME) {
|
|
1050
|
+
console.log(`使用缓存的通用文档内容,文件类型: ${fileType}`);
|
|
1051
|
+
|
|
1052
|
+
// 根据文件类型设置相应的状态
|
|
1053
|
+
if (fileType === 'text' && cached.content) {
|
|
1054
|
+
setTextContent(cached.content);
|
|
1055
|
+
} else if (fileType === 'html' && cached.content) {
|
|
1056
|
+
setHtmlContent(cached.content);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
setCurrentPage(1);
|
|
1060
|
+
// 优先使用用户传入的总页数,如果没有则设为1
|
|
1061
|
+
setTotalPages(userTotalPages || 1);
|
|
1062
|
+
setIsLoading(false);
|
|
1063
|
+
setLoadingStatus('');
|
|
1064
|
+
return cached.content;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// 设置防抖状态
|
|
1068
|
+
isGenericLoadingRef.current = true;
|
|
1069
|
+
setIsLoading(true);
|
|
1070
|
+
setLoadingStatus(`正在加载${fileType}文档...`);
|
|
1071
|
+
setError(null);
|
|
1072
|
+
|
|
1073
|
+
console.log(`开始加载通用文档,文件类型: ${fileType}`);
|
|
1074
|
+
|
|
1075
|
+
// 获取通用文件数据
|
|
1076
|
+
const fileData = await fetchGenericData();
|
|
1077
|
+
|
|
1078
|
+
// 显式传入 text 时不再调用 parseFile,避免 fviewer 根据 fileName 误判为 PDF 导致 Invalid PDF structure
|
|
1079
|
+
if (fileType === 'text') {
|
|
1080
|
+
const textContent = decodeArrayBufferAsText(fileData);
|
|
1081
|
+
const finalContent = { type: 'text' as const, content: textContent };
|
|
1082
|
+
setTextContent(finalContent);
|
|
1083
|
+
const cacheKeyForText = `text_${convertedFilePath}`;
|
|
1084
|
+
setGenericContentCache((prev) => ({
|
|
1085
|
+
...prev,
|
|
1086
|
+
[cacheKeyForText]: { content: finalContent, timestamp: Date.now() },
|
|
1087
|
+
}));
|
|
1088
|
+
setIsLoading(false);
|
|
1089
|
+
setLoadingStatus('');
|
|
1090
|
+
isGenericLoadingRef.current = false;
|
|
1091
|
+
hasLoadedGenericRef.current = true;
|
|
1092
|
+
console.log(`通用文档加载完成(text 直解),文件类型: ${fileType}`);
|
|
1093
|
+
return finalContent;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
// 使用 fileParser 解析 html / unknown 等
|
|
1097
|
+
const parseResult: ParseResult = await parseFile(fileData, {
|
|
1098
|
+
fileName: fileName || `${fileType}文档`,
|
|
1099
|
+
fileType: fileType as any,
|
|
1100
|
+
token: authorization,
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
if (parseResult.error) {
|
|
1104
|
+
throw new Error(parseResult.error);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// 根据解析结果设置相应的状态
|
|
1108
|
+
let finalContent = null;
|
|
1109
|
+
if (parseResult.type === 'text' && parseResult.content) {
|
|
1110
|
+
setTextContent(parseResult.content);
|
|
1111
|
+
finalContent = parseResult.content;
|
|
1112
|
+
} else if (parseResult.type === 'html' && parseResult.content) {
|
|
1113
|
+
setHtmlContent(parseResult.content);
|
|
1114
|
+
finalContent = parseResult.content;
|
|
1115
|
+
} else if (parseResult.type === 'image' && parseResult.content) {
|
|
1116
|
+
setImageContent(parseResult.content);
|
|
1117
|
+
finalContent = parseResult.content;
|
|
1118
|
+
} else {
|
|
1119
|
+
// 如果解析失败,尝试作为文本处理(带编码回退,避免中文乱码)
|
|
1120
|
+
const textContent = decodeArrayBufferAsText(fileData);
|
|
1121
|
+
setTextContent({ type: 'text', content: textContent });
|
|
1122
|
+
finalContent = { type: 'text', content: textContent };
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
// 保存到缓存
|
|
1126
|
+
if (finalContent) {
|
|
1127
|
+
const cacheKey = `${fileType}_${convertedFilePath}`;
|
|
1128
|
+
const newCache = {
|
|
1129
|
+
...genericContentCache,
|
|
1130
|
+
[cacheKey]: {
|
|
1131
|
+
content: finalContent,
|
|
1132
|
+
timestamp: Date.now(),
|
|
1133
|
+
},
|
|
1134
|
+
};
|
|
1135
|
+
setGenericContentCache(newCache);
|
|
1136
|
+
console.log(`通用文档内容已缓存,文件类型: ${fileType}, 缓存键: ${cacheKey}`);
|
|
1137
|
+
console.log(`当前缓存状态:`, newCache);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
setIsLoading(false);
|
|
1141
|
+
setLoadingStatus('');
|
|
1142
|
+
isGenericLoadingRef.current = false; // 清除防抖状态
|
|
1143
|
+
hasLoadedGenericRef.current = true; // 标记已加载
|
|
1144
|
+
console.log(`通用文档加载完成,文件类型: ${fileType}`);
|
|
1145
|
+
return parseResult;
|
|
1146
|
+
} catch (error: any) {
|
|
1147
|
+
console.error('通用文档加载失败:', error);
|
|
1148
|
+
setError(error.message || '通用文档加载失败,请稍后重试');
|
|
1149
|
+
setIsLoading(false);
|
|
1150
|
+
setLoadingStatus('');
|
|
1151
|
+
isGenericLoadingRef.current = false; // 清除防抖状态
|
|
1152
|
+
hasLoadedGenericRef.current = true; // 标记已加载(即使失败也标记,避免无限重试)
|
|
1153
|
+
throw error;
|
|
1154
|
+
}
|
|
1155
|
+
}, [fetchGenericData, fileName, authorization, fileType, convertedFilePath, genericContentCache, userTotalPages]);
|
|
1156
|
+
|
|
1157
|
+
// 移除markdown滚动事件处理,不再支持分块加载
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* 处理页面变化(仅用于PDF文件类型)
|
|
1161
|
+
*/
|
|
1162
|
+
const handlePageChange = useCallback(
|
|
1163
|
+
async (pageNumber: number) => {
|
|
1164
|
+
if (pageNumber === currentPageRef.current) return;
|
|
1165
|
+
if (isLoading) {
|
|
1166
|
+
console.log('页面正在加载中,忽略翻页请求');
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// 根据文件类型决定处理方式
|
|
1171
|
+
const isPDF = fileType === 'pdf' || fileType === 'pdf_slides';
|
|
1172
|
+
|
|
1173
|
+
if (!isPDF) {
|
|
1174
|
+
console.log(`文件类型 ${fileType} 不支持翻页,忽略翻页请求`);
|
|
1175
|
+
return; // 直接返回,不进行任何操作
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
console.log('PDF页面变化:', pageNumber, '当前页:', currentPageRef.current);
|
|
1179
|
+
console.log(`页面 ${pageNumber} 是否在缓存中:`, isPageInCache(pageNumber));
|
|
1180
|
+
|
|
1181
|
+
// 更新ref和state
|
|
1182
|
+
currentPageRef.current = pageNumber;
|
|
1183
|
+
setCurrentPage(pageNumber);
|
|
1184
|
+
|
|
1185
|
+
try {
|
|
1186
|
+
await loadPDFDocument(pageNumber, false); // 非初始加载
|
|
1187
|
+
// 优先使用用户传入的总页数
|
|
1188
|
+
const finalTotalPages = userTotalPages || totalPages;
|
|
1189
|
+
eventsEmit('pageChange', { pageNumber, totalPages: finalTotalPages });
|
|
1190
|
+
} catch (error) {
|
|
1191
|
+
console.error('PDF页面加载失败:', error);
|
|
1192
|
+
// 加载失败时恢复当前页
|
|
1193
|
+
const originalPage = currentPageRef.current;
|
|
1194
|
+
setCurrentPage(originalPage);
|
|
1195
|
+
}
|
|
1196
|
+
},
|
|
1197
|
+
[loadPDFDocument, totalPages, eventsEmit, isPageInCache, isLoading, fileType]
|
|
1198
|
+
);
|
|
1199
|
+
|
|
1200
|
+
// 添加useEffect来监听currentPage变化,确保状态同步
|
|
1201
|
+
useEffect(() => {
|
|
1202
|
+
currentPageRef.current = currentPage;
|
|
1203
|
+
console.log('当前页状态更新:', currentPage);
|
|
1204
|
+
}, [currentPage]);
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* 处理缩放变化
|
|
1208
|
+
*/
|
|
1209
|
+
const handleZoomChange = useCallback(
|
|
1210
|
+
(newScale: number) => {
|
|
1211
|
+
setScale(newScale);
|
|
1212
|
+
eventsEmit('zoomChange', { scale: newScale });
|
|
1213
|
+
},
|
|
1214
|
+
[eventsEmit]
|
|
1215
|
+
);
|
|
1216
|
+
|
|
1217
|
+
/**
|
|
1218
|
+
* 处理关闭
|
|
1219
|
+
*/
|
|
1220
|
+
const handleClose = useCallback(() => {
|
|
1221
|
+
eventsEmit('viewer:close');
|
|
1222
|
+
}, [eventsEmit]);
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* 处理放大
|
|
1226
|
+
*/
|
|
1227
|
+
const handleZoomIn = useCallback(() => {
|
|
1228
|
+
const newScale = Math.min(3, scale + 0.1);
|
|
1229
|
+
handleZoomChange(newScale);
|
|
1230
|
+
}, [scale, handleZoomChange]);
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* 处理缩小
|
|
1234
|
+
*/
|
|
1235
|
+
const handleZoomOut = useCallback(() => {
|
|
1236
|
+
const newScale = Math.max(0.3, scale - 0.1);
|
|
1237
|
+
handleZoomChange(newScale);
|
|
1238
|
+
}, [scale, handleZoomChange]);
|
|
1239
|
+
|
|
1240
|
+
/**
|
|
1241
|
+
* 处理左旋转(仅图片)
|
|
1242
|
+
*/
|
|
1243
|
+
const handleRotateLeft = useCallback(() => {
|
|
1244
|
+
const newRotation = (rotation - 90 + 360) % 360;
|
|
1245
|
+
setRotation(newRotation);
|
|
1246
|
+
eventsEmit('rotateChange', { rotation: newRotation });
|
|
1247
|
+
}, [rotation, eventsEmit]);
|
|
1248
|
+
|
|
1249
|
+
/**
|
|
1250
|
+
* 处理右旋转(仅图片)
|
|
1251
|
+
*/
|
|
1252
|
+
const handleRotateRight = useCallback(() => {
|
|
1253
|
+
const newRotation = (rotation + 90) % 360;
|
|
1254
|
+
setRotation(newRotation);
|
|
1255
|
+
eventsEmit('rotateChange', { rotation: newRotation });
|
|
1256
|
+
}, [rotation, eventsEmit]);
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* 处理上一页(仅用于PDF文件类型)
|
|
1260
|
+
*/
|
|
1261
|
+
const handlePrevPage = useCallback(() => {
|
|
1262
|
+
// 根据文件类型决定处理方式
|
|
1263
|
+
const isPDF = fileType === 'pdf' || fileType === 'pdf_slides';
|
|
1264
|
+
|
|
1265
|
+
if (!isPDF) {
|
|
1266
|
+
console.log(`文件类型 ${fileType} 不支持翻页,忽略翻页请求`);
|
|
1267
|
+
return; // 直接返回,不进行任何操作
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
const prevPage = currentPageRef.current - 1;
|
|
1271
|
+
if (prevPage >= 1) {
|
|
1272
|
+
handlePageChange(prevPage);
|
|
1273
|
+
}
|
|
1274
|
+
}, [handlePageChange, fileType]);
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* 处理下一页(仅用于PDF文件类型)
|
|
1278
|
+
*/
|
|
1279
|
+
const handleNextPage = useCallback(() => {
|
|
1280
|
+
// 根据文件类型决定处理方式
|
|
1281
|
+
const isPDF = fileType === 'pdf' || fileType === 'pdf_slides';
|
|
1282
|
+
|
|
1283
|
+
if (!isPDF) {
|
|
1284
|
+
console.log(`文件类型 ${fileType} 不支持翻页,忽略翻页请求`);
|
|
1285
|
+
return; // 直接返回,不进行任何操作
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
const nextPage = currentPageRef.current + 1;
|
|
1289
|
+
// 优先使用用户传入的总页数
|
|
1290
|
+
const finalTotalPages = userTotalPages || totalPages;
|
|
1291
|
+
if (finalTotalPages && nextPage <= finalTotalPages) {
|
|
1292
|
+
handlePageChange(nextPage);
|
|
1293
|
+
}
|
|
1294
|
+
}, [totalPages, handlePageChange, fileType]);
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* 清理过期缓存
|
|
1298
|
+
*/
|
|
1299
|
+
const cleanupExpiredCache = useCallback(() => {
|
|
1300
|
+
const now = Date.now();
|
|
1301
|
+
|
|
1302
|
+
// 清理单个页面缓存
|
|
1303
|
+
Object.keys(pageCache.current).forEach(pageNo => {
|
|
1304
|
+
const page = pageCache.current[parseInt(pageNo)];
|
|
1305
|
+
if (now - page.timestamp > CACHE_EXPIRY_TIME) {
|
|
1306
|
+
delete pageCache.current[parseInt(pageNo)];
|
|
1307
|
+
console.log(`清理过期页面缓存: ${pageNo}`);
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
|
|
1311
|
+
// 清理chunk缓存
|
|
1312
|
+
Object.keys(chunkCache.current).forEach(chunkKey => {
|
|
1313
|
+
const chunk = chunkCache.current[chunkKey];
|
|
1314
|
+
if (now - chunk.timestamp > CACHE_EXPIRY_TIME) {
|
|
1315
|
+
delete chunkCache.current[chunkKey];
|
|
1316
|
+
console.log(`清理过期chunk缓存: ${chunkKey}`);
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
// 清理markdown内容缓存
|
|
1321
|
+
if (
|
|
1322
|
+
markdownContentCache.current &&
|
|
1323
|
+
now - markdownContentCache.current.timestamp > CACHE_EXPIRY_TIME
|
|
1324
|
+
) {
|
|
1325
|
+
markdownContentCache.current = null;
|
|
1326
|
+
console.log('清理过期markdown内容缓存');
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
// 清理通用文件缓存
|
|
1330
|
+
setGenericContentCache(prev => {
|
|
1331
|
+
const newCache = { ...prev };
|
|
1332
|
+
Object.keys(newCache).forEach(key => {
|
|
1333
|
+
if (now - newCache[key].timestamp > CACHE_EXPIRY_TIME) {
|
|
1334
|
+
delete newCache[key];
|
|
1335
|
+
console.log(`清理过期通用文件缓存: ${key}`);
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1338
|
+
return newCache;
|
|
1339
|
+
});
|
|
1340
|
+
}, []);
|
|
1341
|
+
|
|
1342
|
+
/**
|
|
1343
|
+
* 获取文件名
|
|
1344
|
+
*/
|
|
1345
|
+
const getFileName = useCallback(() => {
|
|
1346
|
+
if (fileName) return fileName;
|
|
1347
|
+
try {
|
|
1348
|
+
const urlObj = new URL(convertedFilePath);
|
|
1349
|
+
const fileNameFromUrl = decodeURIComponent(urlObj.pathname.split('/').pop() || '');
|
|
1350
|
+
return fileNameFromUrl || 'Stream文档';
|
|
1351
|
+
} catch {
|
|
1352
|
+
const pathParts = convertedFilePath.split('/');
|
|
1353
|
+
return decodeURIComponent(pathParts[pathParts.length - 1]) || 'Stream文档';
|
|
1354
|
+
}
|
|
1355
|
+
}, [convertedFilePath, fileName]);
|
|
1356
|
+
|
|
1357
|
+
// 定期清理过期缓存
|
|
1358
|
+
useEffect(() => {
|
|
1359
|
+
const cleanupInterval = setInterval(cleanupExpiredCache, CACHE_EXPIRY_TIME);
|
|
1360
|
+
return () => clearInterval(cleanupInterval);
|
|
1361
|
+
}, [cleanupExpiredCache]);
|
|
1362
|
+
|
|
1363
|
+
// 组件卸载时清理缓存
|
|
1364
|
+
useEffect(() => {
|
|
1365
|
+
return () => {
|
|
1366
|
+
pageCache.current = {};
|
|
1367
|
+
chunkCache.current = {};
|
|
1368
|
+
markdownContentCache.current = null;
|
|
1369
|
+
setGenericContentCache({});
|
|
1370
|
+
console.log('组件卸载,清理所有缓存');
|
|
1371
|
+
};
|
|
1372
|
+
}, []);
|
|
1373
|
+
|
|
1374
|
+
// 初始加载
|
|
1375
|
+
useEffect(() => {
|
|
1376
|
+
console.log(`=== useEffect 被触发 ===`);
|
|
1377
|
+
console.log(`触发时间:`, new Date().toISOString());
|
|
1378
|
+
console.log(`触发原因:`, { initialPage, fileType });
|
|
1379
|
+
|
|
1380
|
+
const loadInitialPage = async () => {
|
|
1381
|
+
try {
|
|
1382
|
+
// 根据文件类型决定是否使用翻页参数
|
|
1383
|
+
const isPDF = fileType === 'pdf' || fileType === 'pdf_slides';
|
|
1384
|
+
const effectivePage = isPDF ? initialPage || 1 : 1;
|
|
1385
|
+
console.log(
|
|
1386
|
+
'开始初始加载,文件类型:',
|
|
1387
|
+
fileType,
|
|
1388
|
+
'有效页码:',
|
|
1389
|
+
effectivePage,
|
|
1390
|
+
'是否PDF:',
|
|
1391
|
+
isPDF
|
|
1392
|
+
);
|
|
1393
|
+
|
|
1394
|
+
if (fileType === 'markdown' || fileType === 'markdown_table') {
|
|
1395
|
+
// Markdown文件加载完整内容,忽略翻页参数
|
|
1396
|
+
await loadMarkdownDocument();
|
|
1397
|
+
setCurrentPage(1);
|
|
1398
|
+
// 优先使用用户传入的总页数,如果没有则设为1
|
|
1399
|
+
setTotalPages(userTotalPages || 1);
|
|
1400
|
+
eventsEmit('pageChange', { pageNumber: 1, totalPages: userTotalPages || 1 });
|
|
1401
|
+
} else if (fileType === 'image') {
|
|
1402
|
+
// 图片文件加载,忽略翻页参数
|
|
1403
|
+
await loadImageDocument();
|
|
1404
|
+
setCurrentPage(1);
|
|
1405
|
+
// 优先使用用户传入的总页数,如果没有则设为1
|
|
1406
|
+
setTotalPages(userTotalPages || 1);
|
|
1407
|
+
setRotation(0);
|
|
1408
|
+
eventsEmit('pageChange', { pageNumber: 1, totalPages: userTotalPages || 1 });
|
|
1409
|
+
} else if (isPDF) {
|
|
1410
|
+
// 只有PDF文件使用页面加载和翻页参数
|
|
1411
|
+
await loadPDFDocument(effectivePage, true);
|
|
1412
|
+
setCurrentPage(effectivePage);
|
|
1413
|
+
// 等待 totalPages 更新后再触发事件,优先使用用户传入的值
|
|
1414
|
+
setTimeout(() => {
|
|
1415
|
+
const finalTotalPages = userTotalPages || totalPages;
|
|
1416
|
+
eventsEmit('pageChange', { pageNumber: effectivePage, totalPages: finalTotalPages });
|
|
1417
|
+
}, 0);
|
|
1418
|
+
} else {
|
|
1419
|
+
// 其他文件类型(text, html, unknown等)使用通用加载函数,忽略翻页参数
|
|
1420
|
+
console.log('=== 初始加载:使用通用加载函数处理文件类型 ===', fileType);
|
|
1421
|
+
await loadGenericDocument();
|
|
1422
|
+
setCurrentPage(1);
|
|
1423
|
+
// 优先使用用户传入的总页数,如果没有则设为1
|
|
1424
|
+
setTotalPages(userTotalPages || 1);
|
|
1425
|
+
eventsEmit('pageChange', { pageNumber: 1, totalPages: userTotalPages || 1 });
|
|
1426
|
+
}
|
|
1427
|
+
} catch (error: any) {
|
|
1428
|
+
console.error('初始加载失败:', error);
|
|
1429
|
+
// 确保错误状态被正确设置,避免组件状态不一致
|
|
1430
|
+
setError(error?.message || '文件加载失败,请稍后重试');
|
|
1431
|
+
setIsLoading(false);
|
|
1432
|
+
setLoadingStatus('');
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
loadInitialPage();
|
|
1437
|
+
}, [initialPage, fileType, convertedFilePath]);
|
|
1438
|
+
|
|
1439
|
+
// 所有 hooks 必须在条件返回之前调用
|
|
1440
|
+
const pdfStartPage = useMemo(() => {
|
|
1441
|
+
return Math.floor((currentPage - 1) / pageSize) * pageSize + 1;
|
|
1442
|
+
}, [currentPage, pageSize]);
|
|
1443
|
+
|
|
1444
|
+
if (error) {
|
|
1445
|
+
return (
|
|
1446
|
+
<ReaderContainer $theme={mergedTheme} className={className}>
|
|
1447
|
+
{customComponents?.ErrorComponent ? (
|
|
1448
|
+
<customComponents.ErrorComponent error={error} theme={mergedTheme} />
|
|
1449
|
+
) : (
|
|
1450
|
+
<ErrorContainer $theme={mergedTheme}>
|
|
1451
|
+
<div>加载失败</div>
|
|
1452
|
+
<div style={{ fontSize: '12px', marginTop: '8px' }}>{error}</div>
|
|
1453
|
+
</ErrorContainer>
|
|
1454
|
+
)}
|
|
1455
|
+
</ReaderContainer>
|
|
1456
|
+
);
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
// 渲染加载状态
|
|
1460
|
+
if (isLoading) {
|
|
1461
|
+
return (
|
|
1462
|
+
<ReaderContainer $theme={mergedTheme} className={className}>
|
|
1463
|
+
{/* 头部工具栏 - 始终显示 */}
|
|
1464
|
+
<Header
|
|
1465
|
+
fileName={getFileName()}
|
|
1466
|
+
currentPage={currentPage}
|
|
1467
|
+
totalPage={totalPages}
|
|
1468
|
+
scale={scale}
|
|
1469
|
+
isAnnotating={false}
|
|
1470
|
+
tools={tools}
|
|
1471
|
+
styles={styles}
|
|
1472
|
+
onPrevPage={() => {}}
|
|
1473
|
+
onNextPage={() => {}}
|
|
1474
|
+
onZoomIn={() => {}}
|
|
1475
|
+
onZoomOut={() => {}}
|
|
1476
|
+
onAnnotationToggle={() => {}}
|
|
1477
|
+
onDownload={() => {}}
|
|
1478
|
+
onClose={handleClose}
|
|
1479
|
+
className={headerClass}
|
|
1480
|
+
/>
|
|
1481
|
+
|
|
1482
|
+
{/* 内容区域 - 显示加载状态 */}
|
|
1483
|
+
{customComponents?.LoadingComponent ? (
|
|
1484
|
+
<customComponents.LoadingComponent status={loadingStatus} theme={mergedTheme} />
|
|
1485
|
+
) : (
|
|
1486
|
+
<DefaultLoadingComponent status={loadingStatus} theme={mergedTheme} />
|
|
1487
|
+
)}
|
|
1488
|
+
</ReaderContainer>
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
return (
|
|
1493
|
+
<ReaderContainer $theme={mergedTheme} className={className}>
|
|
1494
|
+
{/* Header组件 */}
|
|
1495
|
+
<Header
|
|
1496
|
+
fileName={getFileName()}
|
|
1497
|
+
currentPage={currentPage}
|
|
1498
|
+
totalPage={totalPages}
|
|
1499
|
+
scale={scale}
|
|
1500
|
+
isAnnotating={false}
|
|
1501
|
+
tools={{
|
|
1502
|
+
...tools,
|
|
1503
|
+
// 仅PDF和PDF幻灯片显示导航
|
|
1504
|
+
navigation: fileType === 'pdf' || fileType === 'pdf_slides' ? tools.navigation : false,
|
|
1505
|
+
// 仅图片显示旋转
|
|
1506
|
+
rotate: fileType === 'image',
|
|
1507
|
+
}}
|
|
1508
|
+
styles={styles}
|
|
1509
|
+
onPrevPage={handlePrevPage}
|
|
1510
|
+
onNextPage={handleNextPage}
|
|
1511
|
+
onZoomIn={handleZoomIn}
|
|
1512
|
+
onZoomOut={handleZoomOut}
|
|
1513
|
+
onRotateLeft={fileType === 'image' ? handleRotateLeft : undefined}
|
|
1514
|
+
onRotateRight={fileType === 'image' ? handleRotateRight : undefined}
|
|
1515
|
+
onAnnotationToggle={() => {}}
|
|
1516
|
+
onDownload={() => {}}
|
|
1517
|
+
onClose={handleClose}
|
|
1518
|
+
className={headerClass}
|
|
1519
|
+
/>
|
|
1520
|
+
|
|
1521
|
+
{fileType === 'markdown' || fileType === 'markdown_table' ? (
|
|
1522
|
+
// Markdown内容渲染 - 使用Fviewer的markdown渲染逻辑
|
|
1523
|
+
<div
|
|
1524
|
+
ref={scrollContainerRef}
|
|
1525
|
+
style={{
|
|
1526
|
+
flex: 1,
|
|
1527
|
+
overflow: 'auto', // 改为auto,允许滚动条显示
|
|
1528
|
+
position: 'relative',
|
|
1529
|
+
}}
|
|
1530
|
+
className={contentClass}
|
|
1531
|
+
>
|
|
1532
|
+
<Fviewer
|
|
1533
|
+
data={{
|
|
1534
|
+
content: markdownContent, // 直接传递markdown内容字符串
|
|
1535
|
+
...(getFileName() && { fileName: getFileName() }),
|
|
1536
|
+
...(fileType && { fileType }),
|
|
1537
|
+
...(totalPages && { totalPages }),
|
|
1538
|
+
}}
|
|
1539
|
+
annotationData={annotations}
|
|
1540
|
+
totalPage={totalPages}
|
|
1541
|
+
currentPage={currentPage}
|
|
1542
|
+
scale={scale}
|
|
1543
|
+
eventsEmit={(name, data) => {
|
|
1544
|
+
console.log('Fviewer事件:', name, data);
|
|
1545
|
+
// 处理markdown标注事件
|
|
1546
|
+
if (name === 'md_annotation_add') {
|
|
1547
|
+
eventsEmit('md_annotation_add', data);
|
|
1548
|
+
} else if (name === 'table_annotation_add') {
|
|
1549
|
+
eventsEmit('table_annotation_add', data);
|
|
1550
|
+
} else {
|
|
1551
|
+
// 传递其他事件
|
|
1552
|
+
eventsEmit(name, data);
|
|
1553
|
+
}
|
|
1554
|
+
}}
|
|
1555
|
+
styles={styles}
|
|
1556
|
+
tools={tools}
|
|
1557
|
+
customComponents={customComponents}
|
|
1558
|
+
contentClass={contentClass}
|
|
1559
|
+
/>
|
|
1560
|
+
{(() => {
|
|
1561
|
+
console.log('=== 传递给Fviewer的markdown内容 ===');
|
|
1562
|
+
console.log('markdownContent:', markdownContent);
|
|
1563
|
+
console.log('markdownContent长度:', markdownContent.length);
|
|
1564
|
+
console.log('markdownContent前100字符:', markdownContent.substring(0, 100));
|
|
1565
|
+
console.log(
|
|
1566
|
+
'markdownContent后100字符:',
|
|
1567
|
+
markdownContent.substring(markdownContent.length - 100)
|
|
1568
|
+
);
|
|
1569
|
+
return null;
|
|
1570
|
+
})()}
|
|
1571
|
+
|
|
1572
|
+
{/* 移除加载更多指示器,不再支持分块加载 */}
|
|
1573
|
+
</div>
|
|
1574
|
+
) : fileType === 'image' ? (
|
|
1575
|
+
// 图片内容渲染
|
|
1576
|
+
<Fviewer
|
|
1577
|
+
data={{
|
|
1578
|
+
content: imageContent, // { type: 'image', url }
|
|
1579
|
+
...(getFileName() && { fileName: getFileName() }),
|
|
1580
|
+
...(fileType && { fileType }),
|
|
1581
|
+
}}
|
|
1582
|
+
annotationData={annotations}
|
|
1583
|
+
totalPage={1}
|
|
1584
|
+
currentPage={1}
|
|
1585
|
+
scale={scale}
|
|
1586
|
+
rotation={rotation}
|
|
1587
|
+
eventsEmit={eventsEmit}
|
|
1588
|
+
styles={styles}
|
|
1589
|
+
tools={{
|
|
1590
|
+
...tools,
|
|
1591
|
+
navigation: false,
|
|
1592
|
+
rotate: true,
|
|
1593
|
+
}}
|
|
1594
|
+
customComponents={customComponents}
|
|
1595
|
+
contentClass={contentClass}
|
|
1596
|
+
/>
|
|
1597
|
+
) : fileType === 'pdf' || fileType === 'pdf_slides' ? (
|
|
1598
|
+
// PDF内容渲染
|
|
1599
|
+
<Fviewer
|
|
1600
|
+
data={{
|
|
1601
|
+
content: { document: pdfDocument }, // 修复:包装成期望的数据结构
|
|
1602
|
+
...(getFileName() && { fileName: getFileName() }),
|
|
1603
|
+
...(fileType && { fileType }),
|
|
1604
|
+
...(totalPages && { totalPages }),
|
|
1605
|
+
// 添加PDF起始页信息,用于分页PDF的页码映射
|
|
1606
|
+
pdfStartPage,
|
|
1607
|
+
}}
|
|
1608
|
+
annotationData={annotations}
|
|
1609
|
+
totalPage={totalPages}
|
|
1610
|
+
currentPage={currentPage}
|
|
1611
|
+
scale={scale}
|
|
1612
|
+
initialZoom={initialZoom}
|
|
1613
|
+
eventsEmit={(name, data) => {
|
|
1614
|
+
console.log('Fviewer事件:', name, data);
|
|
1615
|
+
// 处理缩放变化事件
|
|
1616
|
+
if (name === 'scaleChange') {
|
|
1617
|
+
console.log('收到缩放变化事件:', data);
|
|
1618
|
+
// 这里需要更新scale状态,但是我们需要一个回调来更新scale
|
|
1619
|
+
// 暂时先传递事件
|
|
1620
|
+
eventsEmit(name, data);
|
|
1621
|
+
} else {
|
|
1622
|
+
// 传递其他事件
|
|
1623
|
+
eventsEmit(name, data);
|
|
1624
|
+
}
|
|
1625
|
+
}}
|
|
1626
|
+
styles={styles}
|
|
1627
|
+
tools={tools}
|
|
1628
|
+
customComponents={customComponents}
|
|
1629
|
+
contentClass={contentClass}
|
|
1630
|
+
setScale={setScale}
|
|
1631
|
+
/>
|
|
1632
|
+
) : (
|
|
1633
|
+
// 通用文件类型渲染(html、text、unknown等)
|
|
1634
|
+
<Fviewer
|
|
1635
|
+
data={{
|
|
1636
|
+
content: textContent || htmlContent || { type: 'text', content: '文件内容加载中...' },
|
|
1637
|
+
...(getFileName() && { fileName: getFileName() }),
|
|
1638
|
+
...(fileType && { fileType }),
|
|
1639
|
+
}}
|
|
1640
|
+
annotationData={annotations}
|
|
1641
|
+
totalPage={1}
|
|
1642
|
+
currentPage={1}
|
|
1643
|
+
scale={scale}
|
|
1644
|
+
eventsEmit={eventsEmit}
|
|
1645
|
+
styles={styles}
|
|
1646
|
+
tools={{
|
|
1647
|
+
...tools,
|
|
1648
|
+
navigation: false, // 通用文件类型不支持翻页
|
|
1649
|
+
}}
|
|
1650
|
+
customComponents={customComponents}
|
|
1651
|
+
contentClass={contentClass}
|
|
1652
|
+
/>
|
|
1653
|
+
)}
|
|
1654
|
+
</ReaderContainer>
|
|
1655
|
+
);
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
export default GientechStreamReader;
|