visualize_how_results.py 138 KB

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