Skip to content

Commit 9ae15b9

Browse files
committed
Update.
1 parent 2d26fb1 commit 9ae15b9

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

cmd/dashboard/controller/member_api.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,14 @@ func (ma *memberAPI) addOrEditMonitor(c *gin.Context) {
826826
m.RecoverTriggerTasksRaw = mf.RecoverTriggerTasksRaw
827827
m.FailTriggerTasksRaw = mf.FailTriggerTasksRaw
828828

829+
// 兼容旧前端取值:3 代表 TCP-Ping,0 视为默认 ICMP-Ping
830+
if m.Type == 3 {
831+
m.Type = model.TaskTypeTCPPing
832+
}
833+
if m.Type == 0 {
834+
m.Type = model.TaskTypeICMPPing
835+
}
836+
829837
// 处理 SkipServersRaw,确保它是有效的JSON数组
830838
if mf.SkipServersRaw == "" {
831839
mf.SkipServersRaw = "[]"

model/monitor.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ func (m *Monitor) BeforeSave(tx *gorm.DB) error {
101101
}
102102

103103
func (m *Monitor) AfterFind(tx *gorm.DB) error {
104+
// 类型兼容:历史数据中可能存在 0 或 3 的取值(旧前端/旧版本遗留)
105+
// 0 归一化为 ICMP(1),3 归一化为 TCP(2)
106+
if m.Type == 0 {
107+
m.Type = TaskTypeICMPPing
108+
// 尝试静默纠正数据库中的值,失败则记录日志但不阻断
109+
if tx != nil {
110+
if err := tx.Model(m).Update("type", TaskTypeICMPPing).Error; err != nil {
111+
log.Printf("修正Monitor %s(Type=0)为ICMP失败: %v", m.Name, err)
112+
}
113+
}
114+
} else if m.Type == 3 {
115+
m.Type = TaskTypeTCPPing
116+
if tx != nil {
117+
if err := tx.Model(m).Update("type", TaskTypeTCPPing).Error; err != nil {
118+
log.Printf("修正Monitor %s(Type=3)为TCP失败: %v", m.Name, err)
119+
}
120+
}
121+
}
122+
104123
m.SkipServers = make(map[uint64]bool)
105124
var skipServers []uint64
106125
if err := utils.Json.Unmarshal([]byte(m.SkipServersRaw), &skipServers); err != nil {

resource/static/main.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@ function showFormModal(modelSelector, formID, URL, getData) {
202202
}
203203
});
204204

205-
$.post(URL, JSON.stringify(data))
205+
$.ajax({
206+
url: URL,
207+
type: "POST",
208+
data: JSON.stringify(data),
209+
contentType: "application/json",
210+
dataType: "json"
211+
})
206212
.done(function (resp) {
207213
if (resp.code == 200) {
208214
window.location.reload()

resource/template/component/monitor.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<div class="field">
2020
<label>{{tr "Type"}}</label>
2121
<select name="Type" class="ui fluid dropdown">
22-
<option value="2">ICMP-Ping</option>
23-
<option value="3">TCP-Ping</option>
22+
<option value="1">ICMP-Ping</option>
23+
<option value="2">TCP-Ping</option>
2424
</select>
2525
</div>
2626
<!--<div class="field">-->

resource/template/dashboard-default/monitor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<td>{{if eq $monitor.Cover 0}}{{tr "CoverAll"}}{{else}}{{tr "IgnoreAll"}}{{end}}</td>
3838
<td>{{$monitor.SkipServersRaw}}</td>
3939
<td>
40-
{{if eq $monitor.Type 2}}ICMP Ping {{else if eq $monitor.Type 3}} {{tr "TCPPort"}} {{end}}
40+
{{if eq $monitor.Type 1}}ICMP Ping {{else if eq $monitor.Type 2}} {{tr "TCPPort"}} {{end}}
4141
</td>
4242
<td>{{$monitor.Duration}} {{tr "Seconds"}}</td>
4343
<td>{{$monitor.NotificationTag}}</td>

0 commit comments

Comments
 (0)