diff --git a/frontend/src/pages/Deploy/Team/List/components/NotificationConfigDialog.tsx b/frontend/src/pages/Deploy/Team/List/components/NotificationConfigDialog.tsx index bffda18b..d176dc1c 100644 --- a/frontend/src/pages/Deploy/Team/List/components/NotificationConfigDialog.tsx +++ b/frontend/src/pages/Deploy/Team/List/components/NotificationConfigDialog.tsx @@ -145,10 +145,10 @@ export const NotificationConfigDialog: React.FC< }; // 加载通知模板列表 - const loadNotificationTemplates = async () => { + const loadNotificationTemplates = async (channelType?: string) => { setLoadingTemplates(true); try { - const templates = await getNotificationTemplates(); + const templates = await getNotificationTemplates(channelType); setNotificationTemplates(templates || []); } catch (error: any) { toast({ @@ -207,11 +207,22 @@ export const NotificationConfigDialog: React.FC< useEffect(() => { if (open) { loadNotificationChannels(); - loadNotificationTemplates(); loadEnvironmentConfig(); } }, [open, teamId, environmentId]); + // 监听通知渠道变化,重新加载模板列表 + const selectedChannelId = form.watch('notificationConfig.notificationChannelId'); + + useEffect(() => { + if (open && notificationChannels.length > 0) { + const selectedChannel = notificationChannels.find( + (channel) => channel.id === selectedChannelId + ); + loadNotificationTemplates(selectedChannel?.type); + } + }, [selectedChannelId, notificationChannels, open]); + const handleSubmit = async (data: FormData) => { console.log('表单提交数据:', data); console.log('当前配置:', currentConfig); @@ -346,219 +357,249 @@ export const NotificationConfigDialog: React.FC< /> {/* 部署通知 */} -
- ( - -
- 部署通知 -
- 部署状态变更时发送通知 -
-
- - - -
- )} - /> +
+
+ {/* 左侧:通知类型标题 */} +
+ 部署通知 +
- ( - - - field.onChange(value ? Number(value) : null) - } - disabled={loadingTemplates} - > + {/* 中间:开关 */} + ( + - { - field.onChange(null); - }} - > - - + - - {notificationTemplates.map((template) => ( - + )} + /> + + {/* 右侧:模板选择 */} + ( + + + + field.onChange(value ? Number(value) : null) + } + disabled={loadingTemplates} + > + { + field.onChange(null); + }} > - {template.name} - - ))} - - -
- 部署通知模板 -
- -
- )} - /> + + + + {notificationTemplates.map((template) => ( + + {template.name} + + ))} + + + + + + )} + /> +
+ {/* 描述文字行 */} +
+
+ 部署状态变更时发送通知 +
+
+
+ 部署通知模板 +
+
{/* 构建通知 */} -
- ( - -
- 构建通知 -
- 构建状态变更时发送通知 -
-
- - - -
- )} - /> +
+
+ {/* 左侧:通知类型标题 */} +
+ 构建通知 +
- ( - - - field.onChange(value ? Number(value) : null) - } - disabled={loadingTemplates} - > + {/* 中间:开关 */} + ( + - { - field.onChange(null); - }} - > - - + - - {notificationTemplates.map((template) => ( - + )} + /> + + {/* 右侧:模板选择 */} + ( + + + + field.onChange(value ? Number(value) : null) + } + disabled={loadingTemplates} + > + { + field.onChange(null); + }} > - {template.name} - - ))} - - -
- 构建通知模板 -
- -
- )} - /> + + + + {notificationTemplates.map((template) => ( + + {template.name} + + ))} + + + + + + )} + /> +
+ {/* 描述文字行 */} +
+
+ 构建状态变更时发送通知 +
+
+
+ 构建通知模板 +
+
{/* 失败日志 */} -
- ( - -
- 失败日志 -
- 构建失败时是否发送日志 -
-
- - - -
- )} - /> +
+
+ {/* 左侧:通知类型标题 */} +
+ 失败日志 +
- ( - - - field.onChange(value ? Number(value) : null) - } - disabled={loadingTemplates} - > + {/* 中间:开关 */} + ( + - { - field.onChange(null); - }} - > - - + - - {notificationTemplates.map((template) => ( - + )} + /> + + {/* 右侧:模板选择 */} + ( + + + + field.onChange(value ? Number(value) : null) + } + disabled={loadingTemplates} + > + { + field.onChange(null); + }} > - {template.name} - - ))} - - -
- 失败日志通知模板 -
- -
- )} - /> + + + + {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 158359b9..9b69a4f0 100644 --- a/frontend/src/pages/Deploy/Team/List/service.ts +++ b/frontend/src/pages/Deploy/Team/List/service.ts @@ -177,7 +177,9 @@ export const deleteTeamEnvironmentConfig = (id: number) => /** * 获取通知模板列表 */ -export const getNotificationTemplates = () => - request.get('/api/v1/notification-template/list'); +export const getNotificationTemplates = (channelType?: string) => + request.get('/api/v1/notification-template/list', { + params: channelType ? { channelType } : undefined + });