From a374bf456dfcf988d0d839ad006390aaff7b756e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E9=9C=96=E9=93=83?= Date: Sat, 6 Jun 2026 10:47:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=8C=89=E9=92=AE=E7=BB=84=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 Select 下拉框 - 改为 JSON/CSV 按钮组 - 选中状态与生成数量按钮样式统一 feat: 优化空值率设置 - 增加 75% 预设选项 - 设置 100% 时自动设为必填 - 限制输入范围 0-100 fix: 空值率预设改为纯数字显示 - 5%/20%/50%/75% 统一样式 fix: 移除空值率低/中/高 i18n 翻译键 fix: 精简生成数量预设选项 - 移除 10、500 - 保留 50、100、1000、5000、10000 --- public/_locales/zh_CN/messages.json | 12 ------ .../components/FieldEditor.tsx | 23 ++++++++--- .../components/GenerateOptions.tsx | 38 ++++++++++--------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/public/_locales/zh_CN/messages.json b/public/_locales/zh_CN/messages.json index 2a92b0d..9f7776a 100644 --- a/public/_locales/zh_CN/messages.json +++ b/public/_locales/zh_CN/messages.json @@ -971,18 +971,6 @@ "message": "空值率", "description": "Translation key: testDataGenerator_nullRate" }, - "testDataGenerator_nullRateLow": { - "message": "低 (5%)", - "description": "Translation key: testDataGenerator_nullRateLow" - }, - "testDataGenerator_nullRateMedium": { - "message": "中 (20%)", - "description": "Translation key: testDataGenerator_nullRateMedium" - }, - "testDataGenerator_nullRateHigh": { - "message": "高 (50%)", - "description": "Translation key: testDataGenerator_nullRateHigh" - }, "testDataGenerator_uniqueConstraint": { "message": "唯一性约束", "description": "Translation key: testDataGenerator_uniqueConstraint" diff --git a/src/pages/TestDataGenerator/components/FieldEditor.tsx b/src/pages/TestDataGenerator/components/FieldEditor.tsx index e074ba0..06af793 100644 --- a/src/pages/TestDataGenerator/components/FieldEditor.tsx +++ b/src/pages/TestDataGenerator/components/FieldEditor.tsx @@ -38,7 +38,14 @@ export default function FieldEditor({ field, onChange }: FieldEditorProps) { }; const handleNullRateChange = (nullRate: number) => { - onChange({ ...field, nullRate }); + // 限制范围 0-100 + const clampedRate = Math.max(0, Math.min(100, nullRate)); + // 设置为 100% 时自动设为必填 + if (clampedRate === 100) { + onChange({ ...field, nullRate: clampedRate, required: true }); + } else { + onChange({ ...field, nullRate: clampedRate }); + } }; const handleUniqueChange = (unique: boolean) => { @@ -63,9 +70,10 @@ export default function FieldEditor({ field, onChange }: FieldEditorProps) { }; const nullRatePresets = [ - { label: t('testDataGenerator_nullRateLow'), value: 5 }, - { label: t('testDataGenerator_nullRateMedium'), value: 20 }, - { label: t('testDataGenerator_nullRateHigh'), value: 50 }, + { label: '5%', value: 5 }, + { label: '20%', value: 20 }, + { label: '50%', value: 50 }, + { label: '75%', value: 75 }, ]; return ( @@ -129,7 +137,12 @@ export default function FieldEditor({ field, onChange }: FieldEditorProps) { handleNullRateChange(Number(e.target.value))} + onChange={(e) => { + const value = Number(e.target.value); + if (value >= 0 && value <= 100) { + handleNullRateChange(value); + } + }} min={0} max={100} step={5} diff --git a/src/pages/TestDataGenerator/components/GenerateOptions.tsx b/src/pages/TestDataGenerator/components/GenerateOptions.tsx index 0e3c8ca..aa8bfef 100644 --- a/src/pages/TestDataGenerator/components/GenerateOptions.tsx +++ b/src/pages/TestDataGenerator/components/GenerateOptions.tsx @@ -5,13 +5,6 @@ import { useI18n } from '@/utils/chromeI18n'; import { Input } from '@/components/ui/input'; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from '@/components/ui/select'; interface GenerateOptionsProps { count: number; @@ -22,7 +15,12 @@ interface GenerateOptionsProps { onDefaultNullRateChange: (rate: number) => void; } -const COUNT_PRESETS = [10, 50, 100, 500, 1000, 5000, 10000]; +const COUNT_PRESETS = [50, 100, 1000, 5000, 10000]; + +const FORMAT_OPTIONS = [ + { value: 'json' as const, label: 'JSON' }, + { value: 'csv' as const, label: 'CSV' }, +]; export default function GenerateOptions({ count, @@ -76,15 +74,21 @@ export default function GenerateOptions({ - +
+ {FORMAT_OPTIONS.map((option) => ( + + ))} +
{/* 默认空值率 */}