fix: 四所统计日历 embed 切换后初始化与加载失败仍渲染网格

统一 initInstanceStatsCalendar,统计 tab 动态注入时重新挂载日历,API 异常时保留月历骨架。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-30 08:42:39 +08:00
parent ac4cdceb39
commit 052dcf63bd
8 changed files with 59 additions and 162 deletions
+2 -31
View File
@@ -664,36 +664,7 @@ function switchStatsSegment(){
q.set("stats_segment", key);
const qs = q.toString();
history.replaceState(null, "", qs ? (window.location.pathname + "?" + qs) : window.location.pathname);
if(statsCalendarWidget) statsCalendarWidget.load();
}
let statsCalendarWidget = null;
function initStatsCalendarWidget(){
const grid = document.getElementById("stats-calendar");
if(!grid || !window.TradeStatsCalendar) return;
statsCalendarWidget = new TradeStatsCalendar({
gridEl: grid,
titleEl: document.getElementById("stats-cal-title"),
prevBtn: document.getElementById("stats-cal-prev"),
nextBtn: document.getElementById("stats-cal-next"),
apiUrl: "/api/stats/calendar",
showSick: false,
buildQuery: function(year, month){
const q = new URLSearchParams();
q.set("year", String(year));
q.set("month", String(month));
const sel = document.getElementById("stats-segment-select");
if(sel) q.set("segment", sel.value || "all");
return q;
},
parseResponse: function(data){
if(data && data.ok === false) return {};
return (data && data.days) || {};
}
});
statsCalendarWidget.ensureMonth(new Date());
statsCalendarWidget.load();
if(window.statsCalendarWidget) window.statsCalendarWidget.load();
}
function initStatsSegmentFromUrl(){
@@ -730,7 +701,7 @@ attachListWindowToExports();
toggleListWindowCustom();
bindListWindowDateAutoCustom();
initStatsSegmentFromUrl();
initStatsCalendarWidget();
if(typeof initInstanceStatsCalendar === "function") initInstanceStatsCalendar();
if(document.getElementById("journal-list")) loadJournals();
if(document.getElementById("review-list")) loadReviews();
const reviewToggle = document.getElementById("review-mode-toggle");
+2 -2
View File
@@ -121,8 +121,8 @@
<script src="/static/manual_order_rr_preview.js?v=5"></script>
<script src="/static/strategy_roll.js?v=5"></script>
<script src="/static/key_monitor_form.js?v=2"></script>
<script src="/static/trade_stats_calendar.js?v=1"></script>
<script src="/static/trade_stats_calendar.js?v=2"></script>
{% include 'embed_boot_scripts.html' %}
<script src="/static/instance_embed.js?v=4"></script>
<script src="/static/instance_embed.js?v=5"></script>
</body>
</html>