report.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. 'use strict';
  2. // 经营报告:同一份 Report JSON 渲染「图文报告 / 交互报告」,PDF 走浏览器打印样式。
  3. // 数据来自 GET /api/ops/report(后端算指标、规则打标,模型只负责文字)。
  4. (function () {
  5. const $ = (id) => document.getElementById(id);
  6. const COLORS = { main: '#ff6b35', soft: '#ffb08a', grey: '#c9c2ba', blue: '#7a9cc6', light: '#ffd6c2' };
  7. const state = {
  8. inited: false,
  9. loading: false,
  10. report: null,
  11. mode: 'text', // text | interactive
  12. from: '',
  13. to: '',
  14. charts: {},
  15. };
  16. function esc(value) {
  17. const div = document.createElement('div');
  18. div.textContent = String(value == null ? '' : value);
  19. return div.innerHTML;
  20. }
  21. function moneyText(v) {
  22. if (v == null) return '–';
  23. const n = Number(v);
  24. return Number.isFinite(n) ? n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) : '–';
  25. }
  26. function kpiText(kpi) {
  27. if (kpi.current == null) return '–';
  28. if (kpi.unit === '%') return kpi.current + '%';
  29. if (kpi.unit === '单' || kpi.unit === '人') return numText(kpi.current);
  30. return moneyText(kpi.current);
  31. }
  32. function numText(v) {
  33. if (v == null) return '–';
  34. const n = Number(v);
  35. return Number.isFinite(n) ? n.toLocaleString('zh-CN') : '–';
  36. }
  37. function deltaText(kpi) {
  38. if (kpi.change_pct == null) return '<span class="rp-delta muted">—</span>';
  39. const up = kpi.change_pct > 0;
  40. const cls = kpi.change_pct === 0 ? 'muted' : up ? 'up' : 'down';
  41. const unit = kpi.unit === '%' ? 'pp' : '%';
  42. return `<span class="rp-delta ${cls}">${up ? '↑' : '↓'} ${Math.abs(kpi.change_pct).toFixed(1)}${unit}</span>`;
  43. }
  44. async function api(url, options) {
  45. const res = await fetch(url, options);
  46. const body = await res.json().catch(() => null);
  47. return { res, body };
  48. }
  49. // ---------- 渲染 ----------
  50. function renderShell() {
  51. const root = $('reportRoot');
  52. if (!root) return;
  53. root.innerHTML = `
  54. <div class="rp-toolbar">
  55. <div class="rp-range">
  56. <input type="date" class="ops-input" id="rpFrom">
  57. <span class="ops-tilde">~</span>
  58. <input type="date" class="ops-input" id="rpTo">
  59. </div>
  60. <div class="rp-tabs" id="rpTabs">
  61. <button type="button" data-mode="text" class="on">图文报告</button>
  62. <button type="button" data-mode="interactive">交互报告</button>
  63. </div>
  64. <div class="rp-actions">
  65. <button type="button" class="btn btn-ghost btn-small" id="rpArchive">历史报告</button>
  66. <button type="button" class="btn btn-ghost btn-small" id="rpSave">保存报告</button>
  67. <button type="button" class="btn btn-ghost btn-small" id="rpRefresh">重新生成</button>
  68. <button type="button" class="btn btn-primary btn-small" id="rpPrint">下载 PDF</button>
  69. </div>
  70. </div>
  71. <article class="rp-page" id="rpPage"></article>
  72. <div class="modal-overlay" id="rpHistoryModal" hidden>
  73. <div class="modal rp-history-modal">
  74. <div class="modal-header">
  75. <div class="modal-title"><span>历史报告</span></div>
  76. <button class="modal-close" id="rpHistoryClose" type="button" aria-label="关闭">×</button>
  77. </div>
  78. <div class="modal-body" id="rpHistoryList"></div>
  79. </div>
  80. </div>`;
  81. root.querySelectorAll('#rpTabs [data-mode]').forEach((btn) => {
  82. btn.addEventListener('click', () => {
  83. state.mode = btn.dataset.mode;
  84. root.querySelectorAll('#rpTabs [data-mode]').forEach((b) => b.classList.toggle('on', b === btn));
  85. $('rpPage').classList.toggle('interactive', state.mode === 'interactive');
  86. if (state.report) drawCharts(state.report);
  87. });
  88. });
  89. $('rpFrom').addEventListener('change', (e) => { state.from = String(e.target.value || '').replace(/-/g, ''); load(true); });
  90. $('rpTo').addEventListener('change', (e) => { state.to = String(e.target.value || '').replace(/-/g, ''); load(true); });
  91. $('rpRefresh').addEventListener('click', () => load(true));
  92. $('rpPrint').addEventListener('click', () => window.print());
  93. $('rpSave').addEventListener('click', saveReport);
  94. $('rpArchive').addEventListener('click', openHistory);
  95. $('rpHistoryClose').addEventListener('click', () => { $('rpHistoryModal').hidden = true; });
  96. }
  97. function renderCover(report) {
  98. const meta = report.meta || {};
  99. return `
  100. <header class="rp-cover">
  101. <div class="rp-cover-main">
  102. <div class="rp-kicker">AI 经营分析报告</div>
  103. <h1>${esc(meta.title || '经营分析报告')}</h1>
  104. <div class="rp-cover-sub">${esc(meta.organization || '')}${meta.organization ? ' · ' : ''}${esc(meta.period_start)} ~ ${esc(meta.period_end)}</div>
  105. </div>
  106. <div class="rp-cover-meta">
  107. <div><span>统计范围</span><b>${esc(meta.data_scope || '–')}</b></div>
  108. <div><span>数据来源</span><b>${esc((meta.source_files || []).join('、') || '平台导出明细')}</b></div>
  109. <div><span>生成时间</span><b>${esc(new Date(meta.generated_at).toLocaleString('zh-CN'))}</b></div>
  110. </div>
  111. </header>`;
  112. }
  113. function renderSummary(report) {
  114. const summary = report.executive_summary || {};
  115. const dot = { positive: 'ok', neutral: 'na', warning: 'warn', critical: 'bad' };
  116. const items = (summary.key_findings || []).map((f) => `
  117. <li>
  118. <span class="rp-dot ${dot[f.severity] || 'na'}"></span>
  119. <div>
  120. <b>${esc(f.finding)}</b>
  121. <p>${esc(f.interpretation || '')}</p>
  122. ${(f.evidence || []).length ? `<div class="rp-evidence">${f.evidence.map((e) => `<code>${esc(e)}</code>`).join('')}</div>` : ''}
  123. </div>
  124. </li>`).join('');
  125. return `
  126. <section class="rp-section rp-summary">
  127. <h2>管理层摘要</h2>
  128. <p class="rp-lead">${esc(summary.overall_assessment || '')}</p>
  129. <ul class="rp-findings">${items}</ul>
  130. </section>`;
  131. }
  132. function renderKpis(report) {
  133. return `
  134. <section class="rp-section">
  135. <h2>核心指标</h2>
  136. <div class="rp-kpis">
  137. ${(report.kpis || []).map((kpi) => `
  138. <div class="rp-kpi" title="${esc(kpi.definition)}">
  139. <div class="rp-kpi-label">${esc(kpi.label)}<span>${esc(kpi.unit)}</span></div>
  140. <div class="rp-kpi-value">${kpiText(kpi)}</div>
  141. <div class="rp-kpi-foot">${deltaText(kpi)}<span class="rp-kpi-hint">较上期</span></div>
  142. </div>`).join('')}
  143. </div>
  144. <p class="rp-note">口径:${(report.kpis || []).map((k) => `${k.label}=${k.definition}`).join(';')}</p>
  145. </section>`;
  146. }
  147. function chartCard(id, title, subtitle) {
  148. return `<figure class="rp-figure">
  149. <figcaption><b>${esc(title)}</b><span>${esc(subtitle || '')}</span></figcaption>
  150. <div class="rp-chart" id="${id}"></div>
  151. </figure>`;
  152. }
  153. function renderSections(report) {
  154. const chartById = new Map((report.charts || []).map((c) => [c.id, c]));
  155. const tableById = new Map((report.tables || []).map((t) => [t.id, t]));
  156. return (report.sections || []).map((section, index) => {
  157. if (section.id === 'quality') return '';
  158. const charts = (section.chart_ids || []).map((id) => chartById.get(id)).filter(Boolean);
  159. const tables = (section.table_ids || []).map((id) => tableById.get(id)).filter(Boolean);
  160. return `
  161. <section class="rp-section">
  162. <h2><em>${String(index + 1).padStart(2, '0')}</em>${esc(section.title)}</h2>
  163. ${section.summary ? `<p class="rp-lead">${esc(section.summary)}</p>` : ''}
  164. ${(section.paragraphs || []).map((p) => `<p>${esc(p)}</p>`).join('')}
  165. ${charts.map((chart) => chartCard(`rpChart_${chart.id}`, chart.title, chart.description)).join('')}
  166. ${tables.map((table) => renderTable(table)).join('')}
  167. </section>`;
  168. }).join('');
  169. }
  170. function renderTable(table) {
  171. return `
  172. <div class="rp-table-wrap">
  173. <table class="rp-table">
  174. <thead><tr>${table.columns.map((c) => `<th>${esc(c.label)}</th>`).join('')}</tr></thead>
  175. <tbody>${(table.rows || []).map((row) => `<tr>${table.columns.map((c) => {
  176. const v = row[c.key];
  177. const text = c.key === 'revenue' ? moneyText(v) : c.key === 'share' ? (v == null ? '–' : v + '%') : (v == null ? '–' : esc(v));
  178. return `<td>${text}</td>`;
  179. }).join('')}</tr>`).join('')}</tbody>
  180. </table>
  181. ${table.footnote ? `<p class="rp-note">${esc(table.footnote)}</p>` : ''}
  182. </div>`;
  183. }
  184. function renderAlerts(report) {
  185. const alerts = report.alerts || [];
  186. const plan = report.action_plan || [];
  187. return `
  188. <section class="rp-section">
  189. <h2><em>05</em>风险与建议</h2>
  190. <div class="rp-alerts">
  191. ${alerts.map((a) => `
  192. <div class="rp-alert ${esc(a.severity)}">
  193. <div class="rp-alert-head"><span class="rp-badge">${esc(a.severity)}</span><b>${esc(a.title)}</b></div>
  194. <ul>${(a.evidence || []).map((e) => `<li>${esc(e)}</li>`).join('')}</ul>
  195. ${(a.hypotheses || []).length ? `<p class="rp-note">待验证:${a.hypotheses.map(esc).join('、')}</p>` : ''}
  196. </div>`).join('') || '<p class="rp-note">本期未触发风险规则。</p>'}
  197. </div>
  198. <h3 class="rp-h3">行动计划</h3>
  199. <table class="rp-table">
  200. <thead><tr><th>优先级</th><th>行动</th><th>负责人</th><th>时间窗</th><th>验收指标</th></tr></thead>
  201. <tbody>${plan.map((p) => `<tr>
  202. <td><span class="rp-badge">${esc(p.priority)}</span></td>
  203. <td>${esc(p.action)}</td>
  204. <td>${esc(p.owner_role)}</td>
  205. <td>${esc(p.time_horizon)}</td>
  206. <td>${esc(p.success_metric)}</td>
  207. </tr>`).join('')}</tbody>
  208. </table>
  209. </section>`;
  210. }
  211. function renderQuality(report) {
  212. const q = report.data_quality || {};
  213. return `
  214. <section class="rp-section rp-quality">
  215. <h2><em>06</em>数据质量与方法论</h2>
  216. <p><b>覆盖范围:</b>${esc(q.coverage || '–')}</p>
  217. <p><b>可比性:</b>${esc(q.comparability || '–')}</p>
  218. ${(q.warnings || []).length ? `<p><b>提示:</b>${q.warnings.map(esc).join(';')}</p>` : ''}
  219. ${(q.missing_metrics || []).length ? `<p><b>缺失指标:</b>${q.missing_metrics.map(esc).join(';')}</p>` : ''}
  220. <p><b>方法论:</b></p>
  221. <ul class="rp-method">${(report.methodology || []).map((m) => `<li>${esc(m)}</li>`).join('')}</ul>
  222. </section>`;
  223. }
  224. function renderReport(report) {
  225. const page = $('rpPage');
  226. page.innerHTML = [
  227. renderCover(report),
  228. renderSummary(report),
  229. renderKpis(report),
  230. renderSections(report),
  231. renderAlerts(report),
  232. renderQuality(report),
  233. `<footer class="rp-footer">${report.ai && report.ai.source === 'llm' ? `文字由 AI 生成(${esc(report.ai.model || '')})` : '当前为规则版文字'};数值均由后端按统一口径计算。${report.aiError ? ' ' + esc(report.aiError) : ''}</footer>`,
  234. ].join('');
  235. drawCharts(report);
  236. }
  237. // ---------- 图表 ----------
  238. function chartBase(interactive) {
  239. return {
  240. animation: !interactive,
  241. silent: !interactive,
  242. tooltip: interactive ? { trigger: 'axis' } : undefined,
  243. };
  244. }
  245. function drawCharts(report) {
  246. const interactive = state.mode === 'interactive';
  247. const byId = new Map((report.charts || []).map((c) => [c.id, c]));
  248. Object.values(state.charts).forEach((chart) => chart && chart.dispose());
  249. state.charts = {};
  250. const mount = (chart) => {
  251. const el = $(`rpChart_${chart.id}`);
  252. if (!el) return null;
  253. const instance = echarts.init(el);
  254. state.charts[chart.id] = instance;
  255. return instance;
  256. };
  257. const trend = byId.get('chart_trend');
  258. if (trend) {
  259. const chart = mount(trend);
  260. chart && chart.setOption({
  261. ...chartBase(interactive),
  262. grid: { left: 56, right: 48, top: 24, bottom: 30 },
  263. legend: { right: 0, top: 0, itemWidth: 10, itemHeight: 10, textStyle: { fontSize: 11 } },
  264. xAxis: { type: 'category', data: trend.data.map((d) => d.date.slice(4)), axisTick: { show: false }, axisLine: { lineStyle: { color: '#e5e0da' } } },
  265. yAxis: [{ type: 'value', splitLine: { lineStyle: { color: '#f2efea' } } }, { type: 'value', splitLine: { show: false } }],
  266. series: [
  267. { name: '营业额', type: 'bar', barMaxWidth: 22, itemStyle: { color: COLORS.main, borderRadius: [3, 3, 0, 0] }, data: trend.data.map((d) => d.revenue) },
  268. { name: '订单', type: 'line', yAxisIndex: 1, symbolSize: 5, lineStyle: { width: 2, color: COLORS.blue }, itemStyle: { color: COLORS.blue }, data: trend.data.map((d) => d.orders) },
  269. ],
  270. });
  271. }
  272. const rank = byId.get('chart_rank');
  273. if (rank) {
  274. const rows = rank.data.slice().reverse();
  275. const chart = mount(rank);
  276. chart && chart.setOption({
  277. ...chartBase(interactive),
  278. grid: { left: 8, right: 60, top: 10, bottom: 10, containLabel: true },
  279. xAxis: { type: 'value', splitLine: { lineStyle: { color: '#f2efea' } } },
  280. yAxis: { type: 'category', data: rows.map((r) => r.shopName), axisTick: { show: false }, axisLine: { show: false }, axisLabel: { width: 140, overflow: 'truncate', fontSize: 11 } },
  281. series: [{ type: 'bar', barMaxWidth: 14, itemStyle: { color: COLORS.soft, borderRadius: [0, 3, 3, 0] }, label: { show: true, position: 'right', fontSize: 10, color: '#6f6862' }, data: rows.map((r) => r.revenue) }],
  282. });
  283. }
  284. const funnel = byId.get('chart_funnel');
  285. if (funnel) {
  286. const f = funnel.data;
  287. const chart = mount(funnel);
  288. chart && chart.setOption({
  289. ...chartBase(interactive),
  290. series: [{
  291. type: 'funnel', left: '10%', right: '10%', top: 12, bottom: 12, minSize: '30%', gap: 3,
  292. label: { show: true, position: 'inside', color: '#fff', fontSize: 11, formatter: (p) => `${p.name} ${Number(p.value).toLocaleString('zh-CN')}` },
  293. itemStyle: { borderWidth: 0 },
  294. color: [COLORS.main, '#ff9a70', COLORS.light],
  295. data: [{ name: '曝光', value: f.exposure }, { name: '进店', value: f.visit }, { name: '下单', value: f.order }],
  296. }],
  297. });
  298. }
  299. const structure = byId.get('chart_structure');
  300. if (structure) {
  301. const chart = mount(structure);
  302. chart && chart.setOption({
  303. ...chartBase(interactive),
  304. grid: { left: 56, right: 20, top: 28, bottom: 30 },
  305. legend: { right: 0, top: 0, itemWidth: 10, itemHeight: 10, textStyle: { fontSize: 11 } },
  306. xAxis: { type: 'category', data: structure.data.map((d) => d.date.slice(4)), axisTick: { show: false }, axisLine: { lineStyle: { color: '#e5e0da' } } },
  307. yAxis: { type: 'value', splitLine: { lineStyle: { color: '#f2efea' } } },
  308. series: [
  309. { name: '收入', type: 'bar', barMaxWidth: 18, itemStyle: { color: COLORS.main }, data: structure.data.map((d) => d.income) },
  310. { name: '支出', type: 'bar', barMaxWidth: 18, itemStyle: { color: COLORS.grey }, data: structure.data.map((d) => d.expense) },
  311. { name: '补贴', type: 'bar', barMaxWidth: 18, itemStyle: { color: COLORS.light }, data: structure.data.map((d) => d.subsidy) },
  312. ],
  313. });
  314. }
  315. }
  316. // ---------- 报告中心 ----------
  317. async function saveReport() {
  318. const btn = $('rpSave');
  319. btn.disabled = true;
  320. btn.textContent = '保存中…';
  321. try {
  322. const { res, body } = await api('/api/ops/reports', {
  323. method: 'POST',
  324. headers: { 'Content-Type': 'application/json' },
  325. body: JSON.stringify({ from: state.from, to: state.to }),
  326. });
  327. if (!res.ok) throw new Error((body && (body.detail || body.error)) || ('HTTP ' + res.status));
  328. btn.textContent = '已保存';
  329. setTimeout(() => { btn.textContent = '保存报告'; btn.disabled = false; }, 1500);
  330. } catch (e) {
  331. btn.textContent = '保存报告';
  332. btn.disabled = false;
  333. alert('保存失败:' + (e.message || e));
  334. }
  335. }
  336. async function openHistory() {
  337. $('rpHistoryModal').hidden = false;
  338. await renderHistory();
  339. }
  340. async function renderHistory() {
  341. const list = $('rpHistoryList');
  342. list.innerHTML = '<div class="rp-loading" style="padding:24px 0">加载中…</div>';
  343. const { res, body } = await api('/api/ops/reports');
  344. if (!res.ok) {
  345. list.innerHTML = `<div class="rp-loading">读取失败:${esc((body && (body.error || body.detail)) || res.status)}</div>`;
  346. return;
  347. }
  348. const reports = (body && body.reports) || [];
  349. if (!reports.length) {
  350. list.innerHTML = '<div class="rp-loading" style="padding:24px 0">还没有保存过报告</div>';
  351. return;
  352. }
  353. list.innerHTML = `<table class="rp-table">
  354. <thead><tr><th>保存时间</th><th>区间</th><th>来源</th><th>关键指标</th><th class="rp-col-actions">操作</th></tr></thead>
  355. <tbody>${reports.map((r) => `<tr>
  356. <td>${esc(new Date(r.createdAt).toLocaleString('zh-CN'))}</td>
  357. <td>${esc(r.from)} ~ ${esc(r.to)}</td>
  358. <td>${r.source === 'llm' ? 'AI 生成' : '规则生成'}</td>
  359. <td class="rp-history-kpis">${(r.kpis || []).map((k) => `${esc(k.label)} ${esc(k.current)}`).join(' · ')}</td>
  360. <td class="rp-col-actions">
  361. <button type="button" class="btn btn-ghost btn-small" data-view="${esc(r.id)}">查看</button>
  362. <button type="button" class="btn btn-ghost btn-small" data-del="${esc(r.id)}">删除</button>
  363. </td>
  364. </tr>`).join('')}</tbody>
  365. </table>`;
  366. list.querySelectorAll('[data-view]').forEach((btn) => {
  367. btn.addEventListener('click', () => loadSaved(btn.dataset.view));
  368. });
  369. list.querySelectorAll('[data-del]').forEach((btn) => {
  370. btn.addEventListener('click', async () => {
  371. if (!confirm('删除这份历史报告?')) return;
  372. btn.disabled = true;
  373. await api('/api/ops/reports/' + encodeURIComponent(btn.dataset.del), { method: 'DELETE' });
  374. renderHistory();
  375. });
  376. });
  377. }
  378. async function loadSaved(id) {
  379. const { res, body } = await api('/api/ops/reports/' + encodeURIComponent(id));
  380. if (!res.ok || !body || !body.report) {
  381. alert('读取失败');
  382. return;
  383. }
  384. const report = body.report;
  385. state.report = report;
  386. const from = String(report.meta.period_start || '').replace(/-/g, '');
  387. const to = String(report.meta.period_end || '').replace(/-/g, '');
  388. state.from = from;
  389. state.to = to;
  390. $('rpFrom').value = String(report.meta.period_start || '');
  391. $('rpTo').value = String(report.meta.period_end || '');
  392. renderReport(report);
  393. $('rpHistoryModal').hidden = true;
  394. }
  395. // ---------- 数据 ----------
  396. async function load(force) {
  397. if (state.loading) return;
  398. state.loading = true;
  399. const page = $('rpPage');
  400. if (page && !state.report) page.innerHTML = '<div class="rp-loading">正在生成报告…</div>';
  401. try {
  402. const params = new URLSearchParams();
  403. if (state.from) params.set('from', state.from);
  404. if (state.to) params.set('to', state.to);
  405. params.set('ai', '1'); // 默认走 AI,失败自动退回规则版
  406. const { res, body } = await api('/api/ops/report?' + params.toString());
  407. if (!res.ok) throw new Error((body && (body.detail || body.error)) || ('HTTP ' + res.status));
  408. if (body.empty) {
  409. page.innerHTML = '<div class="rp-loading">所选范围没有数据,请先导入明细。</div>';
  410. return;
  411. }
  412. state.report = body.report;
  413. renderReport(state.report);
  414. } catch (e) {
  415. page.innerHTML = `<div class="rp-loading">报告生成失败:${esc(e.message || e)}</div>`;
  416. } finally {
  417. state.loading = false;
  418. }
  419. }
  420. async function initDates() {
  421. const search = new URLSearchParams(location.search);
  422. const qFrom = String(search.get('from') || '').replace(/\D/g, '');
  423. const qTo = String(search.get('to') || '').replace(/\D/g, '');
  424. const toInput = (ymd) => `${ymd.slice(0, 4)}-${ymd.slice(4, 6)}-${ymd.slice(6, 8)}`;
  425. if (/^\d{8}$/.test(qFrom) && /^\d{8}$/.test(qTo)) {
  426. state.from = qFrom;
  427. state.to = qTo;
  428. $('rpFrom').value = toInput(qFrom);
  429. $('rpTo').value = toInput(qTo);
  430. return;
  431. }
  432. const { body } = await api('/api/ops/summary');
  433. const coverage = body && body.coverage;
  434. if (!coverage) return;
  435. const to = coverage.to;
  436. const d = new Date(Date.UTC(Number(to.slice(0, 4)), Number(to.slice(4, 6)) - 1, Number(to.slice(6, 8)) - 6));
  437. const from = `${d.getUTCFullYear()}${String(d.getUTCMonth() + 1).padStart(2, '0')}${String(d.getUTCDate()).padStart(2, '0')}`;
  438. state.to = to;
  439. state.from = from < coverage.from ? coverage.from : from;
  440. $('rpFrom').value = toInput(state.from);
  441. $('rpTo').value = toInput(state.to);
  442. }
  443. window.shanReportInit = function () {
  444. if (!state.inited) {
  445. state.inited = true;
  446. renderShell();
  447. initDates().then(() => load());
  448. window.addEventListener('resize', () => {
  449. Object.values(state.charts).forEach((chart) => chart && chart.resize());
  450. });
  451. window.addEventListener('beforeprint', () => {
  452. Object.values(state.charts).forEach((chart) => chart && chart.resize());
  453. });
  454. }
  455. };
  456. })();