@@ -566,6 +566,24 @@ function addOrEditServer(server, conf) {
566566
567567 // 为动态添加的删除图标绑定点击事件
568568 bindDeleteIconEvents ( ) ;
569+
570+ // 专门为服务器模态框初始化dropdown,避免干扰标签创建
571+ setTimeout ( function ( ) {
572+ console . log ( '服务器模态框:延迟初始化dropdown' ) ;
573+ // 只初始化DDNS dropdown,因为这是服务器编辑需要的
574+ $ ( ".server.modal .ui.ddns.search.dropdown" ) . dropdown ( {
575+ clearable : true ,
576+ apiSettings : {
577+ url : "/api/search-ddns?word={query}" ,
578+ cache : false ,
579+ } ,
580+ // 禁用onChange事件,避免干扰现有标签
581+ onChange : function ( value , text , $choice ) {
582+ // 不做任何操作,保持现有标签不变
583+ console . log ( '服务器DDNS dropdown onChange被触发,但已禁用处理' ) ;
584+ }
585+ } ) ;
586+ } , 500 ) ; // 延迟500ms确保标签已经创建完成
569587}
570588
571589function addOrEditMonitor ( monitor ) {
@@ -960,7 +978,11 @@ function initializeServersDropdown() {
960978}
961979
962980$ ( document ) . ready ( ( ) => {
963- initializeServersDropdown ( ) ;
981+ // 只在需要服务器dropdown的页面初始化
982+ const currentPath = window . location . pathname ;
983+ if ( currentPath === '/server' || currentPath === '/monitor' || currentPath === '/cron' ) {
984+ initializeServersDropdown ( ) ;
985+ }
964986} ) ;
965987
966988// 延迟初始化任务dropdown
@@ -1027,7 +1049,11 @@ function initializeTasksDropdown() {
10271049}
10281050
10291051$ ( document ) . ready ( ( ) => {
1030- initializeTasksDropdown ( ) ;
1052+ // 只在需要任务dropdown的页面初始化
1053+ const currentPath = window . location . pathname ;
1054+ if ( currentPath === '/monitor' || currentPath === '/notification' ) {
1055+ initializeTasksDropdown ( ) ;
1056+ }
10311057} ) ;
10321058
10331059// 延迟初始化DDNS dropdown
@@ -1094,7 +1120,11 @@ function initializeDDNSDropdown() {
10941120}
10951121
10961122$ ( document ) . ready ( ( ) => {
1097- initializeDDNSDropdown ( ) ;
1123+ // 只在需要DDNS dropdown的页面初始化
1124+ const currentPath = window . location . pathname ;
1125+ if ( currentPath === '/server' || currentPath === '/ddns' ) {
1126+ initializeDDNSDropdown ( ) ;
1127+ }
10981128} ) ;
10991129
11001130// 为动态添加的删除图标绑定点击事件
@@ -1158,10 +1188,10 @@ window.reinitializeAllDropdowns = function() {
11581188} ;
11591189
11601190// 监听模态框显示事件,但不要立即重新初始化dropdown
1161- // 因为这会干扰Cron编辑时的标签创建
1191+ // 因为这会干扰编辑时的标签创建
11621192$ ( document ) . on ( 'shown.bs.modal' , '.modal' , function ( ) {
1163- // 只在非Cron模态框时重新初始化dropdown
1164- if ( ! $ ( this ) . hasClass ( 'cron' ) ) {
1193+ // 只在非编辑模态框时重新初始化dropdown
1194+ if ( ! $ ( this ) . hasClass ( 'cron' ) && ! $ ( this ) . hasClass ( 'server' ) ) {
11651195 window . reinitializeAllDropdowns ( ) ;
11661196 }
11671197} ) ;
@@ -1171,7 +1201,7 @@ const modalObserver = new MutationObserver(function(mutations) {
11711201 mutations . forEach ( function ( mutation ) {
11721202 if ( mutation . type === 'attributes' && mutation . attributeName === 'class' ) {
11731203 const target = mutation . target ;
1174- if ( $ ( target ) . hasClass ( 'ui modal visible active' ) && ! $ ( target ) . hasClass ( 'cron' ) ) {
1204+ if ( $ ( target ) . hasClass ( 'ui modal visible active' ) && ! $ ( target ) . hasClass ( 'cron' ) && ! $ ( target ) . hasClass ( 'server' ) ) {
11751205 setTimeout ( function ( ) {
11761206 window . reinitializeAllDropdowns ( ) ;
11771207 } , 300 ) ;
@@ -1180,7 +1210,7 @@ const modalObserver = new MutationObserver(function(mutations) {
11801210 // 监听新增的模态框节点
11811211 if ( mutation . type === 'childList' ) {
11821212 mutation . addedNodes . forEach ( function ( node ) {
1183- if ( node . nodeType === Node . ELEMENT_NODE && $ ( node ) . hasClass ( 'ui modal visible active' ) && ! $ ( node ) . hasClass ( 'cron' ) ) {
1213+ if ( node . nodeType === Node . ELEMENT_NODE && $ ( node ) . hasClass ( 'ui modal visible active' ) && ! $ ( node ) . hasClass ( 'cron' ) && ! $ ( node ) . hasClass ( 'server' ) ) {
11841214 setTimeout ( function ( ) {
11851215 window . reinitializeAllDropdowns ( ) ;
11861216 } , 300 ) ;
@@ -1891,16 +1921,48 @@ function convertTableJsonToNames() {
18911921 } ) ;
18921922}
18931923
1894- // 在页面加载时初始化所有映射
1924+ // 根据当前页面智能初始化映射
18951925$ ( document ) . ready ( ( ) => {
1896- updateServerNameMapping ( ) ;
1897- updateDDNSNameMapping ( ) ;
1898- updateTaskNameMapping ( ) ;
1899-
1900- // 等待映射初始化完成后转换表格
1901- setTimeout ( ( ) => {
1902- convertTableJsonToNames ( ) ;
1903- } , 1000 ) ; // 延迟1秒确保映射已加载
1926+ const currentPath = window . location . pathname ;
1927+
1928+ // 只在需要的页面初始化相应的映射
1929+ let needsServerMapping = false ;
1930+ let needsDDNSMapping = false ;
1931+ let needsTaskMapping = false ;
1932+
1933+ // 检查当前页面是否需要服务器映射
1934+ if ( currentPath === '/server' || currentPath === '/monitor' || currentPath === '/cron' ||
1935+ currentPath === '/' || currentPath === '/home' ) {
1936+ needsServerMapping = true ;
1937+ }
1938+
1939+ // 检查当前页面是否需要DDNS映射
1940+ if ( currentPath === '/server' || currentPath === '/ddns' ) {
1941+ needsDDNSMapping = true ;
1942+ }
1943+
1944+ // 检查当前页面是否需要任务映射
1945+ if ( currentPath === '/monitor' || currentPath === '/cron' || currentPath === '/notification' ) {
1946+ needsTaskMapping = true ;
1947+ }
1948+
1949+ // 只初始化需要的映射
1950+ if ( needsServerMapping ) {
1951+ updateServerNameMapping ( ) ;
1952+ }
1953+ if ( needsDDNSMapping ) {
1954+ updateDDNSNameMapping ( ) ;
1955+ }
1956+ if ( needsTaskMapping ) {
1957+ updateTaskNameMapping ( ) ;
1958+ }
1959+
1960+ // 等待映射初始化完成后转换表格(只在有映射需要时)
1961+ if ( needsServerMapping || needsDDNSMapping || needsTaskMapping ) {
1962+ setTimeout ( ( ) => {
1963+ convertTableJsonToNames ( ) ;
1964+ } , 1000 ) ; // 延迟1秒确保映射已加载
1965+ }
19041966} ) ;
19051967
19061968// 统一的系统信息格式化
0 commit comments