From 67553afe9c8492055bc6639dcfd08c137967a927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E9=9C=96=E9=93=83?= Date: Fri, 22 May 2026 21:10:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=86=20TextStatistics=20?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=92=8C=20TextInputArea=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=85=A8=E9=9D=A2=E8=BF=81=E7=A7=BB=E8=87=B3=20shadcn?= =?UTF-8?q?=20=E6=A0=B7=E5=BC=8F=E5=B9=B6=E4=BC=98=E5=8C=96=E5=B8=83?= =?UTF-8?q?=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/TextInputArea.tsx | 25 ++++------ pages/TextStatistics/index.tsx | 88 +++++++++++++++------------------- 2 files changed, 49 insertions(+), 64 deletions(-) diff --git a/components/TextInputArea.tsx b/components/TextInputArea.tsx index cb076da..b644825 100644 --- a/components/TextInputArea.tsx +++ b/components/TextInputArea.tsx @@ -220,7 +220,6 @@ const TextInputArea = forwardRef((props return (
- {/* 顶部工具栏 */} {hasTopBar && (
@@ -247,10 +246,9 @@ const TextInputArea = forwardRef((props
)} - {/* 核心卡片容器:完美适配 shadcn 风格的多行包裹框 */}
((props autoFocus={autoFocus} readOnly={readOnly} placeholder={placeholder} - className="w-full bg-transparent px-3 py-2.5 font-mono text-sm leading-relaxed text-foreground placeholder:text-muted-foreground focus:outline-none resize-none border-0 block" + className="w-full bg-transparent px-4 py-3 font-mono text-sm leading-relaxed text-foreground placeholder:text-muted-foreground/50 focus:outline-none resize-none border-0 block" {...restProps} /> - {/* 底部隔离式功能区:杜绝重叠和塌陷 */} {hasBottomBar && ( -
-
+
+ {/* 左侧自定义动作 */} +
{bottomActions.map((action) => ( ((props ))}
-
+ {/* 右侧系统按钮组 */} +
{allowCopy && value && ( @@ -299,9 +296,7 @@ const TextInputArea = forwardRef((props @@ -311,7 +306,7 @@ const TextInputArea = forwardRef((props )}
- {/* 错误提示区域 */} + {/* 错误提示 */} {displayError && (

{displayError} diff --git a/pages/TextStatistics/index.tsx b/pages/TextStatistics/index.tsx index 9f44c9d..6720a14 100644 --- a/pages/TextStatistics/index.tsx +++ b/pages/TextStatistics/index.tsx @@ -3,15 +3,10 @@ import { FileText } from 'lucide-react'; import PageHeader from '@/components/PageHeader'; import TextInputArea from '@/components/TextInputArea'; import { formatByteSize, getTextStats } from '@/utils/textStatistics'; -import { textStatisticsPageStyles } from '@/config/pageTheme'; import { useLazyTranslation } from '@/utils/useLazyTranslation'; import { useContextMenuData } from '@/utils/useContextMenuData'; +import { cn } from '@/lib/utils'; -/** - * 文本统计页面组件 - * - * 提供实时的文本分析功能,包括字符数、单词数、行数和字节大小。 - */ export default function Index() { const { t } = useLazyTranslation('textStatistics'); const [text, setText] = useState(''); @@ -22,8 +17,7 @@ export default function Index() { useContextMenuData({ featureKey: 'textStatistics', onData: handleContextMenuData }); - // 实时计算统计信息,使用 useMemo 优化性能 - // 对于 10,000 字符以上的文本,Intl.Segmenter 也能保持良好的性能 + // 实时计算统计信息,由 useMemo 拦截非必要计算 const stats = useMemo(() => getTextStats(text), [text]); const statItems = [ @@ -34,49 +28,45 @@ export default function Index() { ]; return ( -

-
- {/* 头部区域 */} - } - iconColor={textStatisticsPageStyles.primaryColor} - /> +
+ {/* 头部区域 */} + } + iconColor="text-purple-500" + /> - {/* 文本输入区域 */} - + {/* 文本输入区域 */} + - {/* 统计结果展示区域 */} -
- {statItems.map((item) => ( -
- - {item.label} - - - {item.value} - -
- ))} -
+ {/* 统计结果展示区域 */} +
+ {statItems.map((item) => ( +
+ + {item.label} + + + {item.value} + +
+ ))}
);