fix:修改时间范围
This commit is contained in:
parent
16f49a47e9
commit
f60077e4c2
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
|||||||
data/*.db
|
data/*.db
|
||||||
data/sensor.db
|
data/sensor.db
|
||||||
logs/
|
logs/
|
||||||
|
./tcp_server
|
||||||
|
data/*
|
||||||
|
./go_rain_dtu.exe
|
||||||
@ -26,17 +26,23 @@ func (h *SensorHandler) GetAggregatedData(w http.ResponseWriter, r *http.Request
|
|||||||
interval = "1hour"
|
interval = "1hour"
|
||||||
}
|
}
|
||||||
|
|
||||||
endTime := time.Now()
|
// 获取中国时区
|
||||||
|
chinaLoc, locErr := time.LoadLocation("Asia/Shanghai")
|
||||||
|
if locErr != nil {
|
||||||
|
chinaLoc = time.FixedZone("CST", 8*60*60)
|
||||||
|
}
|
||||||
|
|
||||||
|
endTime := time.Now().In(chinaLoc)
|
||||||
startTime := endTime.Add(-24 * time.Hour) // 默认显示24小时数据
|
startTime := endTime.Add(-24 * time.Hour) // 默认显示24小时数据
|
||||||
|
|
||||||
if startStr := r.URL.Query().Get("start"); startStr != "" {
|
if startStr := r.URL.Query().Get("start"); startStr != "" {
|
||||||
if t, err := time.Parse("2006-01-02T15:04", startStr); err == nil {
|
if t, parseErr := time.Parse(time.RFC3339, startStr); parseErr == nil {
|
||||||
startTime = t
|
startTime = t.In(chinaLoc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if endStr := r.URL.Query().Get("end"); endStr != "" {
|
if endStr := r.URL.Query().Get("end"); endStr != "" {
|
||||||
if t, err := time.Parse("2006-01-02T15:04", endStr); err == nil {
|
if t, parseErr := time.Parse(time.RFC3339, endStr); parseErr == nil {
|
||||||
endTime = t
|
endTime = t.In(chinaLoc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -174,9 +174,9 @@
|
|||||||
<select id="interval">
|
<select id="interval">
|
||||||
<option value="raw">原始数据</option>
|
<option value="raw">原始数据</option>
|
||||||
<option value="1min">1分钟(测试用)</option>
|
<option value="1min">1分钟(测试用)</option>
|
||||||
<option value="5min" selected>5分钟</option>
|
<option value="5min">5分钟</option>
|
||||||
<option value="30min">30分钟</option>
|
<option value="30min">30分钟</option>
|
||||||
<option value="1hour">1小时</option>
|
<option value="1hour" selected>1小时</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -326,15 +326,22 @@
|
|||||||
const startDateTime = new Date(startDate).toISOString();
|
const startDateTime = new Date(startDate).toISOString();
|
||||||
const endDateTime = new Date(endDate).toISOString();
|
const endDateTime = new Date(endDate).toISOString();
|
||||||
|
|
||||||
|
// 加载状态指示
|
||||||
|
document.getElementById('mainChart').style.opacity = 0.5;
|
||||||
|
|
||||||
fetch(`/api/data?interval=${interval}&start=${startDateTime}&end=${endDateTime}`)
|
fetch(`/api/data?interval=${interval}&start=${startDateTime}&end=${endDateTime}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
updateChart(data);
|
updateChart(data);
|
||||||
updateTable(data);
|
updateTable(data);
|
||||||
|
// 恢复正常显示
|
||||||
|
document.getElementById('mainChart').style.opacity = 1;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
alert('获取数据失败,请检查网络连接');
|
alert('获取数据失败,请检查网络连接');
|
||||||
|
// 恢复正常显示
|
||||||
|
document.getElementById('mainChart').style.opacity = 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user