@@ -145,6 +145,14 @@ const AppMonitor = (props) => {
145145 } ;
146146
147147 const enableMonitoring = async ( ) => {
148+ // 检查是否有可用域名
149+ if ( domain_names . length === 0 ) {
150+ setShowAlert ( true ) ;
151+ setAlertMessage ( _ ( "Please bind a domain name to the application before enabling monitoring." ) ) ;
152+ setAlertType ( "warning" ) ;
153+ return ;
154+ }
155+
148156 if ( ! monitorUrl || ! notificationEmail || ! isEmailValid ) return ;
149157
150158 setLoading ( true ) ;
@@ -183,6 +191,14 @@ const AppMonitor = (props) => {
183191 } ;
184192
185193 const updateMonitoring = async ( ) => {
194+ // 检查是否有可用域名
195+ if ( domain_names . length === 0 ) {
196+ setShowAlert ( true ) ;
197+ setAlertMessage ( _ ( "Please bind a domain name to the application before updating monitoring." ) ) ;
198+ setAlertType ( "warning" ) ;
199+ return ;
200+ }
201+
186202 if ( ! monitorUrl || ! notificationEmail || ! isEmailValid ) return ;
187203
188204 setLoading ( true ) ;
@@ -252,7 +268,18 @@ const AppMonitor = (props) => {
252268 // 组件挂载时查询监控状态
253269 useEffect ( ( ) => {
254270 if ( app_id ) {
255- // 使用统一的配置管理器并查询监控状态
271+ // 检查是否有可用的域名,没有域名时不需要调用监控API
272+ if ( domain_names . length === 0 ) {
273+ // 没有域名绑定时,直接设置为禁用状态,不调用API
274+ setMonitorStatus ( 'disabled' ) ;
275+ setMonitorUrl ( '' ) ;
276+ setNotificationEmail ( '' ) ;
277+ setDashboardUrl ( '' ) ;
278+ setLoading ( false ) ;
279+ return ;
280+ }
281+
282+ // 有域名时才调用监控相关API
256283 const initializeAndQuery = async ( ) => {
257284 try {
258285 await configManager . initialize ( ) ;
@@ -267,7 +294,7 @@ const AppMonitor = (props) => {
267294
268295 initializeAndQuery ( ) ;
269296 }
270- } , [ app_id , props . dataRefreshKey ] ) ; // 添加 dataRefreshKey 作为依赖
297+ } , [ app_id , props . dataRefreshKey , domain_names . length ] ) ; // 添加 domain_names.length 作为依赖
271298
272299 const handleEnableMonitoring = ( ) => {
273300 if ( monitorUrl && notificationEmail && isEmailValid ) {
@@ -287,8 +314,16 @@ const AppMonitor = (props) => {
287314
288315 const handleCancelEdit = ( ) => {
289316 setIsEditing ( false ) ;
290- // 恢复原来的值
291- queryMonitorStatus ( ) ;
317+ // 只有在有域名的情况下才恢复原来的值(调用API)
318+ if ( domain_names . length > 0 ) {
319+ queryMonitorStatus ( ) ;
320+ } else {
321+ // 没有域名时直接重置状态
322+ setMonitorUrl ( '' ) ;
323+ setNotificationEmail ( '' ) ;
324+ setMonitorStatus ( 'disabled' ) ;
325+ setDashboardUrl ( '' ) ;
326+ }
292327 } ;
293328
294329 return (
@@ -339,7 +374,7 @@ const AppMonitor = (props) => {
339374 onChange = { handleEmailChange }
340375 isInvalid = { ! isEmailValid }
341376 size = "sm"
342- disabled = { ( monitorStatus === 'enabled' && ! isEditing ) || loading }
377+ disabled = { domain_names . length === 0 || ( monitorStatus === 'enabled' && ! isEditing ) || loading }
343378 className = "me-2"
344379 />
345380 { ! isEmailValid && (
0 commit comments