diff --git a/frontend/src/pages/Deploy/Team/List/components/NotificationConfigDialog.tsx b/frontend/src/pages/Deploy/Team/List/components/NotificationConfigDialog.tsx index 8fb28db1..bffda18b 100644 --- a/frontend/src/pages/Deploy/Team/List/components/NotificationConfigDialog.tsx +++ b/frontend/src/pages/Deploy/Team/List/components/NotificationConfigDialog.tsx @@ -34,6 +34,7 @@ import { getTeamEnvironmentConfig, updateTeamEnvironmentConfig, getNotificationChannels, + getNotificationTemplates, } from '../service'; // 表单验证 Schema @@ -44,8 +45,11 @@ const formSchema = z id: z.number().optional(), notificationChannelId: z.number().nullish(), deployNotificationEnabled: z.boolean().default(false), + deployNotificationTemplateId: z.number().nullish(), buildNotificationEnabled: z.boolean().default(false), + buildNotificationTemplateId: z.number().nullish(), buildFailureFileEnabled: z.boolean().default(false), + buildFailureNotificationTemplateId: z.number().nullish(), }) .optional(), }) @@ -76,6 +80,12 @@ interface NotificationChannel { type: string; } +interface NotificationTemplate { + id: number; + name: string; + type?: string; +} + interface NotificationConfigDialogProps { open: boolean; onOpenChange: (open: boolean) => void; @@ -97,6 +107,10 @@ export const NotificationConfigDialog: React.FC< NotificationChannel[] >([]); const [loadingChannels, setLoadingChannels] = useState(false); + const [notificationTemplates, setNotificationTemplates] = useState< + NotificationTemplate[] + >([]); + const [loadingTemplates, setLoadingTemplates] = useState(false); const form = useForm({ resolver: zodResolver(formSchema), @@ -104,8 +118,11 @@ export const NotificationConfigDialog: React.FC< notificationConfig: { notificationChannelId: undefined, deployNotificationEnabled: false, + deployNotificationTemplateId: undefined, buildNotificationEnabled: false, - buildFailureFileEnabled: false + buildNotificationTemplateId: undefined, + buildFailureFileEnabled: false, + buildFailureNotificationTemplateId: undefined, }, }, }); @@ -127,6 +144,23 @@ export const NotificationConfigDialog: React.FC< } }; + // 加载通知模板列表 + const loadNotificationTemplates = async () => { + setLoadingTemplates(true); + try { + const templates = await getNotificationTemplates(); + setNotificationTemplates(templates || []); + } catch (error: any) { + toast({ + title: '加载失败', + description: error.message || '无法加载通知模板列表', + variant: 'destructive', + }); + } finally { + setLoadingTemplates(false); + } + }; + // 加载环境配置 const loadEnvironmentConfig = async () => { setLoading(true); @@ -140,8 +174,11 @@ export const NotificationConfigDialog: React.FC< notificationConfig: config.notificationConfig || { notificationChannelId: undefined, deployNotificationEnabled: false, + deployNotificationTemplateId: undefined, buildNotificationEnabled: false, + buildNotificationTemplateId: undefined, buildFailureFileEnabled: false, + buildFailureNotificationTemplateId: undefined, }, }); } @@ -170,6 +207,7 @@ export const NotificationConfigDialog: React.FC< useEffect(() => { if (open) { loadNotificationChannels(); + loadNotificationTemplates(); loadEnvironmentConfig(); } }, [open, teamId, environmentId]); @@ -196,8 +234,11 @@ export const NotificationConfigDialog: React.FC< id: data.notificationConfig.id, notificationChannelId: data.notificationConfig.notificationChannelId, deployNotificationEnabled: data.notificationConfig.deployNotificationEnabled ?? false, + deployNotificationTemplateId: data.notificationConfig.deployNotificationTemplateId ?? undefined, buildNotificationEnabled: data.notificationConfig.buildNotificationEnabled ?? false, + buildNotificationTemplateId: data.notificationConfig.buildNotificationTemplateId ?? undefined, buildFailureFileEnabled: data.notificationConfig.buildFailureFileEnabled ?? false, + buildFailureNotificationTemplateId: data.notificationConfig.buildFailureNotificationTemplateId ?? undefined, }; } @@ -236,7 +277,7 @@ export const NotificationConfigDialog: React.FC< return ( - + 通知配置 @@ -305,70 +346,220 @@ export const NotificationConfigDialog: React.FC< /> {/* 部署通知 */} - ( - -
- 部署通知 -
- 部署状态变更时发送通知 +
+ ( + +
+ 部署通知 +
+ 部署状态变更时发送通知 +
-
- - - - - )} - /> + + + + + )} + /> + + ( + + + field.onChange(value ? Number(value) : null) + } + disabled={loadingTemplates} + > + + { + field.onChange(null); + }} + > + + + + + {notificationTemplates.map((template) => ( + + {template.name} + + ))} + + +
+ 部署通知模板 +
+ +
+ )} + /> +
{/* 构建通知 */} - ( - -
- 构建通知 -
- 构建状态变更时发送通知 +
+ ( + +
+ 构建通知 +
+ 构建状态变更时发送通知 +
-
- - - - - )} - /> + + + + + )} + /> + + ( + + + field.onChange(value ? Number(value) : null) + } + disabled={loadingTemplates} + > + + { + field.onChange(null); + }} + > + + + + + {notificationTemplates.map((template) => ( + + {template.name} + + ))} + + +
+ 构建通知模板 +
+ +
+ )} + /> +
{/* 失败日志 */} - ( - -
- 失败日志 -
- 构建失败时是否发送日志 +
+ ( + +
+ 失败日志 +
+ 构建失败时是否发送日志 +
-
- - - - - )} - /> + + + + + )} + /> + + ( + + + field.onChange(value ? Number(value) : null) + } + disabled={loadingTemplates} + > + + { + field.onChange(null); + }} + > + + + + + {notificationTemplates.map((template) => ( + + {template.name} + + ))} + + +
+ 失败日志通知模板 +
+ +
+ )} + /> +
diff --git a/frontend/src/pages/Deploy/Team/List/service.ts b/frontend/src/pages/Deploy/Team/List/service.ts index 458918f7..158359b9 100644 --- a/frontend/src/pages/Deploy/Team/List/service.ts +++ b/frontend/src/pages/Deploy/Team/List/service.ts @@ -174,3 +174,10 @@ export const updateTeamEnvironmentConfig = ( export const deleteTeamEnvironmentConfig = (id: number) => request.delete(`/api/v1/team-environment-config/${id}`); +/** + * 获取通知模板列表 + */ +export const getNotificationTemplates = () => + request.get('/api/v1/notification-template/list'); + + diff --git a/frontend/src/pages/Deploy/Team/List/types.ts b/frontend/src/pages/Deploy/Team/List/types.ts index 83c4bcb4..8370cee6 100644 --- a/frontend/src/pages/Deploy/Team/List/types.ts +++ b/frontend/src/pages/Deploy/Team/List/types.ts @@ -54,8 +54,11 @@ export interface NotificationConfig { environmentId?: number; notificationChannelId?: number; deployNotificationEnabled?: boolean; + deployNotificationTemplateId?: number; buildNotificationEnabled?: boolean; + buildNotificationTemplateId?: number; buildFailureFileEnabled?: boolean; + buildFailureNotificationTemplateId?: number; notificationChannelName?: string; // 关联数据 channelType?: string; // 渠道类型:WEWORK, EMAIL, DINGTALK等 updateTime?: string; // 更新时间 @@ -94,8 +97,11 @@ export interface TeamEnvironmentConfigRequest { id?: number; notificationChannelId?: number; deployNotificationEnabled?: boolean; + deployNotificationTemplateId?: number; buildNotificationEnabled?: boolean; + buildNotificationTemplateId?: number; buildFailureFileEnabled?: boolean; + buildFailureNotificationTemplateId?: number; }; }