This commit is contained in:
dengqichen 2024-12-23 18:22:58 +08:00
parent 899ce66e36
commit b42dfcb517
3 changed files with 53 additions and 9 deletions

View File

@ -40,7 +40,7 @@ const ApplicationList: React.FC = () => {
try { try {
const data = await getApplicationList(); const data = await getApplicationList();
// TODO: 这里需要根据selectedProjectId筛选应用 // TODO: 这里需要根据selectedProjectId筛选应用
setApplications(data.filter(app => app.projectId === selectedProjectGroupId)); setApplications(data.filter(app => app.projectGroupId === selectedProjectGroupId));
} catch (error) { } catch (error) {
message.error('获取应用列表失败'); message.error('获取应用列表失败');
} finally { } finally {

View File

@ -2,7 +2,7 @@ import type { BaseQuery } from '@/types/base';
export interface Application { export interface Application {
id: number; id: number;
projectId: number; projectGroupId: number;
appCode: string; appCode: string;
appName: string; appName: string;
appDesc?: string; appDesc?: string;
@ -11,7 +11,7 @@ export interface Application {
} }
export interface CreateApplicationRequest { export interface CreateApplicationRequest {
projectId: number; projectGroupId: number;
appCode: string; appCode: string;
appName: string; appName: string;
appDesc?: string; appDesc?: string;
@ -24,7 +24,7 @@ export interface UpdateApplicationRequest extends CreateApplicationRequest {
} }
export interface ApplicationQuery extends BaseQuery { export interface ApplicationQuery extends BaseQuery {
projectId?: number; projectGroupId?: number;
appCode?: string; appCode?: string;
appName?: string; appName?: string;
appStatus?: string; appStatus?: string;

View File

@ -1,7 +1,9 @@
import React, { useEffect } from 'react'; import React, { useEffect, useState } from 'react';
import { Modal, Form, Input, InputNumber, Radio, message } from 'antd'; import { Modal, Form, Input, InputNumber, Radio, message, Select } from 'antd';
import type { ProjectGroup } from '../types'; import type { ProjectGroup } from '../types';
import type { Environment } from '../../../Environment/List/types';
import { createProjectGroup, updateProjectGroup } from '../service'; import { createProjectGroup, updateProjectGroup } from '../service';
import { getEnvironmentList } from '../../../Environment/List/service';
interface ProjectModalProps { interface ProjectModalProps {
visible: boolean; visible: boolean;
@ -17,22 +19,48 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
initialValues, initialValues,
}) => { }) => {
const [form] = Form.useForm(); const [form] = Form.useForm();
const [environments, setEnvironments] = useState<Environment[]>([]);
const isEdit = !!initialValues; const isEdit = !!initialValues;
// 获取环境列表
useEffect(() => {
const fetchEnvironments = async () => {
try {
const data = await getEnvironmentList();
setEnvironments(data);
} catch (error) {
message.error('获取环境列表失败');
}
};
fetchEnvironments();
}, []);
useEffect(() => { useEffect(() => {
if (visible && initialValues) { if (visible && initialValues) {
form.setFieldsValue(initialValues); // 设置初始值包括环境ID列表
const envIds = initialValues.environments?.map(env => env.id) || [];
form.setFieldsValue({
...initialValues,
environments: envIds
});
} }
}, [visible, initialValues, form]); }, [visible, initialValues, form]);
const handleSubmit = async () => { const handleSubmit = async () => {
try { try {
const values = await form.validateFields(); const values = await form.validateFields();
// 转换环境ID数组为对象数组
const environments = (values.environments || []).map((id: number) => ({ id }));
const submitData = {
...values,
environments
};
if (isEdit) { if (isEdit) {
await updateProjectGroup({ ...values, id: initialValues.id }); await updateProjectGroup({ ...submitData, id: initialValues.id });
message.success('更新成功'); message.success('更新成功');
} else { } else {
await createProjectGroup(values); await createProjectGroup(submitData);
message.success('创建成功'); message.success('创建成功');
} }
onSuccess(); onSuccess();
@ -99,6 +127,22 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
<Form.Item
name="environments"
label="关联环境"
rules={[{ required: true, message: '请选择关联环境' }]}
>
<Select
mode="multiple"
placeholder="请选择关联环境"
optionFilterProp="label"
options={environments.map(env => ({
label: env.envName,
value: env.id,
}))}
/>
</Form.Item>
<Form.Item <Form.Item
name="sort" name="sort"
label="排序" label="排序"