From 23f4daf3e9ad88aa1488d8831da0fab770a447eb Mon Sep 17 00:00:00 2001 From: dengqichen Date: Mon, 29 Dec 2025 14:53:29 +0800 Subject: [PATCH] 1.465 --- .../List/components/EditDialog.tsx | 233 ++++++++++++++++++ .../pages/Deploy/Application/List/service.ts | 4 +- 2 files changed, 235 insertions(+), 2 deletions(-) create mode 100644 frontend/src/pages/Deploy/Application/List/components/EditDialog.tsx diff --git a/frontend/src/pages/Deploy/Application/List/components/EditDialog.tsx b/frontend/src/pages/Deploy/Application/List/components/EditDialog.tsx new file mode 100644 index 00000000..3c7fbdf1 --- /dev/null +++ b/frontend/src/pages/Deploy/Application/List/components/EditDialog.tsx @@ -0,0 +1,233 @@ +import React, { useEffect, useState } from 'react'; +import { + Dialog, + DialogContent, + DialogHeader, + DialogBody, + DialogTitle, + DialogFooter, +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Textarea } from '@/components/ui/textarea'; +import { Switch } from '@/components/ui/switch'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from '@/components/ui/select'; +import { useToast } from '@/components/ui/use-toast'; +import { createApplication, updateApplication } from '../service'; +import { getEnabledCategories } from '../../Category/service'; +import type { Application, CreateApplicationRequest } from '../types'; +import { DevelopmentLanguageTypeEnum } from '../types'; +import type { ApplicationCategoryResponse } from '../../Category/types'; + +// 表单数据类型(包含enabled字段) +interface ApplicationFormData extends Partial { + enabled?: boolean; +} + +interface EditDialogProps { + open: boolean; + record?: Application; + onOpenChange: (open: boolean) => void; + onSuccess: () => void; +} + +/** + * 应用编辑对话框 + */ +const EditDialog: React.FC = ({ + open, + record, + onOpenChange, + onSuccess, +}) => { + const { toast } = useToast(); + const [categories, setCategories] = useState([]); + const [formData, setFormData] = useState({ + enabled: true, + sort: 0, + language: DevelopmentLanguageTypeEnum.JAVA, + }); + + // 加载分类列表 + const loadCategories = async () => { + try { + const data = await getEnabledCategories(); + setCategories(data || []); + } catch (error) { + console.error('加载分类失败:', error); + } + }; + + useEffect(() => { + if (open) { + loadCategories(); + if (record) { + setFormData({ + appCode: record.appCode, + appName: record.appName, + appDesc: record.appDesc, + applicationCategoryId: record.applicationCategoryId, + language: record.language, + sort: record.sort, + enabled: record.enabled, + }); + } else { + setFormData({ + enabled: true, + sort: 0, + language: DevelopmentLanguageTypeEnum.JAVA, + }); + } + } + }, [open, record]); + + const handleSubmit = async () => { + try { + // 验证 + if (!formData.appCode?.trim()) { + toast({ title: '提示', description: '请输入应用编码', variant: 'destructive' }); + return; + } + if (!formData.appName?.trim()) { + toast({ title: '提示', description: '请输入应用名称', variant: 'destructive' }); + return; + } + + if (record) { + await updateApplication({ ...formData, id: record.id } as any); + toast({ title: '更新成功', description: `应用 "${formData.appName}" 已更新` }); + } else { + await createApplication(formData as CreateApplicationRequest); + toast({ title: '创建成功', description: `应用 "${formData.appName}" 已创建` }); + } + + onSuccess(); + onOpenChange(false); + } catch (error) { + console.error('保存失败:', error); + toast({ + title: '保存失败', + description: error instanceof Error ? error.message : '未知错误', + variant: 'destructive' + }); + } + }; + + + return ( + + + + {record ? '编辑应用' : '新建应用'} + + +
+
+ + +
+ +
+ + setFormData({ ...formData, appCode: e.target.value })} + placeholder="请输入应用编码" + disabled={!!record} + /> +
+ +
+ + setFormData({ ...formData, appName: e.target.value })} + placeholder="请输入应用名称" + /> +
+ +
+ + +
+ +
+ +