preview.html 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!doctype html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>报告阅读样式预览 · 康师傅工作坊</title>
  7. <base href="/">
  8. <script type="importmap">
  9. {"imports":{
  10. "lit":"/lib/vendor/lit/v3.3.3/index.js",
  11. "lit/":"/lib/vendor/lit/v3.3.3/",
  12. "lit-html":"/lib/vendor/lit-html/v3.3.3/lit-html.js",
  13. "lit-html/":"/lib/vendor/lit-html/v3.3.3/",
  14. "lit-element":"/lib/vendor/lit-element/v4.2.2/index.js",
  15. "lit-element/":"/lib/vendor/lit-element/v4.2.2/",
  16. "@lit/reactive-element":"/lib/vendor/@lit/reactive-element/v2.1.2/reactive-element.js",
  17. "@lit/reactive-element/":"/lib/vendor/@lit/reactive-element/v2.1.2/"
  18. }}
  19. </script>
  20. </head>
  21. <body>
  22. <header class="preview-note">报告样式预览 · 使用既有案例内容 <a href="/">返回成果看板 ↗</a></header>
  23. <main><view-report></view-report><p id="load-state" role="status">正在加载报告预览…</p></main>
  24. <kf-drawer layout="center"></kf-drawer>
  25. <script type="module">
  26. import { html } from 'lit';
  27. import { adoptDocument } from '/src/components/base.js';
  28. import '/src/components/index.js';
  29. import '/src/components/kf-source-detail.js';
  30. import '/src/pages/view-report.js';
  31. import { buildModel, reportEvidence } from '/src/core/index.js';
  32. adoptDocument();
  33. const sheet = new CSSStyleSheet();
  34. sheet.replaceSync(`
  35. body { background:#f5f6fa; }
  36. .preview-note { padding:14px 28px; border-bottom:1px solid var(--kf-line); background:white; color:var(--kf-ink-3); font-size:13px; line-height:1.8; display:flex; gap:12px; justify-content:space-between; flex-wrap:wrap; }
  37. .preview-note a { color:var(--kf-accent-ink); }
  38. main { max-width:1300px; margin:0 auto; padding:28px; }
  39. @media(max-width:767px) { main { padding:18px 12px; } .preview-note { padding:12px 16px; } }
  40. `);
  41. document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
  42. const view = document.querySelector('view-report'), drawer = document.querySelector('kf-drawer');
  43. const previewPath = location.pathname;
  44. try {
  45. const response = await fetch('/docs/workshop-argument-quality-20261111/example-fixture.json');
  46. if (!response.ok) throw new Error('报告示例读取失败');
  47. const db = buildModel(await response.json()), id = 'argument-preview';
  48. view.db = db;
  49. view.artifactId = id;
  50. view.routeQuery = Object.fromEntries(new URLSearchParams(location.search));
  51. document.querySelector('#load-state').remove();
  52. window.addEventListener('popstate', () => {
  53. if (location.pathname === '/report/' + id || location.pathname === previewPath) {
  54. const query = location.search;
  55. history.replaceState(history.state, '', previewPath + query);
  56. view.routeQuery = Object.fromEntries(new URLSearchParams(query));
  57. } else location.assign(location.href);
  58. });
  59. view.addEventListener('source-open', event => {
  60. const source = db.sourceById[event.detail.id];
  61. drawer.heading = source?.title || '来源记录';
  62. drawer.label = '原始资料';
  63. drawer.content = html`<kf-source-detail .source=${source}></kf-source-detail>`;
  64. drawer.open = true;
  65. });
  66. view.addEventListener('evidence-open', event => {
  67. const evidence = reportEvidence(db, event.detail.reportId, event.detail.evId);
  68. if (!evidence) return;
  69. drawer.heading = evidence.claim;
  70. drawer.label = '证据详情';
  71. drawer.content = html`<div style="display:grid;gap:18px">${evidence.quotes.map(quote => html`
  72. <section style="padding:18px;border:1px solid var(--kf-line);border-radius:12px;overflow-wrap:anywhere">
  73. <p style="margin:0 0 14px;line-height:1.95;white-space:pre-wrap">${quote.text}</p>
  74. <p style="margin:0;padding-top:12px;border-top:1px solid var(--kf-line);font-size:12px;line-height:1.9;color:var(--kf-ink-3)">${quote.ref}</p>
  75. </section>`)}</div>`;
  76. drawer.open = true;
  77. });
  78. drawer.addEventListener('drawer-close', () => { drawer.open = false; });
  79. } catch (error) {
  80. document.querySelector('#load-state').textContent = error.message;
  81. }
  82. </script>
  83. </body>
  84. </html>