Skip to content

Commit 7dfc140

Browse files
committed
Update.
1 parent 318e510 commit 7dfc140

File tree

5 files changed

+88
-43
lines changed

5 files changed

+88
-43
lines changed

cmd/dashboard/controller/member_api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ func (ma *memberAPI) searchDDNS(c *gin.Context) {
544544
ddnsOps := db.NewDDNSOps(db.DB)
545545
ddnsProfiles, err := ddnsOps.GetAllDDNSProfiles()
546546
if err != nil {
547+
// 只在严重错误时记录日志
547548
log.Printf("searchDDNS: 查询DDNS配置失败: %v", err)
548549
c.JSON(http.StatusOK, map[string]interface{}{
549550
"success": true,

db/badger.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ func (b *BadgerDB) FindAll(prefix string, result interface{}) error {
302302
return json.Unmarshal([]byte("[]"), result)
303303
}
304304

305-
log.Printf("FindAll: 查询前缀 %s 的数据", prefix)
305+
// 移除频繁的查询日志输出,只在调试模式下输出
306+
// log.Printf("FindAll: 查询前缀 %s 的数据", prefix)
306307

307308
err := b.db.View(func(txn *badger.Txn) error {
308309
opts := badger.DefaultIteratorOptions

pkg/mygin/auth.go

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,23 @@ func Authorize(opt AuthorizeOption) func(*gin.Context) {
6666
}
6767
} else {
6868
// 在内存中查找匹配token的用户
69-
// 减少日志输出频率,只在调试模式下输出
70-
if singleton.Conf.Debug {
71-
tokenPreview := token
72-
if len(token) > 8 {
73-
tokenPreview = token[:8] + "..."
74-
}
75-
log.Printf("认证: 在 %d 个用户中查找token: %s", len(users), tokenPreview)
76-
}
69+
// 移除频繁的认证日志输出,只在出错时输出
7770
for _, user := range users {
7871
if user != nil && user.Token == token {
7972
// 检查token是否过期
8073
if user.TokenExpired.After(time.Now()) {
8174
u = *user
8275
isLogin = true
83-
if singleton.Conf.Debug {
84-
log.Printf("认证: 找到有效用户 %s (ID: %d)", user.Login, user.ID)
85-
}
76+
// 移除频繁的认证成功日志
8677
break
87-
} else if singleton.Conf.Debug {
88-
log.Printf("认证: 用户 %s 的token已过期", user.Login)
8978
}
79+
// 移除token过期的日志输出
9080
}
9181
}
9282

9383
// 如果没有找到有效用户,但token是admin,则使用默认管理员账户
9484
if !isLogin && token == "admin" {
95-
if singleton.Conf.Debug {
96-
log.Printf("使用默认管理员账户")
97-
}
85+
// 移除默认管理员账户的日志输出
9886
u = model.User{
9987
Common: model.Common{ID: 1},
10088
Login: "admin",
@@ -103,13 +91,7 @@ func Authorize(opt AuthorizeOption) func(*gin.Context) {
10391
isLogin = true
10492
}
10593

106-
if !isLogin && singleton.Conf.Debug {
107-
tokenPreview := token
108-
if len(token) > 8 {
109-
tokenPreview = token[:8] + "..."
110-
}
111-
log.Printf("认证: 未找到匹配的有效用户,token: %s", tokenPreview)
112-
}
94+
// 移除认证失败的频繁日志输出
11395
}
11496
} else {
11597
log.Printf("警告:BadgerDB未初始化,用户认证将失败")

resource/static/main.js

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

571589
function 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
// 统一的系统信息格式化

service/singleton/ddns.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ func OnDDNSUpdate() {
4040
if err != nil {
4141
log.Printf("从BadgerDB加载DDNS配置失败: %v", err)
4242
ddns = []*model.DDNSProfile{}
43-
} else {
44-
log.Printf("从BadgerDB成功加载 %d 条DDNS配置", len(ddns))
4543
}
44+
// 移除频繁的DDNS配置加载日志
4645
} else {
4746
log.Println("警告: BadgerDB 未初始化")
4847
ddns = []*model.DDNSProfile{}

0 commit comments

Comments
 (0)