fix: 修复时间显示时区偏移8小时 + 自动化完成时跳过渲染
问题1(时区):Flask jsonify 将 MySQL DATETIME 输出为 'Fri, 05 Jun 2026 14:37:52 GMT',但实际值是服务器本地时间 (UTC+8)。JS new Date() 把 GMT 当真,getHours() 加 8 小时。 修复:fmtTime() 先 strip ' GMT' 后缀再解析,让 JS 按本地 时间处理。 问题2(跳过渲染):pollProgress 中'全部完成'时 stopAuto() + return 跳过了 renderAverages/renderRecords,导致自动化 平均值和本轮明细永远不显示最后一轮数据。 修复:将 4 个 render 调用移到所有 return 之前执行。
This commit is contained in:
@@ -81,7 +81,10 @@ function toSpeed(v) {
|
|||||||
|
|
||||||
function fmtTime(v) {
|
function fmtTime(v) {
|
||||||
if (!v) return '-';
|
if (!v) return '-';
|
||||||
const d = new Date(v);
|
// Flask jsonify 给 MySQL DATETIME 加 "GMT" 后缀,但实际值是服务器本地时间(UTC+8)
|
||||||
|
// 去掉 "GMT" 让 JS 按本地时间解析,避免时区偏移 8 小时
|
||||||
|
const cleaned = String(v).replace(/ GMT$/, '');
|
||||||
|
const d = new Date(cleaned);
|
||||||
if (isNaN(d.getTime())) return String(v).substring(0, 19);
|
if (isNaN(d.getTime())) return String(v).substring(0, 19);
|
||||||
const y = d.getFullYear();
|
const y = d.getFullYear();
|
||||||
const m = String(d.getMonth() + 1).padStart(2, '0');
|
const m = String(d.getMonth() + 1).padStart(2, '0');
|
||||||
|
|||||||
@@ -200,6 +200,12 @@ async function pollProgress() {
|
|||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
const stats = data.stats;
|
const stats = data.stats;
|
||||||
|
|
||||||
|
// ── 先渲染数据(放在所有 return 之前,避免完成时跳过渲染)──
|
||||||
|
try { if (data.latest) renderLatest(data.latest); } catch (e) { console.error("renderLatest:", e); }
|
||||||
|
try { if (data.averages) renderAverages(data.averages); } catch (e) { console.error("renderAverages:", e); }
|
||||||
|
try { if (data.latest_wave) renderLatestWave(data.latest_wave); } catch (e) { console.error("renderLatestWave:", e); }
|
||||||
|
try { if (data.records && data.records.length) renderRecords(data.records); } catch (e) { console.error("renderRecords:", e); }
|
||||||
|
|
||||||
// 更新计数
|
// 更新计数
|
||||||
const newDone = stats.done || 0;
|
const newDone = stats.done || 0;
|
||||||
const newFailed = stats.failed || 0;
|
const newFailed = stats.failed || 0;
|
||||||
@@ -244,12 +250,6 @@ async function pollProgress() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示最新结果(独立 try-catch,避免一处报错影响全部)
|
|
||||||
try { if (data.latest) renderLatest(data.latest); } catch (e) { console.error("renderLatest:", e); }
|
|
||||||
try { if (data.averages) renderAverages(data.averages); } catch (e) { console.error("renderAverages:", e); }
|
|
||||||
try { if (data.latest_wave) renderLatestWave(data.latest_wave); } catch (e) { console.error("renderLatestWave:", e); }
|
|
||||||
try { if (data.records && data.records.length) renderRecords(data.records); } catch (e) { console.error("renderRecords:", e); }
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("轮询失败:", e);
|
console.error("轮询失败:", e);
|
||||||
}
|
}
|
||||||
@@ -293,7 +293,10 @@ function toSpeed(v) {
|
|||||||
|
|
||||||
function fmtTime(v) {
|
function fmtTime(v) {
|
||||||
if (!v) return '-';
|
if (!v) return '-';
|
||||||
const d = new Date(v);
|
// Flask jsonify 给 MySQL DATETIME 加 "GMT" 后缀,但实际值是服务器本地时间(UTC+8)
|
||||||
|
// 去掉 "GMT" 让 JS 按本地时间解析,避免时区偏移 8 小时
|
||||||
|
const cleaned = String(v).replace(/ GMT$/, '');
|
||||||
|
const d = new Date(cleaned);
|
||||||
if (isNaN(d.getTime())) return String(v).substring(0, 19);
|
if (isNaN(d.getTime())) return String(v).substring(0, 19);
|
||||||
const y = d.getFullYear();
|
const y = d.getFullYear();
|
||||||
const m = String(d.getMonth() + 1).padStart(2, '0');
|
const m = String(d.getMonth() + 1).padStart(2, '0');
|
||||||
|
|||||||
Reference in New Issue
Block a user