visualize_how_results.py 138 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775
  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. from script.data_processing.path_config import PathConfig
  19. # 注意:已改用基于相似度的显示方式,不再使用关系类型
  20. # def get_relation_color(relation: str) -> str:
  21. # """根据关系类型返回对应的颜色"""
  22. # color_map = {
  23. # "same": "#10b981", # 绿色 - 同义
  24. # "contains": "#3b82f6", # 蓝色 - 包含
  25. # "contained_by": "#8b5cf6", # 紫色 - 被包含
  26. # "coordinate": "#f59e0b", # 橙色 - 同级
  27. # "overlap": "#ec4899", # 粉色 - 部分重叠
  28. # "related": "#6366f1", # 靛蓝 - 相关
  29. # "unrelated": "#9ca3af" # 灰色 - 无关
  30. # }
  31. # return color_map.get(relation, "#9ca3af")
  32. #
  33. #
  34. # def get_relation_label(relation: str) -> str:
  35. # """返回关系类型的中文标签"""
  36. # label_map = {
  37. # "same": "同义",
  38. # "contains": "包含",
  39. # "contained_by": "被包含",
  40. # "coordinate": "同级",
  41. # "overlap": "部分重叠",
  42. # "related": "相关",
  43. # "unrelated": "无关"
  44. # }
  45. # return label_map.get(relation, relation)
  46. def generate_historical_post_card_html(post_detail: Dict, inspiration_point: Dict) -> str:
  47. """生成历史帖子的紧凑卡片HTML"""
  48. title = post_detail.get("title", "无标题")
  49. body_text = post_detail.get("body_text", "")
  50. images = post_detail.get("images", [])
  51. like_count = post_detail.get("like_count", 0)
  52. collect_count = post_detail.get("collect_count", 0)
  53. comment_count = post_detail.get("comment_count", 0)
  54. author = post_detail.get("channel_account_name", "")
  55. link = post_detail.get("link", "#")
  56. publish_time = post_detail.get("publish_time", "")
  57. # 获取灵感点信息
  58. point_name = inspiration_point.get("点的名称", "")
  59. point_desc = inspiration_point.get("点的描述", "")
  60. # 准备详情数据(用于模态框)
  61. import json
  62. post_detail_data = {
  63. "title": title,
  64. "body_text": body_text,
  65. "images": images,
  66. "like_count": like_count,
  67. "comment_count": comment_count,
  68. "collect_count": collect_count,
  69. "author": author,
  70. "publish_time": publish_time,
  71. "link": link
  72. }
  73. post_data_json = json.dumps(post_detail_data, ensure_ascii=False)
  74. post_data_json_escaped = html_module.escape(post_data_json)
  75. # 截取正文预览(前80个字符)
  76. body_preview = body_text[:80] + "..." if len(body_text) > 80 else body_text
  77. # 生成缩略图
  78. thumbnail_html = ""
  79. if images:
  80. thumbnail_html = f'<img src="{images[0]}" alt="Post thumbnail" class="historical-post-thumbnail" loading="lazy">'
  81. html = f'''
  82. <div class="historical-post-card" data-post-data='{post_data_json_escaped}' onclick="showPostDetail(this)">
  83. <div class="historical-post-image">
  84. {thumbnail_html}
  85. {f'<div class="post-card-image-count">{len(images)}</div>' if len(images) > 1 else ''}
  86. </div>
  87. <div class="historical-post-content">
  88. <div class="historical-post-title">{html_module.escape(title)}</div>
  89. <div class="historical-inspiration-info">
  90. <span class="inspiration-type-badge-small">灵感点</span>
  91. <span class="inspiration-name-small">{html_module.escape(point_name)}</span>
  92. </div>
  93. <div class="historical-inspiration-desc">{html_module.escape(point_desc[:100])}{"..." if len(point_desc) > 100 else ""}</div>
  94. <div class="historical-post-meta">
  95. <span class="historical-post-time">📅 {publish_time}</span>
  96. </div>
  97. <div class="historical-post-stats">
  98. <span>❤ {like_count}</span>
  99. <span>⭐ {collect_count}</span>
  100. <a href="{link}" target="_blank" class="view-link" onclick="event.stopPropagation()">查看原帖 →</a>
  101. </div>
  102. </div>
  103. </div>
  104. '''
  105. return html
  106. def generate_post_detail_html(post_data: Dict, post_idx: int) -> str:
  107. """生成帖子详情HTML(紧凑的卡片样式,点击可展开)"""
  108. post_detail = post_data.get("帖子详情", {})
  109. title = post_detail.get("title", "无标题")
  110. body_text = post_detail.get("body_text", "")
  111. images = post_detail.get("images", [])
  112. like_count = post_detail.get("like_count", 0)
  113. comment_count = post_detail.get("comment_count", 0)
  114. collect_count = post_detail.get("collect_count", 0)
  115. author = post_detail.get("channel_account_name", "")
  116. publish_time = post_detail.get("publish_time", "")
  117. link = post_detail.get("link", "")
  118. post_id = post_data.get("帖子id", f"post-{post_idx}")
  119. # 准备详情数据(用于模态框)
  120. import json
  121. post_detail_data = {
  122. "title": title,
  123. "body_text": body_text,
  124. "images": images,
  125. "like_count": like_count,
  126. "comment_count": comment_count,
  127. "collect_count": collect_count,
  128. "author": author,
  129. "publish_time": publish_time,
  130. "link": link
  131. }
  132. post_data_json = json.dumps(post_detail_data, ensure_ascii=False)
  133. post_data_json_escaped = html_module.escape(post_data_json)
  134. # 生成缩略图HTML
  135. thumbnail_html = ""
  136. if images and len(images) > 0:
  137. # 使用第一张图片作为缩略图,添加懒加载
  138. thumbnail_html = f'<img src="{images[0]}" class="post-card-thumbnail" alt="缩略图" loading="lazy">'
  139. else:
  140. thumbnail_html = '<div class="post-card-thumbnail-placeholder">📄</div>'
  141. # 截断正文用于预览
  142. body_preview = body_text[:80] + "..." if len(body_text) > 80 else body_text
  143. html = f'''
  144. <div class="post-card-compact" data-post-data='{post_data_json_escaped}' onclick="showPostDetail(this)">
  145. <div class="post-card-image">
  146. {thumbnail_html}
  147. {f'<div class="post-card-image-count">📷 {len(images)}</div>' if len(images) > 1 else ''}
  148. </div>
  149. <div class="post-card-content">
  150. <div class="post-card-title">{html_module.escape(title)}</div>
  151. <div class="post-card-preview">{html_module.escape(body_preview) if body_preview else "暂无正文"}</div>
  152. <div class="post-card-meta">
  153. <span class="post-card-author">👤 {html_module.escape(author)}</span>
  154. <span class="post-card-time">📅 {publish_time}</span>
  155. </div>
  156. <div class="post-card-stats">
  157. <span>👍 {like_count}</span>
  158. <span>💬 {comment_count if comment_count else 0}</span>
  159. <span>⭐ {collect_count if collect_count else 0}</span>
  160. </div>
  161. </div>
  162. </div>
  163. '''
  164. return html
  165. def generate_inspiration_detail_html(inspiration_point: Dict, feature_status_map: Dict[str, str] = None, point_type: str = "灵感点") -> str:
  166. """生成点详情HTML
  167. Args:
  168. inspiration_point: 点数据
  169. feature_status_map: 特征名称到状态的映射 {特征名称: "相同"|"相似"|"无关"}
  170. point_type: 点类型(灵感点/关键点/目的点)
  171. """
  172. name = inspiration_point.get("名称", "")
  173. desc = inspiration_point.get("描述", "")
  174. features = inspiration_point.get("特征列表", [])
  175. if feature_status_map is None:
  176. feature_status_map = {}
  177. # 计算该灵感点的整体结论
  178. feature_statuses = []
  179. features_html_list = []
  180. for f in features:
  181. feature_name = f if isinstance(f, str) else f.get("特征名称", "")
  182. weight = f.get("权重", 1.0) if isinstance(f, dict) else 1.0
  183. # 获取该特征的状态
  184. status = feature_status_map.get(feature_name, "无关")
  185. feature_statuses.append(status)
  186. if status == "相同":
  187. status_class = "feature-same"
  188. status_label = "相同"
  189. elif status == "相似":
  190. status_class = "feature-similar"
  191. status_label = "相似"
  192. else:
  193. status_class = "feature-unrelated"
  194. status_label = "无关"
  195. features_html_list.append(
  196. f'<span class="feature-tag {status_class}">'
  197. f'<span class="feature-status-label">{status_label}</span> '
  198. f'{html_module.escape(feature_name)} '
  199. f'<span class="feature-weight">({weight})</span>'
  200. f'</span>'
  201. )
  202. features_html = "".join(features_html_list)
  203. # 计算灵感点结论
  204. has_same = "相同" in feature_statuses
  205. has_similar = "相似" in feature_statuses
  206. has_unrelated = "无关" in feature_statuses
  207. if not has_unrelated:
  208. # 没有无关的 -> 找到
  209. insp_conclusion = "找到"
  210. insp_conclusion_class = "insp-conclusion-found"
  211. elif has_same or has_similar:
  212. # 有相同或相似,但也有无关 -> 部分找到
  213. insp_conclusion = "部分找到"
  214. insp_conclusion_class = "insp-conclusion-partial"
  215. else:
  216. # 都是无关 -> 都找不到
  217. insp_conclusion = "都找不到"
  218. insp_conclusion_class = "insp-conclusion-not-found"
  219. # 根据点类型设置图标
  220. point_icons = {
  221. "灵感点": "💡",
  222. "关键点": "🔑",
  223. "目的点": "🎯"
  224. }
  225. point_icon = point_icons.get(point_type, "💡")
  226. html = f'''
  227. <div class="inspiration-detail-card">
  228. <div class="inspiration-header">
  229. <span class="inspiration-type-badge">{point_icon} {point_type}</span>
  230. <h3 class="inspiration-name">{html_module.escape(name)}</h3>
  231. <span class="inspiration-conclusion {insp_conclusion_class}">{insp_conclusion}</span>
  232. </div>
  233. <div class="inspiration-description">
  234. <div class="desc-label">描述:</div>
  235. <div class="desc-text">{html_module.escape(desc)}</div>
  236. </div>
  237. <div class="inspiration-features">
  238. <div class="features-label">特征列表:</div>
  239. <div class="features-tags">{features_html}</div>
  240. </div>
  241. </div>
  242. '''
  243. return html
  244. def load_feature_category_mapping(config: PathConfig) -> Dict:
  245. """加载特征名称到分类的映射"""
  246. mapping_file = config.feature_category_mapping_file
  247. try:
  248. with open(mapping_file, "r", encoding="utf-8") as f:
  249. return json.load(f)
  250. except Exception as e:
  251. print(f"警告: 无法加载特征分类映射文件: {e}")
  252. return {}
  253. def load_feature_source_mapping(config: PathConfig) -> Dict:
  254. """加载特征名称到帖子来源的映射"""
  255. mapping_file = config.feature_source_mapping_file
  256. try:
  257. with open(mapping_file, "r", encoding="utf-8") as f:
  258. data = json.load(f)
  259. # 转换为便于查询的格式: {特征名称: [来源列表]}
  260. result = {}
  261. for feature_type in ["灵感点", "关键点", "目的点"]:
  262. if feature_type in data:
  263. for item in data[feature_type]:
  264. feature_name = item.get("特征名称")
  265. if feature_name:
  266. result[feature_name] = item.get("特征来源", [])
  267. return result
  268. except Exception as e:
  269. print(f"警告: 无法加载特征来源映射文件: {e}")
  270. return {}
  271. 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, current_point_type: str = "灵感点") -> str:
  272. """生成单个匹配项的HTML
  273. Args:
  274. match: 单个匹配数据
  275. match_idx: 匹配项索引
  276. post_idx: 帖子索引
  277. insp_idx: 灵感点索引
  278. feature_idx: 特征索引
  279. category_mapping: 特征分类映射
  280. source_mapping: 特征来源映射
  281. current_point_type: 当前点的类型(灵感点/关键点/目的点)
  282. """
  283. persona_name = match.get("人设特征名称", "")
  284. feature_type = match.get("特征类型", "")
  285. feature_categories = match.get("特征分类", [])
  286. persona_level = match.get("人设特征层级", "")
  287. match_result = match.get("匹配结果", {})
  288. similarity = match_result.get("相似度", 0.0)
  289. explanation = match_result.get("说明", "")
  290. # 根据相似度确定颜色和标签
  291. if similarity >= 0.9:
  292. color = "#10b981" # 绿色 - 相同
  293. label = "相同"
  294. elif similarity >= 0.8:
  295. color = "#f59e0b" # 橙色 - 相似
  296. label = "相似"
  297. else:
  298. color = "#9ca3af" # 灰色 - 无关
  299. label = "无关"
  300. match_id = f"post-{post_idx}-insp-{insp_idx}-feat-{feature_idx}-match-{match_idx}"
  301. # 判断是否同层级匹配
  302. is_same_level = (persona_level == current_point_type)
  303. same_level_class = "match-same-level" if is_same_level else ""
  304. # 生成合并的层级-类型标签
  305. combined_badge_html = ""
  306. if persona_level and feature_type:
  307. combined_text = f"{persona_level}-{feature_type}"
  308. # 同层级用特殊样式
  309. if is_same_level:
  310. combined_badge_html = f'<span class="feature-combined-badge combined-badge-same">[{html_module.escape(combined_text)}]</span>'
  311. else:
  312. combined_badge_html = f'<span class="feature-combined-badge">[{html_module.escape(combined_text)}]</span>'
  313. categories_badge_html = ""
  314. if feature_categories:
  315. categories_text = " / ".join(feature_categories)
  316. categories_badge_html = f'<span class="feature-category-badge">{html_module.escape(categories_text)}</span>'
  317. # 获取该人设特征的分类信息
  318. categories_html = ""
  319. if category_mapping and persona_name:
  320. found_categories = None
  321. # 依次在灵感点、关键点、目的点中查找
  322. for persona_type in ["灵感点", "关键点", "目的点"]:
  323. if persona_type in category_mapping:
  324. type_mapping = category_mapping[persona_type]
  325. if persona_name in type_mapping:
  326. found_categories = type_mapping[persona_name].get("所属分类", [])
  327. break
  328. if found_categories:
  329. # 简洁样式:[大类/中类/小类]
  330. categories_reversed = list(reversed(found_categories))
  331. categories_text = "/".join(categories_reversed)
  332. categories_html = f'<span class="category-simple">[{html_module.escape(categories_text)}]</span>'
  333. # 获取该人设特征的历史帖子来源
  334. historical_posts_html = ""
  335. if source_mapping and persona_name and persona_name in source_mapping:
  336. source_list = source_mapping[persona_name]
  337. if source_list:
  338. historical_cards = []
  339. for source_item in source_list:
  340. post_detail = source_item.get("帖子详情", {})
  341. if post_detail:
  342. card_html = generate_historical_post_card_html(post_detail, source_item)
  343. historical_cards.append(card_html)
  344. if historical_cards:
  345. historical_posts_html = f'''
  346. <div class="historical-posts-section">
  347. <h4 class="historical-posts-title">历史帖子来源</h4>
  348. <div class="historical-posts-grid">
  349. {"".join(historical_cards)}
  350. </div>
  351. </div>
  352. '''
  353. # 生成历史帖子HTML
  354. historical_posts_html = ""
  355. if source_mapping and persona_name and persona_name in source_mapping:
  356. source_list = source_mapping[persona_name]
  357. if source_list:
  358. for source_item in source_list[:5]: # 最多5个
  359. post_detail = source_item.get("帖子详情", {})
  360. if post_detail:
  361. card_html = generate_historical_post_card_html(post_detail, source_item)
  362. historical_posts_html += card_html
  363. # 将数据编码到data属性中
  364. import html as html_encode
  365. data_explanation = html_encode.escape(explanation)
  366. data_historical = html_encode.escape(historical_posts_html)
  367. # 生成紧凑的匹配项HTML(可点击,弹出模态框)
  368. html = f'''
  369. <div class="match-item-compact {same_level_class}"
  370. data-persona-name="{html_module.escape(persona_name)}"
  371. data-feature-type="{html_module.escape(feature_type)}"
  372. data-persona-level="{html_module.escape(persona_level)}"
  373. data-similarity="{similarity}"
  374. data-label="{label}"
  375. data-explanation="{data_explanation}"
  376. data-historical-posts="{data_historical}"
  377. onclick="showMatchDetail(this)">
  378. {combined_badge_html}
  379. <span class="persona-name">{html_module.escape(persona_name)}</span>
  380. <span class="score-badge">相似度: {similarity:.2f}</span>
  381. <span class="relation-badge" style="background: {color};">{label}</span>
  382. </div>
  383. '''
  384. return html
  385. 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, current_point_type: str = "灵感点", feature_number: int = 1) -> str:
  386. """生成可折叠的匹配结果HTML
  387. Args:
  388. how_steps: how步骤列表
  389. feature_idx: 特征索引
  390. insp_idx: 灵感点索引
  391. post_idx: 帖子索引
  392. category_mapping: 特征分类映射
  393. source_mapping: 特征来源映射
  394. current_point_type: 当前点的类型(灵感点/关键点/目的点)
  395. feature_number: 特征序号(从1开始)
  396. """
  397. if not how_steps or len(how_steps) == 0:
  398. return ""
  399. step = how_steps[0]
  400. features = step.get("特征列表", [])
  401. if feature_idx >= len(features):
  402. return ""
  403. feature_data = features[feature_idx]
  404. feature_name = feature_data.get("特征名称", "")
  405. feature_weight = feature_data.get("权重", 1.0)
  406. match_results = feature_data.get("匹配结果", [])
  407. if category_mapping is None:
  408. category_mapping = {}
  409. # 按相似度排序
  410. sorted_matches = sorted(match_results, key=lambda x: x.get("匹配结果", {}).get("相似度", 0), reverse=True)
  411. # 找出最高相似度,确定状态
  412. max_similarity = 0.0
  413. if match_results:
  414. max_similarity = max(match.get("匹配结果", {}).get("相似度", 0) for match in match_results)
  415. # 根据最高相似度确定状态
  416. if max_similarity >= 0.9:
  417. status = "相同"
  418. status_class = "status-same"
  419. elif max_similarity >= 0.8:
  420. status = "相似"
  421. status_class = "status-similar"
  422. else:
  423. status = "无关"
  424. status_class = "status-unrelated"
  425. found_status_html = f'<span class="feature-match-status {status_class}">{status}</span>'
  426. # 统计相似度分布
  427. similarity_ranges = {
  428. "相同 (≥0.9)": 0,
  429. "相似 (0.8-0.9)": 0,
  430. "无关 (<0.8)": 0
  431. }
  432. for match in match_results:
  433. similarity = match.get("匹配结果", {}).get("相似度", 0)
  434. if similarity >= 0.9:
  435. similarity_ranges["相同 (≥0.9)"] += 1
  436. elif similarity >= 0.8:
  437. similarity_ranges["相似 (0.8-0.9)"] += 1
  438. else:
  439. similarity_ranges["无关 (<0.8)"] += 1
  440. # 生成统计信息
  441. stats_items = []
  442. range_colors = {
  443. "相同 (≥0.9)": "#10b981",
  444. "相似 (0.8-0.9)": "#f59e0b",
  445. "无关 (<0.8)": "#9ca3af"
  446. }
  447. for range_name, count in similarity_ranges.items():
  448. if count > 0:
  449. color = range_colors[range_name]
  450. stats_items.append(f'<span class="stat-badge" style="background: {color};">{range_name}: {count}</span>')
  451. stats_html = "".join(stats_items)
  452. # 按人设特征层级分组匹配项
  453. level_groups = {
  454. "灵感点": {"标签": [], "分类": []},
  455. "关键点": {"标签": [], "分类": []},
  456. "目的点": {"标签": [], "分类": []}
  457. }
  458. for i, match in enumerate(sorted_matches):
  459. persona_level = match.get("人设特征层级", "")
  460. feature_type = match.get("特征类型", "")
  461. if persona_level in level_groups and feature_type in ["标签", "分类"]:
  462. level_groups[persona_level][feature_type].append((i, match))
  463. # 生成分组的匹配项HTML
  464. matches_html = ""
  465. # 按层级顺序显示:灵感点 -> 关键点 -> 目的点
  466. level_index = 1
  467. for level_name in ["灵感点", "关键点", "目的点"]:
  468. level_data = level_groups[level_name]
  469. total_count = len(level_data["标签"]) + len(level_data["分类"])
  470. if total_count == 0:
  471. continue
  472. # 生成该层级的折叠区域
  473. level_section_id = f"post-{post_idx}-{current_point_type}-{insp_idx}-feat-{feature_idx}-level-{level_name}"
  474. # 找出该层级的最高分匹配
  475. all_level_matches = level_data["标签"] + level_data["分类"]
  476. top_match = None
  477. max_similarity = 0
  478. for _, match in all_level_matches:
  479. similarity = match.get("匹配结果", {}).get("相似度", 0)
  480. if similarity > max_similarity:
  481. max_similarity = similarity
  482. top_match = match
  483. # 生成最高分特征信息
  484. top_match_html = ""
  485. if top_match:
  486. top_persona_name = top_match.get("人设特征名称", "")
  487. top_feature_type = top_match.get("特征类型", "")
  488. if max_similarity >= 0.9:
  489. similarity_label = "相同"
  490. similarity_color = "#10b981"
  491. elif max_similarity >= 0.8:
  492. similarity_label = "相似"
  493. similarity_color = "#f59e0b"
  494. else:
  495. similarity_label = "无关"
  496. similarity_color = "#9ca3af"
  497. top_match_html = f'''
  498. <div class="level-top-match">
  499. <span class="top-match-label">最高:</span>
  500. <span class="top-match-type">[{html_module.escape(top_feature_type)}]</span>
  501. <span class="top-match-name">{html_module.escape(top_persona_name)}</span>
  502. <span class="top-match-score" style="background: {similarity_color}; color: white;">{max_similarity:.2f} {similarity_label}</span>
  503. </div>
  504. '''
  505. # 计算该层级的相似度分布
  506. level_stats = {"相同": 0, "相似": 0, "无关": 0}
  507. for _, match in all_level_matches:
  508. similarity = match.get("匹配结果", {}).get("相似度", 0)
  509. if similarity >= 0.9:
  510. level_stats["相同"] += 1
  511. elif similarity >= 0.8:
  512. level_stats["相似"] += 1
  513. else:
  514. level_stats["无关"] += 1
  515. # 生成统计标签
  516. level_stats_html = ""
  517. if level_stats["相同"] > 0:
  518. level_stats_html += f'<span class="stat-badge" style="background: #10b981;">相同: {level_stats["相同"]}</span>'
  519. if level_stats["相似"] > 0:
  520. level_stats_html += f'<span class="stat-badge" style="background: #f59e0b;">相似: {level_stats["相似"]}</span>'
  521. if level_stats["无关"] > 0:
  522. level_stats_html += f'<span class="stat-badge" style="background: #9ca3af;">无关: {level_stats["无关"]}</span>'
  523. matches_html += f'''
  524. <div class="level-group-section">
  525. <div class="level-group-header" onclick="toggleMatchGroup(event, '{level_section_id}')">
  526. <div class="level-header-left">
  527. <span class="expand-icon" id="{level_section_id}-icon">▶</span>
  528. <h4 class="level-group-title">{feature_number}.{level_index} 匹配人设{level_name} ({total_count})</h4>
  529. <div class="level-stats">{level_stats_html}</div>
  530. </div>
  531. {top_match_html}
  532. </div>
  533. <div class="level-group-content" id="{level_section_id}-content" style="display: none;">
  534. '''
  535. # 该层级下的标签分组
  536. subgroup_index = 1
  537. if level_data["标签"]:
  538. group_id = f"post-{post_idx}-{current_point_type}-{insp_idx}-feat-{feature_idx}-level-{level_name}-label"
  539. group_matches_html = ""
  540. # 找出标签中的最高分
  541. tag_top_match = None
  542. tag_max_similarity = 0
  543. for i, match in level_data["标签"]:
  544. similarity = match.get("匹配结果", {}).get("相似度", 0)
  545. if similarity > tag_max_similarity:
  546. tag_max_similarity = similarity
  547. tag_top_match = match
  548. match_html = generate_single_match_html(
  549. match, i, post_idx, insp_idx, feature_idx,
  550. category_mapping, source_mapping, current_point_type
  551. )
  552. group_matches_html += match_html
  553. # 生成标签最高分信息
  554. tag_top_html = ""
  555. if tag_top_match:
  556. tag_persona_name = tag_top_match.get("人设特征名称", "")
  557. tag_persona_level = tag_top_match.get("人设特征层级", "")
  558. tag_feature_type = tag_top_match.get("特征类型", "")
  559. if tag_max_similarity >= 0.9:
  560. tag_color = "#10b981"
  561. tag_label = "相同"
  562. elif tag_max_similarity >= 0.8:
  563. tag_color = "#f59e0b"
  564. tag_label = "相似"
  565. else:
  566. tag_color = "#9ca3af"
  567. tag_label = "无关"
  568. # 生成层级-类型标签
  569. tag_combined = f"[{tag_persona_level}-{tag_feature_type}]" if tag_persona_level and tag_feature_type else ""
  570. tag_top_html = f'''
  571. <div class="subgroup-top-match">
  572. <span class="subgroup-top-label">最高:</span>
  573. <span class="subgroup-top-combined">{tag_combined}</span>
  574. <span class="subgroup-top-name">{html_module.escape(tag_persona_name)}</span>
  575. <span class="subgroup-top-score" style="background: {tag_color}; color: white;">{tag_max_similarity:.2f} {tag_label}</span>
  576. </div>
  577. '''
  578. matches_html += f'''
  579. <div class="match-subgroup-section">
  580. <div class="match-subgroup-header" onclick="toggleMatchGroup(event, '{group_id}')">
  581. <div class="subgroup-header-left">
  582. <span class="expand-icon" id="{group_id}-icon">▼</span>
  583. <h5 class="match-subgroup-title">{feature_number}.{level_index}.{subgroup_index} 标签 ({len(level_data["标签"])})</h5>
  584. </div>
  585. {tag_top_html}
  586. </div>
  587. <div class="match-subgroup-content" id="{group_id}-content">
  588. {group_matches_html}
  589. </div>
  590. </div>
  591. '''
  592. subgroup_index += 1
  593. # 该层级下的分类分组
  594. if level_data["分类"]:
  595. group_id = f"post-{post_idx}-{current_point_type}-{insp_idx}-feat-{feature_idx}-level-{level_name}-category"
  596. group_matches_html = ""
  597. # 找出分类中的最高分
  598. cat_top_match = None
  599. cat_max_similarity = 0
  600. for i, match in level_data["分类"]:
  601. similarity = match.get("匹配结果", {}).get("相似度", 0)
  602. if similarity > cat_max_similarity:
  603. cat_max_similarity = similarity
  604. cat_top_match = match
  605. match_html = generate_single_match_html(
  606. match, i, post_idx, insp_idx, feature_idx,
  607. category_mapping, source_mapping, current_point_type
  608. )
  609. group_matches_html += match_html
  610. # 生成分类最高分信息
  611. cat_top_html = ""
  612. if cat_top_match:
  613. cat_persona_name = cat_top_match.get("人设特征名称", "")
  614. cat_persona_level = cat_top_match.get("人设特征层级", "")
  615. cat_feature_type = cat_top_match.get("特征类型", "")
  616. if cat_max_similarity >= 0.9:
  617. cat_color = "#10b981"
  618. cat_label = "相同"
  619. elif cat_max_similarity >= 0.8:
  620. cat_color = "#f59e0b"
  621. cat_label = "相似"
  622. else:
  623. cat_color = "#9ca3af"
  624. cat_label = "无关"
  625. # 生成层级-类型标签
  626. cat_combined = f"[{cat_persona_level}-{cat_feature_type}]" if cat_persona_level and cat_feature_type else ""
  627. cat_top_html = f'''
  628. <div class="subgroup-top-match">
  629. <span class="subgroup-top-label">最高:</span>
  630. <span class="subgroup-top-combined">{cat_combined}</span>
  631. <span class="subgroup-top-name">{html_module.escape(cat_persona_name)}</span>
  632. <span class="subgroup-top-score" style="background: {cat_color}; color: white;">{cat_max_similarity:.2f} {cat_label}</span>
  633. </div>
  634. '''
  635. matches_html += f'''
  636. <div class="match-subgroup-section">
  637. <div class="match-subgroup-header" onclick="toggleMatchGroup(event, '{group_id}')">
  638. <div class="subgroup-header-left">
  639. <span class="expand-icon" id="{group_id}-icon">▼</span>
  640. <h5 class="match-subgroup-title">{feature_number}.{level_index}.{subgroup_index} 分类 ({len(level_data["分类"])})</h5>
  641. </div>
  642. {cat_top_html}
  643. </div>
  644. <div class="match-subgroup-content" id="{group_id}-content">
  645. {group_matches_html}
  646. </div>
  647. </div>
  648. '''
  649. subgroup_index += 1
  650. matches_html += '''
  651. </div>
  652. </div>
  653. '''
  654. level_index += 1
  655. section_id = f"post-{post_idx}-insp-{insp_idx}-feat-{feature_idx}-section"
  656. # 找出所有匹配中的最高分
  657. overall_top_match = None
  658. overall_max_similarity = 0
  659. for match in match_results:
  660. similarity = match.get("匹配结果", {}).get("相似度", 0)
  661. if similarity > overall_max_similarity:
  662. overall_max_similarity = similarity
  663. overall_top_match = match
  664. # 生成最高分信息
  665. overall_top_html = ""
  666. if overall_top_match:
  667. top_persona_name = overall_top_match.get("人设特征名称", "")
  668. top_feature_type = overall_top_match.get("特征类型", "")
  669. top_persona_level = overall_top_match.get("人设特征层级", "")
  670. if overall_max_similarity >= 0.9:
  671. top_color = "#10b981"
  672. top_label = "相同"
  673. elif overall_max_similarity >= 0.8:
  674. top_color = "#f59e0b"
  675. top_label = "相似"
  676. else:
  677. top_color = "#9ca3af"
  678. top_label = "无关"
  679. overall_top_html = f'''
  680. <div class="overall-top-match">
  681. <span class="overall-top-label">最高:</span>
  682. <span class="overall-top-combined">[{html_module.escape(top_persona_level)}-{html_module.escape(top_feature_type)}]</span>
  683. <span class="overall-top-name">{html_module.escape(top_persona_name)}</span>
  684. <span class="overall-top-score" style="background: {top_color}; color: white;">{overall_max_similarity:.2f} {top_label}</span>
  685. </div>
  686. '''
  687. html = f'''
  688. <div class="match-results-section">
  689. <div class="match-section-header collapsible-header" onclick="toggleFeatureSection(event, '{section_id}')">
  690. <div class="header-left">
  691. <span class="expand-icon" id="{section_id}-icon">▼</span>
  692. <h4>{feature_number}. 匹配结果: {html_module.escape(feature_name)} <span class="feature-weight-display">(权重: {feature_weight})</span></h4>
  693. {found_status_html}
  694. </div>
  695. <div class="match-stats">{stats_html}</div>
  696. {overall_top_html}
  697. </div>
  698. <div class="matches-list" id="{section_id}-content">
  699. {matches_html}
  700. </div>
  701. </div>
  702. '''
  703. return html
  704. def generate_toc_html(post_data: Dict, post_idx: int, feature_status_map: Dict[str, str] = None, overall_conclusion: str = "") -> str:
  705. """生成目录导航HTML
  706. Args:
  707. post_data: 帖子数据
  708. post_idx: 帖子索引
  709. feature_status_map: 特征名称到状态的映射 {特征名称: "相同"|"相似"|"无关"}
  710. overall_conclusion: 整体结论
  711. """
  712. how_result = post_data.get("how解构结果", {})
  713. if feature_status_map is None:
  714. feature_status_map = {}
  715. toc_items = []
  716. # 帖子详情
  717. 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>')
  718. # 处理不同类型的点
  719. point_types = [
  720. ("灵感点列表", "灵感点", "toc-badge-inspiration", "💡"),
  721. ("目的点列表", "目的点", "toc-badge-purpose", "🎯"),
  722. ("关键点列表", "关键点", "toc-badge-key", "🔑")
  723. ]
  724. for list_key, point_name, badge_class, icon in point_types:
  725. point_list = how_result.get(list_key, [])
  726. if not point_list:
  727. continue
  728. # 点类型分组标题
  729. toc_items.append(f'<div class="toc-item toc-level-1 toc-group-header"><span class="toc-badge {badge_class}">{icon} {point_name}</span></div>')
  730. for point_idx, point in enumerate(point_list):
  731. name = point.get("名称", f"{point_name} {point_idx + 1}")
  732. name_short = name[:18] + "..." if len(name) > 18 else name
  733. # 计算该点的整体状态
  734. how_steps = point.get("how步骤列表", [])
  735. point_status = "无关"
  736. has_same = False
  737. has_similar = False
  738. if how_steps:
  739. features = how_steps[0].get("特征列表", [])
  740. for feature_data in features:
  741. feature_name = feature_data.get("特征名称", "")
  742. status = feature_status_map.get(feature_name, "无关")
  743. if status == "相同":
  744. has_same = True
  745. break
  746. elif status == "相似":
  747. has_similar = True
  748. if has_same:
  749. point_status = "找到"
  750. point_status_class = "toc-point-found"
  751. elif has_similar:
  752. point_status = "部分找到"
  753. point_status_class = "toc-point-partial"
  754. else:
  755. point_status = "都找不到"
  756. point_status_class = "toc-point-notfound"
  757. else:
  758. point_status_class = "toc-point-notfound"
  759. toc_items.append(f'<div class="toc-item toc-level-2 {point_status_class}" onclick="scrollToSection(\'post-{post_idx}-point-{list_key}-{point_idx}\')"><span class="toc-badge {badge_class}">{point_name}</span> {html_module.escape(name_short)} <span class="toc-point-status">[{point_status}]</span></div>')
  760. # 特征列表
  761. if how_steps:
  762. features = how_steps[0].get("特征列表", [])
  763. for feat_idx, feature_data in enumerate(features):
  764. feature_name = feature_data.get("特征名称", f"特征 {feat_idx + 1}")
  765. # 获取状态
  766. status = feature_status_map.get(feature_name, "无关")
  767. if status == "相同":
  768. status_class = "toc-feature-same"
  769. status_label = "相同"
  770. elif status == "相似":
  771. status_class = "toc-feature-similar"
  772. status_label = "相似"
  773. else:
  774. status_class = "toc-feature-unrelated"
  775. status_label = "无关"
  776. toc_items.append(f'<div class="toc-item toc-level-3 {status_class}" onclick="scrollToSection(\'post-{post_idx}-feat-{point_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>')
  777. # 整体结论HTML
  778. conclusion_html = ""
  779. if overall_conclusion:
  780. if overall_conclusion == "找到":
  781. conclusion_class = "conclusion-found"
  782. conclusion_icon = "✓"
  783. elif overall_conclusion == "部分找到":
  784. conclusion_class = "conclusion-partial"
  785. conclusion_icon = "~"
  786. else: # 都找不到
  787. conclusion_class = "conclusion-not-found"
  788. conclusion_icon = "✗"
  789. conclusion_html = f'''
  790. <div class="toc-conclusion {conclusion_class}">
  791. <span class="conclusion-icon">{conclusion_icon}</span>
  792. <span class="conclusion-text">{overall_conclusion}</span>
  793. </div>
  794. '''
  795. return f'''
  796. <div class="toc-container">
  797. <div class="toc-header">目录导航</div>
  798. {conclusion_html}
  799. <div class="toc-content">
  800. {"".join(toc_items)}
  801. </div>
  802. </div>
  803. '''
  804. def generate_post_content_html(post_data: Dict, post_idx: int, category_mapping: Dict = None, source_mapping: Dict = None) -> str:
  805. """生成单个帖子的完整内容HTML"""
  806. # 2. 灵感点详情和匹配结果
  807. how_result = post_data.get("how解构结果", {})
  808. inspiration_list = how_result.get("灵感点列表", [])
  809. # 先计算所有特征的状态(基于最高相似度)
  810. feature_status_map = {} # {特征名称: "相同"|"相似"|"无关"}
  811. for inspiration_point in inspiration_list:
  812. how_steps = inspiration_point.get("how步骤列表", [])
  813. if how_steps:
  814. features = how_steps[0].get("特征列表", [])
  815. for feature_data in features:
  816. feature_name = feature_data.get("特征名称", "")
  817. match_results = feature_data.get("匹配结果", [])
  818. # 找出最高相似度
  819. max_similarity = 0.0
  820. if match_results:
  821. max_similarity = max(match.get("匹配结果", {}).get("相似度", 0) for match in match_results)
  822. # 根据最高相似度确定状态
  823. if max_similarity >= 0.9:
  824. feature_status_map[feature_name] = "相同"
  825. elif max_similarity >= 0.8:
  826. feature_status_map[feature_name] = "相似"
  827. else:
  828. feature_status_map[feature_name] = "无关"
  829. # 1. 帖子详情
  830. post_detail_html = generate_post_detail_html(post_data, post_idx)
  831. # 生成所有灵感点的详情HTML(传入状态映射)
  832. inspirations_detail_html = ""
  833. for insp_idx, inspiration_point in enumerate(inspiration_list):
  834. inspiration_detail = generate_inspiration_detail_html(inspiration_point, feature_status_map)
  835. inspirations_detail_html += f'''
  836. <div id="post-{post_idx}-insp-{insp_idx}" class="inspiration-detail-item content-section">
  837. {inspiration_detail}
  838. </div>
  839. '''
  840. # 生成所有匹配结果HTML,按照how步骤分组
  841. all_matches_html = ""
  842. for insp_idx, inspiration_point in enumerate(inspiration_list):
  843. inspiration_name = inspiration_point.get("名称", f"灵感点 {insp_idx + 1}")
  844. how_steps = inspiration_point.get("how步骤列表", [])
  845. if how_steps:
  846. # 为每个灵感点创建一个区域
  847. for step_idx, step in enumerate(how_steps):
  848. step_name = step.get("步骤名称", f"步骤 {step_idx + 1}")
  849. features = step.get("特征列表", [])
  850. # 生成该步骤下所有特征的匹配结果
  851. features_html = ""
  852. for feat_idx, feature_data in enumerate(features):
  853. match_html = generate_match_results_html([step], feat_idx, insp_idx, post_idx, category_mapping, source_mapping, "灵感点", feat_idx + 1)
  854. features_html += f'<div id="post-{post_idx}-feat-{insp_idx}-{feat_idx}" class="feature-match-wrapper">{match_html}</div>'
  855. # 生成步骤区域(可折叠)
  856. step_section_id = f"post-{post_idx}-step-{insp_idx}-{step_idx}"
  857. all_matches_html += f'''
  858. <div class="step-section">
  859. <div class="step-header collapsible-header" onclick="toggleStepSection('{step_section_id}')">
  860. <div class="header-left">
  861. <span class="expand-icon" id="{step_section_id}-icon">▼</span>
  862. <h3 class="step-name">{html_module.escape(step_name)}</h3>
  863. </div>
  864. <span class="step-inspiration-name">来自: {html_module.escape(inspiration_name)}</span>
  865. </div>
  866. <div class="step-features-list" id="{step_section_id}-content">
  867. {features_html}
  868. </div>
  869. </div>
  870. '''
  871. html = f'''
  872. <div class="post-content-wrapper">
  873. <!-- 第一个框:左右分栏(帖子详情 + 灵感点详情) -->
  874. <div class="top-section-box">
  875. <div class="two-column-layout">
  876. <div class="left-column">
  877. <div id="post-{post_idx}-detail" class="post-detail-wrapper">
  878. {post_detail_html}
  879. </div>
  880. </div>
  881. <div class="right-column">
  882. <div class="inspirations-detail-wrapper">
  883. {inspirations_detail_html}
  884. </div>
  885. </div>
  886. </div>
  887. </div>
  888. <!-- 下面:所有匹配结果 -->
  889. <div class="matches-section">
  890. {all_matches_html}
  891. </div>
  892. </div>
  893. '''
  894. return html
  895. def generate_combined_html(posts_data: List[Dict], category_mapping: Dict = None, source_mapping: Dict = None) -> str:
  896. """生成包含所有帖子的单一HTML(左边目录,右边内容)"""
  897. # 生成统一的目录(包含所有帖子)
  898. all_toc_items = []
  899. for post_idx, post in enumerate(posts_data):
  900. post_detail = post.get("帖子详情", {})
  901. title = post_detail.get("title", "无标题")
  902. post_id = post_detail.get("post_id", f"post_{post_idx}")
  903. # 帖子标题作为一级目录(可折叠)
  904. all_toc_items.append(f'''
  905. <div class="toc-item toc-level-0 toc-post-header collapsed" data-post-id="{post_idx}" onclick="toggleTocPost(event, {post_idx})">
  906. <span class="toc-expand-icon">▼</span>
  907. <div class="toc-item-content">
  908. <span class="toc-badge toc-badge-post">📄 帖子</span> {html_module.escape(title[:30])}...
  909. </div>
  910. </div>
  911. <div class="toc-children hidden" id="toc-post-{post_idx}-children">
  912. ''')
  913. # 获取特征状态映射
  914. feature_status_map = {}
  915. how_result = post.get("how解构结果", {})
  916. # 先收集所有特征状态
  917. for point_list_key in ["灵感点列表", "目的点列表", "关键点列表"]:
  918. point_list = how_result.get(point_list_key, [])
  919. for point in point_list:
  920. how_steps = point.get("how步骤列表", [])
  921. if how_steps:
  922. features = how_steps[0].get("特征列表", [])
  923. for feature_data in features:
  924. feature_name = feature_data.get("特征名称", "")
  925. match_results = feature_data.get("匹配结果", [])
  926. max_similarity = 0.0
  927. if match_results:
  928. max_similarity = max(match.get("匹配结果", {}).get("相似度", 0) for match in match_results)
  929. if max_similarity >= 0.9:
  930. feature_status_map[feature_name] = "相同"
  931. elif max_similarity >= 0.8:
  932. feature_status_map[feature_name] = "相似"
  933. else:
  934. feature_status_map[feature_name] = "无关"
  935. # 生成点类型目录
  936. point_types = [
  937. ("灵感点列表", "灵感点", "toc-badge-inspiration", "💡"),
  938. ("目的点列表", "目的点", "toc-badge-purpose", "🎯"),
  939. ("关键点列表", "关键点", "toc-badge-key", "🔑")
  940. ]
  941. for list_key, point_name, badge_class, icon in point_types:
  942. point_list = how_result.get(list_key, [])
  943. if not point_list:
  944. continue
  945. # 点类型分组标题(可折叠),去掉"列表"两字
  946. group_id = f"post-{post_idx}-{list_key}"
  947. all_toc_items.append(f'''
  948. <div class="toc-item toc-level-1 toc-group-header collapsed" onclick="toggleTocGroup(event, '{group_id}')">
  949. <span class="toc-expand-icon">▼</span>
  950. <div class="toc-item-content">
  951. {icon} {point_name}
  952. </div>
  953. </div>
  954. <div class="toc-children hidden" id="toc-{group_id}-children">
  955. ''')
  956. for point_idx, point in enumerate(point_list):
  957. name = point.get("名称", f"{point_name} {point_idx + 1}")
  958. name_short = name[:18] + "..." if len(name) > 18 else name
  959. # 计算该点的状态
  960. how_steps = point.get("how步骤列表", [])
  961. point_status = "无关"
  962. has_same = False
  963. has_similar = False
  964. if how_steps:
  965. features = how_steps[0].get("特征列表", [])
  966. has_unrelated = False
  967. for feature_data in features:
  968. feature_name = feature_data.get("特征名称", "")
  969. status = feature_status_map.get(feature_name, "无关")
  970. if status == "相同":
  971. has_same = True
  972. elif status == "相似":
  973. has_similar = True
  974. elif status == "无关":
  975. has_unrelated = True
  976. # 统一使用与详情页相同的逻辑
  977. if not has_unrelated:
  978. # 没有无关的 -> 找到
  979. point_status = "找到"
  980. point_status_class = "toc-point-found"
  981. elif has_same or has_similar:
  982. # 有相同或相似,但也有无关 -> 部分找到
  983. point_status = "部分找到"
  984. point_status_class = "toc-point-partial"
  985. else:
  986. # 都是无关 -> 都找不到
  987. point_status = "都找不到"
  988. point_status_class = "toc-point-notfound"
  989. else:
  990. point_status = "都找不到"
  991. point_status_class = "toc-point-notfound"
  992. # 点项(可折叠,点击切换到该点的视图)
  993. # 确保ID唯一:包含list_key以区分不同类型的点
  994. point_item_id = f"post-{post_idx}-{list_key}-point-{point_idx}"
  995. point_view_id = f"view-post-{post_idx}-point-{list_key}-{point_idx}"
  996. all_toc_items.append(f'''
  997. <div class="toc-item toc-level-2 {point_status_class} collapsed" onclick="toggleTocPoint(event, '{point_item_id}', '{point_view_id}')">
  998. <span class="toc-expand-icon">▼</span>
  999. <div class="toc-item-content">
  1000. [{point_name}] {html_module.escape(name_short)}
  1001. <span class="toc-point-status">[{point_status}]</span>
  1002. </div>
  1003. </div>
  1004. <div class="toc-children hidden" id="toc-{point_item_id}-children">
  1005. ''')
  1006. # 特征列表
  1007. if how_steps:
  1008. features = how_steps[0].get("特征列表", [])
  1009. for feat_idx, feature_data in enumerate(features):
  1010. feature_name = feature_data.get("特征名称", f"特征 {feat_idx + 1}")
  1011. status = feature_status_map.get(feature_name, "无关")
  1012. if status == "相同":
  1013. status_class = "toc-feature-same"
  1014. status_label = "相同"
  1015. elif status == "相似":
  1016. status_class = "toc-feature-similar"
  1017. status_label = "相似"
  1018. else:
  1019. status_class = "toc-feature-unrelated"
  1020. status_label = "无关"
  1021. # 特征项(点击直接跳转,不展开子项)
  1022. all_toc_items.append(f'''
  1023. <div class="toc-item toc-level-3 {status_class}" onclick="clickFeature(event, '{point_view_id}', 'post-{post_idx}-feat-{point_idx}-{feat_idx}')">
  1024. <div class="toc-item-content">
  1025. [特征] {html_module.escape(feature_name)}
  1026. <span class="toc-feature-status">[{status_label}]</span>
  1027. </div>
  1028. </div>
  1029. ''')
  1030. # 关闭点项的children
  1031. all_toc_items.append('</div>')
  1032. # 关闭点类型分组的children
  1033. all_toc_items.append('</div>')
  1034. # 关闭帖子的children
  1035. all_toc_items.append('</div>')
  1036. # 生成所有独立的内容视图
  1037. all_content_views = []
  1038. for post_idx, post in enumerate(posts_data):
  1039. post_detail = post.get("帖子详情", {})
  1040. how_result = post.get("how解构结果", {})
  1041. # 1. 生成"仅帖子详情"的视图
  1042. post_detail_html = generate_post_detail_html(post, post_idx)
  1043. post_only_view = f'''
  1044. <div class="content-view" id="view-post-{post_idx}-detail" style="display: none;">
  1045. <div class="post-content-wrapper">
  1046. <div class="top-section-box">
  1047. <div id="post-{post_idx}-detail" class="post-detail-wrapper">
  1048. {post_detail_html}
  1049. </div>
  1050. </div>
  1051. </div>
  1052. </div>
  1053. '''
  1054. all_content_views.append(post_only_view)
  1055. # 2. 为每个点生成独立视图(包含帖子详情+点详情+匹配结果)
  1056. for point_list_key in ["灵感点列表", "目的点列表", "关键点列表"]:
  1057. point_list = how_result.get(point_list_key, [])
  1058. # 提取点类型(去掉"列表")
  1059. point_type = point_list_key.replace("列表", "")
  1060. for point_idx, point in enumerate(point_list):
  1061. # 计算该点的特征状态映射
  1062. point_feature_status_map = {}
  1063. how_steps = point.get("how步骤列表", [])
  1064. if how_steps:
  1065. features = how_steps[0].get("特征列表", [])
  1066. for feature_data in features:
  1067. feature_name = feature_data.get("特征名称", "")
  1068. match_results = feature_data.get("匹配结果", [])
  1069. max_similarity = 0.0
  1070. if match_results:
  1071. max_similarity = max(match.get("匹配结果", {}).get("相似度", 0) for match in match_results)
  1072. if max_similarity >= 0.9:
  1073. point_feature_status_map[feature_name] = "相同"
  1074. elif max_similarity >= 0.8:
  1075. point_feature_status_map[feature_name] = "相似"
  1076. else:
  1077. point_feature_status_map[feature_name] = "无关"
  1078. # 生成点的详情HTML,传入特征状态映射和点类型
  1079. point_detail_html = generate_inspiration_detail_html(point, point_feature_status_map, point_type)
  1080. # 生成该点的所有特征匹配结果
  1081. point_name = point.get("名称", f"点 {point_idx + 1}")
  1082. matches_html = ""
  1083. if how_steps:
  1084. for step_idx, step in enumerate(how_steps):
  1085. step_name = step.get("步骤名称", f"步骤 {step_idx + 1}")
  1086. features = step.get("特征列表", [])
  1087. features_html = ""
  1088. for feat_idx, feature_data in enumerate(features):
  1089. match_html = generate_match_results_html([step], feat_idx, point_idx, post_idx, category_mapping, source_mapping, point_list_key.replace("列表", ""), feat_idx + 1)
  1090. features_html += f'<div id="post-{post_idx}-feat-{point_idx}-{feat_idx}" class="feature-match-wrapper">{match_html}</div>'
  1091. step_section_id = f"post-{post_idx}-step-{point_idx}-{step_idx}"
  1092. matches_html += f'''
  1093. <div class="step-section">
  1094. <div class="step-header collapsible-header" onclick="toggleStepSection('{step_section_id}')">
  1095. <div class="header-left">
  1096. <span class="expand-icon" id="{step_section_id}-icon">▼</span>
  1097. <h3 class="step-name">{html_module.escape(step_name)}</h3>
  1098. </div>
  1099. <span class="step-inspiration-name">来自: {html_module.escape(point_name)}</span>
  1100. </div>
  1101. <div class="step-features-list" id="{step_section_id}-content">
  1102. {features_html}
  1103. </div>
  1104. </div>
  1105. '''
  1106. # 组合成完整视图
  1107. point_view_id = f"view-post-{post_idx}-point-{point_list_key}-{point_idx}"
  1108. point_view = f'''
  1109. <div class="content-view" id="{point_view_id}" style="display: none;">
  1110. <div class="post-content-wrapper">
  1111. <div class="top-section-box">
  1112. <div class="two-column-layout">
  1113. <div class="left-column">
  1114. <div class="post-detail-wrapper">
  1115. {post_detail_html}
  1116. </div>
  1117. </div>
  1118. <div class="right-column">
  1119. <div class="inspirations-detail-wrapper">
  1120. <div id="post-{post_idx}-point-{point_list_key}-{point_idx}" class="inspiration-detail-item content-section">
  1121. {point_detail_html}
  1122. </div>
  1123. </div>
  1124. </div>
  1125. </div>
  1126. </div>
  1127. <div class="matches-section">
  1128. {matches_html}
  1129. </div>
  1130. </div>
  1131. </div>
  1132. '''
  1133. all_content_views.append(point_view)
  1134. # 组合所有内容视图
  1135. all_contents_html = "\n".join(all_content_views)
  1136. # 组合目录HTML
  1137. toc_items_html = "\n".join(all_toc_items)
  1138. html = f'''
  1139. <!DOCTYPE html>
  1140. <html lang="zh-CN">
  1141. <head>
  1142. <meta charset="UTF-8">
  1143. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1144. <title>How解构结果可视化</title>
  1145. <style>
  1146. * {{
  1147. margin: 0;
  1148. padding: 0;
  1149. box-sizing: border-box;
  1150. }}
  1151. body {{
  1152. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  1153. background: #f5f5f5;
  1154. color: #333;
  1155. line-height: 1.6;
  1156. }}
  1157. /* 两栏布局容器 */
  1158. .page-container {{
  1159. display: flex;
  1160. height: 100vh;
  1161. overflow: hidden;
  1162. }}
  1163. /* 左侧目录 */
  1164. .left-sidebar {{
  1165. width: 420px;
  1166. background: white;
  1167. border-right: 2px solid #e5e7eb;
  1168. display: flex;
  1169. flex-direction: column;
  1170. overflow: hidden;
  1171. }}
  1172. /* 右侧内容区 */
  1173. .right-content {{
  1174. flex: 1;
  1175. overflow-y: auto;
  1176. background: #f5f5f5;
  1177. padding: 0;
  1178. position: relative;
  1179. }}
  1180. /* 吸顶面包屑导航 */
  1181. .breadcrumb-nav {{
  1182. position: sticky;
  1183. top: 0;
  1184. left: 0;
  1185. right: 0;
  1186. background: white;
  1187. border-bottom: 2px solid #e5e7eb;
  1188. padding: 12px 30px;
  1189. display: flex;
  1190. align-items: center;
  1191. gap: 8px;
  1192. font-size: 14px;
  1193. z-index: 100;
  1194. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  1195. }}
  1196. .breadcrumb-item {{
  1197. color: #667eea;
  1198. cursor: pointer;
  1199. transition: all 0.2s;
  1200. font-weight: 500;
  1201. }}
  1202. .breadcrumb-item:hover {{
  1203. color: #5568d3;
  1204. text-decoration: underline;
  1205. }}
  1206. .breadcrumb-separator {{
  1207. color: #9ca3af;
  1208. user-select: none;
  1209. }}
  1210. .content-view {{
  1211. padding: 30px;
  1212. width: 100%;
  1213. height: 100%;
  1214. }}
  1215. .content-view.active {{
  1216. display: block !important;
  1217. }}
  1218. .post-content-wrapper {{
  1219. max-width: 1600px;
  1220. margin: 0 auto;
  1221. display: flex;
  1222. flex-direction: column;
  1223. gap: 30px;
  1224. }}
  1225. .container {{
  1226. max-width: 1600px;
  1227. margin: 0 auto;
  1228. background: white;
  1229. min-height: 100vh;
  1230. }}
  1231. .header {{
  1232. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  1233. color: white;
  1234. padding: 20px 30px;
  1235. text-align: center;
  1236. }}
  1237. .header h1 {{
  1238. font-size: 28px;
  1239. font-weight: bold;
  1240. margin-bottom: 5px;
  1241. }}
  1242. .header p {{
  1243. font-size: 14px;
  1244. opacity: 0.9;
  1245. }}
  1246. .toc-header {{
  1247. padding: 15px 20px;
  1248. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  1249. color: white;
  1250. font-weight: 600;
  1251. font-size: 16px;
  1252. border-bottom: 2px solid #5a67d8;
  1253. }}
  1254. .toc-content {{
  1255. padding: 10px;
  1256. overflow-y: auto;
  1257. flex: 1;
  1258. }}
  1259. .toc-level-0 {{
  1260. color: #111827;
  1261. font-weight: 700;
  1262. font-size: 15px;
  1263. background: #f9fafb;
  1264. margin-top: 8px;
  1265. margin-bottom: 4px;
  1266. }}
  1267. .toc-post-header {{
  1268. font-weight: 700;
  1269. }}
  1270. .toc-badge-info {{
  1271. background: #dbeafe;
  1272. color: #1e40af;
  1273. }}
  1274. .toc-item {{
  1275. padding: 10px 15px;
  1276. margin: 4px 0;
  1277. cursor: pointer;
  1278. border-radius: 6px;
  1279. font-size: 14px;
  1280. transition: all 0.2s;
  1281. user-select: none;
  1282. display: flex;
  1283. align-items: center;
  1284. gap: 8px;
  1285. }}
  1286. .toc-item:hover {{
  1287. background: #f9fafb;
  1288. }}
  1289. .toc-item.active {{
  1290. color: #667eea;
  1291. font-weight: 600;
  1292. }}
  1293. .toc-item.active-ancestor {{
  1294. color: #667eea;
  1295. }}
  1296. .toc-expand-icon {{
  1297. font-size: 10px;
  1298. transition: transform 0.2s;
  1299. color: #9ca3af;
  1300. flex-shrink: 0;
  1301. }}
  1302. .toc-item.collapsed .toc-expand-icon {{
  1303. transform: rotate(-90deg);
  1304. }}
  1305. .toc-item-content {{
  1306. flex: 1;
  1307. min-width: 0;
  1308. }}
  1309. /* 子项隐藏 */
  1310. .toc-children {{
  1311. display: block;
  1312. }}
  1313. .toc-children.hidden {{
  1314. display: none;
  1315. }}
  1316. .toc-level-1 {{
  1317. color: #111827;
  1318. font-weight: 500;
  1319. padding-left: 20px;
  1320. }}
  1321. .toc-level-2 {{
  1322. color: #6b7280;
  1323. font-size: 13px;
  1324. padding-left: 40px;
  1325. }}
  1326. .toc-level-3 {{
  1327. padding-left: 60px;
  1328. font-size: 12px;
  1329. color: #9ca3af;
  1330. }}
  1331. .toc-level-4 {{
  1332. padding-left: 80px;
  1333. font-size: 11px;
  1334. color: #9ca3af;
  1335. }}
  1336. .toc-feature-status {{
  1337. font-weight: 500;
  1338. font-size: 10px;
  1339. padding: 2px 6px;
  1340. border-radius: 4px;
  1341. margin-left: auto;
  1342. background: #f3f4f6;
  1343. color: #6b7280;
  1344. }}
  1345. /* 目录整体结论 */
  1346. .toc-conclusion {{
  1347. padding: 15px 20px;
  1348. margin: 10px;
  1349. border-radius: 8px;
  1350. display: flex;
  1351. align-items: center;
  1352. gap: 10px;
  1353. font-weight: 600;
  1354. font-size: 14px;
  1355. }}
  1356. .toc-conclusion.conclusion-found {{
  1357. background: #d1fae5;
  1358. color: #065f46;
  1359. border: 2px solid #10b981;
  1360. }}
  1361. .toc-conclusion.conclusion-partial {{
  1362. background: #fed7aa;
  1363. color: #92400e;
  1364. border: 2px solid #f59e0b;
  1365. }}
  1366. .toc-conclusion.conclusion-not-found {{
  1367. background: #fee2e2;
  1368. color: #991b1b;
  1369. border: 2px solid #ef4444;
  1370. }}
  1371. .conclusion-icon {{
  1372. font-size: 18px;
  1373. font-weight: 700;
  1374. }}
  1375. .conclusion-text {{
  1376. flex: 1;
  1377. }}
  1378. .toc-badge {{
  1379. display: inline-block;
  1380. font-size: 12px;
  1381. margin-right: 6px;
  1382. opacity: 0.8;
  1383. }}
  1384. .toc-group-header {{
  1385. font-weight: 600;
  1386. cursor: pointer !important;
  1387. }}
  1388. .toc-point-status {{
  1389. font-size: 10px;
  1390. font-weight: 500;
  1391. padding: 2px 6px;
  1392. border-radius: 4px;
  1393. margin-left: auto;
  1394. background: #f3f4f6;
  1395. color: #6b7280;
  1396. }}
  1397. .main-content {{
  1398. min-width: 0;
  1399. display: flex;
  1400. flex-direction: column;
  1401. gap: 30px;
  1402. }}
  1403. /* 顶部框:包含帖子详情和灵感点详情 */
  1404. .top-section-box {{
  1405. background: white;
  1406. border: 1px solid #e5e7eb;
  1407. border-radius: 12px;
  1408. padding: 25px;
  1409. box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  1410. }}
  1411. /* 顶部框内的两栏布局 */
  1412. .two-column-layout {{
  1413. display: grid;
  1414. grid-template-columns: 380px 1fr;
  1415. gap: 25px;
  1416. align-items: start;
  1417. }}
  1418. .left-column {{
  1419. position: relative;
  1420. }}
  1421. .post-detail-wrapper {{
  1422. /* 帖子详情区域 */
  1423. }}
  1424. .right-column {{
  1425. min-width: 0;
  1426. }}
  1427. .inspirations-detail-wrapper {{
  1428. display: flex;
  1429. flex-direction: column;
  1430. gap: 20px;
  1431. max-height: 600px;
  1432. overflow-y: auto;
  1433. padding-right: 10px;
  1434. }}
  1435. .inspiration-detail-item {{
  1436. /* 单个灵感点详情 */
  1437. }}
  1438. /* 匹配结果区域 */
  1439. .matches-section {{
  1440. display: flex;
  1441. flex-direction: column;
  1442. gap: 20px;
  1443. }}
  1444. /* 步骤区域 */
  1445. .step-section {{
  1446. background: white;
  1447. border: 2px solid #e5e7eb;
  1448. border-radius: 12px;
  1449. overflow: hidden;
  1450. box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  1451. transition: all 0.3s ease;
  1452. }}
  1453. .step-section:hover {{
  1454. box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  1455. border-color: #d1d5db;
  1456. }}
  1457. .step-header {{
  1458. padding: 18px 24px;
  1459. background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
  1460. border-bottom: 2px solid #e5e7eb;
  1461. display: flex;
  1462. justify-content: space-between;
  1463. align-items: center;
  1464. cursor: pointer;
  1465. user-select: none;
  1466. transition: all 0.3s ease;
  1467. }}
  1468. .step-header:hover {{
  1469. background: linear-gradient(135deg, #f3f4f6 0%, #f9fafb 100%);
  1470. }}
  1471. .step-name {{
  1472. font-size: 18px;
  1473. color: #111827;
  1474. font-weight: 600;
  1475. margin: 0;
  1476. }}
  1477. .step-inspiration-name {{
  1478. font-size: 14px;
  1479. color: #6b7280;
  1480. font-style: italic;
  1481. }}
  1482. .step-features-list {{
  1483. padding: 20px;
  1484. display: flex;
  1485. flex-direction: column;
  1486. gap: 15px;
  1487. }}
  1488. .feature-match-wrapper {{
  1489. /* 特征匹配容器 */
  1490. }}
  1491. .content-section {{
  1492. scroll-margin-top: 80px;
  1493. }}
  1494. /* 帖子详情卡片(紧凑样式) */
  1495. .post-card-compact {{
  1496. display: grid;
  1497. grid-template-columns: 200px 1fr;
  1498. gap: 20px;
  1499. background: white;
  1500. border: 1px solid #e5e7eb;
  1501. border-radius: 12px;
  1502. overflow: hidden;
  1503. padding: 20px;
  1504. cursor: pointer;
  1505. transition: all 0.3s;
  1506. margin-bottom: 30px;
  1507. }}
  1508. .post-card-compact:hover {{
  1509. box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  1510. transform: translateY(-2px);
  1511. border-color: #667eea;
  1512. }}
  1513. .post-card-image {{
  1514. position: relative;
  1515. display: flex;
  1516. align-items: center;
  1517. justify-content: center;
  1518. }}
  1519. .post-card-thumbnail {{
  1520. width: 100%;
  1521. height: 150px;
  1522. object-fit: contain;
  1523. border-radius: 8px;
  1524. background: #f9fafb;
  1525. }}
  1526. .post-card-thumbnail-placeholder {{
  1527. width: 100%;
  1528. height: 150px;
  1529. display: flex;
  1530. align-items: center;
  1531. justify-content: center;
  1532. background: #f3f4f6;
  1533. color: #9ca3af;
  1534. font-size: 48px;
  1535. border-radius: 8px;
  1536. }}
  1537. .post-card-image-count {{
  1538. position: absolute;
  1539. bottom: 8px;
  1540. right: 8px;
  1541. background: rgba(0, 0, 0, 0.7);
  1542. color: white;
  1543. padding: 4px 8px;
  1544. border-radius: 12px;
  1545. font-size: 11px;
  1546. font-weight: 600;
  1547. }}
  1548. .post-card-content {{
  1549. display: flex;
  1550. flex-direction: column;
  1551. gap: 12px;
  1552. }}
  1553. .post-card-title {{
  1554. font-size: 18px;
  1555. font-weight: 600;
  1556. color: #111827;
  1557. line-height: 1.4;
  1558. overflow: hidden;
  1559. text-overflow: ellipsis;
  1560. display: -webkit-box;
  1561. -webkit-line-clamp: 2;
  1562. -webkit-box-orient: vertical;
  1563. }}
  1564. .post-card-preview {{
  1565. font-size: 14px;
  1566. color: #6b7280;
  1567. line-height: 1.6;
  1568. overflow: hidden;
  1569. text-overflow: ellipsis;
  1570. display: -webkit-box;
  1571. -webkit-line-clamp: 2;
  1572. -webkit-box-orient: vertical;
  1573. }}
  1574. .post-card-meta {{
  1575. display: flex;
  1576. gap: 15px;
  1577. font-size: 13px;
  1578. color: #9ca3af;
  1579. }}
  1580. .post-card-stats {{
  1581. display: flex;
  1582. gap: 15px;
  1583. font-size: 13px;
  1584. color: #6b7280;
  1585. font-weight: 500;
  1586. }}
  1587. /* 灵感点详情卡片样式保持不变 */
  1588. .inspiration-detail-card {{
  1589. background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
  1590. padding: 25px;
  1591. border-bottom: 2px solid #e5e7eb;
  1592. }}
  1593. .inspiration-header {{
  1594. margin-bottom: 15px;
  1595. display: flex;
  1596. align-items: center;
  1597. gap: 10px;
  1598. flex-wrap: wrap;
  1599. }}
  1600. .inspiration-conclusion {{
  1601. padding: 6px 14px;
  1602. border-radius: 16px;
  1603. font-size: 13px;
  1604. font-weight: 700;
  1605. margin-left: auto;
  1606. }}
  1607. .inspiration-conclusion.insp-conclusion-found {{
  1608. background: #d1fae5;
  1609. color: #065f46;
  1610. border: 2px solid #10b981;
  1611. }}
  1612. .inspiration-conclusion.insp-conclusion-partial {{
  1613. background: #fed7aa;
  1614. color: #92400e;
  1615. border: 2px solid #f59e0b;
  1616. }}
  1617. .inspiration-conclusion.insp-conclusion-not-found {{
  1618. background: #fee2e2;
  1619. color: #991b1b;
  1620. border: 2px solid #ef4444;
  1621. }}
  1622. .inspiration-type-badge {{
  1623. display: inline-block;
  1624. padding: 4px 12px;
  1625. background: #fef3c7;
  1626. color: #92400e;
  1627. border-radius: 12px;
  1628. font-size: 12px;
  1629. font-weight: 600;
  1630. }}
  1631. .inspiration-name {{
  1632. font-size: 20px;
  1633. color: #111827;
  1634. font-weight: 600;
  1635. margin: 0;
  1636. }}
  1637. .inspiration-description {{
  1638. margin-bottom: 15px;
  1639. }}
  1640. .desc-label {{
  1641. font-weight: 600;
  1642. color: #6b7280;
  1643. font-size: 13px;
  1644. margin-bottom: 8px;
  1645. }}
  1646. .desc-text {{
  1647. color: #4b5563;
  1648. font-size: 14px;
  1649. line-height: 1.7;
  1650. }}
  1651. .inspiration-features {{
  1652. margin-top: 15px;
  1653. }}
  1654. .features-label {{
  1655. font-weight: 600;
  1656. color: #6b7280;
  1657. font-size: 13px;
  1658. margin-bottom: 8px;
  1659. }}
  1660. .features-tags {{
  1661. display: flex;
  1662. flex-wrap: wrap;
  1663. gap: 8px;
  1664. }}
  1665. .feature-tag {{
  1666. padding: 5px 12px;
  1667. background: #667eea;
  1668. color: white;
  1669. border-radius: 16px;
  1670. font-size: 13px;
  1671. font-weight: 500;
  1672. display: inline-flex;
  1673. align-items: center;
  1674. gap: 4px;
  1675. }}
  1676. .feature-tag.feature-same {{
  1677. background: #10b981;
  1678. }}
  1679. .feature-tag.feature-similar {{
  1680. background: #f59e0b;
  1681. }}
  1682. .feature-tag.feature-unrelated {{
  1683. background: #9ca3af;
  1684. }}
  1685. .feature-status-label {{
  1686. font-weight: 700;
  1687. font-size: 11px;
  1688. padding: 2px 6px;
  1689. background: rgba(255, 255, 255, 0.3);
  1690. border-radius: 4px;
  1691. }}
  1692. /* 匹配结果部分 */
  1693. .match-results-section {{
  1694. padding: 48px 25px;
  1695. border-bottom: none;
  1696. }}
  1697. .match-results-section:first-child {{
  1698. padding-top: 25px;
  1699. }}
  1700. .match-section-header {{
  1701. display: flex;
  1702. justify-content: space-between;
  1703. align-items: center;
  1704. padding: 10px 0 24px 0;
  1705. background: transparent;
  1706. border: none;
  1707. border-bottom: 1px solid #e5e7eb;
  1708. border-radius: 0;
  1709. gap: 12px;
  1710. cursor: pointer;
  1711. user-select: none;
  1712. transition: all 0.2s ease;
  1713. }}
  1714. .match-section-header:hover {{
  1715. border-bottom-color: #9ca3af;
  1716. }}
  1717. .header-left {{
  1718. display: flex;
  1719. align-items: center;
  1720. gap: 10px;
  1721. flex: 1;
  1722. }}
  1723. .collapsible-header {{
  1724. cursor: pointer;
  1725. user-select: none;
  1726. transition: background 0.2s;
  1727. padding: 10px;
  1728. margin: -10px;
  1729. border-radius: 6px;
  1730. }}
  1731. .collapsible-header:hover {{
  1732. background: #f9fafb;
  1733. }}
  1734. .overall-top-match {{
  1735. display: inline-flex;
  1736. align-items: center;
  1737. gap: 8px;
  1738. padding: 6px 12px;
  1739. background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  1740. border-radius: 8px;
  1741. font-size: 13px;
  1742. border: 1px solid #bae6fd;
  1743. flex-shrink: 0;
  1744. }}
  1745. .overall-top-label {{
  1746. font-weight: 700;
  1747. color: #0369a1;
  1748. }}
  1749. .overall-top-combined {{
  1750. padding: 3px 8px;
  1751. background: linear-gradient(135deg, #e0e7ff 0%, #fef3c7 100%);
  1752. color: #4338ca;
  1753. border-radius: 6px;
  1754. font-size: 11px;
  1755. font-weight: 600;
  1756. border: 1px solid #c7d2fe;
  1757. }}
  1758. .overall-top-name {{
  1759. font-weight: 700;
  1760. color: #1e40af;
  1761. }}
  1762. .overall-top-score {{
  1763. padding: 4px 12px;
  1764. border-radius: 12px;
  1765. font-size: 13px;
  1766. font-weight: 700;
  1767. margin-left: auto;
  1768. }}
  1769. .match-section-header .header-left {{
  1770. display: flex;
  1771. align-items: center;
  1772. gap: 10px;
  1773. flex: 1;
  1774. }}
  1775. .match-section-header h4 {{
  1776. font-size: 18px;
  1777. color: #111827;
  1778. margin: 0;
  1779. }}
  1780. .match-stats {{
  1781. display: flex;
  1782. gap: 10px;
  1783. flex-wrap: wrap;
  1784. }}
  1785. .stat-badge {{
  1786. padding: 4px 10px;
  1787. border-radius: 12px;
  1788. color: white;
  1789. font-size: 12px;
  1790. font-weight: 600;
  1791. }}
  1792. .matches-list {{
  1793. display: flex;
  1794. flex-direction: column;
  1795. gap: 8px;
  1796. transition: all 0.3s ease;
  1797. overflow: hidden;
  1798. }}
  1799. .match-group-section {{
  1800. margin-bottom: 20px;
  1801. background: white;
  1802. border: 1px solid #e5e7eb;
  1803. border-radius: 8px;
  1804. overflow: hidden;
  1805. }}
  1806. .match-group-header {{
  1807. padding: 12px 18px;
  1808. background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  1809. border-bottom: 2px solid #d1d5db;
  1810. cursor: pointer;
  1811. user-select: none;
  1812. display: flex;
  1813. align-items: center;
  1814. gap: 10px;
  1815. transition: background 0.2s;
  1816. }}
  1817. .match-group-header:hover {{
  1818. background: linear-gradient(135deg, #e5e7eb 0%, #d1d5db 100%);
  1819. }}
  1820. .match-group-title {{
  1821. font-size: 15px;
  1822. font-weight: 600;
  1823. color: #374151;
  1824. margin: 0;
  1825. }}
  1826. .match-group-content {{
  1827. padding: 15px;
  1828. display: flex;
  1829. flex-direction: row;
  1830. flex-wrap: wrap;
  1831. gap: 10px;
  1832. }}
  1833. /* 层级分组样式 - 极简无边框 */
  1834. .level-group-section {{
  1835. background: transparent;
  1836. border: none;
  1837. border-radius: 0;
  1838. overflow: visible;
  1839. }}
  1840. .level-group-header {{
  1841. padding: 20px 0 16px 0;
  1842. background: transparent;
  1843. border-bottom: 1px solid #e5e7eb;
  1844. cursor: pointer;
  1845. user-select: none;
  1846. display: flex;
  1847. justify-content: space-between;
  1848. align-items: center;
  1849. transition: all 0.2s ease;
  1850. }}
  1851. .level-group-header:hover {{
  1852. border-bottom-color: #9ca3af;
  1853. }}
  1854. .level-group-header .expand-icon {{
  1855. color: #6b7280;
  1856. font-size: 13px;
  1857. }}
  1858. .level-header-left {{
  1859. display: flex;
  1860. align-items: center;
  1861. gap: 8px;
  1862. }}
  1863. .level-group-title {{
  1864. font-size: 15px;
  1865. font-weight: 600;
  1866. color: #111827;
  1867. margin: 0;
  1868. }}
  1869. .level-stats {{
  1870. display: inline-flex;
  1871. gap: 8px;
  1872. align-items: center;
  1873. }}
  1874. .level-top-match {{
  1875. display: inline-flex;
  1876. align-items: center;
  1877. gap: 6px;
  1878. font-size: 12px;
  1879. color: #6b7280;
  1880. }}
  1881. .top-match-label {{
  1882. font-weight: 500;
  1883. color: #9ca3af;
  1884. }}
  1885. .top-match-type {{
  1886. padding: 2px 6px;
  1887. background: #f3f4f6;
  1888. border-radius: 4px;
  1889. font-size: 11px;
  1890. font-weight: 500;
  1891. color: #6b7280;
  1892. }}
  1893. .top-match-name {{
  1894. font-weight: 500;
  1895. color: #374151;
  1896. }}
  1897. .top-match-score {{
  1898. padding: 3px 10px;
  1899. border-radius: 12px;
  1900. font-size: 12px;
  1901. font-weight: 700;
  1902. margin-left: auto;
  1903. }}
  1904. .level-group-content {{
  1905. padding: 0;
  1906. background: transparent;
  1907. transition: all 0.3s ease;
  1908. overflow: hidden;
  1909. }}
  1910. .level-group-content.collapsed {{
  1911. display: none;
  1912. }}
  1913. /* 子分组样式 - 极简 */
  1914. .match-subgroup-section {{
  1915. display: block;
  1916. width: 100%;
  1917. background: transparent;
  1918. border-radius: 0;
  1919. overflow: visible;
  1920. }}
  1921. .match-subgroup-header {{
  1922. padding: 12px 0 8px 0;
  1923. background: transparent;
  1924. cursor: pointer;
  1925. user-select: none;
  1926. display: flex;
  1927. justify-content: space-between;
  1928. align-items: center;
  1929. transition: all 0.2s ease;
  1930. border-bottom: 1px solid #f3f4f6;
  1931. }}
  1932. .match-subgroup-header:hover {{
  1933. border-bottom-color: #e5e7eb;
  1934. }}
  1935. .subgroup-header-left {{
  1936. display: flex;
  1937. align-items: center;
  1938. gap: 8px;
  1939. }}
  1940. .match-subgroup-title {{
  1941. font-size: 13px;
  1942. font-weight: 600;
  1943. color: #374151;
  1944. margin: 0;
  1945. }}
  1946. .subgroup-top-match {{
  1947. display: inline-flex;
  1948. align-items: center;
  1949. gap: 6px;
  1950. font-size: 11px;
  1951. color: #6b7280;
  1952. }}
  1953. .subgroup-top-label {{
  1954. font-weight: 500;
  1955. color: #9ca3af;
  1956. }}
  1957. .subgroup-top-combined {{
  1958. padding: 2px 6px;
  1959. background: #f3f4f6;
  1960. color: #6b7280;
  1961. border-radius: 4px;
  1962. font-size: 10px;
  1963. font-weight: 500;
  1964. }}
  1965. .subgroup-top-name {{
  1966. font-weight: 500;
  1967. color: #374151;
  1968. }}
  1969. .subgroup-top-score {{
  1970. padding: 2px 8px;
  1971. border-radius: 10px;
  1972. font-size: 11px;
  1973. font-weight: 600;
  1974. }}
  1975. .match-subgroup-content {{
  1976. padding: 0;
  1977. display: flex;
  1978. flex-direction: row;
  1979. flex-wrap: wrap;
  1980. gap: 8px;
  1981. transition: all 0.3s ease;
  1982. overflow: hidden;
  1983. background: transparent;
  1984. }}
  1985. .match-item-compact {{
  1986. display: inline-flex;
  1987. align-items: center;
  1988. gap: 6px;
  1989. padding: 8px 14px;
  1990. background: transparent;
  1991. border: 1.5px solid #e5e7eb;
  1992. border-radius: 8px;
  1993. font-size: 13px;
  1994. transition: all 0.3s ease;
  1995. cursor: pointer;
  1996. }}
  1997. .match-item-compact:hover {{
  1998. border-color: #667eea;
  1999. box-shadow: 0 4px 8px rgba(102, 126, 234, 0.15);
  2000. transform: translateY(-2px);
  2001. background: #fafbff;
  2002. }}
  2003. .match-item-compact:active {{
  2004. transform: translateY(0);
  2005. }}
  2006. /* 匹配项中的层级-类型标签 */
  2007. .match-item-compact .feature-combined-badge {{
  2008. color: #9ca3af;
  2009. }}
  2010. /* 匹配详情模态框 */
  2011. .match-modal {{
  2012. display: none;
  2013. position: fixed;
  2014. z-index: 3000;
  2015. left: 0;
  2016. top: 0;
  2017. width: 100%;
  2018. height: 100%;
  2019. background: rgba(0, 0, 0, 0.5);
  2020. animation: fadeIn 0.2s;
  2021. }}
  2022. .match-modal-content {{
  2023. position: relative;
  2024. background: white;
  2025. margin: 5% auto;
  2026. padding: 0;
  2027. width: 80%;
  2028. max-width: 900px;
  2029. max-height: 80vh;
  2030. border-radius: 12px;
  2031. box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  2032. overflow: hidden;
  2033. animation: slideDown 0.3s;
  2034. }}
  2035. .match-modal-header {{
  2036. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  2037. color: white;
  2038. padding: 20px 25px;
  2039. display: flex;
  2040. align-items: center;
  2041. justify-content: space-between;
  2042. }}
  2043. .match-modal-title {{
  2044. font-size: 18px;
  2045. font-weight: 600;
  2046. margin: 0;
  2047. }}
  2048. .match-modal-close {{
  2049. color: white;
  2050. font-size: 32px;
  2051. font-weight: 300;
  2052. cursor: pointer;
  2053. background: none;
  2054. border: none;
  2055. padding: 0;
  2056. line-height: 1;
  2057. transition: transform 0.2s;
  2058. }}
  2059. .match-modal-close:hover {{
  2060. transform: scale(1.2);
  2061. }}
  2062. .match-modal-body {{
  2063. padding: 25px;
  2064. max-height: calc(80vh - 80px);
  2065. overflow-y: auto;
  2066. }}
  2067. .match-detail-section {{
  2068. margin-bottom: 25px;
  2069. }}
  2070. .match-detail-section h3 {{
  2071. font-size: 16px;
  2072. font-weight: 600;
  2073. color: #374151;
  2074. margin-bottom: 12px;
  2075. padding-bottom: 8px;
  2076. border-bottom: 2px solid #e5e7eb;
  2077. }}
  2078. .match-explanation-text {{
  2079. line-height: 1.8;
  2080. color: #4b5563;
  2081. padding: 15px;
  2082. background: #f9fafb;
  2083. border-radius: 8px;
  2084. border-left: 4px solid #667eea;
  2085. }}
  2086. .match-item-collapsible {{
  2087. border: 1px solid #e5e7eb;
  2088. border-radius: 8px;
  2089. overflow: hidden;
  2090. background: white;
  2091. transition: box-shadow 0.2s;
  2092. }}
  2093. .match-item-collapsible:hover {{
  2094. box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  2095. }}
  2096. .match-header {{
  2097. padding: 12px 16px;
  2098. cursor: pointer;
  2099. user-select: none;
  2100. transition: background 0.2s;
  2101. }}
  2102. .match-header:hover {{
  2103. background: #f9fafb;
  2104. }}
  2105. .match-header-left {{
  2106. display: flex;
  2107. align-items: center;
  2108. gap: 10px;
  2109. }}
  2110. .expand-icon {{
  2111. color: #9ca3af;
  2112. font-size: 14px;
  2113. transition: transform 0.3s ease;
  2114. display: inline-flex;
  2115. align-items: center;
  2116. justify-content: center;
  2117. width: 20px;
  2118. height: 20px;
  2119. flex-shrink: 0;
  2120. }}
  2121. .expand-icon.expanded {{
  2122. transform: rotate(0deg);
  2123. }}
  2124. /* 折叠状态时旋转 */
  2125. .collapsed .expand-icon {{
  2126. transform: rotate(-90deg);
  2127. }}
  2128. .persona-name {{
  2129. font-weight: 600;
  2130. font-size: 14px;
  2131. color: #111827;
  2132. }}
  2133. .match-item-compact .persona-name {{
  2134. font-weight: 500;
  2135. font-size: 13px;
  2136. color: #374151;
  2137. }}
  2138. .relation-badge {{
  2139. padding: 3px 10px;
  2140. border-radius: 12px;
  2141. color: white;
  2142. font-size: 11px;
  2143. font-weight: 600;
  2144. }}
  2145. .score-badge {{
  2146. padding: 3px 10px;
  2147. border-radius: 12px;
  2148. background: #e5e7eb;
  2149. color: #374151;
  2150. font-size: 11px;
  2151. font-weight: 600;
  2152. }}
  2153. .feature-combined-badge {{
  2154. padding: 3px 8px;
  2155. border-radius: 10px;
  2156. background: transparent;
  2157. color: #9ca3af;
  2158. font-size: 10px;
  2159. font-weight: 500;
  2160. border: none;
  2161. }}
  2162. .feature-combined-badge.combined-badge-same {{
  2163. background: transparent;
  2164. color: #9ca3af;
  2165. border: none;
  2166. box-shadow: none;
  2167. font-weight: 500;
  2168. }}
  2169. .feature-category-badge {{
  2170. padding: 3px 8px;
  2171. border-radius: 10px;
  2172. background: #dbeafe;
  2173. color: #1e40af;
  2174. font-size: 10px;
  2175. font-weight: 500;
  2176. border: 1px solid #93c5fd;
  2177. }}
  2178. /* 同层级匹配 - 统一边框颜色 */
  2179. .match-item-compact.match-same-level {{
  2180. border: 1.5px solid #e5e7eb;
  2181. background: transparent;
  2182. box-shadow: none;
  2183. }}
  2184. .match-item-compact.match-same-level:hover {{
  2185. border-color: #667eea;
  2186. box-shadow: 0 4px 8px rgba(102, 126, 234, 0.15);
  2187. transform: translateY(-2px);
  2188. background: #fafbff;
  2189. }}
  2190. .level-badge {{
  2191. padding: 4px 10px;
  2192. border-radius: 12px;
  2193. font-size: 11px;
  2194. font-weight: 600;
  2195. margin-right: 6px;
  2196. }}
  2197. .level-badge-match {{
  2198. background: #e0e7ff;
  2199. color: #4338ca;
  2200. border: 1px solid #a5b4fc;
  2201. }}
  2202. .level-badge-category {{
  2203. background: #fef3c7;
  2204. color: #92400e;
  2205. border: 1px solid #fcd34d;
  2206. }}
  2207. .feature-match-status {{
  2208. padding: 5px 12px;
  2209. border-radius: 12px;
  2210. font-size: 12px;
  2211. font-weight: 700;
  2212. margin-left: 12px;
  2213. }}
  2214. .feature-match-status.status-same {{
  2215. background: #d1fae5;
  2216. color: #065f46;
  2217. border: 2px solid #10b981;
  2218. }}
  2219. .feature-match-status.status-similar {{
  2220. background: #fed7aa;
  2221. color: #92400e;
  2222. border: 2px solid #f59e0b;
  2223. }}
  2224. .feature-match-status.status-unrelated {{
  2225. background: #e5e7eb;
  2226. color: #4b5563;
  2227. border: 2px solid #9ca3af;
  2228. }}
  2229. .match-content {{
  2230. padding: 16px;
  2231. background: #f9fafb;
  2232. border-top: 1px solid #e5e7eb;
  2233. }}
  2234. .match-explanation {{
  2235. font-size: 13px;
  2236. color: #4b5563;
  2237. line-height: 1.7;
  2238. margin-bottom: 16px;
  2239. }}
  2240. /* 历史帖子来源区域 */
  2241. .historical-posts-section {{
  2242. margin-top: 20px;
  2243. padding-top: 20px;
  2244. border-top: 2px solid #e5e7eb;
  2245. }}
  2246. .historical-posts-title {{
  2247. font-size: 14px;
  2248. font-weight: 600;
  2249. color: #374151;
  2250. margin-bottom: 12px;
  2251. }}
  2252. .historical-posts-grid {{
  2253. display: grid;
  2254. grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  2255. gap: 16px;
  2256. }}
  2257. .historical-post-card {{
  2258. display: grid;
  2259. grid-template-columns: 120px 1fr;
  2260. gap: 12px;
  2261. background: white;
  2262. border: 1px solid #e5e7eb;
  2263. border-radius: 8px;
  2264. padding: 12px;
  2265. transition: all 0.2s;
  2266. cursor: pointer;
  2267. }}
  2268. .historical-post-card:hover {{
  2269. border-color: #667eea;
  2270. box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
  2271. transform: translateY(-2px);
  2272. }}
  2273. .historical-post-image {{
  2274. position: relative;
  2275. }}
  2276. .historical-post-thumbnail {{
  2277. width: 100%;
  2278. height: 100px;
  2279. object-fit: contain;
  2280. border-radius: 6px;
  2281. background: #f9fafb;
  2282. }}
  2283. .historical-post-content {{
  2284. display: flex;
  2285. flex-direction: column;
  2286. gap: 8px;
  2287. }}
  2288. .historical-post-title {{
  2289. font-size: 13px;
  2290. font-weight: 600;
  2291. color: #1f2937;
  2292. line-height: 1.4;
  2293. overflow: hidden;
  2294. display: -webkit-box;
  2295. -webkit-line-clamp: 2;
  2296. -webkit-box-orient: vertical;
  2297. }}
  2298. .historical-inspiration-info {{
  2299. display: flex;
  2300. align-items: center;
  2301. gap: 6px;
  2302. }}
  2303. .inspiration-type-badge-small {{
  2304. padding: 2px 6px;
  2305. border-radius: 4px;
  2306. background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  2307. color: white;
  2308. font-size: 10px;
  2309. font-weight: 600;
  2310. }}
  2311. .inspiration-name-small {{
  2312. font-size: 11px;
  2313. color: #667eea;
  2314. font-weight: 500;
  2315. }}
  2316. .historical-inspiration-desc {{
  2317. font-size: 11px;
  2318. color: #6b7280;
  2319. line-height: 1.5;
  2320. overflow: hidden;
  2321. display: -webkit-box;
  2322. -webkit-line-clamp: 2;
  2323. -webkit-box-orient: vertical;
  2324. }}
  2325. .historical-post-meta {{
  2326. margin: 4px 0;
  2327. }}
  2328. .historical-post-time {{
  2329. font-size: 11px;
  2330. color: #9ca3af;
  2331. }}
  2332. .historical-post-stats {{
  2333. display: flex;
  2334. align-items: center;
  2335. gap: 10px;
  2336. font-size: 11px;
  2337. color: #9ca3af;
  2338. }}
  2339. .view-link {{
  2340. margin-left: auto;
  2341. color: #667eea;
  2342. text-decoration: none;
  2343. font-weight: 500;
  2344. }}
  2345. .view-link:hover {{
  2346. color: #764ba2;
  2347. }}
  2348. .category-simple {{
  2349. color: #9ca3af;
  2350. font-size: 12px;
  2351. font-weight: 400;
  2352. margin-right: 6px;
  2353. }}
  2354. /* 帖子详情模态框 */
  2355. .post-detail-modal {{
  2356. display: none;
  2357. position: fixed;
  2358. z-index: 4000;
  2359. left: 0;
  2360. top: 0;
  2361. width: 100%;
  2362. height: 100%;
  2363. background: rgba(0, 0, 0, 0.7);
  2364. overflow: auto;
  2365. animation: fadeIn 0.3s;
  2366. }}
  2367. .post-detail-modal.active {{
  2368. display: flex;
  2369. align-items: center;
  2370. justify-content: center;
  2371. padding: 40px 20px;
  2372. }}
  2373. .post-detail-content {{
  2374. position: relative;
  2375. background: white;
  2376. border-radius: 16px;
  2377. max-width: 900px;
  2378. width: 100%;
  2379. max-height: 90vh;
  2380. overflow-y: auto;
  2381. box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  2382. }}
  2383. .post-detail-close {{
  2384. position: sticky;
  2385. top: 20px;
  2386. right: 20px;
  2387. float: right;
  2388. font-size: 36px;
  2389. font-weight: 300;
  2390. color: #9ca3af;
  2391. background: white;
  2392. border: none;
  2393. cursor: pointer;
  2394. width: 40px;
  2395. height: 40px;
  2396. border-radius: 50%;
  2397. display: flex;
  2398. align-items: center;
  2399. justify-content: center;
  2400. transition: all 0.2s;
  2401. z-index: 10;
  2402. box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  2403. }}
  2404. .post-detail-close:hover {{
  2405. color: #ef4444;
  2406. background: #fee2e2;
  2407. transform: rotate(90deg);
  2408. }}
  2409. .post-detail-header {{
  2410. padding: 40px 40px 20px 40px;
  2411. border-bottom: 2px solid #e5e7eb;
  2412. }}
  2413. .post-detail-title {{
  2414. font-size: 28px;
  2415. font-weight: bold;
  2416. color: #111827;
  2417. line-height: 1.4;
  2418. margin-bottom: 15px;
  2419. }}
  2420. .post-detail-meta {{
  2421. display: flex;
  2422. justify-content: space-between;
  2423. align-items: center;
  2424. color: #6b7280;
  2425. font-size: 14px;
  2426. gap: 20px;
  2427. }}
  2428. .post-detail-author {{
  2429. font-weight: 500;
  2430. }}
  2431. .post-detail-time {{
  2432. color: #9ca3af;
  2433. }}
  2434. .post-detail-stats {{
  2435. display: flex;
  2436. gap: 15px;
  2437. font-weight: 500;
  2438. }}
  2439. .post-detail-body {{
  2440. padding: 30px 40px;
  2441. }}
  2442. .post-detail-desc {{
  2443. font-size: 15px;
  2444. color: #4b5563;
  2445. line-height: 1.8;
  2446. margin-bottom: 25px;
  2447. white-space: pre-wrap;
  2448. }}
  2449. .post-detail-images {{
  2450. display: grid;
  2451. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  2452. gap: 15px;
  2453. margin-top: 20px;
  2454. }}
  2455. .post-detail-image {{
  2456. width: 100%;
  2457. border-radius: 8px;
  2458. object-fit: cover;
  2459. cursor: pointer;
  2460. transition: transform 0.2s;
  2461. }}
  2462. .post-detail-image:hover {{
  2463. transform: scale(1.02);
  2464. }}
  2465. .post-detail-footer {{
  2466. padding: 20px 40px 30px 40px;
  2467. border-top: 1px solid #e5e7eb;
  2468. text-align: center;
  2469. }}
  2470. .post-detail-link {{
  2471. display: inline-block;
  2472. padding: 12px 30px;
  2473. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  2474. color: white;
  2475. text-decoration: none;
  2476. border-radius: 8px;
  2477. font-weight: 500;
  2478. transition: all 0.3s;
  2479. }}
  2480. .post-detail-link:hover {{
  2481. transform: translateY(-2px);
  2482. box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  2483. }}
  2484. /* 响应式 */
  2485. @media (max-width: 1400px) {{
  2486. .content-with-toc {{
  2487. grid-template-columns: 240px 1fr;
  2488. }}
  2489. .two-column-layout {{
  2490. grid-template-columns: 320px 1fr;
  2491. }}
  2492. }}
  2493. @media (max-width: 1200px) {{
  2494. .content-with-toc {{
  2495. grid-template-columns: 200px 1fr;
  2496. }}
  2497. .two-column-layout {{
  2498. grid-template-columns: 280px 1fr;
  2499. }}
  2500. }}
  2501. @media (max-width: 1024px) {{
  2502. .page-container {{
  2503. flex-direction: column;
  2504. height: auto;
  2505. }}
  2506. .left-sidebar {{
  2507. width: 100%;
  2508. max-height: 300px;
  2509. border-right: none;
  2510. border-bottom: 2px solid #e5e7eb;
  2511. }}
  2512. .right-content {{
  2513. height: auto;
  2514. }}
  2515. .two-column-layout {{
  2516. grid-template-columns: 1fr;
  2517. }}
  2518. .inspirations-detail-wrapper {{
  2519. max-height: none;
  2520. }}
  2521. .post-card-compact {{
  2522. grid-template-columns: 150px 1fr;
  2523. }}
  2524. }}
  2525. @media (max-width: 768px) {{
  2526. .header {{
  2527. padding: 15px 20px;
  2528. }}
  2529. .header h1 {{
  2530. font-size: 24px;
  2531. }}
  2532. .left-sidebar {{
  2533. max-height: 250px;
  2534. }}
  2535. .post-info-section {{
  2536. padding: 20px;
  2537. }}
  2538. }}
  2539. </style>
  2540. </head>
  2541. <body>
  2542. <div class="page-container">
  2543. <!-- 左侧目录 -->
  2544. <div class="left-sidebar">
  2545. <div class="header">
  2546. <h1>How 解构结果</h1>
  2547. <p>灵感点特征匹配分析</p>
  2548. </div>
  2549. <div class="toc-content">
  2550. {toc_items_html}
  2551. </div>
  2552. </div>
  2553. <!-- 右侧内容 -->
  2554. <div class="right-content">
  2555. <!-- 吸顶面包屑导航 -->
  2556. <div class="breadcrumb-nav" id="breadcrumb-nav">
  2557. <span class="breadcrumb-item" id="breadcrumb-point">-</span>
  2558. <span class="breadcrumb-separator" id="sep-1" style="display:none;">></span>
  2559. <span class="breadcrumb-item" id="breadcrumb-step" style="display:none;">-</span>
  2560. <span class="breadcrumb-separator" id="sep-2" style="display:none;">></span>
  2561. <span class="breadcrumb-item" id="breadcrumb-feature" style="display:none;">-</span>
  2562. <span class="breadcrumb-separator" id="sep-3" style="display:none;">></span>
  2563. <span class="breadcrumb-item" id="breadcrumb-level" style="display:none;">-</span>
  2564. <span class="breadcrumb-separator" id="sep-4" style="display:none;">></span>
  2565. <span class="breadcrumb-item" id="breadcrumb-subgroup" style="display:none;">-</span>
  2566. </div>
  2567. {all_contents_html}
  2568. </div>
  2569. </div>
  2570. <!-- 匹配详情模态框 -->
  2571. <div id="matchModal" class="match-modal" onclick="closeMatchModal(event)">
  2572. <div class="match-modal-content" onclick="event.stopPropagation()">
  2573. <div class="match-modal-header">
  2574. <h2 class="match-modal-title" id="matchModalTitle"></h2>
  2575. <button class="match-modal-close" onclick="closeMatchModal()">&times;</button>
  2576. </div>
  2577. <div class="match-modal-body" id="matchModalBody"></div>
  2578. </div>
  2579. </div>
  2580. <!-- 帖子详情模态框 -->
  2581. <div id="postDetailModal" class="post-detail-modal" onclick="closePostDetail(event)"></div>
  2582. <script>
  2583. // 切换内容视图
  2584. function showContentView(viewId, clickedElement) {{
  2585. // 隐藏所有视图
  2586. var allViews = document.querySelectorAll('.content-view');
  2587. allViews.forEach(function(view) {{
  2588. view.style.display = 'none';
  2589. view.classList.remove('active');
  2590. }});
  2591. // 显示指定视图
  2592. var targetView = document.getElementById(viewId);
  2593. if (targetView) {{
  2594. targetView.style.display = 'block';
  2595. targetView.classList.add('active');
  2596. }}
  2597. // 更新目录项的active状态:清除所有,然后标记当前项和祖先
  2598. var tocItems = document.querySelectorAll('.toc-item');
  2599. tocItems.forEach(function(item) {{
  2600. item.classList.remove('active', 'active-ancestor');
  2601. }});
  2602. // 标记当前激活项
  2603. var activeItem = clickedElement || (event && event.currentTarget);
  2604. if (activeItem && activeItem.classList.contains('toc-item')) {{
  2605. activeItem.classList.add('active');
  2606. // 标记所有祖先节点
  2607. var parent = activeItem.parentElement;
  2608. while (parent) {{
  2609. // 查找上一个兄弟节点中的toc-item
  2610. var prevSibling = parent.previousElementSibling;
  2611. if (prevSibling && prevSibling.classList.contains('toc-item')) {{
  2612. prevSibling.classList.add('active-ancestor');
  2613. }}
  2614. parent = parent.parentElement;
  2615. // 到达toc-content就停止
  2616. if (parent && parent.classList.contains('toc-content')) {{
  2617. break;
  2618. }}
  2619. }}
  2620. }}
  2621. }}
  2622. // 折叠/展开帖子
  2623. function toggleTocPost(event, postIdx) {{
  2624. event.stopPropagation();
  2625. var item = event.currentTarget;
  2626. var children = document.getElementById('toc-post-' + postIdx + '-children');
  2627. item.classList.toggle('collapsed');
  2628. children.classList.toggle('hidden');
  2629. }}
  2630. // 折叠/展开点类型分组
  2631. function toggleTocGroup(event, groupId) {{
  2632. event.stopPropagation();
  2633. var item = event.currentTarget;
  2634. var children = document.getElementById('toc-' + groupId + '-children');
  2635. item.classList.toggle('collapsed');
  2636. children.classList.toggle('hidden');
  2637. }}
  2638. // 折叠/展开点项(同时切换到该点的内容视图)
  2639. function toggleTocPoint(event, pointItemId, viewId) {{
  2640. event.stopPropagation();
  2641. // 如果点击的是展开图标,只切换折叠状态
  2642. if (event.target.classList.contains('toc-expand-icon')) {{
  2643. event.preventDefault();
  2644. var item = event.currentTarget;
  2645. var children = document.getElementById('toc-' + pointItemId + '-children');
  2646. item.classList.toggle('collapsed');
  2647. children.classList.toggle('hidden');
  2648. }} else {{
  2649. // 如果点击的是其他部分,切换到该点的视图
  2650. showContentView(viewId, event.currentTarget);
  2651. // 滚动到右侧内容区域的顶部
  2652. var rightContent = document.querySelector('.right-content');
  2653. if (rightContent) {{
  2654. rightContent.scrollTo({{ top: 0, behavior: 'smooth' }});
  2655. }}
  2656. }}
  2657. }}
  2658. // 折叠/展开特征项(特征有子层级)
  2659. function toggleTocFeature(event, featureItemId, viewId, featureSectionId) {{
  2660. event.stopPropagation();
  2661. // 如果点击的是展开图标,只切换折叠状态
  2662. if (event.target.classList.contains('toc-expand-icon')) {{
  2663. event.preventDefault();
  2664. var item = event.currentTarget;
  2665. var children = document.getElementById('toc-' + featureItemId + '-children');
  2666. item.classList.toggle('collapsed');
  2667. children.classList.toggle('hidden');
  2668. }} else {{
  2669. // 如果点击的是其他部分,切换到该点的视图并滚动到特征
  2670. showContentView(viewId, event.currentTarget);
  2671. setTimeout(function() {{
  2672. var element = document.getElementById(featureSectionId);
  2673. if (element) {{
  2674. element.scrollIntoView({{ behavior: 'smooth', block: 'start' }});
  2675. }}
  2676. }}, 100);
  2677. }}
  2678. }}
  2679. // 滚动到层级分组(在特征下的子层级)
  2680. function scrollToLevelSection(event, viewId, levelSectionId) {{
  2681. event.stopPropagation();
  2682. // 先切换到对应点的视图
  2683. showContentView(viewId, event.currentTarget);
  2684. // 等待视图切换完成后滚动到层级分组位置
  2685. setTimeout(function() {{
  2686. var element = document.getElementById(levelSectionId);
  2687. if (element) {{
  2688. element.scrollIntoView({{ behavior: 'smooth', block: 'start' }});
  2689. }}
  2690. }}, 100);
  2691. }}
  2692. // 点击特征:先切换到对应点的视图,再滚动到特征位置
  2693. function clickFeature(event, pointViewId, featureSectionId) {{
  2694. event.stopPropagation();
  2695. // 先切换到对应点的视图
  2696. showContentView(pointViewId, event.currentTarget);
  2697. // 等待视图切换完成后滚动到特征位置
  2698. setTimeout(function() {{
  2699. var element = document.getElementById(featureSectionId);
  2700. if (element) {{
  2701. element.scrollIntoView({{ behavior: 'smooth', block: 'start' }});
  2702. }}
  2703. }}, 100);
  2704. }}
  2705. function scrollToSection(sectionId) {{
  2706. var element = document.getElementById(sectionId);
  2707. if (element) {{
  2708. element.scrollIntoView({{ behavior: 'smooth', block: 'start' }});
  2709. }}
  2710. }}
  2711. function toggleMatch(matchId) {{
  2712. var content = document.getElementById(matchId + '-content');
  2713. var icon = document.getElementById(matchId + '-icon');
  2714. if (content.style.display === 'none') {{
  2715. content.style.display = 'block';
  2716. icon.classList.add('expanded');
  2717. }} else {{
  2718. content.style.display = 'none';
  2719. icon.classList.remove('expanded');
  2720. }}
  2721. }}
  2722. function toggleFeatureSection(event, sectionId) {{
  2723. event.stopPropagation();
  2724. var content = document.getElementById(sectionId + '-content');
  2725. var icon = document.getElementById(sectionId + '-icon');
  2726. if (!content || !icon) {{
  2727. console.error('Element not found:', sectionId);
  2728. return;
  2729. }}
  2730. var isHidden = content.style.display === 'none' || !content.style.display || window.getComputedStyle(content).display === 'none';
  2731. if (isHidden) {{
  2732. content.style.display = 'flex';
  2733. icon.textContent = '▼';
  2734. }} else {{
  2735. content.style.display = 'none';
  2736. icon.textContent = '▶';
  2737. }}
  2738. }}
  2739. function toggleStepSection(sectionId) {{
  2740. var content = document.getElementById(sectionId + '-content');
  2741. var icon = document.getElementById(sectionId + '-icon');
  2742. if (content.style.display === 'none') {{
  2743. content.style.display = 'flex';
  2744. icon.textContent = '▼';
  2745. }} else {{
  2746. content.style.display = 'none';
  2747. icon.textContent = '▶';
  2748. }}
  2749. }}
  2750. function toggleMatchGroup(event, groupId) {{
  2751. event.stopPropagation();
  2752. var content = document.getElementById(groupId + '-content');
  2753. var icon = document.getElementById(groupId + '-icon');
  2754. if (!content || !icon) {{
  2755. console.error('Element not found:', groupId);
  2756. return;
  2757. }}
  2758. var isHidden = content.style.display === 'none' || !content.style.display || window.getComputedStyle(content).display === 'none';
  2759. if (isHidden) {{
  2760. // 根据class决定使用什么display值
  2761. if (content.classList.contains('match-subgroup-content')) {{
  2762. content.style.display = 'flex';
  2763. }} else {{
  2764. content.style.display = 'block';
  2765. }}
  2766. icon.textContent = '▼';
  2767. }} else {{
  2768. content.style.display = 'none';
  2769. icon.textContent = '▶';
  2770. }}
  2771. }}
  2772. function showMatchDetail(element) {{
  2773. var modal = document.getElementById('matchModal');
  2774. var title = document.getElementById('matchModalTitle');
  2775. var body = document.getElementById('matchModalBody');
  2776. // 从data属性读取数据
  2777. var personaName = element.dataset.personaName;
  2778. var featureType = element.dataset.featureType;
  2779. var personaLevel = element.dataset.personaLevel;
  2780. var similarity = parseFloat(element.dataset.similarity);
  2781. var label = element.dataset.label;
  2782. var explanation = element.dataset.explanation;
  2783. var historicalPosts = element.dataset.historicalPosts;
  2784. // 设置标题 - 合并显示层级和类型
  2785. var titleText = '';
  2786. if (personaLevel && featureType) {{
  2787. titleText = '[' + personaLevel + '-' + featureType + '] ';
  2788. }}
  2789. titleText += personaName + ' (相似度: ' + similarity.toFixed(2) + ' - ' + label + ')';
  2790. title.textContent = titleText;
  2791. // 生成内容
  2792. var bodyHTML = '<div class="match-detail-section">';
  2793. bodyHTML += '<h3>匹配说明</h3>';
  2794. bodyHTML += '<div class="match-explanation-text">' + explanation + '</div>';
  2795. bodyHTML += '</div>';
  2796. // 如果有历史帖子
  2797. if (historicalPosts && historicalPosts.trim().length > 0) {{
  2798. bodyHTML += '<div class="match-detail-section">';
  2799. bodyHTML += '<h3>历史帖子来源</h3>';
  2800. bodyHTML += '<div class="historical-posts-grid">';
  2801. bodyHTML += historicalPosts;
  2802. bodyHTML += '</div>';
  2803. bodyHTML += '</div>';
  2804. }}
  2805. body.innerHTML = bodyHTML;
  2806. modal.style.display = 'block';
  2807. }}
  2808. function closeMatchModal(event) {{
  2809. var modal = document.getElementById('matchModal');
  2810. if (!event || event.target === modal) {{
  2811. modal.style.display = 'none';
  2812. }}
  2813. }}
  2814. // ESC键关闭模态框
  2815. document.addEventListener('keydown', function(event) {{
  2816. if (event.key === 'Escape') {{
  2817. closeMatchModal();
  2818. }}
  2819. }});
  2820. function showPostDetail(element) {{
  2821. const postDataStr = element.dataset.postData;
  2822. if (!postDataStr) return;
  2823. try {{
  2824. const postData = JSON.parse(postDataStr);
  2825. // 生成图片HTML(添加懒加载)
  2826. let imagesHtml = '';
  2827. if (postData.images && postData.images.length > 0) {{
  2828. imagesHtml = postData.images.map(img =>
  2829. `<img src="${{img}}" class="post-detail-image" alt="图片" loading="lazy">`
  2830. ).join('');
  2831. }} else {{
  2832. imagesHtml = '<div style="text-align: center; color: #9ca3af; padding: 40px;">暂无图片</div>';
  2833. }}
  2834. const modalHtml = `
  2835. <div class="post-detail-content" onclick="event.stopPropagation()">
  2836. <button class="post-detail-close" onclick="closePostDetail()">×</button>
  2837. <div class="post-detail-header">
  2838. <div class="post-detail-title">${{postData.title || '无标题'}}</div>
  2839. <div class="post-detail-meta">
  2840. <div>
  2841. <span class="post-detail-author">👤 ${{postData.author}}</span>
  2842. <span class="post-detail-time"> · 📅 ${{postData.publish_time}}</span>
  2843. </div>
  2844. <div class="post-detail-stats">
  2845. <span>👍 ${{postData.like_count}}</span>
  2846. <span>💬 ${{postData.comment_count}}</span>
  2847. <span>⭐ ${{postData.collect_count}}</span>
  2848. </div>
  2849. </div>
  2850. </div>
  2851. <div class="post-detail-body">
  2852. ${{postData.body_text ? `<div class="post-detail-desc">${{postData.body_text}}</div>` : '<div style="color: #9ca3af;">暂无正文</div>'}}
  2853. <div class="post-detail-images">
  2854. ${{imagesHtml}}
  2855. </div>
  2856. </div>
  2857. <div class="post-detail-footer">
  2858. <a href="${{postData.link}}" target="_blank" class="post-detail-link">
  2859. 在小红书查看完整内容 →
  2860. </a>
  2861. </div>
  2862. </div>
  2863. `;
  2864. let modal = document.getElementById('postDetailModal');
  2865. if (!modal) {{
  2866. modal = document.createElement('div');
  2867. modal.id = 'postDetailModal';
  2868. modal.className = 'post-detail-modal';
  2869. modal.onclick = closePostDetail;
  2870. document.body.appendChild(modal);
  2871. }}
  2872. modal.innerHTML = modalHtml;
  2873. modal.classList.add('active');
  2874. document.body.style.overflow = 'hidden';
  2875. }} catch (e) {{
  2876. console.error('解析帖子数据失败:', e);
  2877. }}
  2878. }}
  2879. function closePostDetail(event) {{
  2880. if (event && event.target !== event.currentTarget) return;
  2881. const modal = document.getElementById('postDetailModal');
  2882. if (modal) {{
  2883. modal.classList.remove('active');
  2884. document.body.style.overflow = '';
  2885. }}
  2886. }}
  2887. function moveImage(postId, direction) {{
  2888. var carousel = document.querySelector(`[data-post-id="${{postId}}"]`);
  2889. var track = document.getElementById(postId + '-track');
  2890. var totalImages = parseInt(carousel.getAttribute('data-total-images'));
  2891. if (!carousel.currentIndex) {{
  2892. carousel.currentIndex = 0;
  2893. }}
  2894. carousel.currentIndex = (carousel.currentIndex + direction + totalImages) % totalImages;
  2895. track.style.transform = `translateX(-${{carousel.currentIndex * 100}}%)`;
  2896. updateIndicators(postId, carousel.currentIndex);
  2897. }}
  2898. function jumpToImage(postId, index) {{
  2899. var carousel = document.querySelector(`[data-post-id="${{postId}}"]`);
  2900. var track = document.getElementById(postId + '-track');
  2901. carousel.currentIndex = index;
  2902. track.style.transform = `translateX(-${{index * 100}}%)`;
  2903. updateIndicators(postId, index);
  2904. }}
  2905. function updateIndicators(postId, activeIndex) {{
  2906. var indicators = document.querySelectorAll(`#${{postId}}-indicators .indicator`);
  2907. indicators.forEach((indicator, i) => {{
  2908. if (i === activeIndex) {{
  2909. indicator.classList.add('active');
  2910. }} else {{
  2911. indicator.classList.remove('active');
  2912. }}
  2913. }});
  2914. }}
  2915. // 目录激活状态追踪
  2916. function updateTocActiveState() {{
  2917. const rightContent = document.querySelector('.right-content');
  2918. if (!rightContent) return;
  2919. // 找到当前激活的view
  2920. const activeView = document.querySelector('.content-view[style*="display: block"], .content-view:not([style*="display: none"])');
  2921. if (!activeView) return;
  2922. // 在激活的view中查找所有sections
  2923. const sections = activeView.querySelectorAll('[id]');
  2924. const tocItems = document.querySelectorAll('.toc-item');
  2925. let currentActive = null;
  2926. let maxVisibility = 0;
  2927. // 找到当前在视口中最visible的section
  2928. sections.forEach(section => {{
  2929. if (!section.id) return;
  2930. const rect = section.getBoundingClientRect();
  2931. const sectionTop = rect.top;
  2932. const sectionBottom = rect.bottom;
  2933. const windowHeight = window.innerHeight;
  2934. // 计算section在视口中的可见度
  2935. if (sectionTop < windowHeight && sectionBottom > 0) {{
  2936. const visibleTop = Math.max(sectionTop, 0);
  2937. const visibleBottom = Math.min(sectionBottom, windowHeight);
  2938. const visibility = visibleBottom - visibleTop;
  2939. // 优先选择顶部在视口上半部分的section
  2940. if (sectionTop < windowHeight / 2 && visibility > maxVisibility) {{
  2941. maxVisibility = visibility;
  2942. currentActive = section.id;
  2943. }}
  2944. }}
  2945. }});
  2946. // 更新目录项的激活状态
  2947. tocItems.forEach(item => {{
  2948. // 移除所有激活状态和祖先状态
  2949. item.classList.remove('active');
  2950. item.classList.remove('active-ancestor');
  2951. const onclick = item.getAttribute('onclick');
  2952. if (!onclick) return;
  2953. // 检查是否匹配当前活动section
  2954. if (currentActive && onclick.includes(currentActive)) {{
  2955. item.classList.add('active');
  2956. // 标记所有祖先节点
  2957. let parent = item.parentElement;
  2958. while (parent) {{
  2959. if (parent.classList && parent.classList.contains('toc-item')) {{
  2960. parent.classList.add('active-ancestor');
  2961. }}
  2962. parent = parent.parentElement;
  2963. }}
  2964. }}
  2965. }});
  2966. // 更新面包屑导航
  2967. updateBreadcrumb(currentActive);
  2968. }}
  2969. // 更新面包屑导航(只显示右侧内容层级,不显示帖子信息)
  2970. function updateBreadcrumb(currentSectionId) {{
  2971. const breadcrumbPoint = document.getElementById('breadcrumb-point');
  2972. const breadcrumbStep = document.getElementById('breadcrumb-step');
  2973. const breadcrumbFeature = document.getElementById('breadcrumb-feature');
  2974. const breadcrumbLevel = document.getElementById('breadcrumb-level');
  2975. const breadcrumbSubgroup = document.getElementById('breadcrumb-subgroup');
  2976. const sep1 = document.getElementById('sep-1');
  2977. const sep2 = document.getElementById('sep-2');
  2978. const sep3 = document.getElementById('sep-3');
  2979. const sep4 = document.getElementById('sep-4');
  2980. // 隐藏所有可选元素
  2981. [breadcrumbStep, breadcrumbFeature, breadcrumbLevel, breadcrumbSubgroup, sep1, sep2, sep3, sep4].forEach(el => {{
  2982. if (el) el.style.display = 'none';
  2983. }});
  2984. if (!currentSectionId) {{
  2985. breadcrumbPoint.textContent = '-';
  2986. return;
  2987. }}
  2988. // 从当前section找到所在的view
  2989. let currentView = null;
  2990. const allViews = document.querySelectorAll('.content-view');
  2991. allViews.forEach(view => {{
  2992. if (view.style.display !== 'none' && view.querySelector('#' + currentSectionId)) {{
  2993. currentView = view;
  2994. }}
  2995. }});
  2996. if (!currentView) return;
  2997. // 从view ID解析信息: view-post-0-point-灵感点列表-0
  2998. const viewId = currentView.id;
  2999. const viewMatch = viewId.match(/view-post-(\d+)-point-(.+?)-(\d+)/);
  3000. if (viewMatch) {{
  3001. const postIdx = viewMatch[1];
  3002. const pointType = viewMatch[2].replace('列表', '');
  3003. const pointIdx = parseInt(viewMatch[3]);
  3004. // 1. 点信息(总是显示)
  3005. const pointElement = currentView.querySelector('.inspiration-detail-card .inspiration-name');
  3006. const pointName = pointElement ? pointElement.textContent : `${{pointType}} ${{pointIdx + 1}}`;
  3007. breadcrumbPoint.textContent = `${{pointType}} ${{pointIdx + 1}}: ${{pointName.substring(0, 20)}}${{pointName.length > 20 ? '...' : ''}}`;
  3008. breadcrumbPoint.onclick = function() {{
  3009. showContentView(viewId, this);
  3010. const rightContent = document.querySelector('.right-content');
  3011. if (rightContent) rightContent.scrollTo({{ top: 0, behavior: 'smooth' }});
  3012. }};
  3013. // 2. 步骤信息(如果在步骤section中)
  3014. if (currentSectionId.includes('step')) {{
  3015. const stepMatch = currentSectionId.match(/step-\d+-(\d+)/);
  3016. if (stepMatch) {{
  3017. sep1.style.display = 'inline';
  3018. breadcrumbStep.style.display = 'inline';
  3019. breadcrumbStep.textContent = `步骤 ${{parseInt(stepMatch[1]) + 1}}`;
  3020. breadcrumbStep.onclick = function() {{
  3021. const el = document.getElementById(currentSectionId);
  3022. if (el) el.scrollIntoView({{ behavior: 'smooth', block: 'start' }});
  3023. }};
  3024. }}
  3025. }}
  3026. // 3. 特征信息(如果在特征相关section中)
  3027. if (currentSectionId.includes('feat')) {{
  3028. const featMatch = currentSectionId.match(/feat-(\d+)-(\d+)/);
  3029. if (featMatch) {{
  3030. const featIdx = parseInt(featMatch[2]);
  3031. // 查找特征名称
  3032. const featureSection = document.getElementById('post-' + postIdx + '-feat-' + pointIdx + '-' + featIdx);
  3033. let featureName = `特征 ${{featIdx + 1}}`;
  3034. if (featureSection) {{
  3035. const header = featureSection.querySelector('.match-section-header h4');
  3036. if (header) {{
  3037. const match = header.textContent.match(/匹配结果:\s*(.+?)\s*\(/);
  3038. if (match) featureName = match[1].substring(0, 15) + (match[1].length > 15 ? '...' : '');
  3039. }}
  3040. }}
  3041. sep2.style.display = 'inline';
  3042. breadcrumbFeature.style.display = 'inline';
  3043. breadcrumbFeature.textContent = featureName;
  3044. breadcrumbFeature.onclick = function() {{
  3045. if (featureSection) featureSection.scrollIntoView({{ behavior: 'smooth', block: 'start' }});
  3046. }};
  3047. // 4. 层级分组信息(如果在level section中)
  3048. if (currentSectionId.includes('level')) {{
  3049. const levelMatch = currentSectionId.match(/level-(.+?)(?:-|$)/);
  3050. if (levelMatch) {{
  3051. const levelName = levelMatch[1];
  3052. const levelElement = document.getElementById(currentSectionId);
  3053. let levelTitle = `匹配人设${{levelName}}`;
  3054. if (levelElement) {{
  3055. const header = levelElement.querySelector('.level-group-title');
  3056. if (header) levelTitle = header.textContent.trim();
  3057. }}
  3058. sep3.style.display = 'inline';
  3059. breadcrumbLevel.style.display = 'inline';
  3060. breadcrumbLevel.textContent = levelTitle.substring(0, 20);
  3061. breadcrumbLevel.onclick = function() {{
  3062. if (levelElement) levelElement.scrollIntoView({{ behavior: 'smooth', block: 'start' }});
  3063. }};
  3064. }}
  3065. }}
  3066. }}
  3067. }}
  3068. }}
  3069. }}
  3070. // 监听滚动事件
  3071. document.addEventListener('DOMContentLoaded', function() {{
  3072. // 默认显示第一个视图
  3073. var allViews = document.querySelectorAll('.content-view');
  3074. if (allViews.length > 0) {{
  3075. // 找到第一个点视图(跳过帖子详情视图)
  3076. var firstPointView = null;
  3077. var firstPointViewId = null;
  3078. for (var i = 0; i < allViews.length; i++) {{
  3079. if (allViews[i].id.includes('point') && allViews[i].id.includes('灵感点列表')) {{
  3080. firstPointView = allViews[i];
  3081. firstPointViewId = allViews[i].id;
  3082. break;
  3083. }}
  3084. }}
  3085. // 如果有点视图,显示第一个点;否则显示第一个帖子详情
  3086. var defaultView = firstPointView || allViews[0];
  3087. defaultView.style.display = 'block';
  3088. defaultView.classList.add('active');
  3089. // 展开第一个帖子
  3090. var firstPost = document.querySelector('.toc-post-header');
  3091. if (firstPost) {{
  3092. firstPost.classList.remove('collapsed');
  3093. var postIdx = firstPost.getAttribute('data-post-id');
  3094. var postChildren = document.getElementById('toc-post-' + postIdx + '-children');
  3095. if (postChildren) {{
  3096. postChildren.classList.remove('hidden');
  3097. }}
  3098. }}
  3099. // 展开第一个灵感点分组
  3100. var firstInspGroup = document.querySelector('[onclick*="post-0-灵感点列表"]');
  3101. if (firstInspGroup && firstInspGroup.classList.contains('toc-group-header')) {{
  3102. firstInspGroup.classList.remove('collapsed');
  3103. var groupChildren = document.getElementById('toc-post-0-灵感点列表-children');
  3104. if (groupChildren) {{
  3105. groupChildren.classList.remove('hidden');
  3106. }}
  3107. }}
  3108. // 展开第一个灵感点
  3109. var firstPoint = document.querySelector('.toc-level-2[onclick*="view-post-0-point-灵感点列表-0"]');
  3110. if (firstPoint) {{
  3111. firstPoint.classList.remove('collapsed');
  3112. var pointId = firstPoint.getAttribute('onclick').match(/toggleTocPoint\(event,\s*'([^']+)'/);
  3113. if (pointId && pointId[1]) {{
  3114. var pointChildren = document.getElementById('toc-' + pointId[1] + '-children');
  3115. if (pointChildren) {{
  3116. pointChildren.classList.remove('hidden');
  3117. }}
  3118. }}
  3119. }}
  3120. // 激活对应的目录项
  3121. if (firstPointViewId) {{
  3122. // 找到对应的目录项并添加active类
  3123. var tocItems = document.querySelectorAll('.toc-item');
  3124. tocItems.forEach(function(item) {{
  3125. var onclick = item.getAttribute('onclick');
  3126. if (onclick && onclick.includes(firstPointViewId)) {{
  3127. item.classList.add('active');
  3128. // 标记祖先节点
  3129. var parent = item.parentElement;
  3130. while (parent) {{
  3131. if (parent.classList && parent.classList.contains('toc-item')) {{
  3132. parent.classList.add('active-ancestor');
  3133. }}
  3134. parent = parent.parentElement;
  3135. }}
  3136. }}
  3137. }});
  3138. }}
  3139. }}
  3140. const rightContent = document.querySelector('.right-content');
  3141. if (rightContent) {{
  3142. rightContent.addEventListener('scroll', function() {{
  3143. // 使用节流避免频繁触发
  3144. if (this.scrollTimeout) clearTimeout(this.scrollTimeout);
  3145. this.scrollTimeout = setTimeout(updateTocActiveState, 50);
  3146. }});
  3147. // 初始化时更新一次
  3148. updateTocActiveState();
  3149. }}
  3150. }});
  3151. </script>
  3152. </body>
  3153. </html>
  3154. '''
  3155. return html
  3156. def minify_html(html: str) -> str:
  3157. """压缩HTML,去除多余空格和换行"""
  3158. import re
  3159. # 保护script和style标签内容
  3160. scripts = []
  3161. styles = []
  3162. def save_script(match):
  3163. scripts.append(match.group(0))
  3164. return f"___SCRIPT_{len(scripts)-1}___"
  3165. def save_style(match):
  3166. styles.append(match.group(0))
  3167. return f"___STYLE_{len(styles)-1}___"
  3168. # 保存script和style
  3169. html = re.sub(r'<script[^>]*>.*?</script>', save_script, html, flags=re.DOTALL)
  3170. html = re.sub(r'<style[^>]*>.*?</style>', save_style, html, flags=re.DOTALL)
  3171. # 去除HTML注释
  3172. html = re.sub(r'<!--.*?-->', '', html, flags=re.DOTALL)
  3173. # 去除多余空格和换行
  3174. html = re.sub(r'\s+', ' ', html)
  3175. html = re.sub(r'>\s+<', '><', html)
  3176. # 恢复script和style
  3177. for i, script in enumerate(scripts):
  3178. html = html.replace(f"___SCRIPT_{i}___", script)
  3179. for i, style in enumerate(styles):
  3180. html = html.replace(f"___STYLE_{i}___", style)
  3181. return html.strip()
  3182. def main():
  3183. """主函数"""
  3184. # 使用路径配置
  3185. config = PathConfig()
  3186. # 确保输出目录存在
  3187. config.ensure_dirs()
  3188. # 获取路径
  3189. input_dir = config.how_results_dir
  3190. output_file = config.visualization_file
  3191. print(f"账号: {config.account_name}")
  3192. print(f"输入目录: {input_dir}")
  3193. print(f"输出文件: {output_file}")
  3194. print()
  3195. print(f"读取 how 解构结果: {input_dir}")
  3196. # 加载特征分类映射
  3197. print(f"加载特征分类映射...")
  3198. category_mapping = load_feature_category_mapping(config)
  3199. print(f"已加载 {sum(len(v) for v in category_mapping.values())} 个特征分类")
  3200. # 加载特征来源映射
  3201. print(f"加载特征来源映射...")
  3202. source_mapping = load_feature_source_mapping(config)
  3203. print(f"已加载 {len(source_mapping)} 个特征的来源信息")
  3204. json_files = list(input_dir.glob("*_how.json"))
  3205. print(f"找到 {len(json_files)} 个文件\n")
  3206. posts_data = []
  3207. for i, file_path in enumerate(json_files, 1):
  3208. print(f"读取文件 [{i}/{len(json_files)}]: {file_path.name}")
  3209. with open(file_path, "r", encoding="utf-8") as f:
  3210. post_data = json.load(f)
  3211. posts_data.append(post_data)
  3212. print(f"\n生成合并的 HTML...")
  3213. html_content = generate_combined_html(posts_data, category_mapping, source_mapping)
  3214. # 保存原始版本
  3215. print(f"保存原始HTML到: {output_file}")
  3216. with open(output_file, "w", encoding="utf-8") as f:
  3217. f.write(html_content)
  3218. original_size = len(html_content) / 1024 / 1024
  3219. print(f"原始HTML大小: {original_size:.1f} MB")
  3220. # 压缩HTML
  3221. print(f"\n压缩HTML...")
  3222. minified_html = minify_html(html_content)
  3223. minified_file = data_dir / "当前帖子_how解构结果_可视化.min.html"
  3224. print(f"保存压缩HTML到: {minified_file}")
  3225. with open(minified_file, "w", encoding="utf-8") as f:
  3226. f.write(minified_html)
  3227. minified_size = len(minified_html) / 1024 / 1024
  3228. print(f"压缩HTML大小: {minified_size:.1f} MB (减少 {(1 - minified_size/original_size)*100:.1f}%)")
  3229. # Gzip压缩
  3230. import gzip
  3231. print(f"\n生成Gzip压缩版本...")
  3232. gzip_file = data_dir / "当前帖子_how解构结果_可视化.html.gz"
  3233. with gzip.open(gzip_file, "wb") as f:
  3234. f.write(minified_html.encode('utf-8'))
  3235. gzip_size = gzip_file.stat().st_size / 1024 / 1024
  3236. print(f"Gzip压缩大小: {gzip_size:.1f} MB (比原始减少 {(1 - gzip_size/original_size)*100:.1f}%)")
  3237. print(f"\n完成! 生成了3个版本:")
  3238. print(f"1. 原始版本: {output_file} ({original_size:.1f} MB)")
  3239. print(f"2. 压缩版本: {minified_file} ({minified_size:.1f} MB)")
  3240. print(f"3. Gzip版本: {gzip_file} ({gzip_size:.1f} MB)")
  3241. print(f"\n建议分享: {gzip_file.name} (浏览器可直接打开)")
  3242. if __name__ == "__main__":
  3243. main()