This commit is contained in:
dengqichen 2025-01-20 16:22:46 +08:00
parent 0313c02198
commit b967af0f2a
2 changed files with 36 additions and 7 deletions

View File

@ -35,10 +35,12 @@ import {getExternalSystemList, getJenkinsViewList, getJenkinsJobList, createDepl
import {getPublishedDefinitions} from '@/pages/Workflow/Definition/service'; import {getPublishedDefinitions} from '@/pages/Workflow/Definition/service';
import type {ExternalSystem} from '@/pages/Deploy/External/types'; import type {ExternalSystem} from '@/pages/Deploy/External/types';
import { Editor } from "@/components/Editor"; import { Editor } from "@/components/Editor";
import { message } from 'antd';
interface Application { interface Application {
id: number; id: number;
appName: string; appName: string;
language: string;
} }
interface JenkinsView { interface JenkinsView {
@ -90,10 +92,12 @@ type FormValues = z.infer<typeof formSchema>;
interface DeploymentConfigModalProps { interface DeploymentConfigModalProps {
open: boolean; open: boolean;
onCancel: () => void; onCancel: () => void;
onSuccess: () => void; onSuccess?: () => void;
environmentId: number;
buildType: string;
} }
const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCancel, onSuccess}) => { const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCancel, onSuccess, environmentId, buildType}) => {
const [applications, setApplications] = useState<Application[]>([]); const [applications, setApplications] = useState<Application[]>([]);
const [externalSystems, setExternalSystems] = useState<ExternalSystem[]>([]); const [externalSystems, setExternalSystems] = useState<ExternalSystem[]>([]);
const [jenkinsViews, setJenkinsViews] = useState<JenkinsView[]>([]); const [jenkinsViews, setJenkinsViews] = useState<JenkinsView[]>([]);
@ -101,6 +105,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCa
const [workflows, setWorkflows] = useState<any[]>([]); const [workflows, setWorkflows] = useState<any[]>([]);
const [fullscreenEditor, setFullscreenEditor] = useState(false); const [fullscreenEditor, setFullscreenEditor] = useState(false);
const [isFullscreen, setIsFullscreen] = useState(false); const [isFullscreen, setIsFullscreen] = useState(false);
const [currentApp, setCurrentApp] = useState<Application | null>(null);
const form = useForm<FormValues>({ const form = useForm<FormValues>({
resolver: zodResolver(formSchema), resolver: zodResolver(formSchema),
@ -176,11 +181,22 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCa
} }
}; };
// 当选择应用时获取应用信息
const handleApplicationChange = (applicationId: number) => {
const app = applications.find(app => app.id === applicationId);
setCurrentApp(app || null);
form.setValue('applicationId', applicationId);
};
const handleSubmit = async (values: FormValues) => { const handleSubmit = async (values: FormValues) => {
try { try {
if (!environmentId) {
message.error('请选择环境');
return;
}
// 将环境变量数组转换为Map格式 // 将环境变量数组转换为Map格式
const envMap = values.envs.reduce((acc, {key, value}) => { const envMap = values.envs.reduce((acc, {key, value}) => {
// 只有当key和value都不为空时才添加到map中
if (key && value) { if (key && value) {
acc[key] = value; acc[key] = value;
} }
@ -188,14 +204,26 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCa
}, {} as Record<string, string>); }, {} as Record<string, string>);
const params = { const params = {
...values, environmentId,
envs: envMap applicationId: values.applicationId,
languageType: currentApp?.language,
workflowDefinitionId: values.workflowId,
buildType,
buildVariables: {
externalSystemId: values.externalSystemId,
viewId: values.jenkinsViewId,
jobId: values.jenkinsJobId,
envs: envMap,
script: values.script
}
}; };
await createDeploymentConfig(params); await createDeploymentConfig(params);
message.success('保存成功');
onSuccess?.(); onSuccess?.();
} catch (error) { } catch (error) {
console.error('Failed to create deployment config:', error); console.error('Failed to create deployment config:', error);
message.error('保存失败');
} }
}; };
@ -218,7 +246,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCa
<FormItem> <FormItem>
<FormLabel></FormLabel> <FormLabel></FormLabel>
<Select <Select
onValueChange={(value) => field.onChange(Number(value))} onValueChange={(value) => handleApplicationChange(Number(value))}
value={field.value?.toString()} value={field.value?.toString()}
> >
<FormControl> <FormControl>

View File

@ -411,7 +411,8 @@ const DeploymentConfigList: React.FC = () => {
onCancel={handleModalClose} onCancel={handleModalClose}
onSuccess={handleSuccess} onSuccess={handleSuccess}
initialValues={currentConfig} initialValues={currentConfig}
envId={selectedEnvId} environmentId={selectedEnvId!}
buildType={environments.find(env => env.id === selectedEnvId)?.buildType || ''}
/> />
)} )}