visualize_how_results.py 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. How解构结果可视化脚本 V2
  5. 改进版:
  6. - 使用标签页展示多个帖子
  7. - 参考 visualize_inspiration_points.py 的帖子详情展示
  8. - 分层可折叠的匹配结果
  9. """
  10. import json
  11. from pathlib import Path
  12. from typing import Dict, List
  13. import sys
  14. import html as html_module
  15. # 添加项目根目录到路径
  16. project_root = Path(__file__).parent.parent.parent
  17. sys.path.insert(0, str(project_root))
  18. # 注意:已改用基于相似度的显示方式,不再使用关系类型
  19. # def get_relation_color(relation: str) -> str:
  20. # """根据关系类型返回对应的颜色"""
  21. # color_map = {
  22. # "same": "#10b981", # 绿色 - 同义
  23. # "contains": "#3b82f6", # 蓝色 - 包含
  24. # "contained_by": "#8b5cf6", # 紫色 - 被包含
  25. # "coordinate": "#f59e0b", # 橙色 - 同级
  26. # "overlap": "#ec4899", # 粉色 - 部分重叠
  27. # "related": "#6366f1", # 靛蓝 - 相关
  28. # "unrelated": "#9ca3af" # 灰色 - 无关
  29. # }
  30. # return color_map.get(relation, "#9ca3af")
  31. #
  32. #
  33. # def get_relation_label(relation: str) -> str:
  34. # """返回关系类型的中文标签"""
  35. # label_map = {
  36. # "same": "同义",
  37. # "contains": "包含",
  38. # "contained_by": "被包含",
  39. # "coordinate": "同级",
  40. # "overlap": "部分重叠",
  41. # "related": "相关",
  42. # "unrelated": "无关"
  43. # }
  44. # return label_map.get(relation, relation)
  45. def generate_historical_post_card_html(post_detail: Dict, inspiration_point: Dict) -> str:
  46. """生成历史帖子的紧凑卡片HTML"""
  47. title = post_detail.get("title", "无标题")
  48. body_text = post_detail.get("body_text", "")
  49. images = post_detail.get("images", [])
  50. like_count = post_detail.get("like_count", 0)
  51. collect_count = post_detail.get("collect_count", 0)
  52. comment_count = post_detail.get("comment_count", 0)
  53. author = post_detail.get("channel_account_name", "")
  54. link = post_detail.get("link", "#")
  55. publish_time = post_detail.get("publish_time", "")
  56. # 获取灵感点信息
  57. point_name = inspiration_point.get("点的名称", "")
  58. point_desc = inspiration_point.get("点的描述", "")
  59. # 准备详情数据(用于模态框)
  60. import json
  61. post_detail_data = {
  62. "title": title,
  63. "body_text": body_text,
  64. "images": images,
  65. "like_count": like_count,
  66. "comment_count": comment_count,
  67. "collect_count": collect_count,
  68. "author": author,
  69. "publish_time": publish_time,
  70. "link": link
  71. }
  72. post_data_json = json.dumps(post_detail_data, ensure_ascii=False)
  73. post_data_json_escaped = html_module.escape(post_data_json)
  74. # 截取正文预览(前80个字符)
  75. body_preview = body_text[:80] + "..." if len(body_text) > 80 else body_text
  76. # 生成缩略图
  77. thumbnail_html = ""
  78. if images:
  79. thumbnail_html = f'<img src="{images[0]}" alt="Post thumbnail" class="historical-post-thumbnail" loading="lazy">'
  80. html = f'''
  81. <div class="historical-post-card" data-post-data='{post_data_json_escaped}' onclick="showPostDetail(this)">
  82. <div class="historical-post-image">
  83. {thumbnail_html}
  84. {f'<div class="post-card-image-count">{len(images)}</div>' if len(images) > 1 else ''}
  85. </div>
  86. <div class="historical-post-content">
  87. <div class="historical-post-title">{html_module.escape(title)}</div>
  88. <div class="historical-inspiration-info">
  89. <span class="inspiration-type-badge-small">灵感点</span>
  90. <span class="inspiration-name-small">{html_module.escape(point_name)}</span>
  91. </div>
  92. <div class="historical-inspiration-desc">{html_module.escape(point_desc[:100])}{"..." if len(point_desc) > 100 else ""}</div>
  93. <div class="historical-post-meta">
  94. <span class="historical-post-time">📅 {publish_time}</span>
  95. </div>
  96. <div class="historical-post-stats">
  97. <span>❤ {like_count}</span>
  98. <span>⭐ {collect_count}</span>
  99. <a href="{link}" target="_blank" class="view-link" onclick="event.stopPropagation()">查看原帖 →</a>
  100. </div>
  101. </div>
  102. </div>
  103. '''
  104. return html
  105. def generate_post_detail_html(post_data: Dict, post_idx: int) -> str:
  106. """生成帖子详情HTML(紧凑的卡片样式,点击可展开)"""
  107. post_detail = post_data.get("帖子详情", {})
  108. title = post_detail.get("title", "无标题")
  109. body_text = post_detail.get("body_text", "")
  110. images = post_detail.get("images", [])
  111. like_count = post_detail.get("like_count", 0)
  112. comment_count = post_detail.get("comment_count", 0)
  113. collect_count = post_detail.get("collect_count", 0)
  114. author = post_detail.get("channel_account_name", "")
  115. publish_time = post_detail.get("publish_time", "")
  116. link = post_detail.get("link", "")
  117. post_id = post_data.get("帖子id", f"post-{post_idx}")
  118. # 准备详情数据(用于模态框)
  119. import json
  120. post_detail_data = {
  121. "title": title,
  122. "body_text": body_text,
  123. "images": images,
  124. "like_count": like_count,
  125. "comment_count": comment_count,
  126. "collect_count": collect_count,
  127. "author": author,
  128. "publish_time": publish_time,
  129. "link": link
  130. }
  131. post_data_json = json.dumps(post_detail_data, ensure_ascii=False)
  132. post_data_json_escaped = html_module.escape(post_data_json)
  133. # 生成缩略图HTML
  134. thumbnail_html = ""
  135. if images and len(images) > 0:
  136. # 使用第一张图片作为缩略图
  137. thumbnail_html = f'<img src="{images[0]}" class="post-card-thumbnail" alt="缩略图">'
  138. else:
  139. thumbnail_html = '<div class="post-card-thumbnail-placeholder">📄</div>'
  140. # 截断正文用于预览
  141. body_preview = body_text[:80] + "..." if len(body_text) > 80 else body_text
  142. html = f'''
  143. <div class="post-card-compact" data-post-data='{post_data_json_escaped}' onclick="showPostDetail(this)">
  144. <div class="post-card-image">
  145. {thumbnail_html}
  146. {f'<div class="post-card-image-count">📷 {len(images)}</div>' if len(images) > 1 else ''}
  147. </div>
  148. <div class="post-card-content">
  149. <div class="post-card-title">{html_module.escape(title)}</div>
  150. <div class="post-card-preview">{html_module.escape(body_preview) if body_preview else "暂无正文"}</div>
  151. <div class="post-card-meta">
  152. <span class="post-card-author">👤 {html_module.escape(author)}</span>
  153. <span class="post-card-time">📅 {publish_time}</span>
  154. </div>
  155. <div class="post-card-stats">
  156. <span>👍 {like_count}</span>
  157. <span>💬 {comment_count if comment_count else 0}</span>
  158. <span>⭐ {collect_count if collect_count else 0}</span>
  159. </div>
  160. </div>
  161. </div>
  162. '''
  163. return html
  164. def generate_inspiration_detail_html(inspiration_point: Dict, feature_status_map: Dict[str, str] = None) -> str:
  165. """生成灵感点详情HTML
  166. Args:
  167. inspiration_point: 灵感点数据
  168. feature_status_map: 特征名称到状态的映射 {特征名称: "相同"|"相似"|"无关"}
  169. """
  170. name = inspiration_point.get("名称", "")
  171. desc = inspiration_point.get("描述", "")
  172. features = inspiration_point.get("特征列表", [])
  173. if feature_status_map is None:
  174. feature_status_map = {}
  175. # 计算该灵感点的整体结论
  176. feature_statuses = []
  177. features_html_list = []
  178. for f in features:
  179. feature_name = f if isinstance(f, str) else f.get("特征名称", "")
  180. weight = f.get("权重", 1.0) if isinstance(f, dict) else 1.0
  181. # 获取该特征的状态
  182. status = feature_status_map.get(feature_name, "无关")
  183. feature_statuses.append(status)
  184. if status == "相同":
  185. status_class = "feature-same"
  186. status_label = "相同"
  187. elif status == "相似":
  188. status_class = "feature-similar"
  189. status_label = "相似"
  190. else:
  191. status_class = "feature-unrelated"
  192. status_label = "无关"
  193. features_html_list.append(
  194. f'<span class="feature-tag {status_class}">'
  195. f'<span class="feature-status-label">{status_label}</span> '
  196. f'{html_module.escape(feature_name)} '
  197. f'<span class="feature-weight">({weight})</span>'
  198. f'</span>'
  199. )
  200. features_html = "".join(features_html_list)
  201. # 计算灵感点结论
  202. has_same = "相同" in feature_statuses
  203. has_similar = "相似" in feature_statuses
  204. has_unrelated = "无关" in feature_statuses
  205. if not has_unrelated:
  206. # 没有无关的 -> 找到
  207. insp_conclusion = "找到"
  208. insp_conclusion_class = "insp-conclusion-found"
  209. elif has_same or has_similar:
  210. # 有相同或相似,但也有无关 -> 部分找到
  211. insp_conclusion = "部分找到"
  212. insp_conclusion_class = "insp-conclusion-partial"
  213. else:
  214. # 都是无关 -> 都找不到
  215. insp_conclusion = "都找不到"
  216. insp_conclusion_class = "insp-conclusion-not-found"
  217. html = f'''
  218. <div class="inspiration-detail-card">
  219. <div class="inspiration-header">
  220. <span class="inspiration-type-badge">灵感点</span>
  221. <h3 class="inspiration-name">{html_module.escape(name)}</h3>
  222. <span class="inspiration-conclusion {insp_conclusion_class}">{insp_conclusion}</span>
  223. </div>
  224. <div class="inspiration-description">
  225. <div class="desc-label">描述:</div>
  226. <div class="desc-text">{html_module.escape(desc)}</div>
  227. </div>
  228. <div class="inspiration-features">
  229. <div class="features-label">特征列表:</div>
  230. <div class="features-tags">{features_html}</div>
  231. </div>
  232. </div>
  233. '''
  234. return html
  235. def load_feature_category_mapping() -> Dict:
  236. """加载特征名称到分类的映射"""
  237. script_dir = Path(__file__).parent
  238. project_root = script_dir.parent.parent
  239. mapping_file = project_root / "data" / "data_1118" / "特征名称_分类映射.json"
  240. try:
  241. with open(mapping_file, "r", encoding="utf-8") as f:
  242. return json.load(f)
  243. except Exception as e:
  244. print(f"警告: 无法加载特征分类映射文件: {e}")
  245. return {}
  246. def load_feature_source_mapping() -> Dict:
  247. """加载特征名称到帖子来源的映射"""
  248. script_dir = Path(__file__).parent
  249. project_root = script_dir.parent.parent
  250. mapping_file = project_root / "data" / "data_1118" / "特征名称_帖子来源.json"
  251. try:
  252. with open(mapping_file, "r", encoding="utf-8") as f:
  253. data = json.load(f)
  254. # 转换为便于查询的格式: {特征名称: [来源列表]}
  255. result = {}
  256. for feature_type in ["灵感点", "关键点", "目的点"]:
  257. if feature_type in data:
  258. for item in data[feature_type]:
  259. feature_name = item.get("特征名称")
  260. if feature_name:
  261. result[feature_name] = item.get("特征来源", [])
  262. return result
  263. except Exception as e:
  264. print(f"警告: 无法加载特征来源映射文件: {e}")
  265. return {}
  266. def generate_single_match_html(match: Dict, match_idx: int, post_idx: int, insp_idx: int, feature_idx: int, category_mapping: Dict = None, source_mapping: Dict = None) -> str:
  267. """生成单个匹配项的HTML
  268. Args:
  269. match: 单个匹配数据
  270. match_idx: 匹配项索引
  271. post_idx: 帖子索引
  272. insp_idx: 灵感点索引
  273. feature_idx: 特征索引
  274. category_mapping: 特征分类映射
  275. source_mapping: 特征来源映射
  276. """
  277. persona_name = match.get("人设特征名称", "")
  278. feature_type = match.get("特征类型", "")
  279. feature_categories = match.get("特征分类", [])
  280. match_result = match.get("匹配结果", {})
  281. similarity = match_result.get("相似度", 0.0)
  282. explanation = match_result.get("说明", "")
  283. # 根据相似度确定颜色和标签
  284. if similarity >= 0.9:
  285. color = "#10b981" # 绿色 - 相同
  286. label = "相同"
  287. elif similarity >= 0.8:
  288. color = "#f59e0b" # 橙色 - 相似
  289. label = "相似"
  290. else:
  291. color = "#9ca3af" # 灰色 - 无关
  292. label = "无关"
  293. match_id = f"post-{post_idx}-insp-{insp_idx}-feat-{feature_idx}-match-{match_idx}"
  294. # 生成特征类型和分类标签
  295. type_badge_html = ""
  296. if feature_type:
  297. type_badge_html = f'<span class="feature-type-badge">{html_module.escape(feature_type)}</span>'
  298. categories_badge_html = ""
  299. if feature_categories:
  300. categories_text = " / ".join(feature_categories)
  301. categories_badge_html = f'<span class="feature-category-badge">{html_module.escape(categories_text)}</span>'
  302. # 获取该人设特征的分类信息
  303. categories_html = ""
  304. if category_mapping and persona_name:
  305. found_categories = None
  306. # 依次在灵感点、关键点、目的点中查找
  307. for persona_type in ["灵感点", "关键点", "目的点"]:
  308. if persona_type in category_mapping:
  309. type_mapping = category_mapping[persona_type]
  310. if persona_name in type_mapping:
  311. found_categories = type_mapping[persona_name].get("所属分类", [])
  312. break
  313. if found_categories:
  314. # 简洁样式:[大类/中类/小类]
  315. categories_reversed = list(reversed(found_categories))
  316. categories_text = "/".join(categories_reversed)
  317. categories_html = f'<span class="category-simple">[{html_module.escape(categories_text)}]</span>'
  318. # 获取该人设特征的历史帖子来源
  319. historical_posts_html = ""
  320. if source_mapping and persona_name and persona_name in source_mapping:
  321. source_list = source_mapping[persona_name]
  322. if source_list:
  323. historical_cards = []
  324. for source_item in source_list:
  325. post_detail = source_item.get("帖子详情", {})
  326. if post_detail:
  327. card_html = generate_historical_post_card_html(post_detail, source_item)
  328. historical_cards.append(card_html)
  329. if historical_cards:
  330. historical_posts_html = f'''
  331. <div class="historical-posts-section">
  332. <h4 class="historical-posts-title">历史帖子来源</h4>
  333. <div class="historical-posts-grid">
  334. {"".join(historical_cards)}
  335. </div>
  336. </div>
  337. '''
  338. # 生成历史帖子HTML
  339. historical_posts_html = ""
  340. if source_mapping and persona_name and persona_name in source_mapping:
  341. source_list = source_mapping[persona_name]
  342. if source_list:
  343. for source_item in source_list[:5]: # 最多5个
  344. post_detail = source_item.get("帖子详情", {})
  345. if post_detail:
  346. card_html = generate_historical_post_card_html(post_detail, source_item)
  347. historical_posts_html += card_html
  348. # 将数据编码到data属性中
  349. import html as html_encode
  350. data_explanation = html_encode.escape(explanation)
  351. data_historical = html_encode.escape(historical_posts_html)
  352. # 生成紧凑的匹配项HTML(可点击,弹出模态框)
  353. html = f'''
  354. <div class="match-item-compact"
  355. data-persona-name="{html_module.escape(persona_name)}"
  356. data-feature-type="{html_module.escape(feature_type)}"
  357. data-similarity="{similarity}"
  358. data-label="{label}"
  359. data-explanation="{data_explanation}"
  360. data-historical-posts="{data_historical}"
  361. onclick="showMatchDetail(this)">
  362. {type_badge_html}
  363. <span class="persona-name">{html_module.escape(persona_name)}</span>
  364. <span class="score-badge">相似度: {similarity:.2f}</span>
  365. <span class="relation-badge" style="background: {color};">{label}</span>
  366. </div>
  367. '''
  368. return html
  369. def generate_match_results_html(how_steps: List[Dict], feature_idx: int, insp_idx: int, post_idx: int, category_mapping: Dict = None, source_mapping: Dict = None) -> str:
  370. """生成可折叠的匹配结果HTML"""
  371. if not how_steps or len(how_steps) == 0:
  372. return ""
  373. step = how_steps[0]
  374. features = step.get("特征列表", [])
  375. if feature_idx >= len(features):
  376. return ""
  377. feature_data = features[feature_idx]
  378. feature_name = feature_data.get("特征名称", "")
  379. feature_weight = feature_data.get("权重", 1.0)
  380. match_results = feature_data.get("匹配结果", [])
  381. if category_mapping is None:
  382. category_mapping = {}
  383. # 按相似度排序
  384. sorted_matches = sorted(match_results, key=lambda x: x.get("匹配结果", {}).get("相似度", 0), reverse=True)
  385. # 找出最高相似度,确定状态
  386. max_similarity = 0.0
  387. if match_results:
  388. max_similarity = max(match.get("匹配结果", {}).get("相似度", 0) for match in match_results)
  389. # 根据最高相似度确定状态
  390. if max_similarity >= 0.9:
  391. status = "相同"
  392. status_class = "status-same"
  393. elif max_similarity >= 0.8:
  394. status = "相似"
  395. status_class = "status-similar"
  396. else:
  397. status = "无关"
  398. status_class = "status-unrelated"
  399. found_status_html = f'<span class="feature-match-status {status_class}">{status}</span>'
  400. # 统计相似度分布
  401. similarity_ranges = {
  402. "相同 (≥0.9)": 0,
  403. "相似 (0.8-0.9)": 0,
  404. "无关 (<0.8)": 0
  405. }
  406. for match in match_results:
  407. similarity = match.get("匹配结果", {}).get("相似度", 0)
  408. if similarity >= 0.9:
  409. similarity_ranges["相同 (≥0.9)"] += 1
  410. elif similarity >= 0.8:
  411. similarity_ranges["相似 (0.8-0.9)"] += 1
  412. else:
  413. similarity_ranges["无关 (<0.8)"] += 1
  414. # 生成统计信息
  415. stats_items = []
  416. range_colors = {
  417. "相同 (≥0.9)": "#10b981",
  418. "相似 (0.8-0.9)": "#f59e0b",
  419. "无关 (<0.8)": "#9ca3af"
  420. }
  421. for range_name, count in similarity_ranges.items():
  422. if count > 0:
  423. color = range_colors[range_name]
  424. stats_items.append(f'<span class="stat-badge" style="background: {color};">{range_name}: {count}</span>')
  425. stats_html = "".join(stats_items)
  426. # 按特征类型分组匹配项
  427. match_groups = {
  428. "标签": [],
  429. "分类": []
  430. }
  431. for i, match in enumerate(sorted_matches):
  432. feature_type = match.get("特征类型", "")
  433. if feature_type in match_groups:
  434. match_groups[feature_type].append((i, match))
  435. # 生成分组的匹配项HTML
  436. matches_html = ""
  437. # 先显示"标签"匹配结果
  438. if match_groups["标签"]:
  439. group_id = f"post-{post_idx}-insp-{insp_idx}-feat-{feature_idx}-group-label"
  440. group_matches_html = ""
  441. for i, match in match_groups["标签"]:
  442. match_html = generate_single_match_html(
  443. match, i, post_idx, insp_idx, feature_idx,
  444. category_mapping, source_mapping
  445. )
  446. group_matches_html += match_html
  447. matches_html += f'''
  448. <div class="match-group-section">
  449. <div class="match-group-header" onclick="toggleMatchGroup('{group_id}')">
  450. <span class="expand-icon" id="{group_id}-icon">▼</span>
  451. <h4 class="match-group-title">匹配标签 ({len(match_groups["标签"])})</h4>
  452. </div>
  453. <div class="match-group-content" id="{group_id}-content">
  454. {group_matches_html}
  455. </div>
  456. </div>
  457. '''
  458. # 再显示"分类"匹配结果
  459. if match_groups["分类"]:
  460. group_id = f"post-{post_idx}-insp-{insp_idx}-feat-{feature_idx}-group-category"
  461. group_matches_html = ""
  462. for i, match in match_groups["分类"]:
  463. match_html = generate_single_match_html(
  464. match, i, post_idx, insp_idx, feature_idx,
  465. category_mapping, source_mapping
  466. )
  467. group_matches_html += match_html
  468. matches_html += f'''
  469. <div class="match-group-section">
  470. <div class="match-group-header" onclick="toggleMatchGroup('{group_id}')">
  471. <span class="expand-icon" id="{group_id}-icon">▼</span>
  472. <h4 class="match-group-title">匹配分类 ({len(match_groups["分类"])})</h4>
  473. </div>
  474. <div class="match-group-content" id="{group_id}-content">
  475. {group_matches_html}
  476. </div>
  477. </div>
  478. '''
  479. section_id = f"post-{post_idx}-insp-{insp_idx}-feat-{feature_idx}-section"
  480. html = f'''
  481. <div class="match-results-section">
  482. <div class="match-section-header collapsible-header" onclick="toggleFeatureSection('{section_id}')">
  483. <div class="header-left">
  484. <span class="expand-icon" id="{section_id}-icon">▼</span>
  485. <h4>匹配结果: {html_module.escape(feature_name)} <span class="feature-weight-display">(权重: {feature_weight})</span></h4>
  486. {found_status_html}
  487. </div>
  488. <div class="match-stats">{stats_html}</div>
  489. </div>
  490. <div class="matches-list" id="{section_id}-content">
  491. {matches_html}
  492. </div>
  493. </div>
  494. '''
  495. return html
  496. def generate_toc_html(post_data: Dict, post_idx: int, feature_status_map: Dict[str, str] = None, overall_conclusion: str = "") -> str:
  497. """生成目录导航HTML
  498. Args:
  499. post_data: 帖子数据
  500. post_idx: 帖子索引
  501. feature_status_map: 特征名称到状态的映射 {特征名称: "相同"|"相似"|"无关"}
  502. overall_conclusion: 整体结论
  503. """
  504. how_result = post_data.get("how解构结果", {})
  505. inspiration_list = how_result.get("灵感点列表", [])
  506. if feature_status_map is None:
  507. feature_status_map = {}
  508. toc_items = []
  509. # 帖子详情
  510. toc_items.append(f'<div class="toc-item toc-level-1" onclick="scrollToSection(\'post-{post_idx}-detail\')"><span class="toc-badge toc-badge-post">帖子详情</span> 帖子信息</div>')
  511. # 灵感点
  512. for insp_idx, inspiration_point in enumerate(inspiration_list):
  513. name = inspiration_point.get("名称", f"灵感点 {insp_idx + 1}")
  514. name_short = name[:18] + "..." if len(name) > 18 else name
  515. toc_items.append(f'<div class="toc-item toc-level-1" onclick="scrollToSection(\'post-{post_idx}-insp-{insp_idx}\')"><span class="toc-badge toc-badge-inspiration">灵感点</span> {html_module.escape(name_short)}</div>')
  516. # 特征列表
  517. how_steps = inspiration_point.get("how步骤列表", [])
  518. if how_steps:
  519. features = how_steps[0].get("特征列表", [])
  520. for feat_idx, feature_data in enumerate(features):
  521. feature_name = feature_data.get("特征名称", f"特征 {feat_idx + 1}")
  522. # 获取状态
  523. status = feature_status_map.get(feature_name, "无关")
  524. if status == "相同":
  525. status_class = "toc-feature-same"
  526. status_label = "相同"
  527. elif status == "相似":
  528. status_class = "toc-feature-similar"
  529. status_label = "相似"
  530. else:
  531. status_class = "toc-feature-unrelated"
  532. status_label = "无关"
  533. toc_items.append(f'<div class="toc-item toc-level-2 {status_class}" onclick="scrollToSection(\'post-{post_idx}-feat-{insp_idx}-{feat_idx}\')"><span class="toc-badge toc-badge-feature">特征</span> {html_module.escape(feature_name)} <span class="toc-feature-status">{status_label}</span></div>')
  534. # 整体结论HTML
  535. conclusion_html = ""
  536. if overall_conclusion:
  537. if overall_conclusion == "找到":
  538. conclusion_class = "conclusion-found"
  539. conclusion_icon = "✓"
  540. elif overall_conclusion == "部分找到":
  541. conclusion_class = "conclusion-partial"
  542. conclusion_icon = "~"
  543. else: # 都找不到
  544. conclusion_class = "conclusion-not-found"
  545. conclusion_icon = "✗"
  546. conclusion_html = f'''
  547. <div class="toc-conclusion {conclusion_class}">
  548. <span class="conclusion-icon">{conclusion_icon}</span>
  549. <span class="conclusion-text">{overall_conclusion}</span>
  550. </div>
  551. '''
  552. return f'''
  553. <div class="toc-container">
  554. <div class="toc-header">目录导航</div>
  555. {conclusion_html}
  556. <div class="toc-content">
  557. {"".join(toc_items)}
  558. </div>
  559. </div>
  560. '''
  561. def generate_post_content_html(post_data: Dict, post_idx: int, category_mapping: Dict = None, source_mapping: Dict = None) -> str:
  562. """生成单个帖子的完整内容HTML"""
  563. # 2. 灵感点详情和匹配结果
  564. how_result = post_data.get("how解构结果", {})
  565. inspiration_list = how_result.get("灵感点列表", [])
  566. # 先计算所有特征的状态(基于最高相似度)
  567. feature_status_map = {} # {特征名称: "相同"|"相似"|"无关"}
  568. for inspiration_point in inspiration_list:
  569. how_steps = inspiration_point.get("how步骤列表", [])
  570. if how_steps:
  571. features = how_steps[0].get("特征列表", [])
  572. for feature_data in features:
  573. feature_name = feature_data.get("特征名称", "")
  574. match_results = feature_data.get("匹配结果", [])
  575. # 找出最高相似度
  576. max_similarity = 0.0
  577. if match_results:
  578. max_similarity = max(match.get("匹配结果", {}).get("相似度", 0) for match in match_results)
  579. # 根据最高相似度确定状态
  580. if max_similarity >= 0.9:
  581. feature_status_map[feature_name] = "相同"
  582. elif max_similarity >= 0.8:
  583. feature_status_map[feature_name] = "相似"
  584. else:
  585. feature_status_map[feature_name] = "无关"
  586. # 计算整体结论
  587. status_values = list(feature_status_map.values())
  588. has_same = "相同" in status_values
  589. has_similar = "相似" in status_values
  590. has_unrelated = "无关" in status_values
  591. if not has_unrelated:
  592. # 没有无关的 -> 找到
  593. overall_conclusion = "找到"
  594. elif has_same or has_similar:
  595. # 有相同或相似,但也有无关 -> 部分找到
  596. overall_conclusion = "部分找到"
  597. else:
  598. # 都是无关 -> 都找不到
  599. overall_conclusion = "都找不到"
  600. # 生成目录(传入状态映射和整体结论)
  601. toc_html = generate_toc_html(post_data, post_idx, feature_status_map, overall_conclusion)
  602. # 1. 帖子详情
  603. post_detail_html = generate_post_detail_html(post_data, post_idx)
  604. # 生成所有灵感点的详情HTML(传入状态映射)
  605. inspirations_detail_html = ""
  606. for insp_idx, inspiration_point in enumerate(inspiration_list):
  607. inspiration_detail = generate_inspiration_detail_html(inspiration_point, feature_status_map)
  608. inspirations_detail_html += f'''
  609. <div id="post-{post_idx}-insp-{insp_idx}" class="inspiration-detail-item content-section">
  610. {inspiration_detail}
  611. </div>
  612. '''
  613. # 生成所有匹配结果HTML,按照how步骤分组
  614. all_matches_html = ""
  615. for insp_idx, inspiration_point in enumerate(inspiration_list):
  616. inspiration_name = inspiration_point.get("名称", f"灵感点 {insp_idx + 1}")
  617. how_steps = inspiration_point.get("how步骤列表", [])
  618. if how_steps:
  619. # 为每个灵感点创建一个区域
  620. for step_idx, step in enumerate(how_steps):
  621. step_name = step.get("步骤名称", f"步骤 {step_idx + 1}")
  622. features = step.get("特征列表", [])
  623. # 生成该步骤下所有特征的匹配结果
  624. features_html = ""
  625. for feat_idx, feature_data in enumerate(features):
  626. match_html = generate_match_results_html([step], feat_idx, insp_idx, post_idx, category_mapping, source_mapping)
  627. features_html += f'<div id="post-{post_idx}-feat-{insp_idx}-{feat_idx}" class="feature-match-wrapper">{match_html}</div>'
  628. # 生成步骤区域(可折叠)
  629. step_section_id = f"post-{post_idx}-step-{insp_idx}-{step_idx}"
  630. all_matches_html += f'''
  631. <div class="step-section">
  632. <div class="step-header collapsible-header" onclick="toggleStepSection('{step_section_id}')">
  633. <div class="header-left">
  634. <span class="expand-icon" id="{step_section_id}-icon">▼</span>
  635. <h3 class="step-name">{html_module.escape(step_name)}</h3>
  636. </div>
  637. <span class="step-inspiration-name">来自: {html_module.escape(inspiration_name)}</span>
  638. </div>
  639. <div class="step-features-list" id="{step_section_id}-content">
  640. {features_html}
  641. </div>
  642. </div>
  643. '''
  644. html = f'''
  645. <div class="content-with-toc">
  646. {toc_html}
  647. <div class="main-content">
  648. <!-- 第一个框:左右分栏(帖子详情 + 灵感点详情) -->
  649. <div class="top-section-box">
  650. <div class="two-column-layout">
  651. <div class="left-column">
  652. <div id="post-{post_idx}-detail" class="post-detail-wrapper">
  653. {post_detail_html}
  654. </div>
  655. </div>
  656. <div class="right-column">
  657. <div class="inspirations-detail-wrapper">
  658. {inspirations_detail_html}
  659. </div>
  660. </div>
  661. </div>
  662. </div>
  663. <!-- 下面:所有匹配结果 -->
  664. <div class="matches-section">
  665. {all_matches_html}
  666. </div>
  667. </div>
  668. </div>
  669. '''
  670. return html
  671. def generate_combined_html(posts_data: List[Dict], category_mapping: Dict = None, source_mapping: Dict = None) -> str:
  672. """生成包含所有帖子的单一HTML(带标签页)"""
  673. # 生成标签页按钮
  674. tabs_html = ""
  675. for i, post in enumerate(posts_data):
  676. post_detail = post.get("帖子详情", {})
  677. title = post_detail.get("title", "无标题")
  678. active_class = "active" if i == 0 else ""
  679. tabs_html += f'<button class="tab-button {active_class}" onclick="openTab(event, \'post-{i}\')">{html_module.escape(title)}</button>\n'
  680. # 生成标签页内容
  681. contents_html = ""
  682. for i, post in enumerate(posts_data):
  683. active_class = "active" if i == 0 else ""
  684. content = generate_post_content_html(post, i, category_mapping, source_mapping)
  685. contents_html += f'''
  686. <div id="post-{i}" class="tab-content {active_class}">
  687. {content}
  688. </div>
  689. '''
  690. html = f'''
  691. <!DOCTYPE html>
  692. <html lang="zh-CN">
  693. <head>
  694. <meta charset="UTF-8">
  695. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  696. <title>How解构结果可视化</title>
  697. <style>
  698. * {{
  699. margin: 0;
  700. padding: 0;
  701. box-sizing: border-box;
  702. }}
  703. body {{
  704. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  705. background: #f5f5f5;
  706. color: #333;
  707. line-height: 1.6;
  708. }}
  709. .container {{
  710. max-width: 1600px;
  711. margin: 0 auto;
  712. background: white;
  713. min-height: 100vh;
  714. }}
  715. .header {{
  716. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  717. color: white;
  718. padding: 30px;
  719. text-align: center;
  720. }}
  721. .header h1 {{
  722. font-size: 32px;
  723. font-weight: bold;
  724. margin-bottom: 10px;
  725. }}
  726. .header p {{
  727. font-size: 16px;
  728. opacity: 0.9;
  729. }}
  730. /* 标签页样式 */
  731. .tabs-container {{
  732. display: flex;
  733. background: #f9fafb;
  734. border-bottom: 2px solid #e5e7eb;
  735. overflow-x: auto;
  736. position: sticky;
  737. top: 0;
  738. z-index: 100;
  739. box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  740. }}
  741. .tab-button {{
  742. flex: 1;
  743. min-width: 200px;
  744. padding: 18px 30px;
  745. background: transparent;
  746. border: none;
  747. border-bottom: 3px solid transparent;
  748. cursor: pointer;
  749. font-size: 15px;
  750. font-weight: 500;
  751. color: #6b7280;
  752. transition: all 0.3s;
  753. white-space: nowrap;
  754. overflow: hidden;
  755. text-overflow: ellipsis;
  756. }}
  757. .tab-button:hover {{
  758. background: #f3f4f6;
  759. color: #374151;
  760. }}
  761. .tab-button.active {{
  762. color: #667eea;
  763. border-bottom-color: #667eea;
  764. background: white;
  765. }}
  766. .tab-content {{
  767. display: none;
  768. padding: 30px;
  769. }}
  770. .tab-content.active {{
  771. display: block;
  772. animation: fadeIn 0.3s;
  773. }}
  774. @keyframes fadeIn {{
  775. from {{ opacity: 0; transform: translateY(10px); }}
  776. to {{ opacity: 1; transform: translateY(0); }}
  777. }}
  778. /* 目录和主内容布局 */
  779. .content-with-toc {{
  780. display: grid;
  781. grid-template-columns: 280px 1fr;
  782. gap: 30px;
  783. align-items: start;
  784. }}
  785. .toc-container {{
  786. position: sticky;
  787. top: 80px;
  788. background: white;
  789. border: 1px solid #e5e7eb;
  790. border-radius: 12px;
  791. overflow: hidden;
  792. max-height: calc(100vh - 100px);
  793. display: flex;
  794. flex-direction: column;
  795. }}
  796. .toc-header {{
  797. padding: 15px 20px;
  798. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  799. color: white;
  800. font-weight: 600;
  801. font-size: 16px;
  802. }}
  803. .toc-content {{
  804. padding: 10px;
  805. overflow-y: auto;
  806. flex: 1;
  807. }}
  808. .toc-item {{
  809. padding: 10px 15px;
  810. margin: 4px 0;
  811. cursor: pointer;
  812. border-radius: 6px;
  813. font-size: 14px;
  814. transition: all 0.2s;
  815. user-select: none;
  816. }}
  817. .toc-item:hover {{
  818. background: #f3f4f6;
  819. }}
  820. .toc-item.active {{
  821. background: #e0e7ff;
  822. color: #667eea;
  823. font-weight: 600;
  824. }}
  825. .toc-level-1 {{
  826. color: #111827;
  827. font-weight: 500;
  828. }}
  829. .toc-level-2 {{
  830. color: #6b7280;
  831. font-size: 13px;
  832. padding-left: 30px;
  833. }}
  834. .toc-level-2.toc-feature-same {{
  835. border-left: 3px solid #10b981;
  836. }}
  837. .toc-level-2.toc-feature-similar {{
  838. border-left: 3px solid #f59e0b;
  839. }}
  840. .toc-level-2.toc-feature-unrelated {{
  841. border-left: 3px solid #9ca3af;
  842. }}
  843. .toc-feature-status {{
  844. font-weight: 600;
  845. font-size: 11px;
  846. padding: 2px 6px;
  847. border-radius: 4px;
  848. margin-left: 8px;
  849. }}
  850. .toc-feature-same .toc-feature-status {{
  851. background: #d1fae5;
  852. color: #065f46;
  853. }}
  854. .toc-feature-similar .toc-feature-status {{
  855. background: #fed7aa;
  856. color: #92400e;
  857. }}
  858. .toc-feature-unrelated .toc-feature-status {{
  859. background: #e5e7eb;
  860. color: #4b5563;
  861. }}
  862. /* 目录整体结论 */
  863. .toc-conclusion {{
  864. padding: 15px 20px;
  865. margin: 10px;
  866. border-radius: 8px;
  867. display: flex;
  868. align-items: center;
  869. gap: 10px;
  870. font-weight: 600;
  871. font-size: 14px;
  872. }}
  873. .toc-conclusion.conclusion-found {{
  874. background: #d1fae5;
  875. color: #065f46;
  876. border: 2px solid #10b981;
  877. }}
  878. .toc-conclusion.conclusion-partial {{
  879. background: #fed7aa;
  880. color: #92400e;
  881. border: 2px solid #f59e0b;
  882. }}
  883. .toc-conclusion.conclusion-not-found {{
  884. background: #fee2e2;
  885. color: #991b1b;
  886. border: 2px solid #ef4444;
  887. }}
  888. .conclusion-icon {{
  889. font-size: 18px;
  890. font-weight: 700;
  891. }}
  892. .conclusion-text {{
  893. flex: 1;
  894. }}
  895. .toc-badge {{
  896. display: inline-block;
  897. padding: 2px 8px;
  898. border-radius: 10px;
  899. font-size: 11px;
  900. font-weight: 600;
  901. margin-right: 6px;
  902. }}
  903. .toc-badge-post {{
  904. background: #dbeafe;
  905. color: #1e40af;
  906. }}
  907. .toc-badge-inspiration {{
  908. background: #fef3c7;
  909. color: #92400e;
  910. }}
  911. .toc-badge-feature {{
  912. background: #e0e7ff;
  913. color: #3730a3;
  914. }}
  915. .main-content {{
  916. min-width: 0;
  917. display: flex;
  918. flex-direction: column;
  919. gap: 30px;
  920. }}
  921. /* 顶部框:包含帖子详情和灵感点详情 */
  922. .top-section-box {{
  923. background: white;
  924. border: 1px solid #e5e7eb;
  925. border-radius: 12px;
  926. padding: 25px;
  927. box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  928. }}
  929. /* 顶部框内的两栏布局 */
  930. .two-column-layout {{
  931. display: grid;
  932. grid-template-columns: 380px 1fr;
  933. gap: 25px;
  934. align-items: start;
  935. }}
  936. .left-column {{
  937. position: relative;
  938. }}
  939. .post-detail-wrapper {{
  940. /* 帖子详情区域 */
  941. }}
  942. .right-column {{
  943. min-width: 0;
  944. }}
  945. .inspirations-detail-wrapper {{
  946. display: flex;
  947. flex-direction: column;
  948. gap: 20px;
  949. max-height: 600px;
  950. overflow-y: auto;
  951. padding-right: 10px;
  952. }}
  953. .inspiration-detail-item {{
  954. /* 单个灵感点详情 */
  955. }}
  956. /* 匹配结果区域 */
  957. .matches-section {{
  958. display: flex;
  959. flex-direction: column;
  960. gap: 20px;
  961. }}
  962. /* 步骤区域 */
  963. .step-section {{
  964. background: white;
  965. border: 1px solid #e5e7eb;
  966. border-radius: 12px;
  967. overflow: hidden;
  968. box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  969. }}
  970. .step-header {{
  971. padding: 20px 25px;
  972. background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
  973. border-bottom: 2px solid #e5e7eb;
  974. display: flex;
  975. justify-content: space-between;
  976. align-items: center;
  977. }}
  978. .step-name {{
  979. font-size: 18px;
  980. color: #111827;
  981. font-weight: 600;
  982. margin: 0;
  983. }}
  984. .step-inspiration-name {{
  985. font-size: 14px;
  986. color: #6b7280;
  987. font-style: italic;
  988. }}
  989. .step-features-list {{
  990. padding: 20px;
  991. display: flex;
  992. flex-direction: column;
  993. gap: 15px;
  994. }}
  995. .feature-match-wrapper {{
  996. /* 特征匹配容器 */
  997. }}
  998. .content-section {{
  999. scroll-margin-top: 80px;
  1000. }}
  1001. /* 帖子详情卡片(紧凑样式) */
  1002. .post-card-compact {{
  1003. display: grid;
  1004. grid-template-columns: 200px 1fr;
  1005. gap: 20px;
  1006. background: white;
  1007. border: 1px solid #e5e7eb;
  1008. border-radius: 12px;
  1009. overflow: hidden;
  1010. padding: 20px;
  1011. cursor: pointer;
  1012. transition: all 0.3s;
  1013. margin-bottom: 30px;
  1014. }}
  1015. .post-card-compact:hover {{
  1016. box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  1017. transform: translateY(-2px);
  1018. border-color: #667eea;
  1019. }}
  1020. .post-card-image {{
  1021. position: relative;
  1022. display: flex;
  1023. align-items: center;
  1024. justify-content: center;
  1025. }}
  1026. .post-card-thumbnail {{
  1027. width: 100%;
  1028. height: 150px;
  1029. object-fit: contain;
  1030. border-radius: 8px;
  1031. background: #f9fafb;
  1032. }}
  1033. .post-card-thumbnail-placeholder {{
  1034. width: 100%;
  1035. height: 150px;
  1036. display: flex;
  1037. align-items: center;
  1038. justify-content: center;
  1039. background: #f3f4f6;
  1040. color: #9ca3af;
  1041. font-size: 48px;
  1042. border-radius: 8px;
  1043. }}
  1044. .post-card-image-count {{
  1045. position: absolute;
  1046. bottom: 8px;
  1047. right: 8px;
  1048. background: rgba(0, 0, 0, 0.7);
  1049. color: white;
  1050. padding: 4px 8px;
  1051. border-radius: 12px;
  1052. font-size: 11px;
  1053. font-weight: 600;
  1054. }}
  1055. .post-card-content {{
  1056. display: flex;
  1057. flex-direction: column;
  1058. gap: 12px;
  1059. }}
  1060. .post-card-title {{
  1061. font-size: 18px;
  1062. font-weight: 600;
  1063. color: #111827;
  1064. line-height: 1.4;
  1065. overflow: hidden;
  1066. text-overflow: ellipsis;
  1067. display: -webkit-box;
  1068. -webkit-line-clamp: 2;
  1069. -webkit-box-orient: vertical;
  1070. }}
  1071. .post-card-preview {{
  1072. font-size: 14px;
  1073. color: #6b7280;
  1074. line-height: 1.6;
  1075. overflow: hidden;
  1076. text-overflow: ellipsis;
  1077. display: -webkit-box;
  1078. -webkit-line-clamp: 2;
  1079. -webkit-box-orient: vertical;
  1080. }}
  1081. .post-card-meta {{
  1082. display: flex;
  1083. gap: 15px;
  1084. font-size: 13px;
  1085. color: #9ca3af;
  1086. }}
  1087. .post-card-stats {{
  1088. display: flex;
  1089. gap: 15px;
  1090. font-size: 13px;
  1091. color: #6b7280;
  1092. font-weight: 500;
  1093. }}
  1094. /* 灵感点详情卡片样式保持不变 */
  1095. .inspiration-detail-card {{
  1096. background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
  1097. padding: 25px;
  1098. border-bottom: 2px solid #e5e7eb;
  1099. }}
  1100. .inspiration-header {{
  1101. margin-bottom: 15px;
  1102. display: flex;
  1103. align-items: center;
  1104. gap: 10px;
  1105. flex-wrap: wrap;
  1106. }}
  1107. .inspiration-conclusion {{
  1108. padding: 6px 14px;
  1109. border-radius: 16px;
  1110. font-size: 13px;
  1111. font-weight: 700;
  1112. margin-left: auto;
  1113. }}
  1114. .inspiration-conclusion.insp-conclusion-found {{
  1115. background: #d1fae5;
  1116. color: #065f46;
  1117. border: 2px solid #10b981;
  1118. }}
  1119. .inspiration-conclusion.insp-conclusion-partial {{
  1120. background: #fed7aa;
  1121. color: #92400e;
  1122. border: 2px solid #f59e0b;
  1123. }}
  1124. .inspiration-conclusion.insp-conclusion-not-found {{
  1125. background: #fee2e2;
  1126. color: #991b1b;
  1127. border: 2px solid #ef4444;
  1128. }}
  1129. .inspiration-type-badge {{
  1130. display: inline-block;
  1131. padding: 4px 12px;
  1132. background: #fef3c7;
  1133. color: #92400e;
  1134. border-radius: 12px;
  1135. font-size: 12px;
  1136. font-weight: 600;
  1137. }}
  1138. .inspiration-name {{
  1139. font-size: 20px;
  1140. color: #111827;
  1141. font-weight: 600;
  1142. margin: 0;
  1143. }}
  1144. .inspiration-description {{
  1145. margin-bottom: 15px;
  1146. }}
  1147. .desc-label {{
  1148. font-weight: 600;
  1149. color: #6b7280;
  1150. font-size: 13px;
  1151. margin-bottom: 8px;
  1152. }}
  1153. .desc-text {{
  1154. color: #4b5563;
  1155. font-size: 14px;
  1156. line-height: 1.7;
  1157. }}
  1158. .inspiration-features {{
  1159. margin-top: 15px;
  1160. }}
  1161. .features-label {{
  1162. font-weight: 600;
  1163. color: #6b7280;
  1164. font-size: 13px;
  1165. margin-bottom: 8px;
  1166. }}
  1167. .features-tags {{
  1168. display: flex;
  1169. flex-wrap: wrap;
  1170. gap: 8px;
  1171. }}
  1172. .feature-tag {{
  1173. padding: 5px 12px;
  1174. background: #667eea;
  1175. color: white;
  1176. border-radius: 16px;
  1177. font-size: 13px;
  1178. font-weight: 500;
  1179. display: inline-flex;
  1180. align-items: center;
  1181. gap: 4px;
  1182. }}
  1183. .feature-tag.feature-same {{
  1184. background: #10b981;
  1185. }}
  1186. .feature-tag.feature-similar {{
  1187. background: #f59e0b;
  1188. }}
  1189. .feature-tag.feature-unrelated {{
  1190. background: #9ca3af;
  1191. }}
  1192. .feature-status-label {{
  1193. font-weight: 700;
  1194. font-size: 11px;
  1195. padding: 2px 6px;
  1196. background: rgba(255, 255, 255, 0.3);
  1197. border-radius: 4px;
  1198. }}
  1199. /* 匹配结果部分 */
  1200. .match-results-section {{
  1201. padding: 25px;
  1202. border-bottom: 1px solid #e5e7eb;
  1203. }}
  1204. .match-results-section:last-child {{
  1205. border-bottom: none;
  1206. }}
  1207. .match-section-header {{
  1208. display: flex;
  1209. justify-content: space-between;
  1210. align-items: center;
  1211. margin-bottom: 20px;
  1212. padding-bottom: 15px;
  1213. border-bottom: 2px solid #e5e7eb;
  1214. }}
  1215. .collapsible-header {{
  1216. cursor: pointer;
  1217. user-select: none;
  1218. transition: background 0.2s;
  1219. padding: 10px;
  1220. margin: -10px;
  1221. border-radius: 6px;
  1222. }}
  1223. .collapsible-header:hover {{
  1224. background: #f9fafb;
  1225. }}
  1226. .header-left {{
  1227. display: flex;
  1228. align-items: center;
  1229. gap: 10px;
  1230. }}
  1231. .match-section-header h4 {{
  1232. font-size: 18px;
  1233. color: #111827;
  1234. margin: 0;
  1235. }}
  1236. .match-stats {{
  1237. display: flex;
  1238. gap: 10px;
  1239. flex-wrap: wrap;
  1240. }}
  1241. .stat-badge {{
  1242. padding: 4px 10px;
  1243. border-radius: 12px;
  1244. color: white;
  1245. font-size: 12px;
  1246. font-weight: 600;
  1247. }}
  1248. .matches-list {{
  1249. display: flex;
  1250. flex-direction: column;
  1251. gap: 8px;
  1252. }}
  1253. .match-group-section {{
  1254. margin-bottom: 20px;
  1255. background: white;
  1256. border: 1px solid #e5e7eb;
  1257. border-radius: 8px;
  1258. overflow: hidden;
  1259. }}
  1260. .match-group-header {{
  1261. padding: 12px 18px;
  1262. background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  1263. border-bottom: 2px solid #d1d5db;
  1264. cursor: pointer;
  1265. user-select: none;
  1266. display: flex;
  1267. align-items: center;
  1268. gap: 10px;
  1269. transition: background 0.2s;
  1270. }}
  1271. .match-group-header:hover {{
  1272. background: linear-gradient(135deg, #e5e7eb 0%, #d1d5db 100%);
  1273. }}
  1274. .match-group-title {{
  1275. font-size: 15px;
  1276. font-weight: 600;
  1277. color: #374151;
  1278. margin: 0;
  1279. }}
  1280. .match-group-content {{
  1281. padding: 15px;
  1282. display: flex;
  1283. flex-direction: row;
  1284. flex-wrap: wrap;
  1285. gap: 10px;
  1286. }}
  1287. .match-item-compact {{
  1288. display: inline-flex;
  1289. align-items: center;
  1290. gap: 6px;
  1291. padding: 6px 12px;
  1292. background: white;
  1293. border: 1px solid #e5e7eb;
  1294. border-radius: 6px;
  1295. font-size: 13px;
  1296. transition: all 0.2s;
  1297. cursor: pointer;
  1298. }}
  1299. .match-item-compact:hover {{
  1300. border-color: #667eea;
  1301. box-shadow: 0 2px 4px rgba(102, 126, 234, 0.1);
  1302. transform: translateY(-1px);
  1303. }}
  1304. /* 匹配详情模态框 */
  1305. .match-modal {{
  1306. display: none;
  1307. position: fixed;
  1308. z-index: 3000;
  1309. left: 0;
  1310. top: 0;
  1311. width: 100%;
  1312. height: 100%;
  1313. background: rgba(0, 0, 0, 0.5);
  1314. animation: fadeIn 0.2s;
  1315. }}
  1316. .match-modal-content {{
  1317. position: relative;
  1318. background: white;
  1319. margin: 5% auto;
  1320. padding: 0;
  1321. width: 80%;
  1322. max-width: 900px;
  1323. max-height: 80vh;
  1324. border-radius: 12px;
  1325. box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  1326. overflow: hidden;
  1327. animation: slideDown 0.3s;
  1328. }}
  1329. .match-modal-header {{
  1330. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  1331. color: white;
  1332. padding: 20px 25px;
  1333. display: flex;
  1334. align-items: center;
  1335. justify-content: space-between;
  1336. }}
  1337. .match-modal-title {{
  1338. font-size: 18px;
  1339. font-weight: 600;
  1340. margin: 0;
  1341. }}
  1342. .match-modal-close {{
  1343. color: white;
  1344. font-size: 32px;
  1345. font-weight: 300;
  1346. cursor: pointer;
  1347. background: none;
  1348. border: none;
  1349. padding: 0;
  1350. line-height: 1;
  1351. transition: transform 0.2s;
  1352. }}
  1353. .match-modal-close:hover {{
  1354. transform: scale(1.2);
  1355. }}
  1356. .match-modal-body {{
  1357. padding: 25px;
  1358. max-height: calc(80vh - 80px);
  1359. overflow-y: auto;
  1360. }}
  1361. .match-detail-section {{
  1362. margin-bottom: 25px;
  1363. }}
  1364. .match-detail-section h3 {{
  1365. font-size: 16px;
  1366. font-weight: 600;
  1367. color: #374151;
  1368. margin-bottom: 12px;
  1369. padding-bottom: 8px;
  1370. border-bottom: 2px solid #e5e7eb;
  1371. }}
  1372. .match-explanation-text {{
  1373. line-height: 1.8;
  1374. color: #4b5563;
  1375. padding: 15px;
  1376. background: #f9fafb;
  1377. border-radius: 8px;
  1378. border-left: 4px solid #667eea;
  1379. }}
  1380. .match-item-collapsible {{
  1381. border: 1px solid #e5e7eb;
  1382. border-radius: 8px;
  1383. overflow: hidden;
  1384. background: white;
  1385. transition: box-shadow 0.2s;
  1386. }}
  1387. .match-item-collapsible:hover {{
  1388. box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  1389. }}
  1390. .match-header {{
  1391. padding: 12px 16px;
  1392. cursor: pointer;
  1393. user-select: none;
  1394. transition: background 0.2s;
  1395. }}
  1396. .match-header:hover {{
  1397. background: #f9fafb;
  1398. }}
  1399. .match-header-left {{
  1400. display: flex;
  1401. align-items: center;
  1402. gap: 10px;
  1403. }}
  1404. .expand-icon {{
  1405. color: #9ca3af;
  1406. font-size: 12px;
  1407. transition: transform 0.2s;
  1408. }}
  1409. .expand-icon.expanded {{
  1410. transform: rotate(90deg);
  1411. }}
  1412. .persona-name {{
  1413. font-weight: 600;
  1414. font-size: 14px;
  1415. color: #111827;
  1416. }}
  1417. .match-item-compact .persona-name {{
  1418. font-weight: 500;
  1419. font-size: 13px;
  1420. color: #374151;
  1421. }}
  1422. .relation-badge {{
  1423. padding: 3px 10px;
  1424. border-radius: 12px;
  1425. color: white;
  1426. font-size: 11px;
  1427. font-weight: 600;
  1428. }}
  1429. .score-badge {{
  1430. padding: 3px 10px;
  1431. border-radius: 12px;
  1432. background: #e5e7eb;
  1433. color: #374151;
  1434. font-size: 11px;
  1435. font-weight: 600;
  1436. }}
  1437. .feature-type-badge {{
  1438. padding: 3px 8px;
  1439. border-radius: 10px;
  1440. background: #fef3c7;
  1441. color: #92400e;
  1442. font-size: 10px;
  1443. font-weight: 600;
  1444. border: 1px solid #fcd34d;
  1445. }}
  1446. .feature-category-badge {{
  1447. padding: 3px 8px;
  1448. border-radius: 10px;
  1449. background: #dbeafe;
  1450. color: #1e40af;
  1451. font-size: 10px;
  1452. font-weight: 500;
  1453. border: 1px solid #93c5fd;
  1454. }}
  1455. .level-badge {{
  1456. padding: 4px 10px;
  1457. border-radius: 12px;
  1458. font-size: 11px;
  1459. font-weight: 600;
  1460. margin-right: 6px;
  1461. }}
  1462. .level-badge-match {{
  1463. background: #e0e7ff;
  1464. color: #4338ca;
  1465. border: 1px solid #a5b4fc;
  1466. }}
  1467. .level-badge-category {{
  1468. background: #fef3c7;
  1469. color: #92400e;
  1470. border: 1px solid #fcd34d;
  1471. }}
  1472. .feature-match-status {{
  1473. padding: 5px 12px;
  1474. border-radius: 12px;
  1475. font-size: 12px;
  1476. font-weight: 700;
  1477. margin-left: 12px;
  1478. }}
  1479. .feature-match-status.status-same {{
  1480. background: #d1fae5;
  1481. color: #065f46;
  1482. border: 2px solid #10b981;
  1483. }}
  1484. .feature-match-status.status-similar {{
  1485. background: #fed7aa;
  1486. color: #92400e;
  1487. border: 2px solid #f59e0b;
  1488. }}
  1489. .feature-match-status.status-unrelated {{
  1490. background: #e5e7eb;
  1491. color: #4b5563;
  1492. border: 2px solid #9ca3af;
  1493. }}
  1494. .match-content {{
  1495. padding: 16px;
  1496. background: #f9fafb;
  1497. border-top: 1px solid #e5e7eb;
  1498. }}
  1499. .match-explanation {{
  1500. font-size: 13px;
  1501. color: #4b5563;
  1502. line-height: 1.7;
  1503. margin-bottom: 16px;
  1504. }}
  1505. /* 历史帖子来源区域 */
  1506. .historical-posts-section {{
  1507. margin-top: 20px;
  1508. padding-top: 20px;
  1509. border-top: 2px solid #e5e7eb;
  1510. }}
  1511. .historical-posts-title {{
  1512. font-size: 14px;
  1513. font-weight: 600;
  1514. color: #374151;
  1515. margin-bottom: 12px;
  1516. }}
  1517. .historical-posts-grid {{
  1518. display: grid;
  1519. grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  1520. gap: 16px;
  1521. }}
  1522. .historical-post-card {{
  1523. display: grid;
  1524. grid-template-columns: 120px 1fr;
  1525. gap: 12px;
  1526. background: white;
  1527. border: 1px solid #e5e7eb;
  1528. border-radius: 8px;
  1529. padding: 12px;
  1530. transition: all 0.2s;
  1531. cursor: pointer;
  1532. }}
  1533. .historical-post-card:hover {{
  1534. border-color: #667eea;
  1535. box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
  1536. transform: translateY(-2px);
  1537. }}
  1538. .historical-post-image {{
  1539. position: relative;
  1540. }}
  1541. .historical-post-thumbnail {{
  1542. width: 100%;
  1543. height: 100px;
  1544. object-fit: contain;
  1545. border-radius: 6px;
  1546. background: #f9fafb;
  1547. }}
  1548. .historical-post-content {{
  1549. display: flex;
  1550. flex-direction: column;
  1551. gap: 8px;
  1552. }}
  1553. .historical-post-title {{
  1554. font-size: 13px;
  1555. font-weight: 600;
  1556. color: #1f2937;
  1557. line-height: 1.4;
  1558. overflow: hidden;
  1559. display: -webkit-box;
  1560. -webkit-line-clamp: 2;
  1561. -webkit-box-orient: vertical;
  1562. }}
  1563. .historical-inspiration-info {{
  1564. display: flex;
  1565. align-items: center;
  1566. gap: 6px;
  1567. }}
  1568. .inspiration-type-badge-small {{
  1569. padding: 2px 6px;
  1570. border-radius: 4px;
  1571. background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  1572. color: white;
  1573. font-size: 10px;
  1574. font-weight: 600;
  1575. }}
  1576. .inspiration-name-small {{
  1577. font-size: 11px;
  1578. color: #667eea;
  1579. font-weight: 500;
  1580. }}
  1581. .historical-inspiration-desc {{
  1582. font-size: 11px;
  1583. color: #6b7280;
  1584. line-height: 1.5;
  1585. overflow: hidden;
  1586. display: -webkit-box;
  1587. -webkit-line-clamp: 2;
  1588. -webkit-box-orient: vertical;
  1589. }}
  1590. .historical-post-meta {{
  1591. margin: 4px 0;
  1592. }}
  1593. .historical-post-time {{
  1594. font-size: 11px;
  1595. color: #9ca3af;
  1596. }}
  1597. .historical-post-stats {{
  1598. display: flex;
  1599. align-items: center;
  1600. gap: 10px;
  1601. font-size: 11px;
  1602. color: #9ca3af;
  1603. }}
  1604. .view-link {{
  1605. margin-left: auto;
  1606. color: #667eea;
  1607. text-decoration: none;
  1608. font-weight: 500;
  1609. }}
  1610. .view-link:hover {{
  1611. color: #764ba2;
  1612. }}
  1613. .category-simple {{
  1614. color: #9ca3af;
  1615. font-size: 12px;
  1616. font-weight: 400;
  1617. margin-right: 6px;
  1618. }}
  1619. /* 帖子详情模态框 */
  1620. .post-detail-modal {{
  1621. display: none;
  1622. position: fixed;
  1623. z-index: 4000;
  1624. left: 0;
  1625. top: 0;
  1626. width: 100%;
  1627. height: 100%;
  1628. background: rgba(0, 0, 0, 0.7);
  1629. overflow: auto;
  1630. animation: fadeIn 0.3s;
  1631. }}
  1632. .post-detail-modal.active {{
  1633. display: flex;
  1634. align-items: center;
  1635. justify-content: center;
  1636. padding: 40px 20px;
  1637. }}
  1638. .post-detail-content {{
  1639. position: relative;
  1640. background: white;
  1641. border-radius: 16px;
  1642. max-width: 900px;
  1643. width: 100%;
  1644. max-height: 90vh;
  1645. overflow-y: auto;
  1646. box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  1647. }}
  1648. .post-detail-close {{
  1649. position: sticky;
  1650. top: 20px;
  1651. right: 20px;
  1652. float: right;
  1653. font-size: 36px;
  1654. font-weight: 300;
  1655. color: #9ca3af;
  1656. background: white;
  1657. border: none;
  1658. cursor: pointer;
  1659. width: 40px;
  1660. height: 40px;
  1661. border-radius: 50%;
  1662. display: flex;
  1663. align-items: center;
  1664. justify-content: center;
  1665. transition: all 0.2s;
  1666. z-index: 10;
  1667. box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  1668. }}
  1669. .post-detail-close:hover {{
  1670. color: #ef4444;
  1671. background: #fee2e2;
  1672. transform: rotate(90deg);
  1673. }}
  1674. .post-detail-header {{
  1675. padding: 40px 40px 20px 40px;
  1676. border-bottom: 2px solid #e5e7eb;
  1677. }}
  1678. .post-detail-title {{
  1679. font-size: 28px;
  1680. font-weight: bold;
  1681. color: #111827;
  1682. line-height: 1.4;
  1683. margin-bottom: 15px;
  1684. }}
  1685. .post-detail-meta {{
  1686. display: flex;
  1687. justify-content: space-between;
  1688. align-items: center;
  1689. color: #6b7280;
  1690. font-size: 14px;
  1691. gap: 20px;
  1692. }}
  1693. .post-detail-author {{
  1694. font-weight: 500;
  1695. }}
  1696. .post-detail-time {{
  1697. color: #9ca3af;
  1698. }}
  1699. .post-detail-stats {{
  1700. display: flex;
  1701. gap: 15px;
  1702. font-weight: 500;
  1703. }}
  1704. .post-detail-body {{
  1705. padding: 30px 40px;
  1706. }}
  1707. .post-detail-desc {{
  1708. font-size: 15px;
  1709. color: #4b5563;
  1710. line-height: 1.8;
  1711. margin-bottom: 25px;
  1712. white-space: pre-wrap;
  1713. }}
  1714. .post-detail-images {{
  1715. display: grid;
  1716. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  1717. gap: 15px;
  1718. margin-top: 20px;
  1719. }}
  1720. .post-detail-image {{
  1721. width: 100%;
  1722. border-radius: 8px;
  1723. object-fit: cover;
  1724. cursor: pointer;
  1725. transition: transform 0.2s;
  1726. }}
  1727. .post-detail-image:hover {{
  1728. transform: scale(1.02);
  1729. }}
  1730. .post-detail-footer {{
  1731. padding: 20px 40px 30px 40px;
  1732. border-top: 1px solid #e5e7eb;
  1733. text-align: center;
  1734. }}
  1735. .post-detail-link {{
  1736. display: inline-block;
  1737. padding: 12px 30px;
  1738. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  1739. color: white;
  1740. text-decoration: none;
  1741. border-radius: 8px;
  1742. font-weight: 500;
  1743. transition: all 0.3s;
  1744. }}
  1745. .post-detail-link:hover {{
  1746. transform: translateY(-2px);
  1747. box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  1748. }}
  1749. /* 响应式 */
  1750. @media (max-width: 1400px) {{
  1751. .content-with-toc {{
  1752. grid-template-columns: 240px 1fr;
  1753. }}
  1754. .two-column-layout {{
  1755. grid-template-columns: 320px 1fr;
  1756. }}
  1757. }}
  1758. @media (max-width: 1200px) {{
  1759. .content-with-toc {{
  1760. grid-template-columns: 200px 1fr;
  1761. }}
  1762. .two-column-layout {{
  1763. grid-template-columns: 280px 1fr;
  1764. }}
  1765. }}
  1766. @media (max-width: 1024px) {{
  1767. .content-with-toc {{
  1768. grid-template-columns: 1fr;
  1769. }}
  1770. .toc-container {{
  1771. position: relative;
  1772. top: 0;
  1773. max-height: 300px;
  1774. }}
  1775. .two-column-layout {{
  1776. grid-template-columns: 1fr;
  1777. }}
  1778. .inspirations-detail-wrapper {{
  1779. max-height: none;
  1780. }}
  1781. .post-card-compact {{
  1782. grid-template-columns: 150px 1fr;
  1783. }}
  1784. }}
  1785. @media (max-width: 768px) {{
  1786. .header {{
  1787. padding: 20px;
  1788. }}
  1789. .header h1 {{
  1790. font-size: 24px;
  1791. }}
  1792. .tab-button {{
  1793. min-width: 150px;
  1794. padding: 15px 20px;
  1795. }}
  1796. .tab-content {{
  1797. padding: 15px;
  1798. }}
  1799. .post-info-section {{
  1800. padding: 20px;
  1801. }}
  1802. }}
  1803. </style>
  1804. </head>
  1805. <body>
  1806. <div class="container">
  1807. <div class="header">
  1808. <h1>How 解构结果可视化</h1>
  1809. <p>灵感点特征匹配分析</p>
  1810. </div>
  1811. <div class="tabs-container">
  1812. {tabs_html}
  1813. </div>
  1814. {contents_html}
  1815. </div>
  1816. <!-- 匹配详情模态框 -->
  1817. <div id="matchModal" class="match-modal" onclick="closeMatchModal(event)">
  1818. <div class="match-modal-content" onclick="event.stopPropagation()">
  1819. <div class="match-modal-header">
  1820. <h2 class="match-modal-title" id="matchModalTitle"></h2>
  1821. <button class="match-modal-close" onclick="closeMatchModal()">&times;</button>
  1822. </div>
  1823. <div class="match-modal-body" id="matchModalBody"></div>
  1824. </div>
  1825. </div>
  1826. <!-- 帖子详情模态框 -->
  1827. <div id="postDetailModal" class="post-detail-modal" onclick="closePostDetail(event)"></div>
  1828. <script>
  1829. function openTab(evt, tabId) {{
  1830. var tabContents = document.getElementsByClassName("tab-content");
  1831. for (var i = 0; i < tabContents.length; i++) {{
  1832. tabContents[i].classList.remove("active");
  1833. }}
  1834. var tabButtons = document.getElementsByClassName("tab-button");
  1835. for (var i = 0; i < tabButtons.length; i++) {{
  1836. tabButtons[i].classList.remove("active");
  1837. }}
  1838. document.getElementById(tabId).classList.add("active");
  1839. evt.currentTarget.classList.add("active");
  1840. }}
  1841. function scrollToSection(sectionId) {{
  1842. var element = document.getElementById(sectionId);
  1843. if (element) {{
  1844. element.scrollIntoView({{ behavior: 'smooth', block: 'start' }});
  1845. // 更新目录项的active状态
  1846. var tocItems = document.querySelectorAll('.toc-item');
  1847. tocItems.forEach(function(item) {{
  1848. item.classList.remove('active');
  1849. }});
  1850. event.currentTarget.classList.add('active');
  1851. }}
  1852. }}
  1853. function toggleMatch(matchId) {{
  1854. var content = document.getElementById(matchId + '-content');
  1855. var icon = document.getElementById(matchId + '-icon');
  1856. if (content.style.display === 'none') {{
  1857. content.style.display = 'block';
  1858. icon.classList.add('expanded');
  1859. }} else {{
  1860. content.style.display = 'none';
  1861. icon.classList.remove('expanded');
  1862. }}
  1863. }}
  1864. function toggleFeatureSection(sectionId) {{
  1865. var content = document.getElementById(sectionId + '-content');
  1866. var icon = document.getElementById(sectionId + '-icon');
  1867. if (content.style.display === 'none') {{
  1868. content.style.display = 'flex';
  1869. icon.textContent = '▼';
  1870. }} else {{
  1871. content.style.display = 'none';
  1872. icon.textContent = '▶';
  1873. }}
  1874. }}
  1875. function toggleStepSection(sectionId) {{
  1876. var content = document.getElementById(sectionId + '-content');
  1877. var icon = document.getElementById(sectionId + '-icon');
  1878. if (content.style.display === 'none') {{
  1879. content.style.display = 'flex';
  1880. icon.textContent = '▼';
  1881. }} else {{
  1882. content.style.display = 'none';
  1883. icon.textContent = '▶';
  1884. }}
  1885. }}
  1886. function toggleMatchGroup(groupId) {{
  1887. var content = document.getElementById(groupId + '-content');
  1888. var icon = document.getElementById(groupId + '-icon');
  1889. if (content.style.display === 'none') {{
  1890. content.style.display = 'flex';
  1891. icon.textContent = '▼';
  1892. }} else {{
  1893. content.style.display = 'none';
  1894. icon.textContent = '▶';
  1895. }}
  1896. }}
  1897. function showMatchDetail(element) {{
  1898. var modal = document.getElementById('matchModal');
  1899. var title = document.getElementById('matchModalTitle');
  1900. var body = document.getElementById('matchModalBody');
  1901. // 从data属性读取数据
  1902. var personaName = element.dataset.personaName;
  1903. var featureType = element.dataset.featureType;
  1904. var similarity = parseFloat(element.dataset.similarity);
  1905. var label = element.dataset.label;
  1906. var explanation = element.dataset.explanation;
  1907. var historicalPosts = element.dataset.historicalPosts;
  1908. // 设置标题
  1909. title.textContent = '[' + featureType + '] ' + personaName + ' (相似度: ' + similarity.toFixed(2) + ' - ' + label + ')';
  1910. // 生成内容
  1911. var bodyHTML = '<div class="match-detail-section">';
  1912. bodyHTML += '<h3>匹配说明</h3>';
  1913. bodyHTML += '<div class="match-explanation-text">' + explanation + '</div>';
  1914. bodyHTML += '</div>';
  1915. // 如果有历史帖子
  1916. if (historicalPosts && historicalPosts.trim().length > 0) {{
  1917. bodyHTML += '<div class="match-detail-section">';
  1918. bodyHTML += '<h3>历史帖子来源</h3>';
  1919. bodyHTML += '<div class="historical-posts-grid">';
  1920. bodyHTML += historicalPosts;
  1921. bodyHTML += '</div>';
  1922. bodyHTML += '</div>';
  1923. }}
  1924. body.innerHTML = bodyHTML;
  1925. modal.style.display = 'block';
  1926. }}
  1927. function closeMatchModal(event) {{
  1928. var modal = document.getElementById('matchModal');
  1929. if (!event || event.target === modal) {{
  1930. modal.style.display = 'none';
  1931. }}
  1932. }}
  1933. // ESC键关闭模态框
  1934. document.addEventListener('keydown', function(event) {{
  1935. if (event.key === 'Escape') {{
  1936. closeMatchModal();
  1937. }}
  1938. }});
  1939. function showPostDetail(element) {{
  1940. const postDataStr = element.dataset.postData;
  1941. if (!postDataStr) return;
  1942. try {{
  1943. const postData = JSON.parse(postDataStr);
  1944. // 生成图片HTML
  1945. let imagesHtml = '';
  1946. if (postData.images && postData.images.length > 0) {{
  1947. imagesHtml = postData.images.map(img =>
  1948. `<img src="${{img}}" class="post-detail-image" alt="图片">`
  1949. ).join('');
  1950. }} else {{
  1951. imagesHtml = '<div style="text-align: center; color: #9ca3af; padding: 40px;">暂无图片</div>';
  1952. }}
  1953. const modalHtml = `
  1954. <div class="post-detail-content" onclick="event.stopPropagation()">
  1955. <button class="post-detail-close" onclick="closePostDetail()">×</button>
  1956. <div class="post-detail-header">
  1957. <div class="post-detail-title">${{postData.title || '无标题'}}</div>
  1958. <div class="post-detail-meta">
  1959. <div>
  1960. <span class="post-detail-author">👤 ${{postData.author}}</span>
  1961. <span class="post-detail-time"> · 📅 ${{postData.publish_time}}</span>
  1962. </div>
  1963. <div class="post-detail-stats">
  1964. <span>👍 ${{postData.like_count}}</span>
  1965. <span>💬 ${{postData.comment_count}}</span>
  1966. <span>⭐ ${{postData.collect_count}}</span>
  1967. </div>
  1968. </div>
  1969. </div>
  1970. <div class="post-detail-body">
  1971. ${{postData.body_text ? `<div class="post-detail-desc">${{postData.body_text}}</div>` : '<div style="color: #9ca3af;">暂无正文</div>'}}
  1972. <div class="post-detail-images">
  1973. ${{imagesHtml}}
  1974. </div>
  1975. </div>
  1976. <div class="post-detail-footer">
  1977. <a href="${{postData.link}}" target="_blank" class="post-detail-link">
  1978. 在小红书查看完整内容 →
  1979. </a>
  1980. </div>
  1981. </div>
  1982. `;
  1983. let modal = document.getElementById('postDetailModal');
  1984. if (!modal) {{
  1985. modal = document.createElement('div');
  1986. modal.id = 'postDetailModal';
  1987. modal.className = 'post-detail-modal';
  1988. modal.onclick = closePostDetail;
  1989. document.body.appendChild(modal);
  1990. }}
  1991. modal.innerHTML = modalHtml;
  1992. modal.classList.add('active');
  1993. document.body.style.overflow = 'hidden';
  1994. }} catch (e) {{
  1995. console.error('解析帖子数据失败:', e);
  1996. }}
  1997. }}
  1998. function closePostDetail(event) {{
  1999. if (event && event.target !== event.currentTarget) return;
  2000. const modal = document.getElementById('postDetailModal');
  2001. if (modal) {{
  2002. modal.classList.remove('active');
  2003. document.body.style.overflow = '';
  2004. }}
  2005. }}
  2006. function moveImage(postId, direction) {{
  2007. var carousel = document.querySelector(`[data-post-id="${{postId}}"]`);
  2008. var track = document.getElementById(postId + '-track');
  2009. var totalImages = parseInt(carousel.getAttribute('data-total-images'));
  2010. if (!carousel.currentIndex) {{
  2011. carousel.currentIndex = 0;
  2012. }}
  2013. carousel.currentIndex = (carousel.currentIndex + direction + totalImages) % totalImages;
  2014. track.style.transform = `translateX(-${{carousel.currentIndex * 100}}%)`;
  2015. updateIndicators(postId, carousel.currentIndex);
  2016. }}
  2017. function jumpToImage(postId, index) {{
  2018. var carousel = document.querySelector(`[data-post-id="${{postId}}"]`);
  2019. var track = document.getElementById(postId + '-track');
  2020. carousel.currentIndex = index;
  2021. track.style.transform = `translateX(-${{index * 100}}%)`;
  2022. updateIndicators(postId, index);
  2023. }}
  2024. function updateIndicators(postId, activeIndex) {{
  2025. var indicators = document.querySelectorAll(`#${{postId}}-indicators .indicator`);
  2026. indicators.forEach((indicator, i) => {{
  2027. if (i === activeIndex) {{
  2028. indicator.classList.add('active');
  2029. }} else {{
  2030. indicator.classList.remove('active');
  2031. }}
  2032. }});
  2033. }}
  2034. // 目录激活状态追踪
  2035. function updateTocActiveState() {{
  2036. const mainContent = document.querySelector('.main-content');
  2037. if (!mainContent) return;
  2038. const sections = document.querySelectorAll('.post-detail-wrapper, .inspiration-detail-card, .step-section');
  2039. const tocItems = document.querySelectorAll('.toc-item');
  2040. let currentActive = null;
  2041. const scrollTop = mainContent.scrollTop;
  2042. const windowHeight = window.innerHeight;
  2043. // 找到当前在视口中的section
  2044. sections.forEach(section => {{
  2045. const rect = section.getBoundingClientRect();
  2046. const sectionTop = rect.top;
  2047. const sectionBottom = rect.bottom;
  2048. // 如果section的顶部在视口上半部分,认为它是当前激活的
  2049. if (sectionTop < windowHeight / 2 && sectionBottom > 0) {{
  2050. currentActive = section.id;
  2051. }}
  2052. }});
  2053. // 更新目录项的激活状态
  2054. tocItems.forEach(item => {{
  2055. const targetId = item.getAttribute('onclick')?.match(/'([^']+)'/)?.[1];
  2056. if (targetId === currentActive) {{
  2057. item.classList.add('active');
  2058. }} else {{
  2059. item.classList.remove('active');
  2060. }}
  2061. }});
  2062. }}
  2063. // 监听滚动事件
  2064. document.addEventListener('DOMContentLoaded', function() {{
  2065. const mainContent = document.querySelector('.main-content');
  2066. if (mainContent) {{
  2067. mainContent.addEventListener('scroll', function() {{
  2068. // 使用节流避免频繁触发
  2069. if (this.scrollTimeout) clearTimeout(this.scrollTimeout);
  2070. this.scrollTimeout = setTimeout(updateTocActiveState, 50);
  2071. }});
  2072. // 初始化时更新一次
  2073. updateTocActiveState();
  2074. }}
  2075. }});
  2076. </script>
  2077. </body>
  2078. </html>
  2079. '''
  2080. return html
  2081. def main():
  2082. """主函数"""
  2083. script_dir = Path(__file__).parent
  2084. project_root = script_dir.parent.parent
  2085. data_dir = project_root / "data" / "data_1118"
  2086. input_dir = data_dir / "当前帖子_how解构结果"
  2087. output_file = data_dir / "当前帖子_how解构结果_可视化.html"
  2088. print(f"读取 how 解构结果: {input_dir}")
  2089. # 加载特征分类映射
  2090. print(f"加载特征分类映射...")
  2091. category_mapping = load_feature_category_mapping()
  2092. print(f"已加载 {sum(len(v) for v in category_mapping.values())} 个特征分类")
  2093. # 加载特征来源映射
  2094. print(f"加载特征来源映射...")
  2095. source_mapping = load_feature_source_mapping()
  2096. print(f"已加载 {len(source_mapping)} 个特征的来源信息")
  2097. json_files = list(input_dir.glob("*_how.json"))
  2098. print(f"找到 {len(json_files)} 个文件\n")
  2099. posts_data = []
  2100. for i, file_path in enumerate(json_files, 1):
  2101. print(f"读取文件 [{i}/{len(json_files)}]: {file_path.name}")
  2102. with open(file_path, "r", encoding="utf-8") as f:
  2103. post_data = json.load(f)
  2104. posts_data.append(post_data)
  2105. print(f"\n生成合并的 HTML...")
  2106. html_content = generate_combined_html(posts_data, category_mapping, source_mapping)
  2107. print(f"保存到: {output_file}")
  2108. with open(output_file, "w", encoding="utf-8") as f:
  2109. f.write(html_content)
  2110. print(f"\n完成! 可视化文件已保存")
  2111. print(f"请在浏览器中打开: {output_file}")
  2112. if __name__ == "__main__":
  2113. main()