diff --git a/frontend/src/components/approval/ApprovalCreateDialog.tsx b/frontend/src/components/approval/ApprovalCreateDialog.tsx index 2704be0..164e57a 100644 --- a/frontend/src/components/approval/ApprovalCreateDialog.tsx +++ b/frontend/src/components/approval/ApprovalCreateDialog.tsx @@ -21,6 +21,7 @@ import { } from '@/components/ui/dialog'; import { Loader2 } from 'lucide-react'; import { toast } from 'sonner'; +import { useTranslation } from 'react-i18next'; import { approvalApi } from '@/api'; import { parseFields, APPROVAL_TYPE_OPTIONS } from './helpers'; import type { JsonData } from '@/types/common'; @@ -39,6 +40,7 @@ export function ApprovalCreateDialog({ templates, onSuccess, }: ApprovalCreateDialogProps) { + const { t } = useTranslation(); const [selectedTemplate, setSelectedTemplate] = useState(null); const [formData, setFormData] = useState({}); const [submitting, setSubmitting] = useState(false); @@ -46,13 +48,13 @@ export function ApprovalCreateDialog({ // 提交新建申请 // Logan.Li const handleSubmit = async () => { if (!selectedTemplate) { - toast.error('请先选择申请类型'); + toast.error(t('approval.flow.pleaseSelectType')); return; } const fields = parseFields(selectedTemplate.form_schema); for (const f of fields) { if (f.required && !formData[f.key]) { - toast.error(`请填写${f.label}`); + toast.error(t('approval.flow.pleaseFillField', { label: f.label })); return; } } @@ -63,13 +65,13 @@ export function ApprovalCreateDialog({ title: formData.app_name || selectedTemplate.name, form_data: JSON.stringify(formData), }); - toast.success('申请已提交'); + toast.success(t('approval.msg.submitSuccess')); onOpenChange(false); setSelectedTemplate(null); setFormData({}); onSuccess(); } catch (e) { - toast.error('提交失败', { description: e?.message }); + toast.error(t('approval.msg.submitFailed'), { description: e?.message }); } finally { setSubmitting(false); } @@ -89,9 +91,9 @@ export function ApprovalCreateDialog({ > - 新建资源申请 + {t('approval.flow.newResourceRequest')} - {selectedTemplate ? '请填写申请信息' : '请选择申请类型'} + {selectedTemplate ? t('approval.flow.fillInfo') : t('approval.flow.selectType')} @@ -100,7 +102,7 @@ export function ApprovalCreateDialog({
{APPROVAL_TYPE_OPTIONS.map((opt) => { const tpl = templates.find( - (t) => t.type === opt.value && (t.enabled !== false) + (tm) => tm.type === opt.value && (tm.enabled !== false) ); const Icon = opt.icon; return ( @@ -124,7 +126,7 @@ export function ApprovalCreateDialog({

{opt.label}

- {tpl ? tpl.description || `共 ${parseFields(tpl.form_schema).length} 个字段` : '暂无可用模板'} + {tpl ? tpl.description || t('approval.flow.fieldCount', { count: parseFields(tpl.form_schema).length }) : t('approval.flow.noTemplateAvailable')}

@@ -140,7 +142,7 @@ export function ApprovalCreateDialog({ onClick={() => { setSelectedTemplate(null); setFormData({}); }} className="text-xs text-[var(--dg-text-muted)] hover:text-[var(--dg-text-primary)]" > - ← 返回选择类型 + {t('approval.flow.backToSelect')}
@@ -158,7 +160,7 @@ export function ApprovalCreateDialog({ onValueChange={(val) => setFormData((prev) => ({ ...prev, [field.key]: val }))} > - + {(field.options || []).map((opt: string) => ( @@ -170,7 +172,7 @@ export function ApprovalCreateDialog({ ) : field.type === 'textarea' ? (