aa23a263fe
- 移除 react-i18next、i18next 及相关依赖
- 删除旧的 i18n/ 目录和 useLazyTranslation 工具
- 新增 utils/chromeI18n.ts 类型安全 wrapper(useI18n Hook + getMessage)
- 生成 public/_locales/{zh,en}/messages.json(298 个翻译 key)
- 批量更新 39+ 组件文件的导入和翻译调用
- 转换翻译键格式:namespace:key → namespace_key
- 修复 ErrorBoundary/PageErrorBoundary 从 withTranslation HOC 改为直接调用 getMessage
- 更新 vitest.setup.ts mock 加载实际翻译文本
- 修复 11 个测试文件的断言以匹配中文翻译
- TypeScript、ESLint、547 项测试全部通过
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { useCallback, useMemo, useState } from 'react';
|
|
import TextInputArea from '@/components/TextInputArea';
|
|
import { formatByteSize, getTextStats } from '@/utils/textStatistics';
|
|
import { useI18n } from '@/utils/chromeI18n';
|
|
import { useContextMenuData } from '@/utils/useContextMenuData';
|
|
import { cn } from '@/lib/utils';
|
|
|
|
export default function Index() {
|
|
const { t } = useI18n('textStatistics');
|
|
const [text, setText] = useState('');
|
|
|
|
const handleContextMenuData = useCallback((payload: string) => {
|
|
setText(payload);
|
|
}, []);
|
|
|
|
useContextMenuData({ featureKey: 'textStatistics', onData: handleContextMenuData });
|
|
|
|
// 实时计算统计信息,由 useMemo 拦截非必要计算
|
|
const stats = useMemo(() => getTextStats(text), [text]);
|
|
|
|
const statItems = [
|
|
{ label: t('textStatistics:characters'), value: stats.characters },
|
|
{ label: t('textStatistics:words'), value: stats.words },
|
|
{ label: t('textStatistics:lines'), value: stats.lines },
|
|
{ label: t('textStatistics:bytes'), value: formatByteSize(stats.bytes) },
|
|
];
|
|
|
|
return (
|
|
<div className="p-4 w-full space-y-4">
|
|
{/* 文本输入区域 */}
|
|
<TextInputArea
|
|
value={text}
|
|
onChange={setText}
|
|
placeholder={t('textStatistics:placeholder')}
|
|
minRows={10}
|
|
maxRows={18}
|
|
showClear={true}
|
|
allowCopy={true}
|
|
/>
|
|
|
|
{/* 统计结果展示区域 */}
|
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
|
|
{statItems.map((item) => (
|
|
<div
|
|
key={item.label}
|
|
className={cn(
|
|
'flex flex-col justify-center items-center p-4 text-center rounded-xl border border-border bg-card shadow-sm text-card-foreground',
|
|
'hover:-translate-y-0.5 hover:shadow-md hover:border-primary/50 focus-within:ring-1 focus-within:ring-ring',
|
|
)}
|
|
>
|
|
<span className="text-xs font-medium text-muted-foreground tracking-wider mb-1 select-none">
|
|
{item.label}
|
|
</span>
|
|
<span className="font-mono text-lg md:text-2xl font-extrabold text-primary break-all tracking-tight leading-none tabular-nums select-all">
|
|
{item.value}
|
|
</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|