From ad02c32ac643ccc72b138264a95ab80ca7cf37ce Mon Sep 17 00:00:00 2001 From: rockbenben Date: Tue, 3 Dec 2024 21:13:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=AE=9A=E4=B9=89=E5=88=86?= =?UTF-8?q?=E5=89=B2=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #18 --- src/app/(text)/text-splitter/client.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app/(text)/text-splitter/client.tsx b/src/app/(text)/text-splitter/client.tsx index d2f5ea8..c8d08df 100644 --- a/src/app/(text)/text-splitter/client.tsx +++ b/src/app/(text)/text-splitter/client.tsx @@ -13,6 +13,7 @@ const ClientPage = () => { const [copiedIndexes, setCopiedIndexes] = useState(new Set()); const [limit, setLimit] = useState(2000); const [useSentenceEnd, setUseSentenceEnd] = useState(false); + const [customFileName, setCustomFileName] = useState(""); const handleInputChange = (e: React.ChangeEvent) => { setInputText(e.target.value); @@ -80,36 +81,37 @@ const ClientPage = () => { }); }; - // New function to export full split text as a single file + // Export full split text as a single file const handleExportFullText = () => { if (splittedTexts.length === 0) { message.error("没有可导出的文本"); return; } + const fileName = customFileName || "split_text_full"; const fullText = splittedTexts.join("\n\n"); const blob = new Blob([fullText], { type: "text/plain;charset=utf-8" }); const link = document.createElement("a"); link.href = URL.createObjectURL(blob); - link.download = `split_text_full.txt`; + link.download = `${fileName}.txt`; link.click(); URL.revokeObjectURL(link.href); message.success("全文本已导出"); }; - // Modified batch export to create individual text files + // Export each split text as a separate file const handleBatchExport = () => { if (splittedTexts.length === 0) { message.error("没有可导出的文本"); return; } - // Export each split text as a separate file + const baseFileName = customFileName || "split_text"; splittedTexts.forEach((text, index) => { const blob = new Blob([text], { type: "text/plain;charset=utf-8" }); const link = document.createElement("a"); link.href = URL.createObjectURL(blob); - link.download = `split_text_${index + 1}.txt`; + link.download = `${baseFileName}_${index + 1}.txt`; link.click(); URL.revokeObjectURL(link.href); }); @@ -157,6 +159,9 @@ const ClientPage = () => { + + setCustomFileName(e.target.value)} /> + )}