dknowc-dsh 1.3.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -19
- package/package.json +4 -4
- package/skills/dknowc-official-doc-writer/README.md +18 -16
- package/skills/dknowc-official-doc-writer/SKILL.md +112 -123
- package/skills/dknowc-official-doc-writer/attribution.json +5 -0
- package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +5 -0
- package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +18 -8
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/research_notes.md +34 -0
- package/skills/dknowc-official-doc-writer/reference/review_checklist.md +2 -9
- package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +922 -270
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +123 -28
- package/skills/dknowc-official-doc-writer/reference/search_intro.md +6 -6
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +88 -53
- package/skills/dknowc-official-doc-writer/reference/task_router.md +6 -6
- package/skills/dknowc-official-doc-writer/scripts/adapt_mcp_result.py +52 -2
- package/skills/dknowc-official-doc-writer/scripts/api_key.py +41 -14
- package/skills/dknowc-official-doc-writer/scripts/attribution.py +60 -0
- package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +288 -0
- package/skills/dknowc-official-doc-writer/scripts/check_materials.py +265 -0
- package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +235 -0
- package/skills/dknowc-official-doc-writer/scripts/deep_query.py +333 -0
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +22 -5
- package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +245 -0
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +106 -18
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +15 -17
- package/skills/dknowc-official-doc-writer/scripts/mcp_convert.py +272 -0
- package/skills/dknowc-official-doc-writer/scripts/mcp_direct.py +257 -143
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +72 -8
- package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +14 -4
- package/skills/dknowc-official-doc-writer/scripts/prose_lint.py +6 -1
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +120 -48
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +1514 -660
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +151 -6
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +13 -0
- package/skills/dknowc-ppt-assistant/README.md +14 -10
- package/skills/dknowc-ppt-assistant/SKILL.md +33 -15
- package/skills/dknowc-ppt-assistant/attribution.json +5 -0
- package/skills/dknowc-ppt-assistant/references/material_usage.md +9 -5
- package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +14 -2
- package/skills/dknowc-ppt-assistant/references/sample_trace_report.html +1343 -292
- package/skills/dknowc-ppt-assistant/references/search_intro.md +1 -1
- package/skills/dknowc-ppt-assistant/scripts/api_key.py +41 -14
- package/skills/dknowc-ppt-assistant/scripts/attribution.py +60 -0
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +9 -17
- package/skills/dknowc-ppt-assistant/scripts/mcp_convert.py +188 -0
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +135 -6
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1539 -714
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +33 -3
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +17 -19
- package/skills/dknowc-trusted-search/README.md +27 -22
- package/skills/dknowc-trusted-search/SKILL.md +213 -140
- package/skills/dknowc-trusted-search/attribution.json +5 -0
- package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +17 -7
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +720 -253
- package/skills/dknowc-trusted-search/scripts/api_key.py +41 -14
- package/skills/dknowc-trusted-search/scripts/attribution.py +61 -0
- package/skills/dknowc-trusted-search/scripts/chart_embed.py +350 -0
- package/skills/dknowc-trusted-search/scripts/deep_query.py +26 -5
- package/skills/dknowc-trusted-search/scripts/initialize.py +20 -29
- package/skills/dknowc-trusted-search/scripts/mcp_convert.py +189 -0
- package/skills/dknowc-trusted-search/scripts/merge_search_results.py +272 -0
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +149 -43
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +1860 -751
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +34 -31
- package/src/index.js +3 -8
- package/skills/dknowc-official-doc-writer/scripts/check_release.py +0 -93
- package/skills/dknowc-ppt-assistant/scripts/adapt_mcp_result.py +0 -279
- package/skills/dknowc-ppt-assistant/scripts/check_release.py +0 -106
- package/skills/dknowc-trusted-consulting/README.md +0 -63
- package/skills/dknowc-trusted-consulting/SKILL.md +0 -236
- package/skills/dknowc-trusted-consulting/reference/consult_intro.md +0 -47
- package/skills/dknowc-trusted-consulting/reference/onboarding_scripts.md +0 -132
- package/skills/dknowc-trusted-consulting/reference/sample_consult_answer.md +0 -31
- package/skills/dknowc-trusted-consulting/reference/sample_trace_report.html +0 -502
- package/skills/dknowc-trusted-consulting/scripts/adapt_mcp_result.py +0 -283
- package/skills/dknowc-trusted-consulting/scripts/api_key.py +0 -41
- package/skills/dknowc-trusted-consulting/scripts/check_release.py +0 -66
- package/skills/dknowc-trusted-consulting/scripts/gov_chat.py +0 -508
- package/skills/dknowc-trusted-consulting/scripts/initialize.py +0 -133
- package/skills/dknowc-trusted-consulting/scripts/mcp_direct.py +0 -166
- package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +0 -279
- package/skills/dknowc-trusted-consulting/scripts/render_trace_html.py +0 -1616
- package/skills/dknowc-trusted-search/scripts/adapt_mcp_result.py +0 -261
- package/skills/dknowc-trusted-search/scripts/check_release.py +0 -79
- package/skills/dknowc-trusted-search/scripts/render_policy_visualization.py +0 -894
|
@@ -1,34 +1,46 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
2
|
+
"""可信溯源核验报告渲染器:把搜索结果 JSON + 最终答案渲染为单文件可核验 HTML。
|
|
3
|
+
|
|
4
|
+
深知可信搜索 SkillHub 版(对齐深知公文写作 3.7.0 渲染层,数据口径保持自有与真实)。
|
|
5
|
+
输入直读 trusted_search.py / deep_query.py 的 --json-only 输出(可信搜索 content.data
|
|
6
|
+
或深度搜索 deep-query/v3 格式),正文用 --answer-file 传入最终答案(关键结论带 [n] 角标),
|
|
7
|
+
成稿自检用 --self-check-file 传入五项结果。
|
|
3
8
|
|
|
4
9
|
报告定位:不止展示"材料从哪来"(溯源),更要传达"我们查过了,可以交付"(核验)。
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
架构(参考深知晓交互原型):
|
|
11
|
+
- 顶栏:身份章 + 标题 + 工具组(只看正文 / 复制全文 / 打印归档)+ 阅读进度条
|
|
12
|
+
- Hero:大标题 + 真实统计(N 次检索 · M 篇来源文章 · K 处引用)+ 双视图切换
|
|
13
|
+
- 过程回顾条:检索 → 入库 → 逐条比对 → 核验完成(静态回放,数字全部真实计算;
|
|
14
|
+
无思考流数据就不展示"思考"步骤——硬造即违背核验诚实性)
|
|
15
|
+
- 核验报告视图(默认):核验报告单 + 正文分节卡;角标点击跳知识专库定位
|
|
16
|
+
- 知识专库视图(全屏):大搜索 + 热词(标题/正文高频词真实计算)+ 检索分组 tabs + 材料卡
|
|
17
|
+
三个核验层次:报告级(核验报告单)/材料级(来源卡核验链标记)/引用级(角标一一绑定)。
|
|
18
|
+
诚实原则:脚本真实计算的结果才打勾;无法自动判定的项不虚构展示("现行效力"人工复核提示行已按产品要求移除,对齐公文写作 3.7.2)。
|
|
19
|
+
生成前预处理(内置):policyFiles 发文字号本地匹配、原文链接活性检测(404/410 + 软 404
|
|
20
|
+
标题嗅探,--skip-link-check 跳过)、存档快照兜底(screenShotPath /A/ 容错 + 格式校验,
|
|
21
|
+
--no-snapshot 关闭);缺原文链接不拖垮核验结论,按提醒呈现。
|
|
22
|
+
布局为单文件静态 HTML;打印归档模式单栏全展开并附材料附录。
|
|
23
|
+
所有输入输出经路径安全层限制在 skill 工作区 official-docs/ 内。
|
|
19
24
|
"""
|
|
20
25
|
|
|
21
26
|
from __future__ import annotations
|
|
22
27
|
|
|
23
28
|
import argparse
|
|
29
|
+
import concurrent.futures
|
|
24
30
|
import html
|
|
25
31
|
import json
|
|
26
32
|
import re
|
|
27
33
|
import sys
|
|
34
|
+
import unicodedata
|
|
35
|
+
import urllib.error
|
|
36
|
+
import urllib.request
|
|
28
37
|
from datetime import datetime
|
|
29
38
|
from pathlib import Path
|
|
30
39
|
from typing import Any, Dict, List, Optional, Tuple
|
|
31
40
|
|
|
41
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
42
|
+
import chart_embed # noqa: E402 图表渲染共享模块(1.4.0,与可视化报告共用)
|
|
43
|
+
|
|
32
44
|
|
|
33
45
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
34
46
|
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
@@ -46,34 +58,48 @@ OUTPUT_DIR = WS_ROOT / "official-docs" / "output"
|
|
|
46
58
|
|
|
47
59
|
def _is_within(path: Path, parent: Path) -> bool:
|
|
48
60
|
try:
|
|
49
|
-
path.relative_to(parent)
|
|
61
|
+
path.relative_to(parent.resolve())
|
|
50
62
|
return True
|
|
51
63
|
except ValueError:
|
|
52
64
|
return False
|
|
53
65
|
|
|
54
66
|
|
|
55
67
|
def _safe_input_path(value: str, allowed_suffixes: set) -> Path:
|
|
56
|
-
"""
|
|
68
|
+
"""输入文件必须位于 skill 工作区内且后缀合法,阻断路径遍历。
|
|
69
|
+
|
|
70
|
+
兼容只写文件名的调用(1.4.0):形如 `xxx.json` 的相对路径先在 SKILL_ROOT 下找,
|
|
71
|
+
找不到再到 official-docs/search-results/ 找——避免 Agent 因"文件不在预期位置"
|
|
72
|
+
转而全盘 find/grep 触发宿主安全策略。
|
|
73
|
+
"""
|
|
57
74
|
raw = Path(value).expanduser()
|
|
58
|
-
|
|
75
|
+
if not raw.is_absolute() and raw.parent == Path("."):
|
|
76
|
+
candidate = SKILL_ROOT / raw
|
|
77
|
+
if not candidate.exists() and (SEARCH_RESULTS_DIR / raw.name).exists():
|
|
78
|
+
raw = SEARCH_RESULTS_DIR / raw.name
|
|
79
|
+
resolved = raw.resolve() if raw.is_absolute() else raw.resolve()
|
|
59
80
|
if resolved.suffix.lower() not in allowed_suffixes:
|
|
60
|
-
raise ValueError(f"
|
|
61
|
-
if not _is_within(resolved, SEARCH_RESULTS_DIR
|
|
62
|
-
|
|
81
|
+
raise ValueError(f"输入文件后缀必须是 {sorted(allowed_suffixes)} 之一: {value}")
|
|
82
|
+
if not (_is_within(resolved, SEARCH_RESULTS_DIR) or _is_within(resolved, SKILL_ROOT / "config") or resolved == SKILL_ROOT / "SKILL.md"):
|
|
83
|
+
# 允许工作区内任意位置的答案/自检/搜索 JSON(search-results、output、根下临时文件)
|
|
84
|
+
if not _is_within(resolved, SKILL_ROOT):
|
|
85
|
+
raise ValueError(f"输入文件必须位于 skill 工作区内: {value}")
|
|
63
86
|
return resolved
|
|
64
87
|
|
|
65
88
|
|
|
66
89
|
def _safe_output_path(value: str, allowed_suffixes: set, default_suffix: str) -> Path:
|
|
67
|
-
"""
|
|
90
|
+
"""输出文件必须位于 official-docs/output/ 内且后缀合法。"""
|
|
68
91
|
raw = Path(value).expanduser()
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if not _is_within(resolved, OUTPUT_DIR
|
|
73
|
-
|
|
92
|
+
if raw.suffix.lower() not in allowed_suffixes:
|
|
93
|
+
raw = raw.with_suffix(default_suffix)
|
|
94
|
+
resolved = raw.resolve() if not raw.is_absolute() else raw
|
|
95
|
+
if not _is_within(resolved, OUTPUT_DIR):
|
|
96
|
+
if raw.is_absolute():
|
|
97
|
+
raise ValueError(f"输出文件必须位于 official-docs/output/ 内: {value}")
|
|
98
|
+
resolved = (OUTPUT_DIR / raw.name).resolve()
|
|
74
99
|
return resolved
|
|
75
100
|
|
|
76
101
|
|
|
102
|
+
|
|
77
103
|
# ============================================================
|
|
78
104
|
# 基础工具
|
|
79
105
|
# ============================================================
|
|
@@ -133,6 +159,156 @@ def strip_citation_markers(text: str) -> str:
|
|
|
133
159
|
return text.strip() + ("\n" if text.strip() else "")
|
|
134
160
|
|
|
135
161
|
|
|
162
|
+
# ============================================================
|
|
163
|
+
# 生成前预处理(文号匹配 / 链接活性检测 / 快照兜底)
|
|
164
|
+
# ============================================================
|
|
165
|
+
|
|
166
|
+
# 快照兜底开关:默认启用。接口 screenShotPath 曾存在路径缺 /A/ 层级的拼接 bug
|
|
167
|
+
# (后端修复中);verify_snapshots 在展示前完成"/A/ 修订 + 格式校验 + 不合法弃用"。
|
|
168
|
+
SNAPSHOT_ENABLED = True
|
|
169
|
+
|
|
170
|
+
# 软 404 关键词:政府站常以 HTTP 200 返回"页面不存在"错误页,状态码识别不了,
|
|
171
|
+
# 需读页面标题嗅探。关键词取自实测样例,且仅匹配 <title>(政策正文不会出现在标题里),
|
|
172
|
+
# 误杀风险极低。
|
|
173
|
+
SOFT_404_KEYWORDS = ("页面不存在", "页面未找到", "您访问的页面", "已删除", "已下线", "无法找到", "not found", "404")
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def check_link_alive(url: str, timeout: int = 8) -> bool:
|
|
177
|
+
"""检测原文链接是否仍然可达。失效判据(客观信号,与请求方无关):
|
|
178
|
+
① HTTP 404/410;② 软 404——HTTP 200 但页面标题为典型失效页。
|
|
179
|
+
连接失败、超时、403、5xx 等一律视为"无法确认"按有效处理——政府站
|
|
180
|
+
常对脚本请求反爬,凭这些判死会误杀可用链接。
|
|
181
|
+
"""
|
|
182
|
+
for method in ("HEAD", "GET"):
|
|
183
|
+
try:
|
|
184
|
+
req = urllib.request.Request(
|
|
185
|
+
url, method=method,
|
|
186
|
+
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"},
|
|
187
|
+
)
|
|
188
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
189
|
+
if resp.status in (404, 410):
|
|
190
|
+
return False
|
|
191
|
+
if method == "GET":
|
|
192
|
+
chunk = resp.read(4096).decode("utf-8", errors="replace")
|
|
193
|
+
title = re.search(r"<title>(.*?)</title>", chunk, re.I | re.S)
|
|
194
|
+
text = title.group(1) if title else chunk[:200]
|
|
195
|
+
lowered = text.lower()
|
|
196
|
+
return not any(k in text or k in lowered for k in SOFT_404_KEYWORDS)
|
|
197
|
+
except urllib.error.HTTPError as e:
|
|
198
|
+
if method == "GET":
|
|
199
|
+
return e.code not in (404, 410)
|
|
200
|
+
except Exception:
|
|
201
|
+
if method == "GET":
|
|
202
|
+
return True
|
|
203
|
+
return True
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def normalize_snapshot_url(url: str) -> str:
|
|
207
|
+
"""快照路径容错:接口部分返回值缺 /A/ 层级(公文版实测 60 条中 5 条,补全后即可访问),
|
|
208
|
+
统一规范化为 https://attach.dknowc.cn/snapshot/A/<2位>/<2位>/<哈希>.jpg。"""
|
|
209
|
+
u = (url or "").strip()
|
|
210
|
+
if u.startswith("https://attach.dknowc.cn/snapshot/") and "/snapshot/A/" not in u:
|
|
211
|
+
return u.replace("/snapshot/", "/snapshot/A/", 1)
|
|
212
|
+
return u
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def mark_dead_links(articles: List[Dict[str, Any]]) -> int:
|
|
216
|
+
"""并发检测全部材料的原文链接,404/410/软404 的标记 链接失效=True。返回失效数。"""
|
|
217
|
+
targets = [(i, a["源网址"]) for i, a in enumerate(articles) if (a.get("源网址") or "").strip()]
|
|
218
|
+
if not targets:
|
|
219
|
+
return 0
|
|
220
|
+
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as pool:
|
|
221
|
+
alive = dict(zip((i for i, _ in targets), pool.map(check_link_alive, (u for _, u in targets))))
|
|
222
|
+
dead = 0
|
|
223
|
+
for i, _ in targets:
|
|
224
|
+
if not alive.get(i, True):
|
|
225
|
+
articles[i]["链接失效"] = True
|
|
226
|
+
dead += 1
|
|
227
|
+
return dead
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def verify_snapshots(articles: List[Dict[str, Any]]) -> int:
|
|
231
|
+
"""快照展示前的路径校验(纯本地检查,不发网络请求):
|
|
232
|
+
组装阶段已由 normalize_snapshot_url 补全 /A/ 层级;此处校验修订后的路径
|
|
233
|
+
是否符合合法格式(https://attach.dknowc.cn/snapshot/A/…),不合法则弃用。
|
|
234
|
+
|
|
235
|
+
不做网络可达检测:attach 前置雷池 WAF 的拦截与请求方 IP 风控相关
|
|
236
|
+
(检测机高频请求会被拦而普通用户正常),可达性实测会误杀好快照;
|
|
237
|
+
快照文件本身的存在性由可信搜索侧的数据质量保障。
|
|
238
|
+
"""
|
|
239
|
+
dropped = 0
|
|
240
|
+
for a in articles:
|
|
241
|
+
u = (a.get("快照链接") or "").strip()
|
|
242
|
+
if not u:
|
|
243
|
+
continue
|
|
244
|
+
if u.startswith("https://attach.dknowc.cn/snapshot/A/"):
|
|
245
|
+
continue
|
|
246
|
+
a["快照链接"] = ""
|
|
247
|
+
dropped += 1
|
|
248
|
+
return dropped
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _normalize_title_for_match(value: str) -> str:
|
|
252
|
+
"""标题归一(文号匹配用):全半角/大小写归一,去书名号括号与空白。"""
|
|
253
|
+
text = unicodedata.normalize("NFKC", str(value or "")).lower()
|
|
254
|
+
text = re.sub(r"[《》〈〉「」『』\[\]【】()()]", "", text)
|
|
255
|
+
text = re.sub(r"\s+", "", text)
|
|
256
|
+
return text
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def attach_doc_numbers(articles: List[Dict[str, Any]], payload: Dict[str, Any]) -> int:
|
|
260
|
+
"""从同一响应的 policyFiles 区按标题本地匹配发文字号(writtenText)。
|
|
261
|
+
|
|
262
|
+
文号与检索文章分开展示在同一响应里,本地标题匹配即可拿到,无需接口改动;
|
|
263
|
+
新闻/解读类不在 policyFiles 中(本就无文号),匹配不上则不显示。
|
|
264
|
+
检索库对同一政策文件常有多个抓取变体(新闻稿版/发文版,文号挂在发文版条目上),
|
|
265
|
+
标题精确匹配不上时**不做模糊猜测**(宁缺勿错)——变体识别与回填由 SKILL.md
|
|
266
|
+
选材规则执行:Agent 引用政策文件时优先带文号的发文版条目(对齐公文写作 3.7.2)。
|
|
267
|
+
"""
|
|
268
|
+
doc_numbers: Dict[str, str] = {}
|
|
269
|
+
for holder in (payload.get("content") if isinstance(payload.get("content"), dict) else {},
|
|
270
|
+
(payload.get("content") or {}).get("data") if isinstance((payload.get("content") or {}).get("data"), dict) else {},
|
|
271
|
+
payload.get("data") if isinstance(payload.get("data"), dict) else {}):
|
|
272
|
+
for pf in (holder.get("policyFiles") or []):
|
|
273
|
+
if not isinstance(pf, dict):
|
|
274
|
+
continue
|
|
275
|
+
doc_no = first_str(pf.get("writtenText"), pf.get("发文字号"))
|
|
276
|
+
title = first_str(pf.get("title"), pf.get("标题"))
|
|
277
|
+
if doc_no and title:
|
|
278
|
+
doc_numbers.setdefault(_normalize_title_for_match(title), doc_no)
|
|
279
|
+
if not doc_numbers:
|
|
280
|
+
return 0
|
|
281
|
+
matched = 0
|
|
282
|
+
for a in articles:
|
|
283
|
+
if a.get("文号"):
|
|
284
|
+
continue
|
|
285
|
+
no = doc_numbers.get(_normalize_title_for_match(first_str(a.get("文章标题"), a.get("title"), a.get("标题"))))
|
|
286
|
+
if no:
|
|
287
|
+
a["文号"] = no
|
|
288
|
+
matched += 1
|
|
289
|
+
return matched
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def preprocess_articles(articles: List[Dict[str, Any]], payload: Dict[str, Any],
|
|
293
|
+
skip_link_check: bool = False, snapshot_enabled: bool = True) -> None:
|
|
294
|
+
"""extract_sources 前的统一预处理:文号匹配、快照兜底、链接活性检测。
|
|
295
|
+
|
|
296
|
+
直接改写文章 dict(注入 文号 / 快照链接 / 链接失效 字段),供
|
|
297
|
+
source_from_article 读取;均为幂等操作,多轮渲染不叠加。
|
|
298
|
+
"""
|
|
299
|
+
attach_doc_numbers(articles, payload)
|
|
300
|
+
if snapshot_enabled:
|
|
301
|
+
for a in articles:
|
|
302
|
+
raw_snap = first_str(a.get("screenShotPath"), a.get("screenshot_path"), a.get("快照链接"), a.get("snapshot"))
|
|
303
|
+
a["快照链接"] = normalize_snapshot_url(raw_snap) if raw_snap else ""
|
|
304
|
+
verify_snapshots(articles)
|
|
305
|
+
else:
|
|
306
|
+
for a in articles:
|
|
307
|
+
a["快照链接"] = ""
|
|
308
|
+
if not skip_link_check:
|
|
309
|
+
mark_dead_links(articles)
|
|
310
|
+
|
|
311
|
+
|
|
136
312
|
# ============================================================
|
|
137
313
|
# 素材四分类
|
|
138
314
|
# ============================================================
|
|
@@ -181,19 +357,37 @@ def parse_year_month(raw: str) -> Optional[Tuple[int, int]]:
|
|
|
181
357
|
# 素材提取(沿用原数据层)
|
|
182
358
|
# ============================================================
|
|
183
359
|
|
|
360
|
+
def clean_paragraph_noise(text: str) -> str:
|
|
361
|
+
"""清洗接口段落文本中的附件链接噪音。
|
|
362
|
+
|
|
363
|
+
接口段落内容格式为「段落标题 https://attach.dknowc.cn/file/<正文>」——
|
|
364
|
+
URL 前是段落标题(已由标题链单独展示),URL 本身是附件地址(卡片有"查看原文"入口)。
|
|
365
|
+
摘录只保留 URL 之后的正文;无该前缀时兜底剔除文本中的裸 URL。
|
|
366
|
+
"""
|
|
367
|
+
value = str(text or "")
|
|
368
|
+
m = re.search(r"https?://\S*attach\.dknowc\.cn/file/", value)
|
|
369
|
+
if m:
|
|
370
|
+
return value[m.end():].strip()
|
|
371
|
+
value = re.sub(r"https?://\S+", " ", value)
|
|
372
|
+
return re.sub(r"[ \t]{2,}", " ", value).strip()
|
|
373
|
+
|
|
374
|
+
|
|
184
375
|
def paragraph_text(item: Dict[str, Any]) -> str:
|
|
185
376
|
paragraphs = item.get("content") or item.get("段落") or item.get("paragraphs") or item.get("paragraphList")
|
|
186
377
|
if isinstance(paragraphs, list):
|
|
187
378
|
chunks = []
|
|
188
379
|
for para in paragraphs:
|
|
189
380
|
if isinstance(para, dict):
|
|
190
|
-
|
|
381
|
+
chunk = first_str(para.get("text"), para.get("内容"), para.get("content"), para.get("summary"), para.get("标题"), para.get("title"))
|
|
191
382
|
else:
|
|
192
|
-
|
|
193
|
-
|
|
383
|
+
chunk = str(para)
|
|
384
|
+
chunk = clean_paragraph_noise(chunk)
|
|
385
|
+
if chunk:
|
|
386
|
+
chunks.append(chunk)
|
|
387
|
+
text = "\n".join(chunks)
|
|
194
388
|
if text:
|
|
195
389
|
return text
|
|
196
|
-
return first_str(
|
|
390
|
+
return clean_paragraph_noise(first_str(
|
|
197
391
|
item.get("摘录"),
|
|
198
392
|
item.get("摘要"),
|
|
199
393
|
item.get("相关段落"),
|
|
@@ -203,7 +397,7 @@ def paragraph_text(item: Dict[str, Any]) -> str:
|
|
|
203
397
|
item.get("content"),
|
|
204
398
|
item.get("text"),
|
|
205
399
|
item.get("snippet"),
|
|
206
|
-
)
|
|
400
|
+
))
|
|
207
401
|
|
|
208
402
|
|
|
209
403
|
def content_segments(item: Dict[str, Any]) -> List[Dict[str, str]]:
|
|
@@ -257,7 +451,7 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
257
451
|
item.get("name"),
|
|
258
452
|
vo.get("showTitle"),
|
|
259
453
|
vo.get("title"),
|
|
260
|
-
"
|
|
454
|
+
"未命名来源文章",
|
|
261
455
|
),
|
|
262
456
|
"agency": first_str(
|
|
263
457
|
item.get("unit") if not isinstance(item.get("unit"), list) else "、".join(str(x) for x in item.get("unit")[:3]),
|
|
@@ -271,45 +465,55 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
271
465
|
),
|
|
272
466
|
"date": first_str(item.get("发布日期"), item.get("date"), item.get("发布时间"), item.get("createDate"), vo.get("dateTime"), vo.get("createDate")),
|
|
273
467
|
"url": first_str(item.get("sourceUrl"), item.get("source_url"), item.get("源网址"), item.get("原文链接"), item.get("url"), item.get("原文"), vo.get("sourceUrl"), vo.get("url")),
|
|
274
|
-
"policy_url": first_str(item.get("policyUrl"), item.get("policy_url"),
|
|
468
|
+
"policy_url": first_str(item.get("policyUrl"), item.get("policy_url"), vo.get("policyUrl")),
|
|
275
469
|
"excerpt": segment.get("text") or paragraph_text(item),
|
|
276
470
|
"section": first_str(item.get("正文对应"), item.get("section"), item.get("支撑")),
|
|
277
471
|
"kind": first_str(item.get("类型"), item.get("type"), item.get("素材类型"), vo.get("typeName"), "材料"),
|
|
278
472
|
"verify_note": first_str(item.get("核验"), item.get("verification"), item.get("核验说明")),
|
|
279
473
|
"area": first_str(item.get("intentionArea"), item.get("area"), item.get("地域")),
|
|
280
474
|
}
|
|
281
|
-
#
|
|
282
|
-
#
|
|
283
|
-
|
|
284
|
-
seg_title = ""
|
|
475
|
+
# 段落级数据(多段分块展示用):每段 {chain:[文章,章节,子节...], text}
|
|
476
|
+
# 段落标题自带 > 层级,拆级成面包屑;段落标题与文章标题相同或缺失时链只含文章一级。
|
|
477
|
+
segments = []
|
|
285
478
|
for seg in content_segments(item):
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
source["
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
479
|
+
seg_title = first_str(seg.get("title"))
|
|
480
|
+
levels = [lvl.strip() for lvl in re.split(r"\s*>\s*", seg_title) if lvl.strip()] if seg_title else []
|
|
481
|
+
if levels and levels[0] == source["title"]:
|
|
482
|
+
levels = levels[1:]
|
|
483
|
+
seg_text = clean_paragraph_noise(seg.get("text"))
|
|
484
|
+
chain_lvls = [source["title"]] + levels
|
|
485
|
+
segments.append({"chain": chain_lvls, "text": strip_leading_chain(seg_text, chain_lvls)})
|
|
486
|
+
source["segments"] = segments
|
|
487
|
+
# 首段章节位置(兼容旧单行引用处)
|
|
488
|
+
first_chain = segments[0]["chain"][1:] if segments else []
|
|
489
|
+
source["doc_section"] = " › ".join(first_chain)
|
|
490
|
+
source["chain_full"] = " › ".join(segments[0]["chain"]) if segments else ""
|
|
491
|
+
# 发文字号(接口 policyFiles.writtenText,本地标题匹配)
|
|
492
|
+
source["doc_number"] = first_str(item.get("文号"), item.get("doc_number"))
|
|
296
493
|
# 所属搜索条件(多路检索分组)与引用状态(未引用=接口召回但正文未采用)
|
|
297
494
|
source["search_key"] = first_str(item.get("搜索条件"), item.get("search_key"))
|
|
298
495
|
source["used"] = item.get("已引用", item.get("used", True))
|
|
299
496
|
if not isinstance(source["used"], bool):
|
|
300
497
|
source["used"] = True
|
|
498
|
+
# 快照兜底:原文链接 404/410(生成时真实检测)或接口未返回源网址时,
|
|
499
|
+
# 改用接口提供的存档快照链接回看——快照是原文的存档副本,按钮文案如实区分。
|
|
500
|
+
source["snapshot"] = first_str(item.get("快照链接"), item.get("snapshot"), item.get("screenShotPath"))
|
|
501
|
+
source["link_dead"] = item.get("链接失效") is True or item.get("link_dead") is True
|
|
301
502
|
# 发布日期可信度(实测:「高」=模型治理入库、标题模型精抽;「较高」=门户抓取、标题规则提取)
|
|
302
503
|
source["conf"] = first_str(item.get("发布日期可信度"), item.get("可信度"), item.get("confidence"))
|
|
303
504
|
key, label, css = normalize_kind(source["kind"])
|
|
304
505
|
source["type_key"] = key
|
|
305
506
|
source["type_label"] = label
|
|
306
507
|
source["type_css"] = css
|
|
307
|
-
|
|
308
|
-
source["
|
|
508
|
+
live_url = bool(source["url"] and source["url"] != "接口未返回") and not source["link_dead"]
|
|
509
|
+
source["has_link"] = live_url or bool(source["policy_url"]) or bool(source["snapshot"])
|
|
510
|
+
# 核验状态只看摘录可比对;原文链接死活与快照有无是回看通道问题,不影响核验结论
|
|
511
|
+
source["verified"] = bool(source["excerpt"])
|
|
309
512
|
return source
|
|
310
513
|
|
|
311
514
|
|
|
312
515
|
def extract_articles_from_search(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
516
|
+
"""可信搜索 dependable/search 格式:content.data.检索文章。"""
|
|
313
517
|
content = payload.get("content") if isinstance(payload.get("content"), dict) else payload
|
|
314
518
|
data = content.get("data") if isinstance(content.get("data"), dict) else content.get("data")
|
|
315
519
|
if isinstance(data, dict) and isinstance(data.get("检索文章"), list):
|
|
@@ -320,7 +524,7 @@ def extract_articles_from_search(payload: Dict[str, Any]) -> List[Dict[str, Any]
|
|
|
320
524
|
def extract_articles_from_deep(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
321
525
|
"""深度搜索 deep-query/v3 非流式格式:{"data": {"searches": [{"result": [...]}], "common_articles": [...]}}。
|
|
322
526
|
|
|
323
|
-
按源网址去重摊平;为每篇材料注入"搜索条件"
|
|
527
|
+
按源网址去重摊平;为每篇材料注入"搜索条件"(子查询的地域·查询词),供知识专库检索分组筛选。
|
|
324
528
|
"""
|
|
325
529
|
data = payload.get("data")
|
|
326
530
|
if not isinstance(data, dict):
|
|
@@ -352,7 +556,8 @@ def extract_articles_from_deep(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
|
352
556
|
for article in search.get("result") or []:
|
|
353
557
|
_add(article, label)
|
|
354
558
|
for article in data.get("common_articles") or []:
|
|
355
|
-
|
|
559
|
+
# 多查询公共文章给独立分组名(空 key 落不进任何分组 tab,无法筛选)
|
|
560
|
+
_add(article, "多查询公共")
|
|
356
561
|
return out
|
|
357
562
|
|
|
358
563
|
|
|
@@ -363,11 +568,21 @@ def extract_reference_materials(payload: Dict[str, Any]) -> List[Dict[str, Any]]
|
|
|
363
568
|
return []
|
|
364
569
|
|
|
365
570
|
|
|
366
|
-
def extract_sources(payload: Dict[str, Any]
|
|
571
|
+
def extract_sources(payload: Dict[str, Any],
|
|
572
|
+
skip_link_check: bool = False, snapshot_enabled: bool = True) -> List[Dict[str, str]]:
|
|
367
573
|
raw_sources: List[Dict[str, Any]] = []
|
|
368
574
|
raw_sources.extend(extract_reference_materials(payload))
|
|
575
|
+
is_deep = bool(extract_articles_from_deep(payload))
|
|
369
576
|
raw_sources.extend(extract_articles_from_search(payload))
|
|
370
577
|
raw_sources.extend(extract_articles_from_deep(payload))
|
|
578
|
+
if not is_deep:
|
|
579
|
+
# 可信搜索单次检索:材料统一标注"本次检索"分组(多轮检索由 Agent 合并 JSON 后各自携带)
|
|
580
|
+
for item in raw_sources:
|
|
581
|
+
if not item.get("搜索条件"):
|
|
582
|
+
item["搜索条件"] = "本次检索"
|
|
583
|
+
|
|
584
|
+
# 生成前预处理:文号匹配(policyFiles)、快照兜底、原文链接活性检测
|
|
585
|
+
preprocess_articles(raw_sources, payload, skip_link_check=skip_link_check, snapshot_enabled=snapshot_enabled)
|
|
371
586
|
|
|
372
587
|
sources: List[Dict[str, str]] = []
|
|
373
588
|
seen = set()
|
|
@@ -396,18 +611,18 @@ def extract_answer(payload: Dict[str, Any]) -> str:
|
|
|
396
611
|
return normalize_citations(answer)
|
|
397
612
|
articles = extract_articles_from_search(payload)
|
|
398
613
|
if articles:
|
|
399
|
-
rows = ["
|
|
614
|
+
rows = ["可信搜索召回了以下重点来源文章:"]
|
|
400
615
|
for idx, item in enumerate(articles[:8], start=1):
|
|
401
|
-
rows.append(f"[{idx}] {first_str(item.get('文章标题'), item.get('title'), item.get('标题'), '
|
|
616
|
+
rows.append(f"[{idx}] {first_str(item.get('文章标题'), item.get('title'), item.get('标题'), '未命名来源文章')}")
|
|
402
617
|
return "\n".join(rows)
|
|
403
618
|
deep_articles = extract_articles_from_deep(payload)
|
|
404
619
|
if deep_articles:
|
|
405
|
-
rows = ["
|
|
620
|
+
rows = ["深度搜索召回了以下重点来源文章:"]
|
|
406
621
|
for idx, item in enumerate(deep_articles[:8], start=1):
|
|
407
622
|
vo = item.get("vo") if isinstance(item.get("vo"), dict) else {}
|
|
408
|
-
rows.append(f"[{idx}] {first_str(item.get('文章标题'), vo.get('showTitle'), vo.get('title'), item.get('title'), '
|
|
623
|
+
rows.append(f"[{idx}] {first_str(item.get('文章标题'), vo.get('showTitle'), vo.get('title'), item.get('title'), '未命名来源文章')}")
|
|
409
624
|
return "\n".join(rows)
|
|
410
|
-
return "
|
|
625
|
+
return "接口返回中未识别到正文内容;请查看知识专库或原始 JSON。"
|
|
411
626
|
|
|
412
627
|
|
|
413
628
|
def extract_question(payload: Dict[str, Any]) -> str:
|
|
@@ -428,28 +643,6 @@ def extract_question(payload: Dict[str, Any]) -> str:
|
|
|
428
643
|
)
|
|
429
644
|
|
|
430
645
|
|
|
431
|
-
def extract_knowledge_base(payload: Dict[str, Any]) -> str:
|
|
432
|
-
content = payload.get("content") if isinstance(payload.get("content"), dict) else payload
|
|
433
|
-
data = content.get("data") if isinstance(content.get("data"), dict) else {}
|
|
434
|
-
return first_str(
|
|
435
|
-
content.get("knowledgeBase"),
|
|
436
|
-
payload.get("knowledgeBase"),
|
|
437
|
-
data.get("knowledgeBase"),
|
|
438
|
-
payload.get("knowledgeBaseUrl"),
|
|
439
|
-
)
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
def extract_knowledge_bases(payload: Dict[str, Any]) -> List[str]:
|
|
443
|
-
content = payload.get("content") if isinstance(payload.get("content"), dict) else payload
|
|
444
|
-
values: List[str] = []
|
|
445
|
-
for value in (payload.get("knowledgeBases"), content.get("knowledgeBases"), payload.get("knowledgeBase"), content.get("knowledgeBase")):
|
|
446
|
-
if isinstance(value, list):
|
|
447
|
-
values.extend(str(item).strip() for item in value if str(item).strip())
|
|
448
|
-
elif isinstance(value, str) and value.strip():
|
|
449
|
-
values.append(value.strip())
|
|
450
|
-
return list(dict.fromkeys(values))
|
|
451
|
-
|
|
452
|
-
|
|
453
646
|
def citation_ids(answer: str) -> List[str]:
|
|
454
647
|
ids: List[str] = []
|
|
455
648
|
for match in re.finditer(r"\[(\d+)\]", answer):
|
|
@@ -482,8 +675,9 @@ def classify_check_value(raw: Any) -> Tuple[str, str]:
|
|
|
482
675
|
"""把自检项的值解析为(状态, 核验说明)。
|
|
483
676
|
|
|
484
677
|
兼容多种写法:`pass` / `true` / `通过` / `通过:说明文字` / `✓` 等;
|
|
485
|
-
|
|
486
|
-
|
|
678
|
+
值后面的说明文字保留下来供核验单展示。无法识别的状态按未记录(none)处理:
|
|
679
|
+
描述性文本不等于"未通过"——红项只给显式声明的未通过,避免书写格式问题
|
|
680
|
+
被放大成核验未通过(2026-09-20 WorkBuddy 实测:Agent 把备注写成自检值导致 5/7 红项)。
|
|
487
681
|
"""
|
|
488
682
|
text = str(raw or "").strip()
|
|
489
683
|
lowered = text.lower()
|
|
@@ -493,7 +687,7 @@ def classify_check_value(raw: Any) -> Tuple[str, str]:
|
|
|
493
687
|
for prefix in ("已通过", "通过", "合格", "pass", "ok", "true", "是", "✓", "yes"):
|
|
494
688
|
if lowered.startswith(prefix):
|
|
495
689
|
return "pass", text[len(prefix):].lstrip("::,,、 ").strip()
|
|
496
|
-
return "
|
|
690
|
+
return "none", text
|
|
497
691
|
|
|
498
692
|
|
|
499
693
|
def normalize_self_check(raw: Any) -> Optional[Dict[str, Tuple[str, str]]]:
|
|
@@ -501,8 +695,13 @@ def normalize_self_check(raw: Any) -> Optional[Dict[str, Tuple[str, str]]]:
|
|
|
501
695
|
return None
|
|
502
696
|
items: Dict[str, Tuple[str, str]] = {}
|
|
503
697
|
for key, value in raw.items():
|
|
698
|
+
# 只认五项标准自检键(英文/中文);白名单外的多余键(如 Agent 自行追加的
|
|
699
|
+
# "备注""待核验/下一步补充"等描述性键)不构成"交付前检查"定义的核验项,
|
|
700
|
+
# 直接忽略不计入——核验单只统计定义过的检查项(2026-09-20 实测修正)。
|
|
701
|
+
label = SELF_CHECK_LABELS.get(key) or SELF_CHECK_LABELS.get(str(key))
|
|
702
|
+
if not label:
|
|
703
|
+
continue
|
|
504
704
|
status, note = classify_check_value(value)
|
|
505
|
-
label = SELF_CHECK_LABELS.get(key, SELF_CHECK_LABELS.get(str(key), str(key)))
|
|
506
705
|
items[label] = (status, note)
|
|
507
706
|
return items or None
|
|
508
707
|
|
|
@@ -512,16 +711,16 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
512
711
|
"""核验报告单数据。只计算脚本真实可得的结果,不虚构通过。"""
|
|
513
712
|
generated_at = generated_at or datetime.now()
|
|
514
713
|
|
|
515
|
-
# ① 依据溯源:摘录可比对 +
|
|
714
|
+
# ① 依据溯源:摘录可比对 + 原文链接可回看。
|
|
516
715
|
# 只统计被正文引用的材料——未引用召回材料未进入正文核验流程,其缺链在自身卡片上如实标注,
|
|
517
716
|
# 不应拖累"正文依据可交付"的报告级结论。
|
|
518
|
-
#
|
|
717
|
+
# 缺原文链接(接口对部分治理库文章不返回源网址,属数据源覆盖问题而非核验工作缺失)
|
|
718
|
+
# 不再拖垮整体结论——报告的正常结论即为"核验完成",缺链在指标行黄色提醒并在卡片标注;
|
|
719
|
+
# 缺摘录(正文依据无可比对的原文)仍视为核验问题计入未通过。
|
|
519
720
|
cited_sources = [s for s in sources if s.get("used", True)]
|
|
520
|
-
|
|
521
|
-
missing_links = [s["title"] for s in cited_sources if not s.get("has_link") and not kb_view]
|
|
721
|
+
missing_links = [s["title"] for s in cited_sources if not s.get("has_link")]
|
|
522
722
|
missing_excerpts = [s["title"] for s in cited_sources if not (s.get("excerpt") or "").strip()]
|
|
523
|
-
|
|
524
|
-
trace_passed = len(cited_sources) - len(set(missing_links) | set(missing_excerpts))
|
|
723
|
+
trace_passed = len(cited_sources) - len(missing_excerpts)
|
|
525
724
|
|
|
526
725
|
# ② 引用绑定:正文角标与来源卡一一对应(按角标出现次数计,与用户在正文中数到的一致)
|
|
527
726
|
cited = citation_ids(answer)
|
|
@@ -532,7 +731,9 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
532
731
|
no_citation = bool(sources) and not cited
|
|
533
732
|
|
|
534
733
|
# ③ 时效检查:材料日期范围与历史材料计数
|
|
535
|
-
|
|
734
|
+
# ③ 时效只统计**正文依据**(2026-09-29,对齐公文 3.7.6):sources 含未引用召回材料,
|
|
735
|
+
# 此前误用全集,未引用材料里的异常日期(如接口标注的未来年份)会写进交付物口径。
|
|
736
|
+
dated = [parse_year_month(s.get("date")) for s in cited_sources]
|
|
536
737
|
dated = [d for d in dated if d]
|
|
537
738
|
freshness = None
|
|
538
739
|
old_count = 0
|
|
@@ -543,9 +744,9 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
543
744
|
"old_count": sum(1 for y, _ in dated if y <= generated_at.year - 3),
|
|
544
745
|
}
|
|
545
746
|
|
|
546
|
-
# ④
|
|
747
|
+
# ④ 类型覆盖:**正文依据**的素材四分类分布(口径同③,2026-09-29 修复)
|
|
547
748
|
coverage = {key: 0 for key in KIND_CATALOG}
|
|
548
|
-
for s in
|
|
749
|
+
for s in cited_sources:
|
|
549
750
|
coverage[s.get("type_key", "material")] = coverage.get(s.get("type_key", "material"), 0) + 1
|
|
550
751
|
|
|
551
752
|
# ⑤ 成稿自检:由溯源 JSON 的 self_check 传入,未传入如实显示未记录
|
|
@@ -556,37 +757,48 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
556
757
|
self_check = None
|
|
557
758
|
if self_items:
|
|
558
759
|
passed = sum(1 for status, _ in self_items.values() if status == "pass")
|
|
559
|
-
|
|
560
|
-
|
|
760
|
+
failed = sum(1 for status, _ in self_items.values() if status == "fail")
|
|
761
|
+
# 状态只由显式 fail 决定:none(值无法识别,如描述性文本)不拖垮结论,
|
|
762
|
+
# 显示为"通过,N 项未记录"——红项只给真正声明未通过的项。
|
|
763
|
+
self_check = {"items": self_items, "passed": passed, "total": len(self_items), "failed": failed,
|
|
764
|
+
"status": "fail" if failed else "pass"}
|
|
561
765
|
else:
|
|
562
|
-
self_check = {"items": {}, "passed": 0, "total": len(SELF_CHECK_ITEMS), "status": "missing"}
|
|
766
|
+
self_check = {"items": {}, "passed": 0, "total": len(SELF_CHECK_ITEMS), "failed": 0, "status": "missing"}
|
|
563
767
|
|
|
564
768
|
# 政策效力:无法自动判定现行效力,列出建议人工复核
|
|
565
769
|
policy_count = coverage.get("policy", 0)
|
|
566
770
|
|
|
567
|
-
trace_ok = cited_sources and
|
|
771
|
+
trace_ok = cited_sources and not missing_excerpts
|
|
568
772
|
binding_ok = (not unbound) and not no_citation
|
|
569
|
-
|
|
773
|
+
# 自检显式"未通过"纳为报告级否决项(对齐公文写作 3.7.4):不能自检失败还顶部打绿章。
|
|
774
|
+
self_check_ok = self_check["status"] != "fail"
|
|
775
|
+
overall_passed = bool(trace_ok and binding_ok and self_check_ok)
|
|
570
776
|
|
|
571
777
|
reasons = []
|
|
572
778
|
if not sources:
|
|
573
|
-
reasons.append("
|
|
779
|
+
reasons.append("没有找到来源文章")
|
|
574
780
|
if no_citation:
|
|
575
|
-
reasons.append("
|
|
576
|
-
if missing_links:
|
|
577
|
-
reasons.append(f"{len(missing_links)} 条引用材料暂缺原文链接(可先交付、建议后续补链)")
|
|
781
|
+
reasons.append("正文里没有来源角标,对不上来源文章")
|
|
578
782
|
if unbound:
|
|
579
|
-
reasons.append(f"有 {len(unbound)}
|
|
783
|
+
reasons.append(f"有 {len(unbound)} 处角标找不到对应来源文章")
|
|
580
784
|
if self_check["status"] == "fail":
|
|
581
785
|
reasons.append("交付前检查有没过的项")
|
|
786
|
+
if missing_links:
|
|
787
|
+
reasons.append(f"有 {len(missing_links)} 条正文依据没有原文链接或存档快照,无法回看")
|
|
788
|
+
|
|
789
|
+
if overall_passed and missing_links:
|
|
790
|
+
# 摘录可比对、结论成立,但确有材料无回看通道时,顶部表述要与事实一致(对齐 3.7.4)
|
|
791
|
+
overall_label = f"核验完成,其中 {len(missing_links)} 条依据无原文或存档快照可回看"
|
|
792
|
+
else:
|
|
793
|
+
overall_label = "核验完成,正文依据逐条对过原文" if overall_passed else "核验未完全通过"
|
|
582
794
|
|
|
583
795
|
return {
|
|
584
796
|
"overall": {
|
|
585
797
|
"passed": overall_passed,
|
|
586
|
-
"label":
|
|
798
|
+
"label": overall_label,
|
|
587
799
|
"reasons": reasons,
|
|
588
800
|
},
|
|
589
|
-
"traceability": {"total": len(cited_sources), "passed": trace_passed,
|
|
801
|
+
"traceability": {"total": len(cited_sources), "passed": trace_passed,
|
|
590
802
|
"missing_links": missing_links, "missing_excerpts": missing_excerpts},
|
|
591
803
|
"binding": {"total": len(all_marks), "bound": len(all_marks) - len(unbound), "unbound": unbound_ids, "no_citation": no_citation},
|
|
592
804
|
"freshness": freshness,
|
|
@@ -597,6 +809,100 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
597
809
|
}
|
|
598
810
|
|
|
599
811
|
|
|
812
|
+
# ============================================================
|
|
813
|
+
# 过程回顾 / 热词(真实计算,不虚构流程)
|
|
814
|
+
# ============================================================
|
|
815
|
+
|
|
816
|
+
def compute_process_stats(sources: List[Dict[str, str]], answer: str) -> Dict[str, Any]:
|
|
817
|
+
"""过程回顾条数据:检索次数、每组检索的召回/采用数、入库与引用计数。
|
|
818
|
+
|
|
819
|
+
全部来自素材自带的真实字段(search_key 分组、used 引用状态、正文角标计数),
|
|
820
|
+
不虚构任何流程步骤。
|
|
821
|
+
"""
|
|
822
|
+
order: List[str] = []
|
|
823
|
+
for s in sources:
|
|
824
|
+
key = (s.get("search_key") or "").strip()
|
|
825
|
+
if key and key not in order:
|
|
826
|
+
order.append(key)
|
|
827
|
+
cond_rows = []
|
|
828
|
+
for key in order:
|
|
829
|
+
group = [s for s in sources if (s.get("search_key") or "").strip() == key]
|
|
830
|
+
cond_rows.append({
|
|
831
|
+
"key": key,
|
|
832
|
+
"total": len(group),
|
|
833
|
+
"used": sum(1 for s in group if s.get("used", True)),
|
|
834
|
+
})
|
|
835
|
+
n_searches = len(cond_rows) or (1 if sources else 0)
|
|
836
|
+
used_count = sum(1 for s in sources if s.get("used", True))
|
|
837
|
+
unused_count = len(sources) - used_count
|
|
838
|
+
n_cite_marks = len(re.findall(r"\[(\d+)\]", answer))
|
|
839
|
+
return {
|
|
840
|
+
"conds": cond_rows,
|
|
841
|
+
"n_searches": n_searches,
|
|
842
|
+
"has_cond_detail": bool(cond_rows),
|
|
843
|
+
"n_materials": len(sources),
|
|
844
|
+
"used_count": used_count,
|
|
845
|
+
"unused_count": unused_count,
|
|
846
|
+
"n_cite_marks": n_cite_marks,
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
HOT_STOP = {
|
|
851
|
+
"关于", "通知", "工作", "意见", "方案", "实施", "有关", "问题", "情况", "报告", "总结",
|
|
852
|
+
"制度", "体系", "机制", "指导", "贯彻", "落实", "进一步", "以及", "其他", "相关", "以下",
|
|
853
|
+
"以上", "共和国", "人民", "中华", "国务院", "人民政府", "办公厅", "印发", "试行",
|
|
854
|
+
"办法", "条例", "若干", "的重点", "有所", "一个", "方面", "方式", "内容", "基本",
|
|
855
|
+
"发展", "建设", "政策", "产业", "企业", "应用", "改革", "目标", "任务", "规划",
|
|
856
|
+
"领域", "措施", "支持", "行动", "服务", "管理", "政府",
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
def extract_hot_terms(answer: str, sources: List[Dict[str, str]], top: int = 8) -> List[str]:
|
|
861
|
+
"""知识专库热词:材料标题(加权)+ 检索条件 + 正文的高频 2-4 字词,真实统计。
|
|
862
|
+
|
|
863
|
+
泛词过滤:出现在超过 60% 材料标题中的词(如库内全部材料共有的主题词)
|
|
864
|
+
无法筛出子集,没有筛选价值,剔除。
|
|
865
|
+
"""
|
|
866
|
+
corpus_parts: List[str] = []
|
|
867
|
+
for s in sources:
|
|
868
|
+
if s.get("title"):
|
|
869
|
+
corpus_parts.extend([s["title"]] * 3)
|
|
870
|
+
if s.get("search_key"):
|
|
871
|
+
corpus_parts.extend([s["search_key"]] * 2)
|
|
872
|
+
clean_answer = re.sub(r"\[\d+\]", "", answer or "")
|
|
873
|
+
corpus_parts.append(clean_answer)
|
|
874
|
+
corpus = "\n".join(corpus_parts)
|
|
875
|
+
|
|
876
|
+
counts: Dict[str, int] = {}
|
|
877
|
+
for run in re.findall(r"[一-鿿]{2,}", corpus):
|
|
878
|
+
for n in (2, 3, 4):
|
|
879
|
+
for i in range(len(run) - n + 1):
|
|
880
|
+
gram = run[i:i + n]
|
|
881
|
+
counts[gram] = counts.get(gram, 0) + 1
|
|
882
|
+
|
|
883
|
+
titles = [s.get("title") or "" for s in sources]
|
|
884
|
+
n_titles = max(1, len(titles))
|
|
885
|
+
df_limit = max(1, int(n_titles * 0.6))
|
|
886
|
+
|
|
887
|
+
cands = [(g, c) for g, c in counts.items()
|
|
888
|
+
if c >= 2 and g not in HOT_STOP and "的" not in g and not any(ch.isdigit() for ch in g)
|
|
889
|
+
and sum(1 for t in titles if g in t) <= df_limit]
|
|
890
|
+
cands.sort(key=lambda x: (-x[1], -len(x[0])))
|
|
891
|
+
kept: List[Tuple[str, int]] = []
|
|
892
|
+
for gram, count in cands:
|
|
893
|
+
redundant = False
|
|
894
|
+
for kgram, kcount in kept:
|
|
895
|
+
# 短词是已入选高频长词的子串且计数接近 → 被长词覆盖,剔除
|
|
896
|
+
if gram in kgram and kcount >= count * 0.6:
|
|
897
|
+
redundant = True
|
|
898
|
+
break
|
|
899
|
+
if not redundant:
|
|
900
|
+
kept.append((gram, count))
|
|
901
|
+
if len(kept) >= top:
|
|
902
|
+
break
|
|
903
|
+
return [g for g, _ in kept]
|
|
904
|
+
|
|
905
|
+
|
|
600
906
|
# ============================================================
|
|
601
907
|
# 正文解析与分节
|
|
602
908
|
# ============================================================
|
|
@@ -635,12 +941,10 @@ def render_markdown_table(lines: List[str], citation_repl) -> str:
|
|
|
635
941
|
return f'<div class="tbl-wrap"><table class="data-tbl"><thead><tr>{head_html}</tr></thead><tbody>{"".join(rows)}</tbody></table></div>'
|
|
636
942
|
|
|
637
943
|
|
|
638
|
-
def
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
cleaned = re.sub(r"(?is)<script.*?</script>", "", value)
|
|
643
|
-
cleaned = re.sub(r"(?is)<style.*?</style>", "", value)
|
|
944
|
+
def sanitize_table_html(text: str) -> str:
|
|
945
|
+
"""清洗接口表格 HTML:仅保留 table/thead/tbody/tr/td/th/br,去脚本样式与属性。"""
|
|
946
|
+
cleaned = re.sub(r"(?is)<script.*?</script>", "", text)
|
|
947
|
+
cleaned = re.sub(r"(?is)<style.*?</style>", "", cleaned)
|
|
644
948
|
cleaned = re.sub(r"\s+on\w+\s*=\s*(['\"]).*?\1", "", cleaned)
|
|
645
949
|
cleaned = re.sub(r"\s+(href|src)\s*=\s*(['\"]).*?\2", "", cleaned)
|
|
646
950
|
allowed = {"table", "thead", "tbody", "tr", "td", "th", "br"}
|
|
@@ -651,17 +955,89 @@ def render_excerpt_html(text: str) -> str:
|
|
|
651
955
|
return ""
|
|
652
956
|
return f"<{closing}{name}>"
|
|
653
957
|
|
|
654
|
-
|
|
655
|
-
|
|
958
|
+
return re.sub(r"<\s*(/?)\s*([a-zA-Z0-9]+)(?:\s+[^>]*)?>", tag_repl, cleaned)
|
|
959
|
+
|
|
656
960
|
|
|
961
|
+
def render_excerpt_html(text: str) -> str:
|
|
962
|
+
value = str(text or "")
|
|
963
|
+
if "<table" not in value.lower():
|
|
964
|
+
return f'<div class="sc-excerpt plain">{esc(value)}</div>'
|
|
965
|
+
return f'<div class="sc-excerpt rich">{sanitize_table_html(value)}</div>'
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
def parse_answer_blocks(answer: str, valid_ids: set, chip_map: Optional[Dict[str, str]] = None) -> Tuple[List[Dict[str, Any]], set]:
|
|
969
|
+
"""把正文 Markdown 解析为结构化块;同时收集全部角标。
|
|
970
|
+
|
|
971
|
+
角标渲染为原型式 sup.cite 上标胶囊;段落对应的溯源卡(src-card)由
|
|
972
|
+
render_section_cards 在段后输出。
|
|
973
|
+
"""
|
|
974
|
+
|
|
975
|
+
def jb_html(cid: str) -> str:
|
|
976
|
+
jb = chip_map.get(cid)
|
|
977
|
+
if not jb:
|
|
978
|
+
return ""
|
|
979
|
+
if jb.get("url"):
|
|
980
|
+
btn_txt = "查看存档全文" if jb.get("dead") else "查看全文"
|
|
981
|
+
link = (f'<a class="jb-src" href="{esc(jb["url"])}" target="_blank" rel="noopener noreferrer">'
|
|
982
|
+
f'{ARROW_SVG}<span>{btn_txt}</span></a>')
|
|
983
|
+
else:
|
|
984
|
+
link = ""
|
|
985
|
+
# 原文直达区展示标题链(多段分块,各段带链——快速人工核验的核心抓手)
|
|
986
|
+
segs = jb.get("segments") or []
|
|
987
|
+
if segs:
|
|
988
|
+
quote = ""
|
|
989
|
+
seg_idx = -1
|
|
990
|
+
for seg in segs:
|
|
991
|
+
text = (seg.get("text") or "").strip()
|
|
992
|
+
if not text:
|
|
993
|
+
continue
|
|
994
|
+
seg_idx += 1
|
|
995
|
+
if "<table" in text.lower():
|
|
996
|
+
# 表格不能静态写进 span(解析器会拆散):此处留占位,
|
|
997
|
+
# 表格数据由 render_html 汇总注入页尾 JSON,展开时 JS 填充
|
|
998
|
+
tbl_key = f"{cid}-{seg_idx}"
|
|
999
|
+
jb.setdefault("_tables", {})[tbl_key] = sanitize_table_html(text)
|
|
1000
|
+
body_txt = f'<span class="sc-excerpt rich tbl-holder" data-tbl="{esc(tbl_key)}"></span>'
|
|
1001
|
+
else:
|
|
1002
|
+
body_txt = f'<span class="sc-excerpt">{esc(text)}</span>'
|
|
1003
|
+
inner = f'<i class="jb-no">{esc(cid)}</i>{body_txt}'
|
|
1004
|
+
item = f'<span class="jb-quote" role="button" tabindex="0">{inner}</span>'
|
|
1005
|
+
quote += render_crumb(seg.get("chain") or []) + item
|
|
1006
|
+
elif jb["excerpt"]:
|
|
1007
|
+
inner = f'<i class="jb-no">{esc(cid)}</i><span>{esc(jb["excerpt"])}</span>'
|
|
1008
|
+
quote = f'<span class="jb-quote" role="button" tabindex="0">{inner}</span>'
|
|
1009
|
+
else:
|
|
1010
|
+
quote = ""
|
|
1011
|
+
site_html = (f'<span class="jb-site"><span class="dot"></span>{esc(jb.get("site") or "")}</span>'
|
|
1012
|
+
if (jb.get("site") or "").strip() else "")
|
|
1013
|
+
return (
|
|
1014
|
+
f'<span class="jb" data-cite="{esc(cid)}">'
|
|
1015
|
+
f'<button class="jb-name" type="button" aria-expanded="false">{CARET_SVG}'
|
|
1016
|
+
f'<i class="jb-id">{esc(cid)}</i>'
|
|
1017
|
+
f'<span class="jb-txt">{esc(jb["title"])}</span></button>'
|
|
1018
|
+
f'<span class="jb-body"><span class="jb-head"><span class="jb-label">{SRC_ICO_SVG}溯源原文:</span>{link}</span>'
|
|
1019
|
+
f'{site_html}'
|
|
1020
|
+
f'{quote}</span></span>'
|
|
1021
|
+
)
|
|
657
1022
|
|
|
658
|
-
def
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
1023
|
+
def make_block_repl(block_text: str):
|
|
1024
|
+
"""按块构造角标替换器:同段同材料只保留最后一次出现的角标(前处整体删除),
|
|
1025
|
+
最后一处挂数字角标 + 引文胶囊——一段中同一材料只出现一次。"""
|
|
1026
|
+
remaining: Dict[str, int] = {}
|
|
1027
|
+
for cid in re.findall(r"\[(\d+)\]", block_text):
|
|
1028
|
+
remaining[cid] = remaining.get(cid, 0) + 1
|
|
1029
|
+
|
|
1030
|
+
def repl(match: re.Match[str]) -> str:
|
|
1031
|
+
cid = match.group(1)
|
|
1032
|
+
remaining[cid] = max(0, remaining.get(cid, 1) - 1)
|
|
1033
|
+
if remaining[cid] > 0:
|
|
1034
|
+
return ""
|
|
1035
|
+
if cid in chip_map:
|
|
1036
|
+
return jb_html(cid)
|
|
1037
|
+
# 未绑定角标(无对应材料):红色数字警示,绝不按位置猜测
|
|
1038
|
+
return f'<sup class="cite unresolved" data-cite="{esc(cid)}" title="核验依据 [{esc(cid)}?]">{esc(cid)}?</sup>'
|
|
1039
|
+
|
|
1040
|
+
return repl
|
|
665
1041
|
|
|
666
1042
|
blocks: List[Dict[str, Any]] = []
|
|
667
1043
|
lines = answer.split("\n")
|
|
@@ -671,7 +1047,11 @@ def parse_answer_blocks(answer: str, valid_ids: set) -> Tuple[List[Dict[str, Any
|
|
|
671
1047
|
if not block:
|
|
672
1048
|
idx += 1
|
|
673
1049
|
continue
|
|
1050
|
+
# 引文胶囊位置规范:角标与后随标点换位——标点紧跟文字,胶囊放标点之后
|
|
1051
|
+
# (避免胶囊把句号挤到下一行孤悬,对齐深知晓原型"…内容。~出处"形态)
|
|
1052
|
+
block = re.sub(r"\[(\d+)\]([。;,、!?:;,.])", r"\2[\1]", block)
|
|
674
1053
|
ids = citation_ids(block)
|
|
1054
|
+
repl = make_block_repl(block)
|
|
675
1055
|
heading_match = re.match(r"^(#{1,4})\s+(.+)$", block)
|
|
676
1056
|
if heading_match:
|
|
677
1057
|
blocks.append({"kind": "heading", "level": len(heading_match.group(1)),
|
|
@@ -683,6 +1063,7 @@ def parse_answer_blocks(answer: str, valid_ids: set) -> Tuple[List[Dict[str, Any
|
|
|
683
1063
|
while idx < len(lines) and "|" in lines[idx].strip() and lines[idx].strip():
|
|
684
1064
|
table_lines.append(lines[idx].strip())
|
|
685
1065
|
idx += 1
|
|
1066
|
+
repl = make_block_repl("\n".join(table_lines))
|
|
686
1067
|
blocks.append({"kind": "table", "html": render_markdown_table(table_lines, repl), "cites": citation_ids("\n".join(table_lines))})
|
|
687
1068
|
elif block in {"---", "***"}:
|
|
688
1069
|
blocks.append({"kind": "hr", "html": '<hr class="doc-divider">', "cites": []})
|
|
@@ -713,7 +1094,7 @@ def group_sections(blocks: List[Dict[str, Any]]) -> Tuple[Optional[str], List[Di
|
|
|
713
1094
|
"""按标题层级切分章节卡。返回(报告标题, 章节列表)。
|
|
714
1095
|
|
|
715
1096
|
规则:最浅层级标题若唯一且居文首,视为报告标题提出;其下一级为卡片边界。
|
|
716
|
-
|
|
1097
|
+
无标题的短公文整篇一卡。
|
|
717
1098
|
"""
|
|
718
1099
|
if not blocks:
|
|
719
1100
|
return None, [{"title": None, "blocks": []}]
|
|
@@ -751,40 +1132,44 @@ def group_sections(blocks: List[Dict[str, Any]]) -> Tuple[Optional[str], List[Di
|
|
|
751
1132
|
# 各部分渲染
|
|
752
1133
|
# ============================================================
|
|
753
1134
|
|
|
754
|
-
def
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
1135
|
+
def build_chip_data(sources: List[Dict[str, str]]) -> Dict[str, Dict[str, str]]:
|
|
1136
|
+
"""行内引文胶囊数据:id → {title, site, url, excerpt}。
|
|
1137
|
+
|
|
1138
|
+
角标后渲染原型式 jb(行内小胶囊,点击展开块级卡)。摘录展示完整
|
|
1139
|
+
原文原段、不截断——段内去重后重复量可控,核对场景下就地读全文。
|
|
1140
|
+
"""
|
|
1141
|
+
chip_map: Dict[str, Dict[str, str]] = {}
|
|
1142
|
+
for source in sources:
|
|
1143
|
+
cid = source["id"]
|
|
1144
|
+
if cid in chip_map:
|
|
760
1145
|
continue
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
)
|
|
777
|
-
if not chips:
|
|
778
|
-
return ""
|
|
779
|
-
return f'<div class="ev-row">{"".join(chips)}</div>'
|
|
1146
|
+
meta_bits = [v for v in [source.get("agency"), source.get("date")] if v and v != "未知来源"]
|
|
1147
|
+
url = source.get("url") if (source.get("url") and source["url"] != "接口未返回") else (source.get("policy_url") or "")
|
|
1148
|
+
if source.get("link_dead"):
|
|
1149
|
+
url = source.get("snapshot") or ""
|
|
1150
|
+
site_bits = ([source["doc_number"]] if source.get("doc_number") else []) + meta_bits
|
|
1151
|
+
chip_map[cid] = {
|
|
1152
|
+
"title": short(source.get("title") or "未命名来源文章", 30),
|
|
1153
|
+
"site": " · ".join(site_bits) or "来源站点",
|
|
1154
|
+
"url": url,
|
|
1155
|
+
"snapshot": source.get("snapshot") or "",
|
|
1156
|
+
"dead": bool(source.get("link_dead")),
|
|
1157
|
+
"excerpt": (source.get("excerpt") or "").strip(),
|
|
1158
|
+
"segments": source.get("segments") or [],
|
|
1159
|
+
}
|
|
1160
|
+
return chip_map
|
|
780
1161
|
|
|
781
1162
|
|
|
782
|
-
def render_source_links(url: str, policy_url: str = "") -> str:
|
|
1163
|
+
def render_source_links(url: str, policy_url: str = "", snapshot: str = "", link_dead: bool = False) -> str:
|
|
1164
|
+
"""链接区四态:原文可回看 / 原文失效改快照 / 原文失效无快照 / 无源网址有快照。
|
|
1165
|
+
快照是接口对原文的存档副本,文案如实标注,不冒充原文链接。"""
|
|
783
1166
|
links = []
|
|
784
|
-
if url and url != "接口未返回":
|
|
785
|
-
links.append(f'<a href="{esc(url)}" target="_blank" rel="noopener"
|
|
786
|
-
if
|
|
787
|
-
|
|
1167
|
+
if url and url != "接口未返回" and not link_dead:
|
|
1168
|
+
links.append(f'<a href="{esc(url)}" target="_blank" rel="noopener">查看全文 ↗</a>')
|
|
1169
|
+
if snapshot:
|
|
1170
|
+
# 有哪个显示哪个:快照统一展示"查看存档全文",不做原文失效的状态解释
|
|
1171
|
+
links.append(f'<a class="snap" href="{esc(snapshot)}" target="_blank" rel="noopener">查看存档全文 ↗</a>')
|
|
1172
|
+
# 回看通道只有原网址与快照(2026-09-29 用户决策:外链知识专库属老能力,已移除)
|
|
788
1173
|
if not links:
|
|
789
1174
|
return ""
|
|
790
1175
|
return '<div class="sc-links">' + "".join(f"<span>{link}</span>" for link in links) + "</div>"
|
|
@@ -798,30 +1183,37 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
798
1183
|
stamp = '<span class="v-stamp">已核验</span>' if ov["passed"] else '<span class="v-stamp bad">核验未通过</span>'
|
|
799
1184
|
reasons_html = ""
|
|
800
1185
|
if ov["reasons"]:
|
|
801
|
-
|
|
802
|
-
reasons_html = f'<div class="{reasons_cls}">' + ";".join(esc(r) for r in ov["reasons"]) + "</div>"
|
|
1186
|
+
reasons_html = '<div class="v-reasons">' + ";".join(esc(r) for r in ov["reasons"]) + "</div>"
|
|
803
1187
|
|
|
804
1188
|
tr = v["traceability"]
|
|
1189
|
+
n_no_link = len(tr.get("missing_links") or [])
|
|
805
1190
|
if not tr["total"]:
|
|
806
1191
|
tr_html = ('<div class="vi"><span class="s fail">✗ 依据溯源 0/0</span>'
|
|
807
|
-
'<span class="d"
|
|
808
|
-
elif tr["passed"] == tr["total"]:
|
|
809
|
-
kb_note = f",其中 {tr.get('kb_only', 0)} 条经知识专库回看" if tr.get("kb_only") else ""
|
|
1192
|
+
'<span class="d">未识别到来源文章</span></div>')
|
|
1193
|
+
elif tr["passed"] == tr["total"] and not n_no_link:
|
|
810
1194
|
tr_html = (f'<div class="vi"><span class="s ok">✓ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
811
|
-
f'<span class="d"
|
|
1195
|
+
f'<span class="d">每条素材摘录可比对,原文或存档快照可回看</span></div>')
|
|
1196
|
+
elif tr["passed"] == tr["total"]:
|
|
1197
|
+
# 摘录齐全但有材料没有回看通道:不得照写"原文或存档快照可回看"
|
|
1198
|
+
# (对齐公文写作 3.7.4:此前 missing_links 算出却从未参与结论,属虚假背书)
|
|
1199
|
+
tr_html = (f'<div class="vi"><span class="s warn">◐ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
1200
|
+
f'<span class="d">摘录可比对,其中 {n_no_link} 条没有原文链接或存档快照、无法回看</span></div>')
|
|
812
1201
|
else:
|
|
1202
|
+
detail = f'待补摘录 {len(tr.get("missing_excerpts") or [])} 条'
|
|
1203
|
+
if n_no_link:
|
|
1204
|
+
detail += f';{n_no_link} 条无原文链接或快照'
|
|
813
1205
|
tr_html = (f'<div class="vi"><span class="s warn">◐ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
814
|
-
f'<span class="d">{
|
|
1206
|
+
f'<span class="d">{detail}</span></div>')
|
|
815
1207
|
|
|
816
1208
|
bd = v["binding"]
|
|
817
1209
|
if bd.get("no_citation"):
|
|
818
1210
|
bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 0/0</span>'
|
|
819
|
-
f'<span class="d">正文里没有来源角标,{v["traceability"]["total"]}
|
|
1211
|
+
f'<span class="d">正文里没有来源角标,{v["traceability"]["total"]} 篇来源文章对不上正文</span></div>')
|
|
820
1212
|
elif not bd["total"]:
|
|
821
1213
|
bd_html = '<div class="vi"><span class="s none">— 引用对应 0/0</span><span class="d">正文里没有来源角标</span></div>'
|
|
822
1214
|
elif not bd["unbound"]:
|
|
823
1215
|
bd_html = (f'<div class="vi"><span class="s ok">✓ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
|
|
824
|
-
f'<span class="d">正文每处 [n]
|
|
1216
|
+
f'<span class="d">正文每处 [n] 都能找到对应来源文章</span></div>')
|
|
825
1217
|
else:
|
|
826
1218
|
unbound_text = "、".join(f"[{esc(x)}]" for x in bd["unbound"][:8])
|
|
827
1219
|
bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
|
|
@@ -830,28 +1222,33 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
830
1222
|
fr = v["freshness"]
|
|
831
1223
|
if fr:
|
|
832
1224
|
rng = f"{fr['min'][0]}-{fr['min'][1]:02d}~{fr['max'][0]}-{fr['max'][1]:02d}"
|
|
833
|
-
|
|
834
|
-
|
|
1225
|
+
# 2026-09-29(对齐公文 3.7.6):去掉"N 条年头较久,按参考口径使用"——对长期有效的
|
|
1226
|
+
# 政策法规偏严,且"按参考口径使用"读者无从理解;old_count 仍照常计算留待后续。
|
|
1227
|
+
fr_html = f'<div class="vi"><span class="s ok">✓ 材料新旧 已核</span><span class="d">材料日期 {esc(rng)}</span></div>'
|
|
835
1228
|
else:
|
|
836
1229
|
fr_html = '<div class="vi"><span class="s none">— 材料新旧 未记录</span><span class="d">材料没标发布日期</span></div>'
|
|
837
1230
|
|
|
1231
|
+
# 材料构成:材料类型(政策依据型/数据支撑型/…)是公文写作的四分类,可信搜索接口不返回该字段
|
|
1232
|
+
# → 没有类型数据时**整行不显示**,不再渲染"材料没标类型"这种永远为空的占位行(2026-09-28 修复)。
|
|
838
1233
|
cov = v["coverage"]
|
|
839
1234
|
parts = [f"{KIND_CATALOG[k][0]} {cov[k]}" for k in ("policy", "data", "case", "reference") if cov.get(k)]
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
f'<span class="d">{esc(" · ".join(parts)) if parts else "材料没标类型"}</span></div>')
|
|
1235
|
+
cov_html = (f'<div class="vi"><span class="s ok">✓ 材料构成</span>'
|
|
1236
|
+
f'<span class="d">{esc(" · ".join(parts))}</span></div>') if parts else ""
|
|
843
1237
|
|
|
844
1238
|
sc = v["self_check"]
|
|
845
1239
|
if sc["status"] == "pass":
|
|
846
1240
|
notes = ";".join(note for _, note in sc["items"].values() if note)
|
|
847
1241
|
title_attr = f' title="{esc(notes)}"' if notes else ""
|
|
848
1242
|
item_names = "、".join(sc["items"].keys()) if sc["items"] else "、".join(label for _, label in SELF_CHECK_ITEMS)
|
|
849
|
-
|
|
1243
|
+
unrecorded = sc["total"] - sc["passed"] - sc.get("failed", 0)
|
|
1244
|
+
sc_head = f'✓ 交付前检查 {sc["passed"]}/{sc["total"]}' if not unrecorded else \
|
|
1245
|
+
f'✓ 交付前检查 通过({unrecorded} 项未记录)'
|
|
1246
|
+
sc_html = (f'<div class="vi"><span class="s ok"{title_attr}>{sc_head}</span>'
|
|
850
1247
|
f'<span class="d">{esc(item_names)}{esc(" · 悬停查看说明" if notes else "")}</span></div>')
|
|
851
1248
|
elif sc["status"] == "fail":
|
|
852
1249
|
failed_parts = []
|
|
853
1250
|
for label, (status, note) in sc["items"].items():
|
|
854
|
-
if status
|
|
1251
|
+
if status == "fail":
|
|
855
1252
|
suffix = f"({note[:40]}…)" if len(note) > 40 else (f"({note})" if note else "")
|
|
856
1253
|
failed_parts.append(label + suffix)
|
|
857
1254
|
sc_html = (f'<div class="vi"><span class="s fail">✗ 交付前检查 {sc["passed"]}/{sc["total"]}</span>'
|
|
@@ -859,10 +1256,9 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
859
1256
|
else:
|
|
860
1257
|
sc_html = '<div class="vi"><span class="s none">— 交付前检查 未记录</span><span class="d">本次溯源 JSON 没写入检查结果</span></div>'
|
|
861
1258
|
|
|
1259
|
+
# "现行效力"人工复核提示行已按产品要求移除(对齐公文写作 3.7.2,2026-09-19):
|
|
1260
|
+
# 政策是否现行有效无法自动判定,此提示对用户无操作价值;policy_count 仅保留在计算层不再展示。
|
|
862
1261
|
manual = ""
|
|
863
|
-
if v["policy_count"]:
|
|
864
|
-
manual = (f'<div class="vi"><span class="s man">◐ 现行效力</span>'
|
|
865
|
-
f'<span class="d">{v["policy_count"]} 份政策文件建议按官方发布确认是否现行有效</span></div>')
|
|
866
1262
|
|
|
867
1263
|
return f"""
|
|
868
1264
|
<div class="verify {state}">
|
|
@@ -871,112 +1267,285 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
871
1267
|
<div class="v-grid">
|
|
872
1268
|
{tr_html}{bd_html}{fr_html}{cov_html}{sc_html}{manual}
|
|
873
1269
|
</div>
|
|
874
|
-
<div class="v-note"
|
|
1270
|
+
<div class="v-note">核验方式:先用深知可信搜索找权威来源,再把正文每处依据和原文逐条比对(都能点开原文回看),最后做了交付前五项检查。{manual_checks_html}</div>
|
|
875
1271
|
</div>"""
|
|
876
1272
|
|
|
877
1273
|
|
|
878
|
-
|
|
1274
|
+
SRC_ICO_SVG = ('<svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.8" '
|
|
1275
|
+
'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">'
|
|
1276
|
+
'<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/>'
|
|
1277
|
+
'<path d="M9 13h6M9 17h4"/></svg>')
|
|
1278
|
+
ARROW_SVG = ('<svg viewBox="0 0 24 24" width="11" height="11" fill="none" stroke="currentColor" stroke-width="2.2" '
|
|
1279
|
+
'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 17 17 7M9 7h8v8"/></svg>')
|
|
1280
|
+
CARET_SVG = ('<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.4" '
|
|
1281
|
+
'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg>')
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
def render_src_card(jb: Dict[str, str], cid: str, dup: bool = False) -> str:
|
|
1285
|
+
"""句后溯源卡(原型 cardHTML 的 Python 移植):标题 + 来源 + 查看原文 + 摘录展开。"""
|
|
1286
|
+
src = jb.get("source") or "来源站点"
|
|
1287
|
+
url = jb.get("url") or ""
|
|
1288
|
+
title = re.sub(r"<br\s*/?>", " ", str(jb.get("title") or ""), flags=re.I)
|
|
1289
|
+
excerpt = (jb.get("excerpt") or "").strip()
|
|
1290
|
+
dup_cls = " dup-card" if dup else ""
|
|
1291
|
+
link_html = (f'<a class="src-link" href="{esc(url)}" target="_blank" rel="noopener noreferrer">查看全文{ARROW_SVG}</a>' if url else "")
|
|
1292
|
+
toggle_html = (f'<button class="src-toggle" type="button"><span class="more">展开</span>'
|
|
1293
|
+
f'<span class="less">收起</span>{CARET_SVG}</button>' if excerpt else "")
|
|
1294
|
+
body_html = f'<div class="src-body"><p>{esc(excerpt)}</p></div>' if excerpt else ""
|
|
1295
|
+
return (
|
|
1296
|
+
f'<figure class="src-card{dup_cls}" data-cite="{esc(cid)}">'
|
|
1297
|
+
f'<div class="src-head"><span class="src-ico" aria-hidden="true">{SRC_ICO_SVG}</span>'
|
|
1298
|
+
f'<figcaption class="src-title">{esc(title)}</figcaption></div>'
|
|
1299
|
+
f'<div class="src-meta"><span class="src-site" title="{esc(src)}"><span class="dot"></span>{esc(src)}</span>'
|
|
1300
|
+
f'{link_html}{toggle_html}</div>{body_html}</figure>'
|
|
1301
|
+
)
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
_CN_DIGITS = {"〇": "0", "零": "0", "一": "1", "二": "2", "三": "3", "四": "4", "五": "5",
|
|
1305
|
+
"六": "6", "七": "7", "八": "8", "九": "9", "十": "10"}
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
def _norm_heading(text: Any) -> str:
|
|
1309
|
+
return re.sub(r"[\s、,,。.::;;()()\[\]【】]+", "", str(text or ""))
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
def _cn_to_digit(text: str) -> str:
|
|
1313
|
+
return _CN_DIGITS.get(text.strip(), text.strip())
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
def resolve_chart_anchor(sections: List[Dict[str, Any]], anchor: Any) -> int:
|
|
1317
|
+
"""把图表的 section 锚点解析为章节序号(1-based);解析不到返回 0。
|
|
1318
|
+
|
|
1319
|
+
锚点容错:可写章节号(`二` / `2` / `二、`)、章节标题(`一次性奖励金额对比`)、
|
|
1320
|
+
或带序号的完整标题(`二、一次性奖励金额对比`)——统一去空白与顿号后按
|
|
1321
|
+
「序号相等」或「标题互相包含」匹配。
|
|
1322
|
+
"""
|
|
1323
|
+
raw = _norm_heading(anchor)
|
|
1324
|
+
if not raw:
|
|
1325
|
+
return 0
|
|
1326
|
+
want_num = _cn_to_digit(raw[0]) if raw and _cn_to_digit(raw[0]).isdigit() else ""
|
|
1327
|
+
for idx, sec in enumerate(sections, 1):
|
|
1328
|
+
number, title_text = split_heading_number(sec["title"] or "")
|
|
1329
|
+
if want_num and number and _cn_to_digit(_norm_heading(number)) == want_num and len(raw) == 1:
|
|
1330
|
+
return idx
|
|
1331
|
+
title_norm = _norm_heading(title_text)
|
|
1332
|
+
if title_norm and (title_norm in raw or raw in title_norm):
|
|
1333
|
+
return idx
|
|
1334
|
+
return 0
|
|
1335
|
+
|
|
1336
|
+
|
|
1337
|
+
def render_section_cards(sections: List[Dict[str, Any]], sources: List[Dict[str, str]],
|
|
1338
|
+
charts_by_section: Optional[Dict[int, str]] = None) -> str:
|
|
1339
|
+
"""正文渲染(原型复刻):chapter(h2)+ lead/para 段落 + 段后 src-card 溯源卡。
|
|
1340
|
+
|
|
1341
|
+
溯源卡按段内角标顺序输出;同一材料在同段只出一张,跨段重复出现标记 dup-card(灰化)。
|
|
1342
|
+
charts_by_section:{章节序号: 图表 HTML}——图表**跟着它展示的数据所在的章节走**
|
|
1343
|
+
(1.4.0:不再固定堆在报告末尾),插在该章节正文之后。
|
|
1344
|
+
"""
|
|
1345
|
+
parts: List[str] = []
|
|
1346
|
+
first_para = True
|
|
879
1347
|
source_ids = {s["id"] for s in sources}
|
|
880
|
-
|
|
881
|
-
for sec in sections:
|
|
1348
|
+
charts_by_section = charts_by_section or {}
|
|
1349
|
+
for sec_idx, sec in enumerate(sections, 1):
|
|
1350
|
+
number, title_text = split_heading_number(sec["title"] or "")
|
|
1351
|
+
chapter_title = f"{number}、{title_text}" if (number and title_text) else (title_text or "")
|
|
882
1352
|
sec_cites: List[str] = []
|
|
883
1353
|
for b in sec["blocks"]:
|
|
884
1354
|
for cid in b.get("cites", []):
|
|
885
1355
|
if cid not in sec_cites:
|
|
886
1356
|
sec_cites.append(cid)
|
|
887
|
-
|
|
888
|
-
number, title_text = split_heading_number(sec["title"] or "")
|
|
889
|
-
no_html = f'<span class="sec-no">{esc(number)}</span>' if number else ""
|
|
890
|
-
title_html = f"<h3>{esc(title_text)}</h3>" if title_text else ""
|
|
891
|
-
if sec_cites:
|
|
892
|
-
badge_state = "bad" if unbound_count else ""
|
|
893
|
-
badge_text = f"本章引用 {len(sec_cites)} 处" + (f" · {unbound_count} 处未绑定" if unbound_count else " · 已核验")
|
|
894
|
-
badge_html = f'<span class="sec-badge {badge_state}">{esc(badge_text)}</span>'
|
|
895
|
-
else:
|
|
1357
|
+
if chapter_title:
|
|
896
1358
|
badge_html = ""
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
1359
|
+
if sec_cites:
|
|
1360
|
+
unbound = sum(1 for cid in sec_cites if cid not in source_ids)
|
|
1361
|
+
state = "bad" if unbound else ""
|
|
1362
|
+
text = f"本章引用 {len(sec_cites)} 处" + (f" · {unbound} 处未绑定" if unbound else " · 已核验")
|
|
1363
|
+
badge_html = f'<span class="sec-badge {state}">{esc(text)}</span>'
|
|
1364
|
+
parts.append(f'<section class="chapter" id="sec-{sec_idx}">'
|
|
1365
|
+
f'<header class="ch-head"><h2>{esc(chapter_title)}</h2>{badge_html}</header>')
|
|
900
1366
|
for b in sec["blocks"]:
|
|
901
1367
|
if b["kind"] == "heading":
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
1368
|
+
parts.append(f'<p class="para"><b class="kw">{esc(b["text"])}</b></p>')
|
|
1369
|
+
first_para = False
|
|
1370
|
+
continue
|
|
1371
|
+
cls = "lead" if first_para else "para"
|
|
1372
|
+
first_para = False
|
|
1373
|
+
if b["kind"] == "list_item":
|
|
905
1374
|
marker = f'{esc(b.get("number", "•"))}.' if b.get("numbered") else "•"
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
)
|
|
1375
|
+
parts.append(f'<p class="{cls}"><b class="kw">{marker}</b> {b["html"]}</p>')
|
|
1376
|
+
elif b["kind"] == "hr":
|
|
1377
|
+
parts.append('<hr class="doc-divider">')
|
|
910
1378
|
else:
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1379
|
+
parts.append(f'<p class="{cls}">{b["html"]}</p>')
|
|
1380
|
+
if chapter_title:
|
|
1381
|
+
if sec_idx in charts_by_section:
|
|
1382
|
+
parts.append(charts_by_section[sec_idx])
|
|
1383
|
+
parts.append("</section>")
|
|
1384
|
+
return "\n".join(parts)
|
|
914
1385
|
|
|
915
1386
|
|
|
916
|
-
def
|
|
1387
|
+
def strip_leading_chain(text: str, chain: List[str]) -> str:
|
|
1388
|
+
"""剥掉段落文本开头与标题链各级重复的前缀。
|
|
1389
|
+
|
|
1390
|
+
接口部分材料的"内容"字段自带段落标题前缀(个别还重复两遍),标题链已承载
|
|
1391
|
+
位置信息,摘录开头再出现同级文本即冗余;逐级最长匹配剥离,无重复则原样返回。
|
|
1392
|
+
"""
|
|
1393
|
+
t = (text or "").strip()
|
|
1394
|
+
cands = set()
|
|
1395
|
+
for lvl in chain:
|
|
1396
|
+
lvl = (lvl or "").strip()
|
|
1397
|
+
if lvl:
|
|
1398
|
+
cands.add(lvl)
|
|
1399
|
+
# 粘连标题(接口未给分隔符,如"建设交通强省5.民航和低空")拆出编号尾部子串
|
|
1400
|
+
parts = re.split(r"(?<=[\u4e00-\u9fff])(?=\d+[.、])", lvl)
|
|
1401
|
+
if len(parts) > 1 and parts[-1].strip():
|
|
1402
|
+
cands.add(parts[-1].strip())
|
|
1403
|
+
levels = sorted(cands, key=len, reverse=True)
|
|
1404
|
+
changed = True
|
|
1405
|
+
while changed and t:
|
|
1406
|
+
changed = False
|
|
1407
|
+
for lvl in levels:
|
|
1408
|
+
if t.startswith(lvl):
|
|
1409
|
+
t = t[len(lvl):].lstrip(" \n\r\t、。;;,,").strip()
|
|
1410
|
+
changed = True
|
|
1411
|
+
break
|
|
1412
|
+
return t
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
def render_crumb(chain: List[str]) -> str:
|
|
1416
|
+
"""面包屑标题链:文章 › 章 › 节(标题链是模型生成的结构化位置,核验核心抓手)。
|
|
1417
|
+
段落本身无章节层级(链上只有文章名)时不显示——材料卡标题已是文章名,
|
|
1418
|
+
单独一行重复文章名对定位无增量(对齐公文写作 3.7.2,2026-09-19 反馈)。"""
|
|
1419
|
+
parts = [esc(level) for level in chain if level]
|
|
1420
|
+
if len(parts) < 2:
|
|
1421
|
+
return ""
|
|
1422
|
+
return '<span class="crumb">' + ' <i>›</i> '.join(parts) + "</span>"
|
|
1423
|
+
|
|
1424
|
+
|
|
1425
|
+
def render_segments(source: Dict[str, Any]) -> str:
|
|
1426
|
+
"""多段分块摘录:每段独立区块,各带自己的标题链——段落结构与位置直接可见。"""
|
|
1427
|
+
segments = source.get("segments") or []
|
|
1428
|
+
if not segments:
|
|
1429
|
+
return render_excerpt_html(source.get("excerpt") or "接口返回中未识别到可展示的摘录。")
|
|
1430
|
+
blocks = []
|
|
1431
|
+
for seg in segments:
|
|
1432
|
+
text = (seg.get("text") or "").strip()
|
|
1433
|
+
if not text:
|
|
1434
|
+
continue
|
|
1435
|
+
blocks.append(f'<div class="seg-block">{render_crumb(seg.get("chain") or [])}'
|
|
1436
|
+
f'{render_excerpt_html(text)}</div>')
|
|
1437
|
+
return "".join(blocks) if blocks else render_excerpt_html(source.get("excerpt") or "接口返回中未识别到可展示的摘录。")
|
|
1438
|
+
|
|
1439
|
+
|
|
1440
|
+
def render_source_card(source: Dict[str, str], for_print: bool = False) -> str:
|
|
917
1441
|
if not source.get("used", True):
|
|
918
1442
|
# 未引用召回材料:不标"已核验"(未进入正文核验流程),只标可否查看
|
|
919
|
-
vk = ('<span class="sc-vk" style="color:var(--muted)"
|
|
1443
|
+
vk = ('<span class="sc-vk" style="color:var(--muted)">可查看全文</span>' if source.get("has_link")
|
|
920
1444
|
else '<span class="sc-vk warn">待补链接</span>')
|
|
921
1445
|
note_html = ""
|
|
922
1446
|
elif source.get("verified"):
|
|
923
|
-
note = source.get("verify_note") or "
|
|
1447
|
+
note = source.get("verify_note") or "摘录可比对,原文或存档快照可回看"
|
|
924
1448
|
vk = f'<span class="sc-vk ok" title="{esc(note)}">✓ 已核验</span>'
|
|
925
1449
|
note_html = f'<div class="sc-vnote">{esc(short(note, 90))}</div>' if source.get("verify_note") else ""
|
|
926
1450
|
else:
|
|
927
1451
|
reason = "待补原文链接" if not source.get("has_link") else "待补摘录"
|
|
928
1452
|
vk = f'<span class="sc-vk warn">◐ {reason}</span>'
|
|
929
1453
|
note_html = ""
|
|
930
|
-
links = render_source_links(source.get("url"), source.get("policy_url", ""))
|
|
931
|
-
|
|
932
|
-
#
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1454
|
+
links = render_source_links(source.get("url"), source.get("policy_url", ""), source.get("snapshot", ""), source.get("link_dead", False))
|
|
1455
|
+
# 关键性行:有文号(接口 policyFiles 匹配)时"文号 · 数据源 · 日期",否则"数据源 · 日期"。
|
|
1456
|
+
# 文号必须是标准格式——政府公文"〔年份〕序号"(杭政函〔2022〕81号)、公告/令类"第X号"
|
|
1457
|
+
# (财政部税务总局公告2023年第19号、主席令第三十五号、国务院令第765号,含汉字数字);
|
|
1458
|
+
# 描述性文字("XX印发"类自造描述)不显示,当无文号处理(对齐公文写作 3.7.3/3.7.4)。
|
|
1459
|
+
_dn = source.get("doc_number") or ""
|
|
1460
|
+
_dn = _dn if re.search(r"〔\d{4}〕\s*\d+\s*号|第\s*(?:\d+|[〇零一二三四五六七八九十百千]+)\s*号", _dn) else ""
|
|
1461
|
+
meta_parts = [v for v in [_dn, source.get("agency"), source.get("date"), source.get("area")]
|
|
1462
|
+
if v and v != "未知来源"]
|
|
1463
|
+
meta = " | ".join(meta_parts)
|
|
936
1464
|
# 高可信徽标:仅"发布日期可信度=高"(模型治理入库、标题模型精抽)的材料;"较高"(门户抓取)不标。
|
|
937
|
-
# 原文原段身份由摘录上方的"▍ 原文原段(非 AI 生成)"标注行承担,不在卡片头部重复挂标签。
|
|
938
1465
|
conf_badge = ""
|
|
939
1466
|
if source.get("conf") == "高":
|
|
940
1467
|
conf_badge = ('<span class="sc-conf" title="发布日期可信度:高。内容经模型治理入库,'
|
|
941
1468
|
'标题为模型从原文动态抽取,非规则提取">高可信</span>')
|
|
942
|
-
excerpt_tag = '<div class="sc-extag">▍ 原文原段(非 AI 生成)</div>'
|
|
943
1469
|
# 已引用材料显示角标编号;未引用召回材料显示"未引用"灰标(不占正文角标号)
|
|
944
1470
|
id_html = f'<span class="sc-id">[{esc(source["id"])}]</span>' if source.get("used", True) else '<span class="sc-unused">未引用</span>'
|
|
1471
|
+
body_html = (f'<div class="sc-head">{id_html}'
|
|
1472
|
+
f'<span class="sc-type">{esc(source["type_label"])}</span>{conf_badge}{vk}</div>'
|
|
1473
|
+
f'<h4>{esc(source.get("title"))}</h4>'
|
|
1474
|
+
f'<div class="sc-meta">{esc(meta)}</div>'
|
|
1475
|
+
f'{note_html}'
|
|
1476
|
+
f'{render_segments(source)}'
|
|
1477
|
+
f'{links}')
|
|
1478
|
+
if for_print:
|
|
1479
|
+
# 打印附录版:无交互属性,避免与专库卡片 id 冲突
|
|
1480
|
+
return f'<article class="scard print-only {source["type_css"]}">{body_html}</article>'
|
|
945
1481
|
unused_attr = "" if source.get("used", True) else ' data-unused="1"'
|
|
946
1482
|
return (
|
|
947
|
-
f'<article class="scard {source["type_css"]}" id="src-{esc(source["id"])}" data-type="{esc(source["type_key"])}"
|
|
948
|
-
f'
|
|
949
|
-
f'<span class="sc-type">{esc(source["type_label"])}</span>{conf_badge}{vk}</div>'
|
|
950
|
-
f'<h4>{esc(source.get("title"))}</h4>'
|
|
951
|
-
f'<div class="sc-meta">{esc(meta)}</div>'
|
|
952
|
-
f'{chain_html}{section_html}{note_html}'
|
|
953
|
-
f'{excerpt_tag}'
|
|
954
|
-
f'{render_excerpt_html(source.get("excerpt") or "接口返回中未识别到可展示的摘录。")}'
|
|
955
|
-
f'<div class="sc-more" role="button" tabindex="0"></div>'
|
|
956
|
-
f'{links}</article>'
|
|
1483
|
+
f'<article class="scard {source["type_css"]}" id="src-{esc(source["id"])}" data-type="{esc(source["type_key"])}" '
|
|
1484
|
+
f'data-cite-id="{esc(source["id"])}" data-search="{esc(source.get("search_key", ""))}"{unused_attr}>{body_html}</article>'
|
|
957
1485
|
)
|
|
958
1486
|
|
|
959
1487
|
|
|
960
|
-
def
|
|
1488
|
+
def render_process_bar(stats: Dict[str, Any], verification: Dict[str, Any]) -> str:
|
|
1489
|
+
"""过程回顾条:静态回放真实流程。无思考流数据,不做"深度思考"步骤。"""
|
|
1490
|
+
ov = verification["overall"]
|
|
1491
|
+
tr = verification["traceability"]
|
|
1492
|
+
first_query = stats["conds"][0]["key"] if stats["conds"] else ""
|
|
1493
|
+
detail_rows = "".join(
|
|
1494
|
+
f'<div class="pd-row"><b>{esc(row["key"])}</b>'
|
|
1495
|
+
f'<span>召回 {row["total"]} 条 · 正文采用 {row["used"]} 条</span></div>'
|
|
1496
|
+
for row in stats["conds"]
|
|
1497
|
+
) or '<div class="pd-row"><span>本次溯源 JSON 未记录各次检索条件</span></div>'
|
|
1498
|
+
detail_hint = f'{esc(short(first_query, 26))}…' if (stats["n_searches"] > 1 and first_query) else "查看检索明细"
|
|
1499
|
+
if stats["n_searches"] > 1:
|
|
1500
|
+
step1_sub = f"共 {stats['n_searches']} 路检索 · {detail_hint}"
|
|
1501
|
+
elif first_query:
|
|
1502
|
+
step1_sub = esc(short(first_query, 26))
|
|
1503
|
+
else:
|
|
1504
|
+
step1_sub = "深知可信搜索"
|
|
1505
|
+
step4_state = "done" if ov["passed"] else "bad"
|
|
1506
|
+
step4_icon = "✓" if ov["passed"] else "!"
|
|
1507
|
+
step4_label = "核验完成" if ov["passed"] else "核验未完全通过"
|
|
1508
|
+
step4_sub = "结论:正文依据逐条对过原文" if ov["passed"] else esc(short(";".join(ov["reasons"]) or "见核验报告单", 30))
|
|
1509
|
+
return f"""
|
|
1510
|
+
<section class="process" aria-label="生成过程回顾">
|
|
1511
|
+
<div class="p-head"><b>过程回顾</b><span>数字来自本次任务的真实记录</span></div>
|
|
1512
|
+
<ol class="p-steps">
|
|
1513
|
+
<li class="p-step expandable" id="p-step-search" role="button" tabindex="0" title="展开各路检索明细">
|
|
1514
|
+
<span class="p-no">1</span>
|
|
1515
|
+
<div class="p-txt"><b>深知检索 {stats['n_searches']} 路</b><i>{step1_sub}</i></div>
|
|
1516
|
+
</li>
|
|
1517
|
+
<li class="p-arrow" aria-hidden="true">›</li>
|
|
1518
|
+
<li class="p-step">
|
|
1519
|
+
<span class="p-no">2</span>
|
|
1520
|
+
<div class="p-txt"><b>来源文章入库 {stats['n_materials']} 篇</b><i>正文采用 {stats['used_count']} · 召回未采用 {stats['unused_count']}</i></div>
|
|
1521
|
+
</li>
|
|
1522
|
+
<li class="p-arrow" aria-hidden="true">›</li>
|
|
1523
|
+
<li class="p-step">
|
|
1524
|
+
<span class="p-no">3</span>
|
|
1525
|
+
<div class="p-txt"><b>逐条比对原文</b><i>依据溯源 {tr['passed']}/{tr['total']} · 摘录可比对</i></div>
|
|
1526
|
+
</li>
|
|
1527
|
+
<li class="p-arrow" aria-hidden="true">›</li>
|
|
1528
|
+
<li class="p-step {step4_state}">
|
|
1529
|
+
<span class="p-no">{step4_icon}</span>
|
|
1530
|
+
<div class="p-txt"><b>{esc(step4_label)}</b><i>{step4_sub}</i></div>
|
|
1531
|
+
</li>
|
|
1532
|
+
</ol>
|
|
1533
|
+
<div class="p-detail" id="p-detail">{detail_rows}</div>
|
|
1534
|
+
</section>"""
|
|
1535
|
+
|
|
1536
|
+
|
|
1537
|
+
def render_library_view(sources: List[Dict[str, str]], hot_terms: List[str]) -> str:
|
|
1538
|
+
"""知识专库全屏视图:大搜索 + 热词 + 检索分组 tabs + 材料卡列表。"""
|
|
961
1539
|
if not sources:
|
|
962
|
-
return '<
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
# 不用 <details> 折叠:部分宿主(WorkBuddy 等)的 HTML 预览服务会改写折叠区导致卡片丢失
|
|
969
|
-
uncited_html = (
|
|
970
|
-
'<div class="uncited-group"><div class="ug-title">未引用素材('
|
|
971
|
-
f'{len(uncited)} 条 · 接口召回但正文未采用,供比对参考)</div>'
|
|
972
|
-
f'<div class="uncited-list">{uncited_cards}</div></div>'
|
|
973
|
-
)
|
|
974
|
-
verified_count = sum(1 for s in sources if s.get("verified"))
|
|
975
|
-
# 筛选维度 = 检索分组(多路检索时按来源分组,如"北京·AI政策/北京·产业数据"):胶囊样式沿用类型筛选样式,单选 + 全部。
|
|
976
|
-
# 类型不再作为筛选维度(卡片徽章已展示类型,且类型为模型主观标注)。
|
|
1540
|
+
return ('<section class="view" id="view-library" aria-label="知识专库">'
|
|
1541
|
+
'<div class="lib-empty">接口返回中未识别到可展示的来源文章。</div></section>')
|
|
1542
|
+
used_sources = [s for s in sources if s.get("used", True)]
|
|
1543
|
+
unused_sources = [s for s in sources if not s.get("used", True)]
|
|
1544
|
+
|
|
1545
|
+
# tabs = 检索分组(全部 / 各路检索 / 未引用),数字真实统计
|
|
977
1546
|
conds: List[Tuple[str, int]] = []
|
|
978
1547
|
for s in sources:
|
|
979
|
-
key = s.get("search_key"
|
|
1548
|
+
key = (s.get("search_key") or "").strip()
|
|
980
1549
|
if not key:
|
|
981
1550
|
continue
|
|
982
1551
|
for i, (name, count) in enumerate(conds):
|
|
@@ -985,33 +1554,86 @@ def render_sources_panel(sources: List[Dict[str, str]], used: List[str]) -> str:
|
|
|
985
1554
|
break
|
|
986
1555
|
else:
|
|
987
1556
|
conds.append((key, 1))
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1557
|
+
tabs = [f'<button class="on" data-cond="" type="button">全部({len(sources)})</button>']
|
|
1558
|
+
for name, count in conds:
|
|
1559
|
+
tabs.append(f'<button data-cond="{esc(name)}" type="button">{esc(name)}({count})</button>')
|
|
1560
|
+
if unused_sources:
|
|
1561
|
+
tabs.append(f'<button data-cond="__unused__" type="button">未引用({len(unused_sources)})</button>')
|
|
1562
|
+
|
|
1563
|
+
hot_html = ""
|
|
1564
|
+
if hot_terms:
|
|
1565
|
+
hot_items = "".join(f'<button class="hot-term" type="button">{esc(term)}</button>' for term in hot_terms)
|
|
1566
|
+
hot_html = f'<div class="hot-terms" aria-label="热门搜索词"><span class="hot-label">大家都在搜</span>{hot_items}</div>'
|
|
1567
|
+
|
|
1568
|
+
cards_html = "".join(render_source_card(s) for s in used_sources)
|
|
1569
|
+
cards_html += "".join(render_source_card(s) for s in unused_sources)
|
|
1570
|
+
|
|
1571
|
+
cited_verified = sum(1 for s in used_sources if s.get("verified"))
|
|
1572
|
+
badge = "全部已核验" if used_sources and cited_verified == len(used_sources) else f"{cited_verified}/{len(used_sources)} 已核验"
|
|
1573
|
+
return f"""
|
|
1574
|
+
<section class="view" id="view-library" aria-label="知识专库">
|
|
1575
|
+
<div class="lib-head">
|
|
1576
|
+
<div class="lib-title"><b>知识专库</b>
|
|
1577
|
+
<span>共 {len(sources)} 条 · 已引用 {len(used_sources)} · {esc(badge)}</span>
|
|
1578
|
+
</div>
|
|
1579
|
+
<div class="lib-searchWrap">
|
|
1580
|
+
<span class="lib-searchIcon" aria-hidden="true">⌕</span>
|
|
1581
|
+
<input class="lib-search" type="search" placeholder="搜索标题 / 来源 / 摘录…" aria-label="搜索来源文章">
|
|
1582
|
+
</div>
|
|
1583
|
+
{hot_html}
|
|
1584
|
+
<div class="lib-tabs" role="tablist" aria-label="按检索分组筛选">{"".join(tabs)}</div>
|
|
1585
|
+
</div>
|
|
1586
|
+
<div class="lib-list" id="lib-list">{cards_html}</div>
|
|
1587
|
+
<div class="lib-empty hide" id="lib-empty">没有符合当前筛选的来源文章。</div>
|
|
1588
|
+
<div class="lib-foot">来源:深知可信搜索 · 每条摘录均取自原文原段</div>
|
|
1589
|
+
</section>"""
|
|
1590
|
+
|
|
1591
|
+
|
|
1592
|
+
def render_toc(sections: List[Dict[str, Any]], extra: str = "") -> str:
|
|
1593
|
+
"""章节目录(滚动 spy):长报告(≥6 个**有标题**的章节)显示,桌面端左侧浮动。
|
|
1010
1594
|
|
|
1595
|
+
无标题节(正文开头的导语段)跳过——此前兜底成「第 N 节」占位项,且该锚点
|
|
1596
|
+
#sec-i 在 render_section_cards 里根本不生成(死链接),点它没反应(对齐公文 3.7.6)。
|
|
1597
|
+
extra 为附加条目 HTML(图表独立呈现时);门槛按有标题章节数计。
|
|
1598
|
+
"""
|
|
1599
|
+
items = []
|
|
1600
|
+
for i, sec in enumerate(sections, 1):
|
|
1601
|
+
title = (sec.get("title") or "").strip()
|
|
1602
|
+
if not title:
|
|
1603
|
+
continue # 导语内容照常在正文展示,只是不占目录条目
|
|
1604
|
+
number, title_text = split_heading_number(title)
|
|
1605
|
+
label = f"{number} {title_text}" if (number and title_text) else title_text
|
|
1606
|
+
items.append(f'<a href="#sec-{i}">{esc(short(label, 16))}</a>')
|
|
1607
|
+
if len(items) < 6 and not extra:
|
|
1608
|
+
return ""
|
|
1609
|
+
items.append(extra)
|
|
1610
|
+
return f'<nav class="toc" aria-label="章节目录">{"".join(items)}</nav>'
|
|
1611
|
+
|
|
1612
|
+
|
|
1613
|
+
def render_print_appendix(sources: List[Dict[str, str]]) -> str:
|
|
1614
|
+
"""打印归档附录:全部材料卡全展开(屏幕不显示,仅打印)。"""
|
|
1615
|
+
if not sources:
|
|
1616
|
+
return ""
|
|
1617
|
+
cards = "".join(render_source_card(s, for_print=True) for s in sources)
|
|
1618
|
+
return (f'<section class="print-appendix" aria-label="来源文章附录(打印归档)">'
|
|
1619
|
+
f'<h3>来源文章(全 {len(sources)} 篇)</h3>{cards}</section>')
|
|
1011
1620
|
|
|
1012
|
-
|
|
1013
|
-
|
|
1621
|
+
|
|
1622
|
+
def safe_output_filename(question: str, timestamp: datetime, fallback: str = "dknowc_search_trace", suffix_ext: str = ".html") -> str:
|
|
1014
1623
|
raw = question.strip() or fallback
|
|
1624
|
+
# 清理对话指令性措辞(1.4.0):文件名用主题本身,不保留"帮我梳理一下…做个系统"这类口吻
|
|
1625
|
+
# (实测:WB 交付物文件名直接带用户原话的"帮我梳理一下…做个系统",冗长且不像正式交付名)
|
|
1626
|
+
for _ in range(3): # 反复剥离直到无变化(如"请帮我…一下吧")
|
|
1627
|
+
before = raw
|
|
1628
|
+
raw = re.sub(r"^(请|麻烦|帮我|帮忙|给我|我想|想问下|请问|你能|帮我看看|帮我看下)+", "", raw)
|
|
1629
|
+
# 只剥离明确不是主题词的整理类动词("分析/对比"等可能是主题的一部分,如"分析化学",不剥离)
|
|
1630
|
+
raw = re.sub(r"^(梳理|整理|汇总|总结|归纳|罗列)(一下)?", "", raw)
|
|
1631
|
+
raw = re.sub(r"(一下|吧|谢谢|多谢|可以吗|好吗|行吗|呢)+$", "", raw)
|
|
1632
|
+
raw = re.sub(r"(做个?系统(对比|比较|梳理)?|系统对比|系统梳理|对比一下|整理一下|汇总一下|总结一下)$", "", raw)
|
|
1633
|
+
raw = raw.strip(" ,,。.、!!??~~")
|
|
1634
|
+
if raw == before:
|
|
1635
|
+
break
|
|
1636
|
+
raw = raw or question.strip() or fallback
|
|
1015
1637
|
normalized = re.sub(r"\s+", "_", raw)
|
|
1016
1638
|
normalized = re.sub(r"[\\/:*?\"<>|#%&{}$!@`+=;',。、?!:;“”‘’()()【】《》\[\]]+", "", normalized)
|
|
1017
1639
|
normalized = normalized.strip("._-")
|
|
@@ -1019,552 +1641,1028 @@ def safe_output_filename(question: str, timestamp: datetime, fallback: str = "dk
|
|
|
1019
1641
|
normalized = fallback
|
|
1020
1642
|
suffix = timestamp.strftime("%Y%m%d_%H%M")
|
|
1021
1643
|
stem = normalized[:32].strip("._-") or fallback
|
|
1022
|
-
return f"{stem}
|
|
1023
|
-
|
|
1644
|
+
return f"{stem}_{suffix}{suffix_ext}"
|
|
1024
1645
|
|
|
1025
|
-
def renumber_citations(answer: str, sources: List[Dict[str, str]]) -> Tuple[str, List[Dict[str, str]]]:
|
|
1026
|
-
"""把答案角标按首次出现顺序重排为 [1][2][3]…,材料卡同步重编号。
|
|
1027
1646
|
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
cited_order = citation_ids(answer)
|
|
1032
|
-
if not cited_order:
|
|
1033
|
-
for s in sources:
|
|
1034
|
-
s["used"] = False
|
|
1035
|
-
return answer, sources
|
|
1036
|
-
mapping = {old: str(new) for new, old in enumerate(cited_order, start=1)}
|
|
1037
|
-
answer = re.sub(r"\[(\d+)\]", lambda m: "[" + mapping.get(m.group(1), m.group(1)) + "]", answer)
|
|
1038
|
-
by_old: Dict[str, Dict[str, str]] = {}
|
|
1039
|
-
for s in sources:
|
|
1040
|
-
by_old.setdefault(s["id"], s)
|
|
1041
|
-
cited_sorted: List[Dict[str, str]] = []
|
|
1042
|
-
for old in cited_order:
|
|
1043
|
-
s = by_old.get(old)
|
|
1044
|
-
if s is None:
|
|
1045
|
-
continue
|
|
1046
|
-
s2 = dict(s)
|
|
1047
|
-
s2["id"] = mapping[old]
|
|
1048
|
-
s2["used"] = True
|
|
1049
|
-
cited_sorted.append(s2)
|
|
1050
|
-
next_panel = len(mapping)
|
|
1051
|
-
rest: List[Dict[str, str]] = []
|
|
1052
|
-
for s in sources:
|
|
1053
|
-
if s["id"] in mapping:
|
|
1054
|
-
continue
|
|
1055
|
-
next_panel += 1
|
|
1056
|
-
s2 = dict(s)
|
|
1057
|
-
s2["used"] = False
|
|
1058
|
-
# 未引用材料 id 一并改为面板锚点号,避免旧编号与重排后的角标空间撞号
|
|
1059
|
-
s2["id"] = str(next_panel)
|
|
1060
|
-
rest.append(s2)
|
|
1061
|
-
return answer, cited_sorted + rest
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
def render_html(payload: Dict[str, Any], title: str, answer_override: str = "", question_override: str = "",
|
|
1065
|
-
generated_at: Optional[datetime] = None) -> str:
|
|
1066
|
-
payload = unwrap(payload)
|
|
1067
|
-
answer = normalize_citations(answer_override) if answer_override.strip() else extract_answer(payload)
|
|
1068
|
-
sources = align_sources_to_answer(answer, extract_sources(payload))
|
|
1069
|
-
answer, sources = renumber_citations(answer, sources)
|
|
1070
|
-
used = citation_ids(answer)
|
|
1071
|
-
used_set = set(used)
|
|
1072
|
-
# 卡片级核验标记与核验单口径对齐:被引用材料缺原文链接但知识专库可回看 → 视为已核验
|
|
1073
|
-
kb_urls_for_cards = extract_knowledge_bases(payload)
|
|
1074
|
-
for s in sources:
|
|
1075
|
-
if s.get("used", True) and not s.get("verified") and kb_urls_for_cards:
|
|
1076
|
-
if (s.get("excerpt") or "").strip():
|
|
1077
|
-
s["verified"] = True
|
|
1078
|
-
s["verify_note"] = s.get("verify_note") or "原文链接暂缺,可经知识专库回看核验"
|
|
1079
|
-
generated_at = generated_at or datetime.now()
|
|
1080
|
-
generated = generated_at.strftime("%Y-%m-%d %H:%M")
|
|
1081
|
-
|
|
1082
|
-
verification = compute_verification(answer, sources, payload, generated_at)
|
|
1083
|
-
citation_warning = ""
|
|
1084
|
-
if sources and not used:
|
|
1085
|
-
citation_warning = (
|
|
1086
|
-
'<div class="warn-box"><b>生成检查未通过:答案没有来源角标。</b>'
|
|
1087
|
-
'本报告无法建立"结论-素材"核验对应,仅作素材清单参考。'
|
|
1088
|
-
'请修正最终答案(--answer-file):在关键结论后标注 [1]、[2] 等角标并逐条对应召回材料,'
|
|
1089
|
-
'然后重新运行本脚本生成核验报告。</div>'
|
|
1090
|
-
)
|
|
1091
|
-
blocks, _ = parse_answer_blocks(answer, {s["id"] for s in sources})
|
|
1092
|
-
doc_title, sections = group_sections(blocks)
|
|
1093
|
-
display_title = doc_title or title
|
|
1647
|
+
# ============================================================
|
|
1648
|
+
# 样式与脚本(独立常量,避免模板转义)
|
|
1649
|
+
# ============================================================
|
|
1094
1650
|
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1651
|
+
PAGE_CSS = """
|
|
1652
|
+
:root{
|
|
1653
|
+
--navy:#20242c; --navy-2:#3a4152;
|
|
1654
|
+
--ink:#1f2328; --muted:#6b7280; --line:#e5e7eb; --line-strong:#cbd2dd;
|
|
1655
|
+
--brand:#6512ad; --brand-2:#8b5cf6; --brand-soft:#ede9fe;
|
|
1656
|
+
--grad:linear-gradient(135deg,#6512ad,#8b5cf6);
|
|
1657
|
+
--policy:#0f9d6e; --policy-soft:#e3f5ee;
|
|
1658
|
+
--case:#9a6700; --case-soft:#fdf3dc;
|
|
1659
|
+
--ref:#4b5563; --ref-soft:#f0f1f4;
|
|
1660
|
+
--warn:#9a6700; --danger:#e5484d; --ok:#0f9d6e;
|
|
1661
|
+
--shadow-1:0 1px 3px rgba(24,20,40,.04),0 8px 30px rgba(24,20,40,.08);
|
|
1662
|
+
--shadow-2:0 3px 9px rgba(101,18,173,.22),0 14px 36px rgba(24,20,40,.14);
|
|
1663
|
+
--primary-bright:#8b5cf6; --tint:#f3edfc; --tint-2:#faf7ff; --tint-bd:#e9dff9;
|
|
1664
|
+
--tint-strong:#e6d9f9; --tint-bd-strong:#d3bef0; --body-c:#3b4152; --card-bd:#e8e6f0;
|
|
1665
|
+
}
|
|
1666
|
+
*{box-sizing:border-box}
|
|
1667
|
+
html{scroll-behavior:smooth}
|
|
1668
|
+
body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Roboto,"PingFang SC","HarmonyOS Sans SC","Microsoft YaHei",sans-serif;
|
|
1669
|
+
color:var(--ink);background:#f4f5f7;line-height:1.75;font-size:14.5px}
|
|
1670
|
+
a{color:var(--brand)}
|
|
1671
|
+
|
|
1672
|
+
/* ===== 数据可视化(1.4.0 一体化:图表并入核验报告,不再另出独立报告) ===== */
|
|
1673
|
+
/* 主形态:图表跟着它展示的数据所在章节走(.chart-inline 插在该章节正文之后) */
|
|
1674
|
+
.chart-inline{margin:18px 0 4px;padding-top:14px;border-top:1px dashed var(--line)}
|
|
1675
|
+
.chart-h3{margin:0 0 4px;font-size:14px;font-weight:600;color:var(--ink)}
|
|
1676
|
+
/* 退化形态:锚点缺失/匹配不上时,作为独立章节排在核验报告单之后、正文之前 */
|
|
1677
|
+
.chart-section{background:#fff;border-radius:14px;box-shadow:var(--shadow-1);padding:22px 26px 18px;margin:0 0 16px}
|
|
1678
|
+
.chart-h2{margin:0 0 6px;font-size:16px;line-height:1.4}
|
|
1679
|
+
.chart-note{margin:0 0 14px;color:var(--muted);font-size:12px}
|
|
1680
|
+
.chart-section .card,.chart-inline .card{box-shadow:none;padding:0;border:0;background:transparent}
|
|
1681
|
+
.chart-section .viz-panel h3,.chart-inline .viz-panel h3{margin:0 0 6px;font-size:13.5px;font-weight:600;color:var(--ink)}
|
|
1682
|
+
.viz-duo{display:grid;grid-template-columns:1fr 1fr;gap:8px 18px;align-items:start}
|
|
1683
|
+
@media(max-width:900px){.viz-duo{grid-template-columns:1fr}}
|
|
1684
|
+
|
|
1685
|
+
/* ===== 顶栏 ===== */
|
|
1686
|
+
.topbar{position:sticky;top:0;z-index:50;display:flex;justify-content:space-between;align-items:center;gap:10px;
|
|
1687
|
+
padding:9px 22px;background:rgba(255,255,255,.92);backdrop-filter:blur(10px);
|
|
1688
|
+
border-bottom:1px solid var(--line)}
|
|
1689
|
+
.tb-left{display:flex;align-items:center;gap:10px;min-width:0}
|
|
1690
|
+
.tb-stamp{flex:none;font-size:12.5px;font-weight:800;color:var(--navy);letter-spacing:4px;text-indent:4px}
|
|
1691
|
+
.tb-stamp::before,.tb-stamp::after{content:"";display:inline-block;width:22px;border-top:1px solid var(--line-strong);
|
|
1692
|
+
vertical-align:middle;margin:0 6px}
|
|
1693
|
+
.tb-title{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--muted);font-size:13px}
|
|
1694
|
+
.tb-right{display:flex;align-items:center;gap:8px;flex:none}
|
|
1695
|
+
.view-switch{display:inline-flex;border:1px solid var(--line);border-radius:999px;overflow:hidden;background:#fff}
|
|
1696
|
+
.view-switch button{border:0;background:transparent;color:var(--muted);font-size:12.5px;font-weight:700;
|
|
1697
|
+
padding:5px 14px;cursor:pointer}
|
|
1698
|
+
.view-switch button.on{background:var(--grad);color:#fff}
|
|
1699
|
+
.tb-tools{display:flex;gap:6px}
|
|
1700
|
+
.tb-tools button{border:1px solid var(--line);border-radius:8px;background:#fff;color:#3b3550;
|
|
1701
|
+
font-size:12.5px;font-weight:700;padding:5px 11px;cursor:pointer}
|
|
1702
|
+
.tb-tools button:hover{border-color:var(--brand-2);color:var(--brand)}
|
|
1703
|
+
.tb-tools button[aria-pressed="true"]{background:var(--grad);border-color:var(--brand);color:#fff}
|
|
1704
|
+
.print-menu{position:relative;display:inline-flex}
|
|
1705
|
+
.print-drop{position:absolute;top:calc(100% + 6px);right:0;z-index:70;display:flex;flex-direction:column;gap:4px;
|
|
1706
|
+
min-width:190px;padding:6px;background:#fff;border:1px solid var(--tint-bd);border-radius:10px;
|
|
1707
|
+
box-shadow:var(--shadow-2);text-align:left}
|
|
1708
|
+
.print-drop[hidden]{display:none}
|
|
1709
|
+
.print-drop button{border:0;background:none;border-radius:7px;color:var(--ink);font-size:12.5px;font-weight:600;
|
|
1710
|
+
padding:8px 12px;cursor:pointer;text-align:left;font-family:inherit;white-space:nowrap}
|
|
1711
|
+
.print-drop button:hover{background:var(--tint);color:var(--brand)}
|
|
1712
|
+
.progress{position:absolute;left:0;right:0;bottom:-1px;height:2px;background:transparent}
|
|
1713
|
+
.progress i{display:block;height:100%;width:0;background:linear-gradient(90deg,#6512ad,#8b5cf6)}
|
|
1714
|
+
|
|
1715
|
+
/* ===== Hero ===== */
|
|
1716
|
+
.hero{position:relative;background:linear-gradient(180deg,#fbfaff 0%,#f7f4fd 100%);
|
|
1717
|
+
color:var(--ink);padding:32px 22px 58px;text-align:center;border-bottom:1px solid var(--line)}
|
|
1718
|
+
.r-badge{display:inline-flex;align-items:center;gap:14px;margin:0 0 8px;
|
|
1719
|
+
background:var(--grad);color:#fff;border-radius:999px;padding:4px 22px;
|
|
1720
|
+
font-size:15px;font-weight:800;letter-spacing:7px;text-indent:7px;line-height:1.6;
|
|
1721
|
+
box-shadow:0 2px 8px rgba(101,18,173,.22)}
|
|
1722
|
+
.hero h1{margin:0 0 10px;font-size:24px;line-height:1.5;max-width:860px;margin-left:auto;margin-right:auto;color:var(--ink)}
|
|
1723
|
+
.hero .meta{color:var(--muted);font-size:13px;letter-spacing:.5px}
|
|
1724
|
+
.hero-switch{margin-top:16px;display:flex;justify-content:center}
|
|
1725
|
+
.hero-switch .view-switch{border-color:#d9c9f4;background:#fff;box-shadow:0 1px 3px rgba(24,20,40,.04)}
|
|
1726
|
+
.hero-switch .view-switch button{color:#70678a;padding:6px 22px;font-size:13px}
|
|
1727
|
+
.hero-switch .view-switch button.on{background:var(--grad);color:#fff}
|
|
1728
|
+
|
|
1729
|
+
/* ===== 容器与视图 ===== */
|
|
1730
|
+
.container{max-width:1080px;margin:0 auto;padding:0 18px}
|
|
1731
|
+
.app[data-view="library"] #view-report{display:none}
|
|
1732
|
+
#view-library{display:none}
|
|
1733
|
+
.app[data-view="library"] #view-library{display:block}
|
|
1734
|
+
|
|
1735
|
+
/* ===== 过程回顾条 ===== */
|
|
1736
|
+
.process{background:#fff;border:1px solid var(--line);border-radius:14px;box-shadow:var(--shadow-1);
|
|
1737
|
+
padding:15px 20px 13px;margin:-36px auto 16px;position:relative}
|
|
1738
|
+
.p-head{display:flex;align-items:baseline;gap:10px;margin-bottom:10px}
|
|
1739
|
+
.p-head b{font-size:14.5px;color:var(--navy);letter-spacing:1px}
|
|
1740
|
+
.p-head span{font-size:11.5px;color:var(--muted)}
|
|
1741
|
+
.p-steps{list-style:none;display:flex;align-items:stretch;gap:8px;margin:0;padding:0;flex-wrap:wrap}
|
|
1742
|
+
.p-step{display:flex;gap:9px;align-items:center;min-width:0;flex:1 1 150px;
|
|
1743
|
+
border:1px solid var(--line);border-radius:10px;padding:8px 11px;background:#fafbfc}
|
|
1744
|
+
.p-no{flex:none;width:24px;height:24px;border-radius:50%;background:var(--grad);color:#fff;
|
|
1745
|
+
display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:800}
|
|
1746
|
+
.p-txt{min-width:0}
|
|
1747
|
+
.p-txt b{display:block;font-size:12.8px;color:var(--navy);line-height:1.5}
|
|
1748
|
+
.p-txt i{display:block;font-style:normal;font-size:11px;color:var(--muted);line-height:1.5;
|
|
1749
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1750
|
+
.p-step.done{border-color:#bfe8da;background:#f2faf7}
|
|
1751
|
+
.p-step.done .p-no{background:var(--ok)}
|
|
1752
|
+
.p-step.bad{border-color:#f6c9cb;background:#fffafa}
|
|
1753
|
+
.p-step.bad .p-no{background:var(--danger)}
|
|
1754
|
+
.p-step.expandable{cursor:pointer}
|
|
1755
|
+
.p-step.expandable:hover{border-color:var(--brand)}
|
|
1756
|
+
.p-arrow{align-self:center;color:#b9c6d9;font-size:16px;font-weight:700;flex:none}
|
|
1757
|
+
.p-detail{display:none;margin-top:10px;border-top:1px dashed var(--line-strong);padding-top:9px}
|
|
1758
|
+
.p-detail.show{display:block}
|
|
1759
|
+
.pd-row{display:flex;justify-content:space-between;gap:14px;padding:3px 2px;font-size:12.3px;flex-wrap:wrap}
|
|
1760
|
+
.pd-row b{color:var(--navy);font-weight:700;min-width:0}
|
|
1761
|
+
.pd-row span{color:var(--muted)}
|
|
1762
|
+
|
|
1763
|
+
/* ===== 核验报告视图 ===== */
|
|
1764
|
+
#view-report{padding-bottom:26px}
|
|
1765
|
+
.warn-box{margin:0 0 16px;padding:13px 16px;border:1.5px solid var(--danger);border-radius:10px;
|
|
1766
|
+
background:#fdf3f3;color:#8f2626;font-size:13.5px;line-height:1.7}
|
|
1767
|
+
.verify{margin:0 0 16px;background:#fff;border:1px solid #bfe8da;border-left:4px solid var(--ok);
|
|
1768
|
+
border-radius:14px;padding:16px 20px;box-shadow:var(--shadow-1)}
|
|
1769
|
+
.verify.fail{border-color:#f6c9cb;border-left-color:var(--danger);background:#fffafa}
|
|
1770
|
+
.v-head{display:flex;align-items:center;gap:9px;font-size:15px;font-weight:800;color:var(--ok)}
|
|
1771
|
+
.verify.fail .v-head{color:var(--danger)}
|
|
1772
|
+
.v-shield{display:inline-flex;width:22px;height:22px;border-radius:50%;background:var(--ok);color:#fff;
|
|
1773
|
+
align-items:center;justify-content:center;font-size:12px;flex:none}
|
|
1774
|
+
.verify.fail .v-shield{background:var(--danger)}
|
|
1775
|
+
.v-stamp{margin-left:auto;font-size:11px;border:1.5px solid var(--ok);color:var(--ok);border-radius:5px;
|
|
1776
|
+
padding:1px 8px;letter-spacing:2px;flex:none}
|
|
1777
|
+
.v-stamp.bad{border-color:var(--danger);color:var(--danger)}
|
|
1778
|
+
.v-reasons{margin-top:6px;font-size:12.5px;color:var(--danger)}
|
|
1779
|
+
.v-grid{display:grid;grid-template-columns:1fr 1fr;gap:4px 20px;margin-top:10px}
|
|
1780
|
+
.vi{display:flex;gap:7px;align-items:baseline;font-size:12.5px;color:#3b3550;line-height:1.7;min-width:0}
|
|
1781
|
+
.vi .s{font-weight:800;flex:none}
|
|
1782
|
+
.vi .s.ok{color:var(--ok)}
|
|
1783
|
+
.vi .s.warn{color:var(--warn)}
|
|
1784
|
+
.vi .s.fail{color:var(--danger)}
|
|
1785
|
+
.vi .s.man{color:var(--case)}
|
|
1786
|
+
.vi .s.none{color:var(--muted)}
|
|
1787
|
+
.vi .d{color:var(--muted);min-width:0}
|
|
1788
|
+
.v-note{margin-top:11px;padding-top:9px;border-top:1px dashed var(--line);font-size:11.5px;color:var(--muted);line-height:1.7}
|
|
1789
|
+
|
|
1790
|
+
/* 正文(原型复刻):章节 / 段落 / 角标 / 句后溯源卡 */
|
|
1791
|
+
.doc-paper{background:#fff;border-radius:14px;box-shadow:var(--shadow-1);padding:26px 34px 22px;margin:0 0 16px}
|
|
1792
|
+
.chapter{margin:40px 0 0}
|
|
1793
|
+
.chapter:first-child{margin-top:6px}
|
|
1794
|
+
.ch-head{display:flex;align-items:center;gap:14px;margin-bottom:18px;scroll-margin-top:86px}
|
|
1795
|
+
.ch-head h2{font-size:19.5px;font-weight:700;color:var(--ink);letter-spacing:.2px;line-height:1.4;flex:1;min-width:0}
|
|
1796
|
+
.ch-head::after{content:"";flex-basis:110px;height:1px;background:linear-gradient(90deg,#e9dff9,transparent);order:3;flex-grow:0;flex-shrink:0}
|
|
1797
|
+
.ch-head .sec-badge{order:4;flex:none;font-size:11.5px;color:var(--ok);background:var(--policy-soft);border-radius:6px;padding:2px 9px;font-weight:700}
|
|
1798
|
+
.ch-head .sec-badge.bad{color:var(--danger);background:#fdecec}
|
|
1799
|
+
@media(min-width:1000px){.ch-head::after{flex-basis:200px}}
|
|
1800
|
+
.lead{font-size:15.5px;line-height:1.95;color:var(--body-c);margin:14px 0;padding:0 2px;word-break:break-word}
|
|
1801
|
+
.para{font-size:15.5px;line-height:1.95;color:var(--body-c);margin:14px 0;padding:0 2px;word-break:break-word}
|
|
1802
|
+
.para b.kw,.lead b.kw{font-weight:600;color:var(--ink)}
|
|
1803
|
+
.doc-divider{border:0;border-top:1px solid var(--line);margin:18px 0}
|
|
1804
|
+
code{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#3f3d52;
|
|
1805
|
+
font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px}
|
|
1806
|
+
.tbl-wrap{max-width:100%;overflow-x:auto;margin:8px 0}
|
|
1807
|
+
.data-tbl{width:100%;border-collapse:collapse;border:1px solid var(--line);font-size:13px}
|
|
1808
|
+
.data-tbl th,.data-tbl td{border:1px solid var(--line);padding:8px 10px;text-align:left;vertical-align:top;line-height:1.65}
|
|
1809
|
+
.data-tbl th{background:#f5f6f8;font-weight:700;color:#3f3d52}
|
|
1104
1810
|
|
|
1105
|
-
return f"""<!doctype html>
|
|
1106
|
-
<html lang="zh-CN">
|
|
1107
|
-
<head>
|
|
1108
|
-
<meta charset="utf-8">
|
|
1109
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
1110
|
-
<title>{esc(display_title)} · 溯源核验报告</title>
|
|
1111
|
-
<style>
|
|
1112
|
-
:root{{
|
|
1113
|
-
--navy:#0b1f3a; --ink:#172236; --muted:#667085; --line:#dce4ef; --line-strong:#b9c6d9;
|
|
1114
|
-
--brand:#1559c7; --brand-soft:#e8f0ff;
|
|
1115
|
-
--policy:#0c9b78; --policy-soft:#e2f6ef;
|
|
1116
|
-
--case:#b26a00; --case-soft:#fff4e0;
|
|
1117
|
-
--ref:#4b5563; --ref-soft:#eef1f6;
|
|
1118
|
-
--warn:#b26a00; --danger:#b93939; --ok:#0c9b78;
|
|
1119
|
-
}}
|
|
1120
|
-
*{{box-sizing:border-box}}
|
|
1121
|
-
body{{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;
|
|
1122
|
-
color:var(--ink);background:#f4f7fb;line-height:1.75;font-size:14.5px}}
|
|
1123
|
-
a{{color:var(--brand)}}
|
|
1124
|
-
.topbar{{position:sticky;top:0;z-index:10;display:flex;justify-content:space-between;align-items:center;gap:10px;
|
|
1125
|
-
padding:10px 22px;background:var(--navy);color:#fff;font-size:13px}}
|
|
1126
|
-
.topbar .tb-title{{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}}
|
|
1127
|
-
.topbar .tags{{display:flex;align-items:center;gap:6px;flex:none}}
|
|
1128
|
-
.topbar .tags span{{padding:2px 10px;border:1px solid rgba(255,255,255,.3);border-radius:999px;font-size:11.5px}}
|
|
1129
|
-
.layout{{display:grid;grid-template-columns:minmax(0,760px) minmax(340px,420px);gap:26px;
|
|
1130
|
-
max-width:1240px;margin:0 auto;padding:26px 18px 60px}}
|
|
1131
|
-
/* 左栏 */
|
|
1132
|
-
.report{{min-width:0}}
|
|
1133
|
-
.r-head{{padding:22px 26px;background:#fff;border:1px solid var(--line);border-radius:12px;margin-bottom:16px;text-align:center}}
|
|
1134
|
-
.r-badge{{display:inline-flex;align-items:center;gap:14px;margin:0 0 6px;color:var(--navy);
|
|
1135
|
-
font-size:16px;font-weight:800;letter-spacing:7px;text-indent:7px;line-height:1.5}}
|
|
1136
|
-
.r-badge::before,.r-badge::after{{content:"";width:64px;border-top:1px solid var(--line-strong)}}
|
|
1137
|
-
.r-head h1{{margin:0 0 8px;font-size:22px;color:var(--navy);line-height:1.5}}
|
|
1138
|
-
.r-head .sub{{color:var(--muted);font-size:12.5px}}
|
|
1139
|
-
.warn-box{{margin:0 0 16px;padding:13px 16px;border:1.5px solid var(--danger);border-radius:10px;
|
|
1140
|
-
background:#fdf3f3;color:#8f2626;font-size:13.5px;line-height:1.7}}
|
|
1141
|
-
.verify{{margin:0 0 16px;background:#fff;border:1px solid #bfe5d6;border-radius:12px;padding:16px 20px}}
|
|
1142
|
-
.verify.fail{{border-color:#f2c4c4;background:#fffafa}}
|
|
1143
|
-
.v-head{{display:flex;align-items:center;gap:9px;font-size:15px;font-weight:800;color:var(--ok)}}
|
|
1144
|
-
.verify.fail .v-head{{color:var(--danger)}}
|
|
1145
|
-
.v-shield{{display:inline-flex;width:22px;height:22px;border-radius:50%;background:var(--ok);color:#fff;
|
|
1146
|
-
align-items:center;justify-content:center;font-size:12px;flex:none}}
|
|
1147
|
-
.verify.fail .v-shield{{background:var(--danger)}}
|
|
1148
|
-
.v-stamp{{margin-left:auto;font-size:11px;border:1.5px solid var(--ok);color:var(--ok);border-radius:5px;
|
|
1149
|
-
padding:1px 8px;letter-spacing:2px;flex:none}}
|
|
1150
|
-
.v-stamp.bad{{border-color:var(--danger);color:var(--danger)}}
|
|
1151
|
-
.v-reasons{{margin-top:6px;font-size:12.5px;color:var(--danger)}}
|
|
1152
|
-
.v-reasons.note{{color:var(--warn)}}
|
|
1153
|
-
.v-grid{{display:grid;grid-template-columns:1fr 1fr;gap:4px 20px;margin-top:10px}}
|
|
1154
|
-
.vi{{display:flex;gap:7px;align-items:baseline;font-size:12.5px;color:#35445c;line-height:1.7;min-width:0}}
|
|
1155
|
-
.vi .s{{font-weight:800;flex:none}}
|
|
1156
|
-
.vi .s.ok{{color:var(--ok)}}
|
|
1157
|
-
.vi .s.warn{{color:var(--warn)}}
|
|
1158
|
-
.vi .s.fail{{color:var(--danger)}}
|
|
1159
|
-
.vi .s.man{{color:var(--case)}}
|
|
1160
|
-
.vi .s.none{{color:var(--muted)}}
|
|
1161
|
-
.vi .d{{color:var(--muted);min-width:0}}
|
|
1162
|
-
.v-note{{margin-top:11px;padding-top:9px;border-top:1px dashed var(--line);font-size:11.5px;color:var(--muted);line-height:1.7}}
|
|
1163
|
-
/* 正文章节卡 */
|
|
1164
|
-
.doc-sec{{background:#fff;border:1px solid var(--line);border-radius:12px;padding:20px 24px;margin-bottom:16px}}
|
|
1165
|
-
.sec-head{{display:flex;align-items:center;gap:9px;flex-wrap:wrap;margin-bottom:10px;
|
|
1166
|
-
padding-bottom:10px;border-bottom:1px solid var(--line)}}
|
|
1167
|
-
.sec-no{{display:inline-flex;width:26px;height:26px;border-radius:7px;background:var(--brand);color:#fff;
|
|
1168
|
-
align-items:center;justify-content:center;font-size:13.5px;font-weight:700;flex:none}}
|
|
1169
|
-
.sec-head h3{{margin:0;font-size:16.5px;color:var(--navy);line-height:1.5}}
|
|
1170
|
-
.sec-badge{{margin-left:auto;font-size:11.5px;color:var(--ok);background:var(--policy-soft);
|
|
1171
|
-
border-radius:6px;padding:2px 9px;font-weight:700;flex:none}}
|
|
1172
|
-
.sec-badge.bad{{color:var(--danger);background:#fdecea}}
|
|
1173
|
-
.doc-sub{{margin:16px 0 8px;color:var(--navy);font-size:14.5px;font-weight:700}}
|
|
1174
|
-
h5.doc-sub{{font-size:13.5px}}
|
|
1175
|
-
.doc-block,.doc-item{{margin:0 0 12px}}
|
|
1176
|
-
.doc-block p,.doc-item p{{margin:0;font-size:14px;line-height:1.9}}
|
|
1177
|
-
.doc-item{{display:grid;grid-template-columns:22px minmax(0,1fr);gap:8px}}
|
|
1178
|
-
.doc-item.numbered{{grid-template-columns:28px minmax(0,1fr)}}
|
|
1179
|
-
.doc-bullet{{padding-top:1px;color:#111827;font-size:15px;line-height:1.85}}
|
|
1180
|
-
.doc-divider{{border:0;border-top:1px solid var(--line);margin:18px 0}}
|
|
1181
|
-
code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
1182
|
-
font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px}}
|
|
1183
|
-
.tbl-wrap{{max-width:100%;overflow-x:auto;margin:8px 0}}
|
|
1184
|
-
.data-tbl{{width:100%;border-collapse:collapse;border:1px solid var(--line);font-size:13px}}
|
|
1185
|
-
.data-tbl th,.data-tbl td{{border:1px solid var(--line);padding:8px 10px;text-align:left;vertical-align:top;line-height:1.65}}
|
|
1186
|
-
.data-tbl th{{background:#f2f5fb;font-weight:700;color:#374151}}
|
|
1187
1811
|
/* 角标 */
|
|
1188
|
-
.cite{
|
|
1189
|
-
|
|
1190
|
-
.cite
|
|
1191
|
-
.cite.unresolved{
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
.
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
.
|
|
1199
|
-
.
|
|
1200
|
-
.
|
|
1201
|
-
.
|
|
1202
|
-
.
|
|
1203
|
-
|
|
1204
|
-
.
|
|
1205
|
-
.
|
|
1206
|
-
.
|
|
1207
|
-
.
|
|
1208
|
-
.
|
|
1209
|
-
.
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
.
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
.
|
|
1216
|
-
.
|
|
1217
|
-
.
|
|
1218
|
-
|
|
1219
|
-
.
|
|
1220
|
-
.
|
|
1221
|
-
|
|
1222
|
-
.
|
|
1223
|
-
.
|
|
1224
|
-
|
|
1225
|
-
.
|
|
1226
|
-
.
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
.
|
|
1230
|
-
.
|
|
1231
|
-
.
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
.
|
|
1235
|
-
.
|
|
1236
|
-
.
|
|
1237
|
-
.
|
|
1238
|
-
.sc-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
.
|
|
1244
|
-
.
|
|
1245
|
-
.
|
|
1246
|
-
.
|
|
1247
|
-
.
|
|
1248
|
-
.
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
.
|
|
1252
|
-
.
|
|
1253
|
-
.
|
|
1254
|
-
.
|
|
1255
|
-
|
|
1256
|
-
.
|
|
1257
|
-
.
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
.
|
|
1261
|
-
.
|
|
1262
|
-
.
|
|
1263
|
-
.
|
|
1264
|
-
.
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
.
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
.
|
|
1274
|
-
.
|
|
1275
|
-
|
|
1276
|
-
.
|
|
1277
|
-
.
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1812
|
+
.cite{display:inline-flex;align-items:center;justify-content:center;min-width:19px;height:18px;padding:0 5px;margin:0 2px 2px 3px;font-size:10.5px;font-weight:700;font-variant-numeric:tabular-nums;color:var(--brand);background:var(--tint);border:1px solid var(--tint-bd);border-radius:5px;cursor:pointer;vertical-align:super;line-height:1;transition:.14s;position:relative;top:-1px;user-select:none;font-family:inherit}
|
|
1813
|
+
.cite:hover{background:var(--brand);border-color:var(--brand);color:#fff}
|
|
1814
|
+
.cite.flash{background:var(--primary-bright);border-color:var(--primary-bright);color:#fff}
|
|
1815
|
+
.cite.unresolved{color:var(--danger);border-color:#f6c9cb;background:#fdf7f7}
|
|
1816
|
+
|
|
1817
|
+
/* 段落级证据 chips(引文卡) */
|
|
1818
|
+
/* 行内引文 jb(原型复刻):角标后小胶囊,点击展开块级卡(溯源原文+引文摘录) */
|
|
1819
|
+
.jb{display:inline-block;vertical-align:top;max-width:100%;margin:2px 4px 2px 0;position:relative}
|
|
1820
|
+
.jb.active{display:block;margin:12px 0 2px;max-width:none}
|
|
1821
|
+
.jb-name{display:inline-flex;align-items:center;gap:6px;max-width:380px;min-height:26px;padding:4px 13px;border-radius:13px;border:1px solid var(--tint-bd);background:var(--tint);color:#540e8f;font-family:inherit;font-size:12px;font-weight:600;line-height:18px;cursor:pointer;transition:.16s;white-space:nowrap}
|
|
1822
|
+
.jb-name:hover{background:#fff;border-color:var(--brand)}
|
|
1823
|
+
.jb-name .jb-id{flex:none;width:18px;height:18px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-style:normal;font-size:10.5px;font-weight:800;font-variant-numeric:tabular-nums;color:#fff;background:linear-gradient(135deg,#6512ad,#8b5cf6);box-shadow:0 1px 3px rgba(101,18,173,.28)}
|
|
1824
|
+
.jb-name .jb-txt{overflow:hidden;text-overflow:ellipsis}
|
|
1825
|
+
.jb-name svg{flex:none;transition:transform .2s}
|
|
1826
|
+
.jb.active .jb-name{max-width:100%;white-space:normal;line-height:20px;color:var(--ink);background:#fff;font-size:13.5px;font-weight:700;text-align:left}
|
|
1827
|
+
.jb.active .jb-name svg{transform:rotate(180deg)}
|
|
1828
|
+
.jb-src{display:inline-flex;align-items:center;gap:5px;min-height:26px;padding:4px 13px;border-radius:13px;background:linear-gradient(135deg,#6512ad,#8b5cf6);color:#fff;font-size:11px;font-weight:600;text-decoration:none;box-shadow:0 2px 8px rgba(101,18,173,.22);transition:.15s;flex-shrink:0}
|
|
1829
|
+
.jb-src:hover{filter:brightness(1.1)}
|
|
1830
|
+
.jb-src span{max-width:210px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1831
|
+
.jb-body{display:none}
|
|
1832
|
+
.jb.active .jb-body{position:relative;display:block;margin-top:13px;background:#fff;border:1px solid var(--card-bd);border-radius:12px;padding:13px 15px;box-shadow:var(--shadow-1)}
|
|
1833
|
+
.jb-head{display:flex;align-items:center;gap:9px;flex-wrap:wrap}
|
|
1834
|
+
.jb-label{display:inline-flex;align-items:center;gap:6px;font-size:12.5px;font-weight:700;color:var(--brand);letter-spacing:.5px}
|
|
1835
|
+
.jb-label svg{flex:none}
|
|
1836
|
+
.jb-site{display:inline-flex;align-items:center;gap:6px;font-size:11.5px;color:#70678a;background:#f6f4fa;
|
|
1837
|
+
border:1px solid var(--line);border-radius:999px;padding:3.5px 10px;max-width:100%;overflow:hidden;
|
|
1838
|
+
text-overflow:ellipsis;white-space:nowrap;margin:0 0 2px}
|
|
1839
|
+
.jb-site .dot{width:6px;height:6px;border-radius:50%;background:linear-gradient(135deg,#6512ad,#8b5cf6);flex-shrink:0}
|
|
1840
|
+
.jb-quote{display:flex;gap:9px;align-items:flex-start;margin-top:9px;padding:10px 12px;background:#faf9fd;border:1px solid var(--line);border-radius:9px;text-decoration:none;transition:.15s;cursor:pointer}
|
|
1841
|
+
.jb-quote{cursor:pointer}
|
|
1842
|
+
.jb-quote:hover{border-color:var(--brand);background:#f7f4fc}
|
|
1843
|
+
.jb-no{flex:none;width:17px;height:17px;margin-top:4px;border-radius:4px;background:var(--tint);border:1px solid var(--tint-bd);color:var(--brand);font-size:10px;font-weight:700;font-style:normal;display:flex;align-items:center;justify-content:center}
|
|
1844
|
+
.jb-quote span{font-size:12.5px;line-height:1.95;color:#4b4658;word-break:break-word;text-align:justify}
|
|
1845
|
+
.jb-quote .sc-excerpt{flex:1;min-width:0;display:block}
|
|
1846
|
+
a.jb-quote{text-decoration:none}
|
|
1847
|
+
.jb.flash{animation:cardFlash 1.6s ease}
|
|
1848
|
+
.ev-title{font-weight:700;font-size:13.5px;margin-bottom:4px;color:var(--ink)}
|
|
1849
|
+
.ev-meta{color:var(--muted);font-size:12px;margin-bottom:6px}
|
|
1850
|
+
.ev-chip summary{display:inline-flex;align-items:center;gap:5px;max-width:100%;min-height:26px;padding:4px 13px;
|
|
1851
|
+
border-radius:13px;color:#fff;background:var(--grad);cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
|
|
1852
|
+
list-style:none;font-size:11px;font-weight:600;box-shadow:0 2px 8px rgba(101,18,173,.22);transition:.15s}
|
|
1853
|
+
.ev-chip summary:hover{filter:brightness(1.12)}
|
|
1854
|
+
.ev-chip summary::-webkit-details-marker{display:none}
|
|
1855
|
+
.ev-chip summary b{color:#fff;margin-right:2px;font-weight:700}
|
|
1856
|
+
|
|
1857
|
+
.ev-title{font-weight:700;font-size:13.5px;margin-bottom:4px;color:var(--navy)}
|
|
1858
|
+
.ev-meta{color:var(--muted);font-size:12px;margin-bottom:6px}
|
|
1859
|
+
.ev-panel p{margin:0 0 8px;color:#3f3d52;font-size:12.8px;line-height:1.7}
|
|
1860
|
+
.sc-links{display:flex;flex-wrap:wrap;gap:8px;margin-top:6px}
|
|
1861
|
+
.sc-links span{display:inline-flex}
|
|
1862
|
+
.sc-links a{display:inline-flex;align-items:center;min-height:24px;padding:3px 9px;border-radius:6px;
|
|
1863
|
+
background:var(--brand-soft);color:var(--brand);font-weight:700;text-decoration:none;font-size:12px}
|
|
1864
|
+
|
|
1865
|
+
/* ===== 知识专库视图 ===== */
|
|
1866
|
+
#view-library{padding:26px 0 30px}
|
|
1867
|
+
.lib-head{max-width:860px;margin:0 auto 16px;text-align:center}
|
|
1868
|
+
.lib-title{margin-bottom:14px}
|
|
1869
|
+
.lib-title b{font-size:17px;color:var(--navy);letter-spacing:2px}
|
|
1870
|
+
.lib-title span{display:block;font-size:12px;color:var(--muted);margin-top:2px}
|
|
1871
|
+
.lib-searchWrap{position:relative;max-width:620px;margin:0 auto}
|
|
1872
|
+
.lib-searchIcon{position:absolute;left:14px;top:50%;transform:translateY(-50%);color:#a6adbd;font-size:16px;font-weight:700}
|
|
1873
|
+
.lib-search{width:100%;padding:11px 16px 11px 38px;border:1.5px solid var(--line-strong);border-radius:999px;
|
|
1874
|
+
font-size:14px;background:#fff;box-shadow:var(--shadow-1);outline:none}
|
|
1875
|
+
.lib-search:focus{border-color:var(--brand-2);box-shadow:0 0 0 3px rgba(139,92,246,.18)}
|
|
1876
|
+
.hot-terms{display:flex;flex-wrap:wrap;justify-content:center;gap:7px;margin-top:12px;align-items:center}
|
|
1877
|
+
.hot-label{font-size:12px;color:var(--muted)}
|
|
1878
|
+
.hot-term{border:0;border-radius:999px;background:var(--brand-soft);color:var(--brand);
|
|
1879
|
+
font-size:12.3px;font-weight:700;padding:3px 13px;cursor:pointer}
|
|
1880
|
+
.hot-term:hover{background:var(--grad);color:#fff}
|
|
1881
|
+
.lib-tabs{display:flex;flex-wrap:wrap;justify-content:center;gap:6px;margin-top:14px}
|
|
1882
|
+
.lib-tabs button{border:1px solid var(--line);border-radius:999px;background:#fff;color:var(--muted);
|
|
1883
|
+
padding:4px 13px;font-size:12.3px;cursor:pointer}
|
|
1884
|
+
.lib-tabs button.on{background:var(--grad);border-color:var(--brand);color:#fff;font-weight:700}
|
|
1885
|
+
.lib-list{max-width:860px;margin:0 auto;display:grid;grid-template-columns:1fr;gap:14px}
|
|
1886
|
+
.lib-empty{max-width:860px;margin:30px auto;text-align:center;color:var(--muted);font-size:13.5px}
|
|
1887
|
+
.lib-empty.hide{display:none}
|
|
1888
|
+
.lib-foot{text-align:center;color:var(--muted);font-size:11.5px;padding:18px 0 0;line-height:1.8}
|
|
1889
|
+
|
|
1890
|
+
/* ===== 材料卡 ===== */
|
|
1891
|
+
.scard{border:1px solid var(--line);border-left-width:3px;border-radius:12px;padding:14px 18px;
|
|
1892
|
+
background:#fff;box-shadow:var(--shadow-1);transition:box-shadow .25s}
|
|
1893
|
+
.scard:hover{box-shadow:var(--shadow-2)}
|
|
1894
|
+
.scard.pol{border-left-color:var(--policy)}
|
|
1895
|
+
.scard.dat{border-left-color:var(--brand-2)}
|
|
1896
|
+
.scard.cas{border-left-color:var(--case)}
|
|
1897
|
+
.scard.ref,.scard.mat{border-left-color:var(--ref)}
|
|
1898
|
+
.scard.hl{box-shadow:0 0 0 3px rgba(139,92,246,.35),var(--shadow-2)}
|
|
1899
|
+
.scard.hide{display:none}
|
|
1900
|
+
.sc-head{display:flex;align-items:center;gap:7px;margin-bottom:6px}
|
|
1901
|
+
.sc-id{font-family:monospace;font-weight:800;font-size:11px;color:#fff;background:var(--grad);
|
|
1902
|
+
border-radius:5px;padding:1px 8px}
|
|
1903
|
+
.sc-type{font-size:11px;font-weight:700;border-radius:4px;padding:1px 8px;background:var(--ref-soft);color:var(--ref)}
|
|
1904
|
+
.scard.pol .sc-type{background:var(--policy-soft);color:var(--policy)}
|
|
1905
|
+
.scard.dat .sc-type{background:var(--brand-soft);color:var(--brand)}
|
|
1906
|
+
.scard.cas .sc-type{background:var(--case-soft);color:var(--case)}
|
|
1907
|
+
.sc-vk{margin-left:auto;font-size:11px;font-weight:800;color:var(--ok)}
|
|
1908
|
+
.sc-vk.warn{color:var(--warn)}
|
|
1909
|
+
.sc-unused{font-size:10.5px;font-weight:800;color:var(--muted);background:#efedf4;border-radius:4px;
|
|
1910
|
+
padding:1px 7px;flex:none}
|
|
1911
|
+
.sc-conf{font-size:10.5px;font-weight:800;color:#8a5a00;background:var(--case-soft);border:1px solid #e6cf8f;
|
|
1912
|
+
border-radius:4px;padding:0 7px;flex:none}
|
|
1913
|
+
.scard h4{margin:0 0 5px;font-size:14.5px;color:var(--ink);line-height:1.55}
|
|
1914
|
+
.sc-meta{font-size:11.5px;color:var(--muted)}
|
|
1915
|
+
/* 标题链面包屑(模型生成的结构化位置,核验核心抓手)与多段分块 */
|
|
1916
|
+
.crumb{font-size:11.5px;color:var(--brand);margin:10px 0 4px;font-weight:600;line-height:1.6;
|
|
1917
|
+
padding:3px 9px;background:var(--tint);border-radius:7px;display:inline-block;max-width:100%;
|
|
1918
|
+
overflow-wrap:break-word}
|
|
1919
|
+
.crumb i{font-style:normal;color:#c9b3ec;margin:0 2px;font-weight:400}
|
|
1920
|
+
.seg-block{margin-top:8px}
|
|
1921
|
+
.seg-block:first-child{margin-top:2px}
|
|
1922
|
+
.seg-block .sc-excerpt{margin-top:5px}
|
|
1923
|
+
.sc-vnote{margin-top:5px;font-size:11.3px;color:var(--ok);line-height:1.6}
|
|
1924
|
+
.sc-excerpt{margin:8px 0 0;padding:10px 12px;border:1px solid #eceaf2;border-radius:9px;
|
|
1925
|
+
background:#faf9fd;color:#4a4260;font-size:12.3px;line-height:1.75}
|
|
1926
|
+
.sc-excerpt.rich{overflow-x:auto}
|
|
1927
|
+
.sc-excerpt.rich table{width:max-content;min-width:100%;border-collapse:collapse;background:#fff;font-size:12px}
|
|
1928
|
+
.sc-excerpt.rich td,.sc-excerpt.rich th{min-width:92px;max-width:220px;padding:7px 8px;border:1px solid var(--line);
|
|
1929
|
+
vertical-align:top;word-break:break-word}
|
|
1930
|
+
.sc-excerpt.rich thead td,.sc-excerpt.rich th{background:#f3f4f6;color:#3f3d52;font-weight:700}
|
|
1931
|
+
.scard .sc-links a{font-size:12px}
|
|
1932
|
+
.scard .sc-links{margin-top:4px}
|
|
1933
|
+
.no-link{font-size:11.5px;color:var(--muted)}
|
|
1934
|
+
.sc-links a.snap{background:#faf5ff;border-color:#d9c9f4;color:#5b21b6}
|
|
1935
|
+
.dead-link{font-size:11.5px;color:var(--warn)}
|
|
1936
|
+
|
|
1937
|
+
/* ===== 章节目录(spy,长报告) ===== */
|
|
1938
|
+
.toc{position:fixed;left:calc((100vw - 1080px)/2 - 168px);top:120px;width:140px;max-height:60vh;overflow:auto;
|
|
1939
|
+
display:flex;flex-direction:column;gap:2px;font-size:12px}
|
|
1940
|
+
.toc a{color:var(--muted);text-decoration:none;padding:4px 10px;border-left:2px solid var(--line);
|
|
1941
|
+
line-height:1.5;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1942
|
+
.toc a.on{color:var(--brand);border-left-color:var(--brand);font-weight:700}
|
|
1943
|
+
/* 知识专库视图下隐藏章节目录(2026-09-29,对齐公文 3.7.6):.toc 渲染在 .app 之外,
|
|
1944
|
+
视图切换只由 .app[data-view] 驱动,此前无任何规则处理 .toc,专库视图下目录仍挂在左侧 */
|
|
1945
|
+
.app[data-view="library"] ~ .toc,.app[data-view="library"] .toc{display:none}
|
|
1946
|
+
@media (max-width:1460px){.toc{display:none}}
|
|
1947
|
+
|
|
1948
|
+
.foot{text-align:center;color:var(--muted);font-size:11.5px;padding:16px 0 4px;line-height:1.8}
|
|
1949
|
+
|
|
1950
|
+
/* ===== 只看正文(纯净阅读态) ===== */
|
|
1951
|
+
body.reading .process,body.reading .verify,body.reading .jb,body.reading .sec-badge,
|
|
1952
|
+
body.reading .cite,body.reading .toc,body.reading .p-detail{display:none!important}
|
|
1953
|
+
|
|
1954
|
+
/* ===== 打印附录 ===== */
|
|
1955
|
+
.print-appendix{display:none}
|
|
1956
|
+
|
|
1957
|
+
/* ===== 移动端 ===== */
|
|
1958
|
+
.sheet-mask{display:none}
|
|
1959
|
+
.sheet{display:none}
|
|
1960
|
+
@media (max-width:680px){
|
|
1961
|
+
body{font-size:14px;line-height:1.8}
|
|
1962
|
+
.topbar{padding:7px 10px;gap:6px}
|
|
1963
|
+
.tb-stamp{font-size:11px;letter-spacing:2px;text-indent:2px}
|
|
1964
|
+
.tb-stamp::before,.tb-stamp::after{width:12px;margin:0 4px}
|
|
1965
|
+
.tb-title{display:none}
|
|
1966
|
+
.topbar .view-switch{display:none}
|
|
1967
|
+
.tb-tools button{font-size:11.5px;padding:4px 8px}
|
|
1968
|
+
.hero{padding:24px 14px 50px}
|
|
1969
|
+
.ch-head{gap:8px;margin-bottom:14px;flex-wrap:nowrap}
|
|
1970
|
+
.ch-head h2{font-size:17px;line-height:1.45}
|
|
1971
|
+
.ch-head::after{display:none}
|
|
1972
|
+
.ch-head .sec-badge{font-size:10.5px;padding:2px 7px;white-space:nowrap}
|
|
1973
|
+
.jb-name{max-width:calc(100vw - 72px)}
|
|
1974
|
+
.r-badge{font-size:13.5px;letter-spacing:6px;text-indent:6px;gap:10px}
|
|
1975
|
+
.hero h1{font-size:18.5px}
|
|
1976
|
+
.hero .meta{font-size:11.5px;line-height:1.7}
|
|
1977
|
+
.hero-switch .view-switch button{padding:6px 16px;font-size:12.5px}
|
|
1978
|
+
.process{margin-top:-30px;padding:12px 12px 11px}
|
|
1979
|
+
.p-step{flex:1 1 100%}
|
|
1980
|
+
.p-arrow{display:none}
|
|
1981
|
+
.verify{padding:13px 14px}
|
|
1982
|
+
.v-head{font-size:14px}
|
|
1983
|
+
.v-grid{grid-template-columns:1fr;gap:2px 0}
|
|
1984
|
+
.vi{flex-wrap:wrap;gap:4px 8px}
|
|
1985
|
+
.vi .d{min-width:0}
|
|
1986
|
+
.warn-box{font-size:12.5px;padding:11px 12px}
|
|
1987
|
+
.doc-paper{padding:16px 14px 10px;border-radius:10px}
|
|
1988
|
+
.sec-head{gap:7px;padding-bottom:8px;margin-bottom:8px}
|
|
1989
|
+
.sec-head h3{font-size:15px}
|
|
1990
|
+
.sec-badge{margin-left:0;font-size:11px}
|
|
1991
|
+
.doc-block p,.doc-item p{font-size:15px;line-height:1.95}
|
|
1992
|
+
.doc-sub{font-size:14px;margin:12px 0 6px}
|
|
1993
|
+
.data-tbl{font-size:12px}
|
|
1994
|
+
.data-tbl th,.data-tbl td{padding:6px 7px;line-height:1.55}
|
|
1995
|
+
.cite{font-size:11px;padding:0 4px}
|
|
1996
|
+
.ev-chip summary{font-size:11px}
|
|
1997
|
+
#view-library{padding:18px 0 24px}
|
|
1998
|
+
.lib-search{padding:10px 14px 10px 34px;font-size:13.5px}
|
|
1999
|
+
.lib-tabs{justify-content:flex-start;flex-wrap:nowrap;overflow-x:auto;padding-bottom:4px;
|
|
2000
|
+
-webkit-overflow-scrolling:touch;scrollbar-width:none}
|
|
2001
|
+
.lib-tabs::-webkit-scrollbar{display:none}
|
|
2002
|
+
.lib-tabs button{flex:none}
|
|
2003
|
+
.lib-list{grid-template-columns:1fr;gap:10px}
|
|
2004
|
+
.scard{padding:10px 11px}
|
|
2005
|
+
.crumb{font-size:11px}
|
|
2006
|
+
.sc-excerpt{font-size:11.5px}
|
|
2007
|
+
/* 移动端材料底部弹层:点角标就地弹出材料卡,不跳转打断阅读 */
|
|
2008
|
+
.sheet-mask{display:block;position:fixed;inset:0;background:rgba(11,31,58,.45);z-index:99;opacity:0;
|
|
2009
|
+
pointer-events:none;transition:opacity .2s}
|
|
2010
|
+
.sheet-mask.show{opacity:1;pointer-events:auto}
|
|
2011
|
+
.sheet{display:block;position:fixed;left:0;right:0;bottom:0;z-index:100;background:#fff;
|
|
1319
2012
|
border-radius:14px 14px 0 0;box-shadow:0 -8px 30px rgba(11,31,58,.25);
|
|
1320
2013
|
max-height:68vh;overflow-y:auto;-webkit-overflow-scrolling:touch;
|
|
1321
|
-
padding:10px 16px 22px;transform:translateY(105%);transition:transform .25s ease}
|
|
1322
|
-
.sheet.show{
|
|
1323
|
-
.sheet-grab{
|
|
1324
|
-
.sheet-head{
|
|
1325
|
-
.sheet-head b{
|
|
1326
|
-
.sheet-close{
|
|
1327
|
-
font-size:12.5px;font-weight:700;padding:5px 14px;cursor:pointer}
|
|
1328
|
-
.sheet .scard{
|
|
1329
|
-
.sheet .sc-excerpt{
|
|
2014
|
+
padding:10px 16px 22px;transform:translateY(105%);transition:transform .25s ease}
|
|
2015
|
+
.sheet.show{transform:translateY(0)}
|
|
2016
|
+
.sheet-grab{width:38px;height:4px;border-radius:2px;background:#c9d4e2;margin:2px auto 8px}
|
|
2017
|
+
.sheet-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}
|
|
2018
|
+
.sheet-head b{font-size:13.5px;color:var(--navy)}
|
|
2019
|
+
.sheet-close{border:1px solid var(--line);background:#f5f3fa;border-radius:8px;color:#3b4a61;
|
|
2020
|
+
font-size:12.5px;font-weight:700;padding:5px 14px;cursor:pointer}
|
|
2021
|
+
.sheet .scard{box-shadow:none;margin-bottom:0}
|
|
2022
|
+
.sheet .sc-excerpt{display:block;-webkit-line-clamp:unset;cursor:auto}
|
|
1330
2023
|
/* 正文表述 ↔ 原文原段 对照区(弹层顶部) */
|
|
1331
|
-
.cmp{
|
|
1332
|
-
.cmp-tag{
|
|
1333
|
-
.cmp-side{
|
|
1334
|
-
.cmp-side p{
|
|
1335
|
-
.cmp-ai{
|
|
1336
|
-
.cmp-ai .cmp-tag{
|
|
1337
|
-
.cmp-src{
|
|
1338
|
-
.cmp-src .cmp-tag{
|
|
1339
|
-
.cmp-src .sc-excerpt{
|
|
1340
|
-
}
|
|
1341
|
-
@media print{{
|
|
1342
|
-
.topbar,.filters,.src-search{{display:none!important}}
|
|
1343
|
-
.layout{{grid-template-columns:1fr;max-width:none;padding:0;gap:14px}}
|
|
1344
|
-
body{{background:#fff;font-size:12.5px}}
|
|
1345
|
-
.sources{{position:static;max-height:none;border:0;padding:0;overflow:visible}}
|
|
1346
|
-
.r-head,.verify,.doc-sec{{border-color:#bbb;box-shadow:none;break-inside:avoid}}
|
|
1347
|
-
.sc-excerpt{{display:block;-webkit-line-clamp:unset;cursor:auto}}
|
|
1348
|
-
.uncited-group[open] .uncited-list,.uncited-group{{break-inside:avoid}}
|
|
1349
|
-
.scard{{break-inside:avoid}}
|
|
1350
|
-
.cite{{background:#eee;color:#333}}
|
|
1351
|
-
}}
|
|
1352
|
-
</style>
|
|
1353
|
-
</head>
|
|
1354
|
-
<body>
|
|
1355
|
-
|
|
1356
|
-
<header class="topbar">
|
|
1357
|
-
<div class="tb-title">{esc(display_title)} · 溯源核验报告</div>
|
|
1358
|
-
<div class="tags">
|
|
1359
|
-
<span>生成于 {esc(generated)}</span>
|
|
1360
|
-
<span>素材来源:深知可信搜索</span>
|
|
1361
|
-
</div>
|
|
1362
|
-
</header>
|
|
1363
|
-
|
|
1364
|
-
<div class="layout">
|
|
1365
|
-
<main class="report" aria-label="核验报告正文">
|
|
1366
|
-
<div class="r-head" id="doc-top">
|
|
1367
|
-
<div class="r-badge">溯源核验报告</div>
|
|
1368
|
-
<h1>{esc(display_title)}</h1>
|
|
1369
|
-
<div class="sub">{esc(meta_line)}</div>
|
|
1370
|
-
</div>
|
|
1371
|
-
{citation_warning}
|
|
1372
|
-
{render_verify_panel(verification)}
|
|
1373
|
-
<a class="mobile-nav" href="#sources-panel">查看核验材料({len(sources)} 条 · 点击角标可定位原文)↓</a>
|
|
1374
|
-
{render_section_cards(sections, sources)}
|
|
1375
|
-
<div class="foot">深知可信搜索(法律、政策、标准)· 溯源核验报告 | 内容由 AI 生成,仅供参考,政策现行效力以官方发布为准</div>
|
|
1376
|
-
</main>
|
|
1377
|
-
{render_sources_panel(sources, used)}
|
|
1378
|
-
</div>
|
|
2024
|
+
.cmp{margin:0 0 10px;border:1px solid var(--line);border-radius:10px;overflow:hidden}
|
|
2025
|
+
.cmp-tag{font-size:11px;font-weight:800;padding:3px 10px}
|
|
2026
|
+
.cmp-side{padding:9px 12px;font-size:12.8px;line-height:1.7}
|
|
2027
|
+
.cmp-side p{margin:0}
|
|
2028
|
+
.cmp-ai{background:#fbfaff;color:#3f3d52}
|
|
2029
|
+
.cmp-ai .cmp-tag{background:#eef1f6;color:var(--ref)}
|
|
2030
|
+
.cmp-src{background:#f4faf7;color:#2f4a3e;border-top:1px dashed var(--line-strong)}
|
|
2031
|
+
.cmp-src .cmp-tag{background:var(--policy-soft);color:#0b6e4f}
|
|
2032
|
+
.cmp-src .sc-excerpt{display:block;-webkit-line-clamp:unset;background:#fff;cursor:auto;font-size:12px;padding:8px 10px;margin:0}
|
|
2033
|
+
}
|
|
1379
2034
|
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
2035
|
+
/* ===== 打印归档 ===== */
|
|
2036
|
+
@media print{
|
|
2037
|
+
.topbar,.process .p-detail,.hero-switch,.tb-tools,.view-switch,.lib-head,.toc,.sheet,.sheet-mask,
|
|
2038
|
+
.progress{display:none!important}
|
|
2039
|
+
#view-library{display:none!important}
|
|
2040
|
+
#view-report{display:block!important}
|
|
2041
|
+
.app[data-view="library"] #view-report{display:block!important}
|
|
2042
|
+
.hero{background:none;border:0;color:var(--ink);padding:10px 0 4px}
|
|
2043
|
+
.hero .meta{color:var(--muted)}
|
|
2044
|
+
*{-webkit-print-color-adjust:exact;print-color-adjust:exact}
|
|
2045
|
+
.process{box-shadow:none;margin:6px 0 12px}
|
|
2046
|
+
.verify{border-color:#bbb;box-shadow:none;break-inside:avoid}
|
|
2047
|
+
.doc-paper{box-shadow:none;border-radius:0;padding:0}
|
|
2048
|
+
body{background:#fff;font-size:12.5px}
|
|
2049
|
+
.sc-excerpt{display:block;-webkit-line-clamp:unset;cursor:auto}
|
|
2050
|
+
.scard{break-inside:avoid}
|
|
2051
|
+
.cite{background:none!important;color:#333!important;text-decoration:none!important}
|
|
2052
|
+
.cite::before{content:"["}.cite::after{content:"]"}
|
|
2053
|
+
.jb{display:inline!important}
|
|
2054
|
+
.jb .jb-name{border:0;background:none;padding:0;color:#333;font-weight:600}
|
|
2055
|
+
.jb .jb-name .jb-id{color:#333;background:none;border:1px solid #999;border-radius:3px}
|
|
2056
|
+
.jb .jb-body{display:none!important}
|
|
2057
|
+
.jb.active{break-inside:avoid}
|
|
2058
|
+
.jb.active .jb-body{display:block!important}
|
|
2059
|
+
.jb.active .jb-body .jb-quote{break-inside:avoid}
|
|
2060
|
+
body.reading .verify,body.reading .process,body.reading .ev-row,body.reading .sec-badge,
|
|
2061
|
+
body.reading .cite{display:none!important}
|
|
2062
|
+
.print-appendix{display:block;break-before:page}
|
|
2063
|
+
body.print-body-only .verify,body.print-body-only .process,body.print-body-only .print-appendix,
|
|
2064
|
+
body.print-body-only .jb,body.print-body-only .foot{display:none!important}
|
|
2065
|
+
.print-appendix h3{font-size:15px;color:var(--navy);border-bottom:1px solid #999;padding-bottom:6px;margin:0 0 12px}
|
|
2066
|
+
.print-appendix .scard{margin-bottom:10px}
|
|
2067
|
+
}
|
|
2068
|
+
"""
|
|
1386
2069
|
|
|
1387
|
-
|
|
1388
|
-
(function () {
|
|
2070
|
+
PAGE_JS = """
|
|
2071
|
+
(function () {
|
|
1389
2072
|
"use strict";
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
2073
|
+
function $(sel, root) { return (root || document).querySelector(sel); }
|
|
2074
|
+
function $$(sel, root) { return Array.prototype.slice.call((root || document).querySelectorAll(sel)); }
|
|
2075
|
+
|
|
2076
|
+
var app = $(".app");
|
|
2077
|
+
var isMobile = function () { return window.matchMedia("(max-width:680px)").matches; };
|
|
2078
|
+
|
|
2079
|
+
/* ===== 1. 双视图切换(保存/恢复各自滚动位置) ===== */
|
|
2080
|
+
var savedScroll = { report: 0, library: 0 };
|
|
2081
|
+
function setView(view) {
|
|
2082
|
+
if (!app || app.getAttribute("data-view") === view) return;
|
|
2083
|
+
savedScroll[app.getAttribute("data-view") || "report"] = window.scrollY;
|
|
2084
|
+
app.setAttribute("data-view", view);
|
|
2085
|
+
$$(".view-switch button").forEach(function (b) {
|
|
2086
|
+
b.classList.toggle("on", b.getAttribute("data-view") === view);
|
|
2087
|
+
});
|
|
2088
|
+
window.scrollTo(0, Math.max(0, savedScroll[view] || 0));
|
|
2089
|
+
}
|
|
2090
|
+
$$(".view-switch button").forEach(function (b) {
|
|
2091
|
+
b.addEventListener("click", function () { setView(b.getAttribute("data-view")); });
|
|
2092
|
+
});
|
|
2093
|
+
|
|
2094
|
+
/* ===== 2. 阅读进度条 ===== */
|
|
2095
|
+
var progress = $(".progress i");
|
|
2096
|
+
function updateProgress() {
|
|
2097
|
+
if (!progress) return;
|
|
2098
|
+
var h = document.documentElement;
|
|
2099
|
+
var max = h.scrollHeight - h.clientHeight;
|
|
2100
|
+
progress.style.width = (max > 0 ? Math.min(100, (h.scrollTop / max) * 100) : 0) + "%";
|
|
2101
|
+
}
|
|
2102
|
+
window.addEventListener("scroll", updateProgress, { passive: true });
|
|
2103
|
+
updateProgress();
|
|
2104
|
+
|
|
2105
|
+
/* ===== 3. 只看正文(纯净阅读态切换) ===== */
|
|
2106
|
+
var readBtn = $("#btn-reading");
|
|
2107
|
+
if (readBtn) {
|
|
2108
|
+
readBtn.addEventListener("click", function () {
|
|
2109
|
+
var on = document.body.classList.toggle("reading");
|
|
2110
|
+
readBtn.setAttribute("aria-pressed", on ? "true" : "false");
|
|
2111
|
+
readBtn.textContent = on ? "显示核验" : "只看正文";
|
|
2112
|
+
/* 只看正文只作用于核验报告视图:正在知识专库时切回报告,专库不受影响 */
|
|
2113
|
+
if (on && app && app.getAttribute("data-view") !== "report") setView("report");
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
/* ===== 4. 复制全文(章节标题 + 段落 + 表格,去角标) ===== */
|
|
2118
|
+
var copyBtn = $("#btn-copy");
|
|
2119
|
+
if (copyBtn) {
|
|
2120
|
+
copyBtn.addEventListener("click", function () {
|
|
2121
|
+
var parts = [];
|
|
2122
|
+
/* 按文档流顺序收集章节标题/段落/表格;克隆后剔除引文胶囊与角标,
|
|
2123
|
+
只复制正文本身(胶囊标题/展开摘录/编号数字均不带出) */
|
|
2124
|
+
var nodes = $$("#view-report .ch-head h2, #view-report .lead, #view-report .para, #view-report .tbl-wrap");
|
|
2125
|
+
nodes.sort(function (a, b) { return (a.compareDocumentPosition(b) & 4) ? -1 : 1; });
|
|
2126
|
+
nodes.forEach(function (el) {
|
|
2127
|
+
var clone = el.cloneNode(true);
|
|
2128
|
+
clone.querySelectorAll(".jb, sup.cite").forEach(function (x) { x.remove(); });
|
|
2129
|
+
var t = clone.textContent.replace(/[ \t]+/g, " ").trim();
|
|
2130
|
+
if (t) parts.push(t);
|
|
2131
|
+
});
|
|
2132
|
+
var text = parts.filter(Boolean).join("\\n\\n");
|
|
2133
|
+
function done(ok) {
|
|
2134
|
+
var old = copyBtn.textContent;
|
|
2135
|
+
copyBtn.textContent = ok ? "已复制 ✓" : "复制失败";
|
|
2136
|
+
setTimeout(function () { copyBtn.textContent = old; }, 1600);
|
|
2137
|
+
}
|
|
2138
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
2139
|
+
navigator.clipboard.writeText(text).then(function () { done(true); }, function () { done(fallback(text)); });
|
|
2140
|
+
} else {
|
|
2141
|
+
done(fallback(text));
|
|
2142
|
+
}
|
|
2143
|
+
function fallback(value) {
|
|
2144
|
+
try {
|
|
2145
|
+
var ta = document.createElement("textarea");
|
|
2146
|
+
ta.value = value;
|
|
2147
|
+
ta.style.position = "fixed";
|
|
2148
|
+
ta.style.opacity = "0";
|
|
2149
|
+
document.body.appendChild(ta);
|
|
2150
|
+
ta.select();
|
|
2151
|
+
var ok = document.execCommand("copy");
|
|
2152
|
+
document.body.removeChild(ta);
|
|
2153
|
+
return ok;
|
|
2154
|
+
} catch (e) { return false; }
|
|
2155
|
+
}
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
/* ===== 5. 打印归档(PDF):下拉双选项——只打印正文 / 完整归档 ===== */
|
|
2160
|
+
var printBtn = $("#btn-print");
|
|
2161
|
+
var printDrop = $("#print-drop");
|
|
2162
|
+
function printBy(mode) {
|
|
2163
|
+
if (mode === "body") document.body.classList.add("print-body-only");
|
|
2164
|
+
if (printDrop) printDrop.hidden = true;
|
|
2165
|
+
window.print();
|
|
2166
|
+
}
|
|
2167
|
+
if (printBtn && printDrop) {
|
|
2168
|
+
printBtn.addEventListener("click", function (e) {
|
|
2169
|
+
e.stopPropagation();
|
|
2170
|
+
printDrop.hidden = !printDrop.hidden;
|
|
2171
|
+
});
|
|
2172
|
+
printDrop.addEventListener("click", function (e) {
|
|
2173
|
+
e.stopPropagation();
|
|
2174
|
+
var t = e.target.closest("button");
|
|
2175
|
+
if (!t) return;
|
|
2176
|
+
printBy(t.id === "print-body" ? "body" : "full");
|
|
2177
|
+
});
|
|
2178
|
+
document.addEventListener("click", function () { printDrop.hidden = true; });
|
|
2179
|
+
/* 打印结束移除临时模式(浏览器打印窗口关闭后触发) */
|
|
2180
|
+
window.addEventListener("afterprint", function () { document.body.classList.remove("print-body-only"); });
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
/* ===== 6. 材料卡索引(专库列表内,不含打印附录) ===== */
|
|
2184
|
+
var cards = $$("#lib-list .scard");
|
|
2185
|
+
var byId = {};
|
|
2186
|
+
cards.forEach(function (c) {
|
|
1393
2187
|
var id = c.getAttribute("data-cite-id");
|
|
1394
2188
|
if (id) byId[id] = c;
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
/*
|
|
1398
|
-
var sheet =
|
|
1399
|
-
var mask =
|
|
1400
|
-
function
|
|
1401
|
-
return window.matchMedia("(max-width:680px)").matches;
|
|
1402
|
-
}}
|
|
1403
|
-
function escHtml(s) {{
|
|
2189
|
+
});
|
|
2190
|
+
|
|
2191
|
+
/* 移动端底部弹层:正文表述 ↔ 原文原段 对照 + 材料卡 */
|
|
2192
|
+
var sheet = $(".sheet");
|
|
2193
|
+
var mask = $(".sheet-mask");
|
|
2194
|
+
function escHtml(s) {
|
|
1404
2195
|
var d = document.createElement("div");
|
|
1405
2196
|
d.textContent = s;
|
|
1406
2197
|
return d.innerHTML;
|
|
1407
|
-
}
|
|
1408
|
-
function sentenceOf(el) {
|
|
2198
|
+
}
|
|
2199
|
+
function sentenceOf(el) {
|
|
1409
2200
|
var para = el && el.closest ? el.closest(".doc-block,.doc-item") : null;
|
|
1410
2201
|
return para && para.querySelector("p") ? para.querySelector("p").innerText.trim() : "";
|
|
1411
|
-
}
|
|
1412
|
-
function openSheet(card, sentence) {
|
|
2202
|
+
}
|
|
2203
|
+
function openSheet(card, sentence) {
|
|
1413
2204
|
if (!sheet) return;
|
|
1414
2205
|
var body = sheet.querySelector(".sheet-body");
|
|
1415
2206
|
body.innerHTML = "";
|
|
1416
|
-
if (sentence) {
|
|
2207
|
+
if (sentence) {
|
|
1417
2208
|
var excerpt = card.querySelector(".sc-excerpt");
|
|
1418
2209
|
var cmp = document.createElement("div");
|
|
1419
2210
|
cmp.className = "cmp";
|
|
1420
2211
|
cmp.innerHTML =
|
|
1421
|
-
'<div class="cmp-side cmp-ai"><div class="cmp-tag"
|
|
1422
|
-
'<div class="cmp-side cmp-src"><div class="cmp-tag"
|
|
2212
|
+
'<div class="cmp-side cmp-ai"><div class="cmp-tag">正文表述</div><p>' + escHtml(sentence) + '</p></div>' +
|
|
2213
|
+
'<div class="cmp-side cmp-src"><div class="cmp-tag">原文原段</div>' +
|
|
1423
2214
|
'<div class="sc-excerpt">' + (excerpt ? excerpt.innerHTML : "") + '</div></div>';
|
|
1424
2215
|
body.appendChild(cmp);
|
|
1425
|
-
}
|
|
2216
|
+
}
|
|
1426
2217
|
var clone = card.cloneNode(true);
|
|
1427
2218
|
clone.removeAttribute("id");
|
|
1428
2219
|
clone.classList.remove("hide");
|
|
1429
2220
|
clone.classList.add("open");
|
|
1430
|
-
var sheetMore = clone.querySelector(".sc-more");
|
|
1431
|
-
if (sheetMore) sheetMore.remove();
|
|
1432
2221
|
body.appendChild(clone);
|
|
1433
2222
|
sheet.classList.add("show");
|
|
1434
2223
|
mask.classList.add("show");
|
|
1435
2224
|
document.body.style.overflow = "hidden";
|
|
1436
2225
|
sheet.scrollTop = 0;
|
|
1437
|
-
}
|
|
1438
|
-
function closeSheet() {
|
|
2226
|
+
}
|
|
2227
|
+
function closeSheet() {
|
|
1439
2228
|
if (!sheet) return;
|
|
1440
2229
|
sheet.classList.remove("show");
|
|
1441
2230
|
mask.classList.remove("show");
|
|
1442
2231
|
document.body.style.overflow = "";
|
|
1443
|
-
}
|
|
1444
|
-
if (sheet && mask) {
|
|
2232
|
+
}
|
|
2233
|
+
if (sheet && mask) {
|
|
1445
2234
|
mask.addEventListener("click", closeSheet);
|
|
1446
2235
|
var closeBtn = sheet.querySelector(".sheet-close");
|
|
1447
2236
|
if (closeBtn) closeBtn.addEventListener("click", closeSheet);
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
/*
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
if (
|
|
1462
|
-
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
/* 行内引文 jb(原型行为):点小胶囊 toggle 展开卡;点角标展开对应 jb 并 flash。
|
|
2240
|
+
未绑定角标红色警示,绝不按位置猜测。 */
|
|
2241
|
+
var JB_TABLES = {};
|
|
2242
|
+
try {
|
|
2243
|
+
var jbTablesEl = document.getElementById("jb-tables");
|
|
2244
|
+
if (jbTablesEl) JB_TABLES = JSON.parse(jbTablesEl.textContent || "{}");
|
|
2245
|
+
} catch (e) { JB_TABLES = {}; }
|
|
2246
|
+
function fillTableHolders(jb) {
|
|
2247
|
+
jb.querySelectorAll(".tbl-holder[data-tbl]").forEach(function (h) {
|
|
2248
|
+
if (h.getAttribute("data-filled")) return;
|
|
2249
|
+
var html = JB_TABLES[h.getAttribute("data-tbl")];
|
|
2250
|
+
if (html) h.innerHTML = html;
|
|
2251
|
+
h.setAttribute("data-filled", "1");
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2254
|
+
function toggleJb(jb, forceOpen) {
|
|
2255
|
+
var open = forceOpen === true ? true : !jb.classList.contains("active");
|
|
2256
|
+
document.querySelectorAll(".jb.active").forEach(function (x) { if (x !== jb) x.classList.remove("active"); });
|
|
2257
|
+
jb.classList.toggle("active", open);
|
|
2258
|
+
if (open) fillTableHolders(jb);
|
|
2259
|
+
var name = jb.querySelector(".jb-name");
|
|
2260
|
+
if (name) name.setAttribute("aria-expanded", open ? "true" : "false");
|
|
2261
|
+
return open;
|
|
2262
|
+
}
|
|
2263
|
+
document.querySelectorAll(".jb-name").forEach(function (name) {
|
|
2264
|
+
name.addEventListener("click", function () { toggleJb(name.closest(".jb")); });
|
|
2265
|
+
});
|
|
2266
|
+
|
|
2267
|
+
/* 引文条目点击 → 知识专库定位对应卡:库内导航看完整材料;
|
|
2268
|
+
外部原文跳转只保留 jb-head 的"查看全文"按钮,动线分离 */
|
|
2269
|
+
function jumpToLibrary(id) {
|
|
2270
|
+
var card = byId[id];
|
|
2271
|
+
if (!card) return;
|
|
2272
|
+
setView("library");
|
|
2273
|
+
card.classList.remove("hide", "open");
|
|
2274
|
+
card.classList.add("hl", "open");
|
|
2275
|
+
requestAnimationFrame(function () {
|
|
2276
|
+
requestAnimationFrame(function () { card.scrollIntoView({ block: "center", behavior: "smooth" }); });
|
|
2277
|
+
});
|
|
2278
|
+
setTimeout(function () { card.classList.remove("hl"); }, 2200);
|
|
2279
|
+
}
|
|
2280
|
+
document.querySelectorAll(".jb-quote").forEach(function (q) {
|
|
2281
|
+
function go() {
|
|
2282
|
+
var jbEl = q.closest(".jb");
|
|
2283
|
+
var id = jbEl && jbEl.getAttribute("data-cite");
|
|
2284
|
+
if (id) jumpToLibrary(id);
|
|
2285
|
+
}
|
|
2286
|
+
q.addEventListener("click", go);
|
|
2287
|
+
q.addEventListener("keydown", function (e) {
|
|
2288
|
+
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); go(); }
|
|
2289
|
+
});
|
|
2290
|
+
});
|
|
2291
|
+
document.querySelectorAll("sup.cite").forEach(function (btn) {
|
|
2292
|
+
/* 仅剩未绑定角标(红色数字)走到这里:点击控制台留痕 */
|
|
2293
|
+
btn.addEventListener("click", function () {
|
|
2294
|
+
if (console.error) console.error("[核验] 未绑定角标:", btn.getAttribute("data-cite"));
|
|
2295
|
+
});
|
|
2296
|
+
});
|
|
2297
|
+
|
|
2298
|
+
/* 材料卡摘录直接全文展开(句后胶囊已承载即点即看,专库不再折叠) */
|
|
2299
|
+
|
|
2300
|
+
/* 胶囊点击:桌面开关对照气泡(同一气泡再点收起);手机端弹出底部材料弹层 */
|
|
2301
|
+
document.querySelectorAll(".ev-chip").forEach(function (chip) {
|
|
2302
|
+
chip.addEventListener("click", function () {
|
|
2303
|
+
var id = chip.getAttribute("data-cite");
|
|
2304
|
+
if (isMobile()) {
|
|
2305
|
+
var card = byId[id];
|
|
2306
|
+
if (card) openSheet(card, sentenceOf(chip));
|
|
1463
2307
|
return;
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
}});
|
|
1471
|
-
|
|
1472
|
-
/* 摘录点击展开/收起:内容被截断(超出 4 行)的卡片显示"展开全文"引导,
|
|
1473
|
-
未截断的短摘录不显示,避免误导 */
|
|
1474
|
-
cards.forEach(function (c) {{
|
|
1475
|
-
var ex = c.querySelector(".sc-excerpt");
|
|
1476
|
-
if (!ex) return;
|
|
1477
|
-
if (ex.scrollHeight > ex.clientHeight + 4) c.classList.add("clampable");
|
|
1478
|
-
var more = c.querySelector(".sc-more");
|
|
1479
|
-
function toggleExcerpt() {{ c.classList.toggle("open"); }}
|
|
1480
|
-
ex.addEventListener("click", function (e) {{
|
|
1481
|
-
if (e.target.closest("a")) return;
|
|
1482
|
-
toggleExcerpt();
|
|
1483
|
-
}});
|
|
1484
|
-
if (more) {{
|
|
1485
|
-
more.addEventListener("click", toggleExcerpt);
|
|
1486
|
-
more.addEventListener("keydown", function (e) {{
|
|
1487
|
-
if (e.key === "Enter" || e.key === " ") {{ e.preventDefault(); toggleExcerpt(); }}
|
|
1488
|
-
}});
|
|
1489
|
-
}}
|
|
1490
|
-
}});
|
|
1491
|
-
|
|
1492
|
-
/* 证据 chips(灰框):桌面端点击就地展开并高亮右栏来源卡;手机端不就地展开,点击直接弹出底部材料弹层。
|
|
1493
|
-
展开锁定:浏览器(Chrome 系)对 <details> 展开会自动滚动露出内容、收起时滚动位置会被回夹,
|
|
1494
|
-
点击时锁定滚动位置并在展开/收起后滚回,消除页面"轻微滚动"感。 */
|
|
1495
|
-
document.querySelectorAll(".ev-chip").forEach(function (chip) {{
|
|
1496
|
-
var summary = chip.querySelector("summary");
|
|
1497
|
-
if (summary) {{
|
|
1498
|
-
summary.addEventListener("click", function (e) {{
|
|
1499
|
-
if (isMobile()) {{
|
|
1500
|
-
e.preventDefault();
|
|
1501
|
-
var card = byId[chip.getAttribute("data-cite")];
|
|
1502
|
-
if (card) openSheet(card, sentenceOf(chip));
|
|
1503
|
-
return;
|
|
1504
|
-
}}
|
|
1505
|
-
var y = window.scrollY;
|
|
1506
|
-
var restore = function () {{ window.scrollTo(0, y); }};
|
|
1507
|
-
requestAnimationFrame(function () {{ restore(); requestAnimationFrame(restore); }});
|
|
1508
|
-
}});
|
|
1509
|
-
}}
|
|
1510
|
-
chip.addEventListener("toggle", function () {{
|
|
1511
|
-
if (!chip.open || isMobile()) return;
|
|
1512
|
-
var card = byId[chip.getAttribute("data-cite")];
|
|
1513
|
-
if (!card) return;
|
|
1514
|
-
cards.forEach(function (c) {{ c.classList.remove("hl"); }});
|
|
1515
|
-
card.classList.add("hl");
|
|
1516
|
-
setTimeout(function () {{ card.classList.remove("hl"); }}, 2200);
|
|
1517
|
-
}});
|
|
1518
|
-
}});
|
|
1519
|
-
|
|
1520
|
-
/* 检索分组筛选(单选 + 全部 + 未引用,胶囊样式)+ 关键字搜索叠加 */
|
|
2308
|
+
}
|
|
2309
|
+
togglePop(chip, id);
|
|
2310
|
+
});
|
|
2311
|
+
});
|
|
2312
|
+
|
|
2313
|
+
/* ===== 7. 知识专库:tabs + 搜索 + 热词 ===== */
|
|
1521
2314
|
var cond = "";
|
|
1522
2315
|
var kw = "";
|
|
1523
|
-
function
|
|
1524
|
-
|
|
2316
|
+
function applyFilter() {
|
|
2317
|
+
var visible = 0;
|
|
2318
|
+
cards.forEach(function (c) {
|
|
1525
2319
|
var okCond = !cond;
|
|
1526
2320
|
if (cond === "__unused__") okCond = c.getAttribute("data-unused") === "1";
|
|
1527
2321
|
else if (cond) okCond = c.getAttribute("data-search") === cond;
|
|
1528
2322
|
var okKw = !kw || (c.textContent || "").toLowerCase().indexOf(kw) !== -1;
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
2323
|
+
var show = okCond && okKw;
|
|
2324
|
+
c.classList.toggle("hide", !show);
|
|
2325
|
+
if (show) visible++;
|
|
2326
|
+
});
|
|
2327
|
+
var empty = $("#lib-empty");
|
|
2328
|
+
if (empty) empty.classList.toggle("hide", visible !== 0);
|
|
2329
|
+
}
|
|
2330
|
+
$$(".lib-tabs button").forEach(function (b) {
|
|
2331
|
+
b.addEventListener("click", function () {
|
|
2332
|
+
$$(".lib-tabs button").forEach(function (x) { x.classList.remove("on"); });
|
|
1535
2333
|
b.classList.add("on");
|
|
1536
2334
|
cond = b.getAttribute("data-cond") || "";
|
|
1537
|
-
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
var search =
|
|
1541
|
-
if (search) search.addEventListener("input", function () {
|
|
1542
|
-
|
|
1543
|
-
|
|
2335
|
+
applyFilter();
|
|
2336
|
+
});
|
|
2337
|
+
});
|
|
2338
|
+
var search = $(".lib-search");
|
|
2339
|
+
if (search) search.addEventListener("input", function () { kw = search.value.trim().toLowerCase(); applyFilter(); });
|
|
2340
|
+
$$(".hot-term").forEach(function (t) {
|
|
2341
|
+
t.addEventListener("click", function () {
|
|
2342
|
+
if (!search) return;
|
|
2343
|
+
search.value = t.textContent.trim();
|
|
2344
|
+
kw = search.value.toLowerCase();
|
|
2345
|
+
applyFilter();
|
|
2346
|
+
if (search.focus) search.focus();
|
|
2347
|
+
});
|
|
2348
|
+
});
|
|
2349
|
+
|
|
2350
|
+
/* ===== 8. 过程回顾条:检索步骤展开 ===== */
|
|
2351
|
+
var pStep = $("#p-step-search");
|
|
2352
|
+
var pDetail = $("#p-detail");
|
|
2353
|
+
if (pStep && pDetail) {
|
|
2354
|
+
function toggleDetail() { pDetail.classList.toggle("show"); }
|
|
2355
|
+
pStep.addEventListener("click", toggleDetail);
|
|
2356
|
+
pStep.addEventListener("keydown", function (e) {
|
|
2357
|
+
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); toggleDetail(); }
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
/* ===== 9. 章节目录(spy) ===== */
|
|
2362
|
+
var toc = $(".toc");
|
|
2363
|
+
if (toc) {
|
|
2364
|
+
var links = $$("a", toc);
|
|
2365
|
+
var secs = links.map(function (a) { return document.querySelector(a.getAttribute("href")); });
|
|
2366
|
+
links.forEach(function (a) {
|
|
2367
|
+
a.addEventListener("click", function (e) {
|
|
2368
|
+
e.preventDefault();
|
|
2369
|
+
var target = document.querySelector(a.getAttribute("href"));
|
|
2370
|
+
if (!target) return;
|
|
2371
|
+
/* 手动定位而非 scrollIntoView({block:"start"}):后者把标题顶到视口 y=0,
|
|
2372
|
+
会被 sticky 顶栏盖住。偏移量与目录吸顶位置同一基准(顶栏高 + 20px)。 */
|
|
2373
|
+
var bar = document.querySelector(".topbar");
|
|
2374
|
+
var offset = (bar ? bar.offsetHeight : 0) + 20;
|
|
2375
|
+
var y = target.getBoundingClientRect().top + window.scrollY - offset;
|
|
2376
|
+
window.scrollTo({ top: Math.max(0, y), behavior: "smooth" });
|
|
2377
|
+
});
|
|
2378
|
+
});
|
|
2379
|
+
function spy() {
|
|
2380
|
+
var pos = window.scrollY + 130;
|
|
2381
|
+
var current = -1;
|
|
2382
|
+
secs.forEach(function (s, i) { if (s && s.offsetTop <= pos) current = i; });
|
|
2383
|
+
links.forEach(function (a, i) { a.classList.toggle("on", i === current); });
|
|
2384
|
+
}
|
|
2385
|
+
window.addEventListener("scroll", spy, { passive: true });
|
|
2386
|
+
|
|
2387
|
+
/* 目录纵向定位(2026-09-29,对齐公文 3.7.6):此前 CSS 写死 top:120px,目录顶部与页头
|
|
2388
|
+
齐平、离正文很远。改为——直接跟随正文首节,只保留"不低于顶栏下方"的下限;首屏看不到
|
|
2389
|
+
目录属正常,向下滚动后自然吸附在顶栏下方。目录过长由 CSS max-height:60vh+overflow:auto
|
|
2390
|
+
内部滚动兜底。 */
|
|
2391
|
+
var topbar = document.querySelector(".topbar");
|
|
2392
|
+
function placeToc() {
|
|
2393
|
+
var first = secs[0];
|
|
2394
|
+
if (!first) return;
|
|
2395
|
+
var stick = (topbar ? topbar.offsetHeight : 0) + 20;
|
|
2396
|
+
var want = Math.round(first.getBoundingClientRect().top);
|
|
2397
|
+
toc.style.top = Math.max(stick, want) + "px";
|
|
2398
|
+
}
|
|
2399
|
+
window.addEventListener("scroll", placeToc, { passive: true });
|
|
2400
|
+
window.addEventListener("resize", placeToc);
|
|
2401
|
+
placeToc();
|
|
2402
|
+
spy();
|
|
2403
|
+
}
|
|
2404
|
+
})();
|
|
2405
|
+
"""
|
|
2406
|
+
|
|
2407
|
+
|
|
2408
|
+
def render_html(payload: Dict[str, Any], title: str, answer_override: str = "", question_override: str = "",
|
|
2409
|
+
generated_at: Optional[datetime] = None,
|
|
2410
|
+
skip_link_check: bool = False, snapshot_enabled: bool = True,
|
|
2411
|
+
charts_data: Optional[Dict[str, Any]] = None) -> str:
|
|
2412
|
+
payload = unwrap(payload)
|
|
2413
|
+
answer = normalize_citations(answer_override) if answer_override.strip() else extract_answer(payload)
|
|
2414
|
+
sources = align_sources_to_answer(answer, extract_sources(payload, skip_link_check=skip_link_check, snapshot_enabled=snapshot_enabled))
|
|
2415
|
+
# 角标按首次出现顺序重排为 1..N(含材料卡同步重编号与未引用分组),WorkBuddy 实测反馈要求
|
|
2416
|
+
answer, sources = renumber_citations(answer, sources)
|
|
2417
|
+
used = citation_ids(answer)
|
|
2418
|
+
generated_at = generated_at or datetime.now()
|
|
2419
|
+
generated = generated_at.strftime("%Y-%m-%d %H:%M")
|
|
2420
|
+
|
|
2421
|
+
verification = compute_verification(answer, sources, payload, generated_at)
|
|
2422
|
+
process_stats = compute_process_stats(sources, answer)
|
|
2423
|
+
hot_terms = extract_hot_terms(answer, sources)
|
|
2424
|
+
citation_warning = ""
|
|
2425
|
+
if sources and not used:
|
|
2426
|
+
citation_warning = (
|
|
2427
|
+
'<div class="warn-box"><b>生成检查未通过:正文没有来源角标。</b>'
|
|
2428
|
+
'本报告无法建立"结论-素材"核验对应,仅作素材清单参考。'
|
|
2429
|
+
'请修正最终答案(--answer-file):在关键结论后标注 [1]、[2] 等角标并逐条对应来源文章,'
|
|
2430
|
+
'然后重新运行本脚本生成核验报告。</div>'
|
|
2431
|
+
)
|
|
2432
|
+
chip_map = build_chip_data(sources)
|
|
2433
|
+
blocks, _ = parse_answer_blocks(answer, {s["id"] for s in sources}, chip_map)
|
|
2434
|
+
# 胶囊内表格数据汇总(span 内静态表格会被解析器拆散,改为页尾 JSON + 展开时 JS 注入)
|
|
2435
|
+
jb_tables: Dict[str, str] = {}
|
|
2436
|
+
for cid, jb in chip_map.items():
|
|
2437
|
+
for key, html in (jb.pop("_tables", {}) or {}).items():
|
|
2438
|
+
jb_tables[key] = html
|
|
2439
|
+
doc_title, sections = group_sections(blocks)
|
|
2440
|
+
display_title = doc_title or title
|
|
2441
|
+
|
|
2442
|
+
jb_tables_json = json.dumps(jb_tables, ensure_ascii=False).replace("</", "<\\/")
|
|
2443
|
+
jb_tables_script = (f'<script type="application/json" id="jb-tables">{jb_tables_json}</script>\n'
|
|
2444
|
+
if jb_tables else "")
|
|
2445
|
+
|
|
2446
|
+
meta_bits = []
|
|
2447
|
+
if process_stats["n_searches"]:
|
|
2448
|
+
meta_bits.append(f"深知检索 {process_stats['n_searches']} 路")
|
|
2449
|
+
if sources:
|
|
2450
|
+
meta_bits.append(f"来源文章 {len(sources)} 篇")
|
|
2451
|
+
if process_stats["n_cite_marks"]:
|
|
2452
|
+
meta_bits.append(f"正文引用 {process_stats['n_cite_marks']} 处")
|
|
2453
|
+
meta_bits.append(f"生成于 {generated}")
|
|
2454
|
+
meta_line = " · ".join(meta_bits)
|
|
2455
|
+
|
|
2456
|
+
# 图表并入核验报告(1.4.0 一体化):有图表数据且包内 ECharts 可用时,
|
|
2457
|
+
# 图表并入核验报告(1.4.0 一体化)——交付物始终是**一个** HTML,不再另出独立图表报告。
|
|
2458
|
+
# 位置按 metadata.section 锚点插进对应章节(图表跟着它展示的数据走);锚点缺失或不匹配
|
|
2459
|
+
# 才退化为核验报告单之后的独立"数据可视化"章节。资源缺失或数据不可用则整块不渲染
|
|
2460
|
+
# (不出现空白图,也不阻断报告生成)。
|
|
2461
|
+
charts_html = ""
|
|
2462
|
+
charts_script = ""
|
|
2463
|
+
chart_toc = ""
|
|
2464
|
+
charts_by_section: Dict[int, str] = {}
|
|
2465
|
+
if charts_data:
|
|
2466
|
+
echarts_src = chart_embed.load_echarts_source()
|
|
2467
|
+
if not echarts_src:
|
|
2468
|
+
print(f"提示:未找到 {chart_embed.ECHARTS_RESOURCE},本次不生成图表章节(报告其余部分不受影响)。",
|
|
2469
|
+
file=sys.stderr)
|
|
2470
|
+
charts = chart_embed.build_charts(charts_data) if echarts_src else []
|
|
2471
|
+
if echarts_src and not charts:
|
|
2472
|
+
print("提示:图表数据不足以成图(需 ≥2 个数据点/系列),本次不生成图表章节。", file=sys.stderr)
|
|
2473
|
+
if charts:
|
|
2474
|
+
chart_meta = charts_data.get("metadata") or {}
|
|
2475
|
+
chart_title = str(chart_meta.get("title") or "").strip() or "数据可视化"
|
|
2476
|
+
note = '<p class="chart-note">图表由已核验材料数据生成,点击图例或数据项可跳转对应来源原文。</p>'
|
|
2477
|
+
blocks = chart_embed.render_blocks(charts)
|
|
2478
|
+
# 图表跟着它展示的数据所在的章节走(1.4.0):metadata.section 指定章节号/标题,
|
|
2479
|
+
# 命中就插进该章节正文之后;未指定或匹配不上,才退化为独立的"数据可视化"章节
|
|
2480
|
+
# (放在核验报告单之后、正文之前,作为总体摘要,不再堆到报告最末尾)。
|
|
2481
|
+
anchor_idx = resolve_chart_anchor(sections, chart_meta.get("section"))
|
|
2482
|
+
if anchor_idx:
|
|
2483
|
+
charts_by_section[anchor_idx] = (
|
|
2484
|
+
f'<div class="chart-inline" aria-label="数据可视化">'
|
|
2485
|
+
f'<h3 class="chart-h3">{esc(chart_title)}</h3>{note}{blocks}</div>'
|
|
2486
|
+
)
|
|
2487
|
+
else:
|
|
2488
|
+
charts_html = (
|
|
2489
|
+
f'<section class="chart-section" id="chart-block" aria-label="数据可视化">'
|
|
2490
|
+
f'<h2 class="chart-h2">{esc(chart_title)}</h2>{note}{blocks}</section>'
|
|
2491
|
+
)
|
|
2492
|
+
chart_toc = f'<a href="#chart-block">{esc(short(chart_title, 16))}</a>'
|
|
2493
|
+
if chart_meta.get("section"):
|
|
2494
|
+
print(f"提示:图表锚点「{chart_meta.get('section')}」在正文里找不到对应章节,"
|
|
2495
|
+
f"已改为独立章节呈现。", file=sys.stderr)
|
|
2496
|
+
charts_script = chart_embed.render_script(charts, echarts_src)
|
|
2497
|
+
|
|
2498
|
+
return f"""<!doctype html>
|
|
2499
|
+
<html lang="zh-CN">
|
|
2500
|
+
<head>
|
|
2501
|
+
<meta charset="utf-8">
|
|
2502
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2503
|
+
<title>{esc(display_title)} · 溯源核验报告</title>
|
|
2504
|
+
<style>{PAGE_CSS}</style>
|
|
2505
|
+
</head>
|
|
2506
|
+
<body>
|
|
2507
|
+
|
|
2508
|
+
<header class="topbar">
|
|
2509
|
+
<div class="tb-left">
|
|
2510
|
+
<span class="tb-stamp">溯源核验报告</span>
|
|
2511
|
+
<span class="tb-title">{esc(display_title)}</span>
|
|
2512
|
+
</div>
|
|
2513
|
+
<div class="tb-right">
|
|
2514
|
+
<div class="view-switch" role="tablist" aria-label="视图切换">
|
|
2515
|
+
<button class="on" data-view="report" type="button">核验报告</button>
|
|
2516
|
+
<button data-view="library" type="button">知识专库</button>
|
|
2517
|
+
</div>
|
|
2518
|
+
<div class="tb-tools">
|
|
2519
|
+
<button id="btn-reading" type="button" aria-pressed="false" title="隐藏核验元素,纯阅读正文">只看正文</button>
|
|
2520
|
+
<button id="btn-copy" type="button" title="复制正文纯文本">复制全文</button>
|
|
2521
|
+
<span class="print-menu">
|
|
2522
|
+
<button id="btn-print" type="button" aria-haspopup="true" title="浏览器打印/另存为 PDF">打印归档 ▾</button>
|
|
2523
|
+
<span class="print-drop" id="print-drop" hidden>
|
|
2524
|
+
<button id="print-body" type="button">只打印正文</button>
|
|
2525
|
+
<button id="print-full" type="button">完整归档(含来源文章)</button>
|
|
2526
|
+
</span>
|
|
2527
|
+
</span>
|
|
2528
|
+
</div>
|
|
2529
|
+
</div>
|
|
2530
|
+
<div class="progress" aria-hidden="true"><i></i></div>
|
|
2531
|
+
</header>
|
|
2532
|
+
|
|
2533
|
+
<div class="hero">
|
|
2534
|
+
<div class="r-badge">溯源核验报告</div>
|
|
2535
|
+
<h1>{esc(display_title)}</h1>
|
|
2536
|
+
<div class="meta">{esc(meta_line)} | 素材来源:深知可信搜索</div>
|
|
2537
|
+
<div class="hero-switch">
|
|
2538
|
+
<div class="view-switch" role="tablist" aria-label="视图切换">
|
|
2539
|
+
<button class="on" data-view="report" type="button">核验报告</button>
|
|
2540
|
+
<button data-view="library" type="button">知识专库({len(sources)})</button>
|
|
2541
|
+
</div>
|
|
2542
|
+
</div>
|
|
2543
|
+
</div>
|
|
2544
|
+
|
|
2545
|
+
<div class="app container" data-view="report">
|
|
2546
|
+
{render_process_bar(process_stats, verification)}
|
|
2547
|
+
|
|
2548
|
+
<main class="view" id="view-report" aria-label="核验报告正文">
|
|
2549
|
+
{citation_warning}
|
|
2550
|
+
{render_verify_panel(verification)}
|
|
2551
|
+
{charts_html}
|
|
2552
|
+
<div class="doc-paper">
|
|
2553
|
+
{render_section_cards(sections, sources, charts_by_section)}
|
|
2554
|
+
</div>
|
|
2555
|
+
<div class="foot">深知可信搜索 · 溯源核验报告 | 内容由 AI 生成,仅供参考</div>
|
|
2556
|
+
</main>
|
|
2557
|
+
|
|
2558
|
+
{render_library_view(sources, hot_terms)}
|
|
2559
|
+
{render_print_appendix(sources)}
|
|
2560
|
+
</div>
|
|
2561
|
+
|
|
2562
|
+
{render_toc(sections, chart_toc)}
|
|
2563
|
+
|
|
2564
|
+
<div class="ev-panel" id="ev-pop" hidden></div>
|
|
2565
|
+
{jb_tables_script}<div class="sheet-mask" aria-hidden="true"></div>
|
|
2566
|
+
<div class="sheet" role="dialog" aria-label="来源文章">
|
|
2567
|
+
<div class="sheet-grab"></div>
|
|
2568
|
+
<div class="sheet-head"><b>依据对照</b><button class="sheet-close" type="button">收起</button></div>
|
|
2569
|
+
<div class="sheet-body"></div>
|
|
2570
|
+
</div>
|
|
2571
|
+
|
|
2572
|
+
<script>{PAGE_JS}</script>
|
|
2573
|
+
{charts_script}
|
|
1544
2574
|
</body>
|
|
1545
2575
|
</html>"""
|
|
1546
2576
|
|
|
1547
2577
|
|
|
2578
|
+
def renumber_citations(answer: str, sources: List[Dict[str, str]]) -> Tuple[str, List[Dict[str, str]]]:
|
|
2579
|
+
"""把答案角标按首次出现顺序重排为 [1][2][3]…,材料卡同步重编号。
|
|
2580
|
+
|
|
2581
|
+
被引用的材料按新编号排在前面(编号与正文角标一一对应,used=True);
|
|
2582
|
+
未引用召回材料移入"未引用素材"分组(used=False,不占角标编号,锚点用独立递增号)。
|
|
2583
|
+
"""
|
|
2584
|
+
cited_order = citation_ids(answer)
|
|
2585
|
+
if not cited_order:
|
|
2586
|
+
for s in sources:
|
|
2587
|
+
s["used"] = False
|
|
2588
|
+
return answer, sources
|
|
2589
|
+
mapping = {old: str(new) for new, old in enumerate(cited_order, start=1)}
|
|
2590
|
+
answer = re.sub(r"\[(\d+)\]", lambda m: "[" + mapping.get(m.group(1), m.group(1)) + "]", answer)
|
|
2591
|
+
by_old: Dict[str, Dict[str, str]] = {}
|
|
2592
|
+
for s in sources:
|
|
2593
|
+
by_old.setdefault(s["id"], s)
|
|
2594
|
+
cited_sorted: List[Dict[str, str]] = []
|
|
2595
|
+
for old in cited_order:
|
|
2596
|
+
s = by_old.get(old)
|
|
2597
|
+
if s is None:
|
|
2598
|
+
continue
|
|
2599
|
+
s2 = dict(s)
|
|
2600
|
+
s2["id"] = mapping[old]
|
|
2601
|
+
s2["used"] = True
|
|
2602
|
+
cited_sorted.append(s2)
|
|
2603
|
+
next_panel = len(mapping)
|
|
2604
|
+
rest: List[Dict[str, str]] = []
|
|
2605
|
+
for s in sources:
|
|
2606
|
+
if s["id"] in mapping:
|
|
2607
|
+
continue
|
|
2608
|
+
next_panel += 1
|
|
2609
|
+
s2 = dict(s)
|
|
2610
|
+
s2["used"] = False
|
|
2611
|
+
# 未引用材料 id 一并改为面板锚点号,避免旧编号与重排后的角标空间撞号
|
|
2612
|
+
s2["id"] = str(next_panel)
|
|
2613
|
+
rest.append(s2)
|
|
2614
|
+
return answer, cited_sorted + rest
|
|
2615
|
+
|
|
2616
|
+
|
|
1548
2617
|
def align_sources_to_answer(answer: str, sources: List[Dict[str, str]]) -> List[Dict[str, str]]:
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
2618
|
+
"""不再按位置给材料重编号。
|
|
2619
|
+
|
|
2620
|
+
对齐公文写作 3.7.4 修复:原实现会在"正文角标与素材 id 完全不相交"时按顺序把素材改号
|
|
2621
|
+
迎合角标——正文写 [7] 而只有 1 篇来源文章时,会被洗成"✓ 引用对应 1/1",与
|
|
2622
|
+
"未绑定角标绝不按位置猜测"的核验诚实性原则相反。现如实返回原素材,由核验单报未绑定。
|
|
2623
|
+
角标 1..N 的连续重排由 renumber_citations 独立完成(按首现顺序,1.1.5 用户要求)。
|
|
2624
|
+
"""
|
|
2625
|
+
return sources
|
|
2626
|
+
|
|
2627
|
+
|
|
2628
|
+
def resolve_charts_data(value: str) -> Optional[Dict[str, Any]]:
|
|
2629
|
+
"""解析 --charts-json:支持直接内联 JSON,也支持 official-docs/search-results/ 内的文件名。
|
|
2630
|
+
|
|
2631
|
+
非法/为空一律返回 None(图表章节不渲染),绝不因此阻断核验报告生成——
|
|
2632
|
+
报告的核验正文是主交付,图表是附加视图。
|
|
2633
|
+
"""
|
|
2634
|
+
raw = (value or "").strip()
|
|
2635
|
+
if not raw:
|
|
2636
|
+
return None
|
|
2637
|
+
try:
|
|
2638
|
+
if raw.startswith("{"):
|
|
2639
|
+
data = json.loads(raw)
|
|
2640
|
+
else:
|
|
2641
|
+
data = json.loads(_safe_input_path(raw, {".json"}).read_text(encoding="utf-8"))
|
|
2642
|
+
except (ValueError, OSError, json.JSONDecodeError) as exc:
|
|
2643
|
+
print(f"提示:图表数据无法读取({exc}),本次不生成图表章节。", file=sys.stderr)
|
|
2644
|
+
return None
|
|
2645
|
+
return data if isinstance(data, dict) else None
|
|
2646
|
+
|
|
2647
|
+
|
|
2648
|
+
def _next_version_path(path: Path) -> Path:
|
|
2649
|
+
"""输出文件已存在时不覆盖(1.4.0,用户决策):自动改为 原名_v2 / _v3 … 另存。
|
|
2650
|
+
|
|
2651
|
+
追加图表/修改答案后重跑渲染时,旧版本保留、新版本号递增——不覆盖已交付内容,
|
|
2652
|
+
也不会再靠宿主目录里的 "名字 (2)" 兜底。命名与 deliver_outputs.py 的重名规则一致。
|
|
2653
|
+
"""
|
|
2654
|
+
if not path.exists():
|
|
2655
|
+
return path
|
|
2656
|
+
for index in range(2, 100):
|
|
2657
|
+
candidate = path.with_name(f"{path.stem}_v{index}{path.suffix}")
|
|
2658
|
+
if not candidate.exists():
|
|
2659
|
+
print(f"提示:{path.name} 已存在,本次输出改为 {candidate.name}(不覆盖旧版,用户决策 1.4.0)。")
|
|
2660
|
+
return candidate
|
|
2661
|
+
raise SystemExit(f"错误:{path.name} 的版本号 _v2~_v99 均已占用,请清理 {path.parent} 后重试。")
|
|
1564
2662
|
|
|
1565
2663
|
|
|
1566
2664
|
def main() -> None:
|
|
1567
|
-
parser = argparse.ArgumentParser(description="生成溯源核验报告 HTML")
|
|
2665
|
+
parser = argparse.ArgumentParser(description="生成溯源核验报告 HTML(深知可信搜索 SkillHub 版)")
|
|
1568
2666
|
parser.add_argument("input_json", help="trusted_search.py / deep_query.py 的 --json-only 输出 JSON")
|
|
1569
2667
|
parser.add_argument("--output", help="输出 HTML 文件名(official-docs/output/);不传时按问题自动生成《标题_溯源核验报告_时间戳.html》")
|
|
1570
2668
|
parser.add_argument("--title", default="溯源核验报告", help="页面标题")
|
|
@@ -1572,6 +2670,9 @@ def main() -> None:
|
|
|
1572
2670
|
parser.add_argument("--clean-md-output", help="输出干净 Markdown 路径;内容来自同一份最终答案,并移除 [1]、【1】等溯源角标。")
|
|
1573
2671
|
parser.add_argument("--question", default="", help="用户原始问题,用于自动生成文件名。")
|
|
1574
2672
|
parser.add_argument("--self-check-file", help="答案自检结果 JSON(五项:fact_basis/binding/consistency/freshness/no_gap,值写 通过/未通过:原因);未传时核验单如实显示'未记录'。")
|
|
2673
|
+
parser.add_argument("--skip-link-check", action="store_true", help="跳过原文链接活性检测(默认检测:404/410/软404 标记失效,连接失败/403 保守放行)")
|
|
2674
|
+
parser.add_argument("--no-snapshot", action="store_true", help="关闭存档快照兜底展示(默认启用:原文失效时以 /A/ 修订后的存档快照回看)")
|
|
2675
|
+
parser.add_argument("--charts-json", help="图表数据:official-docs/search-results/ 内的 JSON 文件名,或直接内联 JSON。传入后图表并入本报告(一体化,不另出独立 HTML)。")
|
|
1575
2676
|
args = parser.parse_args()
|
|
1576
2677
|
|
|
1577
2678
|
input_path = _safe_input_path(args.input_json, {".json"})
|
|
@@ -1587,16 +2688,18 @@ def main() -> None:
|
|
|
1587
2688
|
if isinstance(check_data, dict):
|
|
1588
2689
|
unwrap(payload)["selfCheck"] = check_data
|
|
1589
2690
|
|
|
1590
|
-
|
|
2691
|
+
snapshot_enabled = not args.no_snapshot
|
|
1591
2692
|
unwrapped = unwrap(payload)
|
|
1592
2693
|
final_answer = normalize_citations(answer_override) if answer_override.strip() else extract_answer(unwrapped)
|
|
1593
|
-
|
|
2694
|
+
|
|
2695
|
+
# 生成前硬校验:核验报告必须以可交付状态产出——无角标或角标未绑定材料均拒绝生成
|
|
2696
|
+
preview_sources = extract_sources(unwrapped, skip_link_check=True, snapshot_enabled=snapshot_enabled)
|
|
1594
2697
|
preview_cited = citation_ids(final_answer)
|
|
1595
2698
|
if preview_sources and not preview_cited:
|
|
1596
2699
|
print(
|
|
1597
2700
|
"错误:生成检查未通过——已召回 "
|
|
1598
|
-
f"{len(preview_sources)}
|
|
1599
|
-
"请修正最终答案(--answer-file
|
|
2701
|
+
f"{len(preview_sources)} 篇来源文章,但答案中没有 [1]、[2] 等来源角标,无法建立\"结论-来源文章\"核验对应。\n"
|
|
2702
|
+
"请修正最终答案(--answer-file):在关键结论后标注角标并逐条对应来源文章,然后重新运行本脚本。",
|
|
1600
2703
|
file=sys.stderr,
|
|
1601
2704
|
)
|
|
1602
2705
|
raise SystemExit(1)
|
|
@@ -1605,9 +2708,9 @@ def main() -> None:
|
|
|
1605
2708
|
if unbound_preview:
|
|
1606
2709
|
shown = "、".join(f"[{c}]" for c in unbound_preview[:8])
|
|
1607
2710
|
print(
|
|
1608
|
-
f"错误:生成检查未通过——答案角标 {shown}
|
|
2711
|
+
f"错误:生成检查未通过——答案角标 {shown} 未绑定到任何来源文章"
|
|
1609
2712
|
f"(共召回 {len(preview_sources)} 条,可绑定编号 {min(preview_ids) if preview_ids else '-'}~{max(preview_ids) if preview_ids else '-'})。\n"
|
|
1610
|
-
"
|
|
2713
|
+
"请修正最终答案:角标必须逐条对应实际引用的来源文章,然后重新运行本脚本。",
|
|
1611
2714
|
file=sys.stderr,
|
|
1612
2715
|
)
|
|
1613
2716
|
raise SystemExit(1)
|
|
@@ -1619,13 +2722,19 @@ def main() -> None:
|
|
|
1619
2722
|
else:
|
|
1620
2723
|
output = _safe_output_path(safe_output_filename(question, generated_at), {".html", ".htm"}, ".html")
|
|
1621
2724
|
|
|
2725
|
+
output = _next_version_path(output)
|
|
1622
2726
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
1623
|
-
output.write_text(
|
|
2727
|
+
output.write_text(
|
|
2728
|
+
render_html(payload, args.title, answer_override=answer_override, question_override=args.question,
|
|
2729
|
+
generated_at=generated_at, skip_link_check=args.skip_link_check,
|
|
2730
|
+
snapshot_enabled=snapshot_enabled, charts_data=resolve_charts_data(args.charts_json)),
|
|
2731
|
+
encoding="utf-8")
|
|
1624
2732
|
print(f"已生成:{output}")
|
|
1625
2733
|
if args.clean_md_output:
|
|
1626
2734
|
clean_output = _safe_output_path(args.clean_md_output, {".md"}, ".md")
|
|
1627
2735
|
else:
|
|
1628
2736
|
clean_output = _safe_output_path(output.with_suffix(".clean.md").name, {".md"}, ".md")
|
|
2737
|
+
clean_output = _next_version_path(clean_output)
|
|
1629
2738
|
clean_output.parent.mkdir(parents=True, exist_ok=True)
|
|
1630
2739
|
clean_answer = strip_citation_markers(final_answer)
|
|
1631
2740
|
clean_output.write_text(clean_answer, encoding="utf-8")
|