index.html 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430
  1. <!doctype html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta
  6. name="viewport"
  7. content="width=device-width, initial-scale=1"
  8. />
  9. <title>mode_workflow · 解构工作台</title>
  10. <script src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
  11. <link
  12. rel="preconnect"
  13. href="https://fonts.googleapis.com"
  14. />
  15. <link
  16. href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@600;900&family=Noto+Sans+SC:wght@400;500;700&family=IBM+Plex+Mono:wght@500;700&display=swap"
  17. rel="stylesheet"
  18. />
  19. <style>
  20. /* ── 主题:净白工作台 + 墨蓝/朱砂点缀 ─────────────────────────────────────── */
  21. :root {
  22. --bg: #f4f4f1;
  23. --card: #ffffff;
  24. --ink: #1c2433;
  25. --ink-soft: #5a6577;
  26. --ink-faint: #9aa3b0;
  27. --line: #e8e6e0;
  28. --line-dark: #d4d1c8;
  29. --navy: #1e3a5f;
  30. --navy-deep: #13243a; /* 需求区 / 品牌 */
  31. --blue: #2563eb;
  32. --blue-bg: #eef3fe; /* 评分/交互强调 */
  33. --amber: #b45309;
  34. --amber-bg: #fff7e8; /* 输入区 */
  35. --teal: #0f6b5c;
  36. --teal-bg: #eef8f3; /* 实现区 */
  37. --green: #15803d;
  38. --green-bg: #effaf1; /* 输出区 / 采纳 */
  39. --seal: #bb3a22; /* 朱砂印 */
  40. --infer: #fdf0d2;
  41. --infer-edge: #d97706;
  42. --shadow: 0 1px 2px rgba(20, 30, 46, 0.04), 0 8px 24px -12px rgba(20, 30, 46, 0.12);
  43. --shadow-lg: 0 4px 10px rgba(20, 30, 46, 0.06), 0 24px 60px -20px rgba(20, 30, 46, 0.25);
  44. }
  45. * {
  46. box-sizing: border-box;
  47. margin: 0;
  48. padding: 0;
  49. }
  50. html {
  51. font-size: 14px;
  52. }
  53. body {
  54. font-family: "Noto Sans SC", sans-serif;
  55. color: var(--ink);
  56. background: var(--bg);
  57. background-image: radial-gradient(900px 360px at 90% -8%, rgba(37, 99, 235, 0.045), transparent 60%);
  58. min-height: 100vh;
  59. }
  60. .num {
  61. font-family: "IBM Plex Mono", monospace;
  62. }
  63. h1,
  64. h2,
  65. .serif {
  66. font-family: "Noto Serif SC", serif;
  67. }
  68. a {
  69. color: var(--blue);
  70. }
  71. button {
  72. font-family: inherit;
  73. cursor: pointer;
  74. }
  75. /* ── 顶部 ── */
  76. header {
  77. display: flex;
  78. align-items: center;
  79. gap: 20px;
  80. padding: 0 30px;
  81. height: 60px;
  82. background: linear-gradient(135deg, #13243a, #1c3552);
  83. color: #eef2f8;
  84. position: sticky;
  85. top: 0;
  86. z-index: 40;
  87. box-shadow: 0 2px 14px rgba(19, 36, 58, 0.28);
  88. }
  89. .logo {
  90. display: flex;
  91. align-items: center;
  92. gap: 12px;
  93. }
  94. .logo .seal {
  95. width: 33px;
  96. height: 33px;
  97. background: var(--seal);
  98. color: #fff;
  99. display: grid;
  100. place-items: center;
  101. font-family: "Noto Serif SC", serif;
  102. font-weight: 900;
  103. font-size: 17px;
  104. border-radius: 7px;
  105. box-shadow:
  106. inset 0 0 0 2px rgba(255, 255, 255, 0.22),
  107. 0 3px 8px rgba(187, 58, 34, 0.35);
  108. transform: rotate(-4deg);
  109. }
  110. .logo b {
  111. font-family: "Noto Serif SC", serif;
  112. font-weight: 900;
  113. font-size: 16px;
  114. letter-spacing: 1px;
  115. }
  116. .logo small {
  117. display: block;
  118. font-size: 10px;
  119. color: #93a7c0;
  120. letter-spacing: 3px;
  121. }
  122. nav {
  123. display: flex;
  124. gap: 6px;
  125. margin-left: 26px;
  126. }
  127. nav a {
  128. display: flex;
  129. align-items: center;
  130. padding: 7px 18px;
  131. color: #a8b9cd;
  132. text-decoration: none;
  133. font-weight: 500;
  134. letter-spacing: 0.5px;
  135. border-radius: 99px;
  136. transition: 0.15s;
  137. font-size: 13px;
  138. }
  139. nav a:hover {
  140. color: #fff;
  141. background: rgba(255, 255, 255, 0.07);
  142. }
  143. nav a.on {
  144. color: #fff;
  145. background: rgba(255, 255, 255, 0.13);
  146. box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
  147. }
  148. header .spacer {
  149. flex: 1;
  150. }
  151. header .hint {
  152. font-size: 11px;
  153. color: #6e83a0;
  154. letter-spacing: 2px;
  155. }
  156. main {
  157. display: none;
  158. padding: 24px 30px 80px;
  159. max-width: 1920px;
  160. margin: 0 auto;
  161. }
  162. main.on {
  163. display: block;
  164. }
  165. /* 数据集视图:整体定高占满视口,左侧列表与右侧解构各自独立滚动 */
  166. #view-dataset {
  167. padding-bottom: 20px;
  168. }
  169. #view-dataset.on {
  170. display: flex;
  171. flex-direction: column;
  172. height: calc(100vh - 60px);
  173. overflow: hidden;
  174. }
  175. /* 聚类库:内嵌知识检索页,占满视口、无内边距 */
  176. #view-cluster {
  177. padding: 0;
  178. max-width: none;
  179. }
  180. #view-cluster.on {
  181. display: flex;
  182. }
  183. #cluster-frame {
  184. border: 0;
  185. width: 100%;
  186. height: calc(100vh - 60px);
  187. display: block;
  188. }
  189. /* ── 通用卡片/标签/按钮 ── */
  190. .card {
  191. background: var(--card);
  192. border: 1px solid var(--line);
  193. border-radius: 12px;
  194. box-shadow: var(--shadow);
  195. }
  196. .pill {
  197. display: inline-block;
  198. padding: 1px 9px;
  199. border-radius: 99px;
  200. font-size: 11px;
  201. font-weight: 500;
  202. border: 1px solid var(--line-dark);
  203. background: #f7f6f2;
  204. color: var(--ink-soft);
  205. white-space: nowrap;
  206. }
  207. .pill.navy {
  208. background: #e8eef6;
  209. border-color: #bccbde;
  210. color: var(--navy);
  211. }
  212. .pill.amber {
  213. background: var(--amber-bg);
  214. border-color: #ecc88a;
  215. color: var(--amber);
  216. }
  217. .pill.teal {
  218. background: var(--teal-bg);
  219. border-color: #a9d6c8;
  220. color: var(--teal);
  221. }
  222. .pill.red {
  223. background: #fbeae5;
  224. border-color: #e4ab9c;
  225. color: var(--seal);
  226. }
  227. .pill.green {
  228. background: var(--green-bg);
  229. border-color: #a7d9b4;
  230. color: var(--green);
  231. }
  232. .pill.blue {
  233. background: var(--blue-bg);
  234. border-color: #b6cdf7;
  235. color: var(--blue);
  236. }
  237. /* 目的列 intent 胶囊: 底色 = 所引用列的分组色, 与表头/列 chip 一致
  238. (需求=navy / 输入=amber / 实现=teal / 输出=green; 口径同 procedure-dsl「token 色对应来源列」) */
  239. .intent-text { color: var(--ink); line-height: 1.6; }
  240. .intent-tok { display: inline-block; padding: 1px 6px; border-radius: 4px; margin: 0 1px; font-size: 11.5px; font-weight: 500; }
  241. .intent-tok.ik-effect { background: #e8eef6; color: var(--navy); } /* 作用列 (需求组) */
  242. .intent-tok.ik-via { background: var(--teal-bg); color: var(--teal); font-family: "IBM Plex Mono", ui-monospace, monospace; } /* 外部工具列 (实现组) */
  243. .intent-tok.ik-act { background: var(--teal-bg); color: var(--teal); } /* 动作列 (实现组) */
  244. .intent-tok.ik-in-type { background: var(--amber-bg); color: var(--amber); border: 1px solid #ecc88a; border-radius: 99px; padding: 1px 8px; } /* 输入·类型 */
  245. .intent-tok.ik-out-type { background: var(--blue-bg); color: var(--blue); border: 1px solid #b6cdf7; border-radius: 99px; padding: 1px 8px; } /* 输出·类型 (蓝色,避免与实现组绿色混淆) */
  246. .intent-tok.ik-other { background: #fbeae5; color: var(--seal); text-decoration: line-through; } /* 非法类别(lint 警告) */
  247. .btn {
  248. border: 1px solid var(--line-dark);
  249. background: var(--card);
  250. color: var(--ink);
  251. padding: 6px 14px;
  252. border-radius: 8px;
  253. font-size: 13px;
  254. font-weight: 500;
  255. transition: 0.15s;
  256. }
  257. .btn:hover {
  258. border-color: var(--blue);
  259. color: var(--blue);
  260. box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
  261. }
  262. .btn.primary {
  263. background: var(--blue);
  264. border-color: var(--blue);
  265. color: #fff;
  266. }
  267. .btn.primary:hover {
  268. background: #1d4fc4;
  269. color: #fff;
  270. box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  271. }
  272. .btn.seal {
  273. background: var(--seal);
  274. border-color: var(--seal);
  275. color: #fff;
  276. }
  277. .btn.seal:hover {
  278. background: #a02f1a;
  279. color: #fff;
  280. box-shadow: 0 4px 12px rgba(187, 58, 34, 0.3);
  281. }
  282. .btn.sm {
  283. padding: 3px 11px;
  284. font-size: 12px;
  285. }
  286. .btn:disabled {
  287. opacity: 0.45;
  288. cursor: not-allowed;
  289. box-shadow: none;
  290. }
  291. select,
  292. input[type="text"],
  293. input[type="number"] {
  294. font-family: inherit;
  295. font-size: 13px;
  296. padding: 6px 10px;
  297. border: 1px solid var(--line-dark);
  298. border-radius: 8px;
  299. background: #fff;
  300. color: var(--ink);
  301. outline: none;
  302. transition: 0.15s;
  303. }
  304. select:focus,
  305. input:focus {
  306. border-color: var(--blue);
  307. box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  308. }
  309. .empty {
  310. text-align: center;
  311. color: var(--ink-faint);
  312. padding: 48px 20px;
  313. font-size: 13px;
  314. line-height: 2;
  315. }
  316. .empty .glyph {
  317. font-family: "Noto Serif SC", serif;
  318. font-size: 42px;
  319. color: var(--line-dark);
  320. display: block;
  321. }
  322. .spinner {
  323. display: inline-block;
  324. width: 16px;
  325. height: 16px;
  326. border: 2px solid var(--line-dark);
  327. border-top-color: var(--blue);
  328. border-radius: 50%;
  329. animation: spin 0.7s linear infinite;
  330. vertical-align: -3px;
  331. margin-right: 8px;
  332. }
  333. @keyframes spin {
  334. to {
  335. transform: rotate(360deg);
  336. }
  337. }
  338. /* ── Dashboard ── */
  339. .dash-section {
  340. margin-bottom: 14px;
  341. display: flex;
  342. align-items: baseline;
  343. gap: 10px;
  344. }
  345. .dash-section h2 {
  346. font-size: 16px;
  347. font-weight: 900;
  348. letter-spacing: 2px;
  349. }
  350. .dash-section .rule {
  351. flex: 1;
  352. border-top: 1px dashed var(--line-dark);
  353. }
  354. .dash-section .tag {
  355. font-size: 10px;
  356. letter-spacing: 2px;
  357. color: var(--ink-faint);
  358. }
  359. .cards {
  360. display: grid;
  361. grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  362. gap: 14px;
  363. margin-bottom: 26px;
  364. }
  365. .stat {
  366. padding: 16px 18px 14px;
  367. position: relative;
  368. overflow: hidden;
  369. }
  370. .stat::after {
  371. content: "";
  372. position: absolute;
  373. left: 0;
  374. top: 0;
  375. bottom: 0;
  376. width: 3px;
  377. background: var(--navy);
  378. }
  379. .stat.a::after {
  380. background: var(--amber);
  381. }
  382. .stat.t::after {
  383. background: var(--teal);
  384. }
  385. .stat.r::after {
  386. background: var(--seal);
  387. }
  388. .stat .lbl {
  389. font-size: 11px;
  390. letter-spacing: 2px;
  391. color: var(--ink-soft);
  392. margin-bottom: 8px;
  393. }
  394. .stat .val {
  395. font-size: 30px;
  396. font-weight: 700;
  397. line-height: 1;
  398. }
  399. .stat .sub {
  400. font-size: 11px;
  401. color: var(--ink-faint);
  402. margin-top: 7px;
  403. }
  404. .stat .sub.plat-break {
  405. margin-top: 5px;
  406. color: var(--ink-soft);
  407. font-weight: 600;
  408. display: flex;
  409. flex-wrap: wrap;
  410. align-items: center;
  411. gap: 4px 12px;
  412. }
  413. .stat .sub.plat-break .pb-item {
  414. display: inline-flex;
  415. align-items: center;
  416. gap: 5px;
  417. }
  418. .stat .sub.plat-break .pb-item b {
  419. font-size: 12px;
  420. color: var(--ink);
  421. }
  422. .ring-row {
  423. display: flex;
  424. align-items: center;
  425. gap: 14px;
  426. }
  427. .ring {
  428. width: 64px;
  429. height: 64px;
  430. border-radius: 50%;
  431. display: grid;
  432. place-items: center;
  433. flex: none;
  434. background: conic-gradient(var(--teal) calc(var(--p) * 1%), #e9e7e0 0);
  435. }
  436. .ring > div {
  437. width: 48px;
  438. height: 48px;
  439. border-radius: 50%;
  440. background: var(--card);
  441. display: grid;
  442. place-items: center;
  443. font-size: 12px;
  444. font-weight: 700;
  445. }
  446. .charts {
  447. display: grid;
  448. grid-template-columns: repeat(12, 1fr);
  449. gap: 16px;
  450. }
  451. .chart-card {
  452. padding: 14px 16px 8px;
  453. }
  454. .chart-card h3 {
  455. font-size: 13px;
  456. font-weight: 700;
  457. letter-spacing: 1px;
  458. color: var(--ink-soft);
  459. margin-bottom: 4px;
  460. display: flex;
  461. align-items: baseline;
  462. gap: 8px;
  463. }
  464. .chart-card h3 .num {
  465. color: var(--seal);
  466. font-size: 12px;
  467. }
  468. .chart {
  469. width: 100%;
  470. }
  471. .span12 {
  472. grid-column: span 12;
  473. }
  474. .span6 {
  475. grid-column: span 6;
  476. }
  477. .span4 {
  478. grid-column: span 4;
  479. }
  480. @media (max-width: 1100px) {
  481. .span6,
  482. .span4 {
  483. grid-column: span 12;
  484. }
  485. }
  486. /* ── Dataset 三栏 ── */
  487. .ds-top {
  488. display: flex;
  489. align-items: center;
  490. gap: 12px;
  491. margin-bottom: 16px;
  492. }
  493. .mode-switch {
  494. display: flex;
  495. border: 1px solid var(--line-dark);
  496. border-radius: 10px;
  497. overflow: hidden;
  498. background: #fff;
  499. }
  500. .mode-switch button {
  501. border: 0;
  502. background: transparent;
  503. padding: 7px 24px;
  504. font-size: 13px;
  505. font-weight: 700;
  506. color: var(--ink-soft);
  507. transition: 0.15s;
  508. }
  509. .mode-switch button.on {
  510. background: var(--navy);
  511. color: #fff;
  512. }
  513. .ds-grid {
  514. display: grid;
  515. grid-template-columns: 235px 350px minmax(0, 1fr);
  516. gap: 16px;
  517. align-items: stretch;
  518. flex: 1;
  519. min-height: 0;
  520. }
  521. @media (max-width: 1280px) {
  522. .ds-grid {
  523. grid-template-columns: 200px 320px minmax(0, 1fr);
  524. }
  525. }
  526. /* 每一列卡片纵向铺满网格高度,内部滚动区独立滚动 */
  527. .ds-grid > .card {
  528. display: flex;
  529. flex-direction: column;
  530. min-height: 0;
  531. overflow: hidden;
  532. }
  533. .col-head {
  534. display: flex;
  535. align-items: center;
  536. justify-content: space-between;
  537. padding: 11px 14px;
  538. border-bottom: 1px solid var(--line);
  539. font-weight: 700;
  540. font-size: 13px;
  541. letter-spacing: 1px;
  542. }
  543. .col-head .n {
  544. font-size: 11px;
  545. color: var(--ink-faint);
  546. font-weight: 500;
  547. }
  548. /* 帖子列头:标题一行、操作按钮另起一行(按钮不和「帖子 N/M」挤一行) */
  549. .col-head.posts-head {
  550. flex-direction: column;
  551. align-items: stretch;
  552. gap: 8px;
  553. }
  554. .posts-head .ph-title {
  555. display: flex;
  556. align-items: center;
  557. gap: 8px;
  558. }
  559. .posts-head .ph-actions {
  560. display: flex;
  561. flex-wrap: wrap;
  562. gap: 8px;
  563. }
  564. /* 按钮内计数:未做数(灰) / 已采纳总数(绿) */
  565. .ph-actions .cnt-rest {
  566. color: #9aa0a6;
  567. font-weight: 700;
  568. }
  569. .ph-actions .cnt-total {
  570. color: #2e9e5b;
  571. font-weight: 700;
  572. }
  573. .qlist {
  574. flex: 1;
  575. min-height: 0;
  576. overflow: auto;
  577. }
  578. .qitem {
  579. padding: 12px 14px;
  580. border-bottom: 1px solid var(--line);
  581. cursor: pointer;
  582. transition: 0.12s;
  583. }
  584. .qitem:hover {
  585. background: #f8f8f4;
  586. }
  587. .qitem.on {
  588. background: var(--blue-bg);
  589. box-shadow: inset 3px 0 0 var(--blue);
  590. }
  591. .qitem .qid {
  592. font-size: 10px;
  593. letter-spacing: 1px;
  594. color: var(--ink-faint);
  595. display: flex;
  596. gap: 6px;
  597. align-items: center;
  598. }
  599. .qitem .qt {
  600. font-weight: 500;
  601. margin: 4px 0 7px;
  602. line-height: 1.45;
  603. }
  604. .qitem .qm {
  605. font-size: 11px;
  606. color: var(--ink-soft);
  607. display: flex;
  608. gap: 10px;
  609. flex-wrap: wrap;
  610. align-items: center;
  611. }
  612. .qitem .qm b.hit {
  613. color: var(--blue);
  614. font-size: 13px;
  615. }
  616. /* 渠道 tab */
  617. .plat-tabs {
  618. display: flex;
  619. gap: 4px;
  620. padding: 8px 10px;
  621. border-bottom: 1px solid var(--line);
  622. overflow-x: auto;
  623. background: #fbfbf8;
  624. border-radius: 0;
  625. }
  626. .plat-tabs button {
  627. border: 1px solid transparent;
  628. background: transparent;
  629. color: var(--ink-soft);
  630. padding: 3px 11px;
  631. border-radius: 99px;
  632. font-size: 12px;
  633. font-weight: 500;
  634. white-space: nowrap;
  635. transition: 0.15s;
  636. }
  637. .plat-tabs button:hover {
  638. background: #efeee8;
  639. color: var(--ink);
  640. }
  641. .plat-tabs button.on {
  642. background: var(--navy);
  643. color: #fff;
  644. font-weight: 700;
  645. }
  646. .plat-tabs button .c {
  647. font-size: 10px;
  648. opacity: 0.75;
  649. margin-left: 3px;
  650. }
  651. /* 已解构筛选按钮:靠右,激活态用 teal 呼应「已解构」 */
  652. .plat-tabs .done-filter {
  653. margin-left: auto;
  654. flex: none;
  655. border: 1px solid var(--line);
  656. display: inline-flex;
  657. align-items: center;
  658. gap: 4px;
  659. color: var(--ink-soft);
  660. }
  661. .plat-tabs .done-filter:hover {
  662. background: #efeee8;
  663. color: var(--ink);
  664. }
  665. .plat-tabs .done-filter.on {
  666. background: var(--teal-bg, #e3f1ec);
  667. border-color: #a9d6c8;
  668. color: var(--teal);
  669. font-weight: 700;
  670. }
  671. .plat-tabs .done-filter .dot {
  672. font-size: 8px;
  673. }
  674. .plist {
  675. flex: 1;
  676. min-height: 0;
  677. overflow: auto;
  678. }
  679. .post {
  680. padding: 12px 13px;
  681. border-bottom: 1px solid var(--line);
  682. cursor: pointer;
  683. display: flex;
  684. gap: 10px;
  685. transition: 0.12s;
  686. align-items: flex-start;
  687. }
  688. .post:hover {
  689. background: #f8f8f4;
  690. }
  691. .post.on {
  692. background: var(--blue-bg);
  693. box-shadow: inset 3px 0 0 var(--blue);
  694. }
  695. .post input {
  696. margin-top: 4px;
  697. accent-color: var(--blue);
  698. }
  699. .post .pt {
  700. font-weight: 500;
  701. line-height: 1.45;
  702. font-size: 13px;
  703. }
  704. .post .pm {
  705. display: flex;
  706. flex-wrap: wrap;
  707. gap: 5px;
  708. margin-top: 7px;
  709. align-items: center;
  710. }
  711. .plat {
  712. display: inline-block;
  713. padding: 1px 7px;
  714. border-radius: 4px;
  715. font-size: 10px;
  716. font-weight: 700;
  717. color: #fff;
  718. }
  719. .plat.xhs {
  720. background: #d63a2f;
  721. }
  722. .plat.gzh {
  723. background: #2e9939;
  724. }
  725. .plat.zhihu {
  726. background: #1772f6;
  727. }
  728. .plat.douyin {
  729. background: #170b1a;
  730. }
  731. .plat.sph {
  732. background: #fa6d20;
  733. }
  734. .plat.youtube {
  735. background: #c00;
  736. }
  737. .plat.x {
  738. background: #15202b;
  739. }
  740. .plat.other {
  741. background: #777;
  742. }
  743. .plat-logo {
  744. display: inline-flex;
  745. line-height: 0;
  746. flex: none;
  747. }
  748. .plat-logo svg,
  749. .plat-logo img {
  750. display: block;
  751. }
  752. .done-dot {
  753. font-size: 10px;
  754. color: var(--teal);
  755. font-weight: 700;
  756. }
  757. /* 评分徽章:大、亮、可点 */
  758. .score-badge {
  759. flex: none;
  760. position: relative;
  761. font-family: "IBM Plex Mono", monospace;
  762. font-weight: 700;
  763. font-size: 16.5px;
  764. line-height: 1;
  765. padding: 8px 10px;
  766. border-radius: 9px;
  767. cursor: pointer;
  768. transition: 0.15s;
  769. align-self: center;
  770. border: 1px solid transparent;
  771. }
  772. .score-badge.s9 {
  773. color: #fff;
  774. background: linear-gradient(135deg, #16a34a, #15803d);
  775. box-shadow: 0 3px 10px rgba(22, 163, 74, 0.35);
  776. }
  777. .score-badge.s8 {
  778. color: #fff;
  779. background: linear-gradient(135deg, #3b82f6, #2563eb);
  780. box-shadow: 0 3px 10px rgba(37, 99, 235, 0.35);
  781. }
  782. .score-badge.s6 {
  783. color: #fff;
  784. background: linear-gradient(135deg, #f59e0b, #d97706);
  785. box-shadow: 0 3px 10px rgba(217, 119, 6, 0.32);
  786. }
  787. .score-badge.s0 {
  788. color: var(--ink-soft);
  789. background: #eceae4;
  790. border-color: var(--line-dark);
  791. }
  792. .score-badge:hover {
  793. transform: translateY(-2px) scale(1.06);
  794. }
  795. .score-badge::after {
  796. content: "查看详情";
  797. position: absolute;
  798. left: 50%;
  799. bottom: calc(100% + 6px);
  800. transform: translateX(-50%) scale(0.92);
  801. background: var(--ink);
  802. color: #fff;
  803. font-family: "Noto Sans SC", sans-serif;
  804. font-size: 10px;
  805. font-weight: 500;
  806. padding: 3px 8px;
  807. border-radius: 5px;
  808. white-space: nowrap;
  809. opacity: 0;
  810. pointer-events: none;
  811. transition: 0.15s;
  812. z-index: 5;
  813. }
  814. .score-badge:hover::after {
  815. opacity: 1;
  816. transform: translateX(-50%) scale(1);
  817. }
  818. .xp {
  819. min-height: 60vh;
  820. }
  821. .xp-head {
  822. display: flex;
  823. align-items: center;
  824. gap: 10px;
  825. padding: 12px 16px;
  826. border-bottom: 1px solid var(--line);
  827. flex-wrap: wrap;
  828. }
  829. .xp-head .st {
  830. font-family: "Noto Serif SC", serif;
  831. font-weight: 900;
  832. font-size: 15px;
  833. }
  834. .xp-head .st em {
  835. color: var(--seal);
  836. font-style: normal;
  837. }
  838. .xp-head .spacer {
  839. flex: 1;
  840. }
  841. .xp-body {
  842. padding: 16px;
  843. flex: 1;
  844. min-height: 0;
  845. overflow: auto;
  846. }
  847. /* 工序卡 */
  848. .proc {
  849. border: 1px solid var(--line);
  850. border-radius: 10px;
  851. margin-bottom: 22px;
  852. overflow: hidden;
  853. background: #fff;
  854. box-shadow: var(--shadow);
  855. }
  856. .proc-head {
  857. padding: 14px 16px;
  858. border-bottom: 1px solid var(--line);
  859. background: #fafaf6;
  860. }
  861. .proc-head .nm {
  862. font-family: "Noto Serif SC", serif;
  863. font-weight: 900;
  864. font-size: 15px;
  865. }
  866. .proc-head .nm .pid {
  867. color: var(--seal);
  868. margin-right: 6px;
  869. font-size: 13px;
  870. }
  871. .proc-head .pp {
  872. font-size: 12px;
  873. color: var(--ink-soft);
  874. margin-top: 5px;
  875. line-height: 1.6;
  876. }
  877. .proc-head .meta {
  878. display: flex;
  879. gap: 6px;
  880. flex-wrap: wrap;
  881. margin-top: 8px;
  882. }
  883. .decl {
  884. display: grid;
  885. grid-template-columns: 1fr 1fr;
  886. gap: 0;
  887. border-bottom: 1px solid var(--line);
  888. }
  889. .decl > div {
  890. padding: 10px 16px;
  891. }
  892. .decl > div + div {
  893. border-left: 1px solid var(--line);
  894. }
  895. .decl .dl {
  896. font-size: 10px;
  897. letter-spacing: 2px;
  898. color: var(--ink-faint);
  899. margin-bottom: 6px;
  900. }
  901. .decl .di {
  902. font-size: 12px;
  903. line-height: 1.7;
  904. }
  905. .decl .di b {
  906. font-weight: 700;
  907. }
  908. /* 步骤表:固定列宽撑开,宿主容器 overflow-x 滚动 */
  909. .steps {
  910. width: 100%;
  911. min-width: 1760px;
  912. table-layout: fixed;
  913. border-collapse: collapse;
  914. font-size: 12px;
  915. }
  916. .steps th {
  917. padding: 6px 8px;
  918. font-size: 11px;
  919. font-weight: 700;
  920. letter-spacing: 1px;
  921. color: #fff;
  922. text-align: left;
  923. }
  924. .steps thead tr:first-child th {
  925. text-align: center;
  926. font-size: 12px;
  927. letter-spacing: 4px;
  928. padding: 7px 4px;
  929. }
  930. .steps .h-req {
  931. background: var(--navy);
  932. }
  933. .steps .h-req2 {
  934. background: #33547a;
  935. }
  936. .steps .h-in {
  937. background: var(--amber);
  938. }
  939. .steps .h-in2 {
  940. background: #cd7522;
  941. }
  942. .steps .h-im {
  943. background: var(--teal);
  944. }
  945. .steps .h-im2 {
  946. background: #2d8273;
  947. }
  948. .steps .h-out {
  949. background: var(--blue);
  950. }
  951. .steps .h-out2 {
  952. background: #4f7fe6;
  953. }
  954. .steps td {
  955. padding: 8px 9px;
  956. border: 1px solid var(--line);
  957. vertical-align: top;
  958. line-height: 1.6;
  959. }
  960. .steps tbody tr:nth-child(odd) td {
  961. background: #fdfdf9;
  962. }
  963. .steps td.c-in {
  964. background: var(--amber-bg) !important;
  965. }
  966. .steps td.c-out {
  967. background: var(--blue-bg) !important;
  968. }
  969. .steps .sid {
  970. font-family: "IBM Plex Mono", monospace;
  971. font-weight: 700;
  972. color: var(--navy);
  973. white-space: nowrap;
  974. }
  975. .steps .vtxt {
  976. color: var(--ink-soft);
  977. font-size: 11.5px;
  978. word-break: break-all;
  979. }
  980. /* 归类命中(实质/形式):原值 → 命中值 逐行配对 */
  981. .steps .sf-map {
  982. display: flex;
  983. flex-direction: column;
  984. gap: 4px;
  985. }
  986. .steps .sf-pair {
  987. display: flex;
  988. align-items: center;
  989. gap: 4px;
  990. flex-wrap: wrap;
  991. line-height: 1.5;
  992. }
  993. .steps .sf-old {
  994. color: #9aa0a6;
  995. text-decoration: line-through;
  996. }
  997. .steps .sf-plain {
  998. color: var(--ink);
  999. }
  1000. .steps .sf-arrow {
  1001. color: #2e9e5b;
  1002. flex: none;
  1003. }
  1004. .steps .sf-new {
  1005. display: inline-block;
  1006. padding: 1px 7px;
  1007. border-radius: 10px;
  1008. background: #e3f3e8;
  1009. color: #2e6b45;
  1010. border: 1px solid #bfe3cb;
  1011. font-weight: 600;
  1012. white-space: nowrap;
  1013. }
  1014. .inf {
  1015. background: var(--infer) !important;
  1016. position: relative;
  1017. outline: 1px dashed var(--infer-edge);
  1018. outline-offset: -2px;
  1019. }
  1020. .inf .ib {
  1021. position: absolute;
  1022. top: -1px;
  1023. right: -1px;
  1024. background: var(--infer-edge);
  1025. color: #fff;
  1026. font-size: 9px;
  1027. padding: 0 4px;
  1028. border-radius: 0 0 0 4px;
  1029. font-weight: 700;
  1030. }
  1031. .anchor {
  1032. font-family: "IBM Plex Mono", monospace;
  1033. font-size: 10.5px;
  1034. color: var(--ink-faint);
  1035. word-break: break-all;
  1036. }
  1037. /* 输入/输出「值」单元格:超过 4 行加蒙版,点击展开/收起 */
  1038. .clamp-val {
  1039. position: relative;
  1040. }
  1041. .clamp-val.clampable {
  1042. max-height: 6.6em;
  1043. overflow: hidden;
  1044. cursor: zoom-in;
  1045. }
  1046. .clamp-val.clampable::after {
  1047. content: "";
  1048. position: absolute;
  1049. left: 0;
  1050. right: 0;
  1051. bottom: 0;
  1052. height: 2.4em;
  1053. pointer-events: none;
  1054. }
  1055. .steps td.c-in .clamp-val.clampable::after {
  1056. background: linear-gradient(180deg, rgba(255, 247, 232, 0), rgba(255, 247, 232, 1));
  1057. }
  1058. .steps td.c-out .clamp-val.clampable::after {
  1059. background: linear-gradient(180deg, rgba(238, 243, 254, 0), rgba(238, 243, 254, 1));
  1060. }
  1061. .clamp-val.open {
  1062. max-height: none;
  1063. overflow: visible;
  1064. cursor: zoom-out;
  1065. }
  1066. .clamp-val.open::after {
  1067. display: none;
  1068. }
  1069. /* 工具表格(移植自 fixed_query_eval:案例逐行 rowspan + 限高展开) */
  1070. .mw-ttwrap {
  1071. overflow-x: auto;
  1072. border: 1px solid var(--line);
  1073. border-radius: 10px;
  1074. box-shadow: var(--shadow);
  1075. }
  1076. .mw-tt {
  1077. border-collapse: separate;
  1078. border-spacing: 0;
  1079. width: 100%;
  1080. min-width: 1180px;
  1081. background: #fff;
  1082. font-size: 12.5px;
  1083. }
  1084. .mw-tt thead th {
  1085. position: sticky;
  1086. top: 0;
  1087. z-index: 2;
  1088. text-align: left;
  1089. white-space: nowrap;
  1090. background: linear-gradient(180deg, #2aa79b, #1c8076);
  1091. color: #fff;
  1092. font-weight: 700;
  1093. padding: 10px 12px;
  1094. letter-spacing: 0.3px;
  1095. border-right: 1px solid rgba(255, 255, 255, 0.18);
  1096. }
  1097. .mw-tt thead th:last-child {
  1098. border-right: none;
  1099. }
  1100. .mw-tt thead tr:first-child th {
  1101. top: 0;
  1102. }
  1103. .mw-tt thead tr:nth-child(2) th {
  1104. top: 38px;
  1105. }
  1106. .mw-tt .th-group {
  1107. text-align: center;
  1108. }
  1109. .mw-tt .th-sub {
  1110. background: linear-gradient(180deg, #36bdb0, #23897f);
  1111. font-weight: 600;
  1112. }
  1113. .mw-tt tbody td {
  1114. padding: 9px 12px;
  1115. vertical-align: top;
  1116. line-height: 1.6;
  1117. border-bottom: 1px solid #f0eee8;
  1118. border-right: 1px solid #f5f3ee;
  1119. color: #3a3a3a;
  1120. }
  1121. .mw-tt tbody td:last-child {
  1122. border-right: none;
  1123. }
  1124. .mw-tt td.col-case {
  1125. background: #fafdfc;
  1126. }
  1127. .mw-tt tbody tr.tr-b td {
  1128. background: #fbfaf6;
  1129. }
  1130. .mw-tt tbody tr.tr-b td.col-case {
  1131. background: #f6fbfa;
  1132. }
  1133. .mw-tt tbody td.col-tool {
  1134. font-weight: 700;
  1135. color: #176d64;
  1136. white-space: nowrap;
  1137. border-left: 3px solid #2aa79b;
  1138. background: #f3faf8;
  1139. }
  1140. .mw-tt tbody tr:hover td.col-tool {
  1141. background: #e3f4f0;
  1142. }
  1143. .mw-tt ul {
  1144. margin: 0;
  1145. padding-left: 17px;
  1146. }
  1147. .mw-tt ul li {
  1148. margin: 3px 0;
  1149. }
  1150. .mw-tt ul li::marker {
  1151. color: #2aa79b;
  1152. }
  1153. .mw-tt .layer-badge {
  1154. display: inline-block;
  1155. font-weight: 700;
  1156. font-size: 11px;
  1157. padding: 2px 10px;
  1158. border-radius: 20px;
  1159. white-space: nowrap;
  1160. }
  1161. .mw-tt .layer-badge.make {
  1162. color: #0e7490;
  1163. background: #d6f0ee;
  1164. }
  1165. .mw-tt .layer-badge.create {
  1166. color: #b8731a;
  1167. background: #fef0db;
  1168. }
  1169. .mw-tt .dash {
  1170. color: #c9c2b6;
  1171. }
  1172. .mw-tt .tcell {
  1173. position: relative;
  1174. max-height: 7.8em;
  1175. overflow: hidden;
  1176. transition: max-height 0.15s;
  1177. }
  1178. .mw-tt .tcell.clamped {
  1179. cursor: zoom-in;
  1180. }
  1181. .mw-tt .tcell.clamped::after {
  1182. content: "▾ 展开";
  1183. position: absolute;
  1184. left: 0;
  1185. right: 0;
  1186. bottom: 0;
  1187. height: 2.6em;
  1188. display: flex;
  1189. align-items: flex-end;
  1190. justify-content: center;
  1191. padding-bottom: 2px;
  1192. font-size: 11px;
  1193. font-weight: 700;
  1194. color: #176d64;
  1195. background: linear-gradient(rgba(255, 255, 255, 0), #fff 72%);
  1196. pointer-events: none;
  1197. }
  1198. .mw-tt tbody tr.tr-b .tcell.clamped::after {
  1199. background: linear-gradient(rgba(251, 250, 246, 0), #fbfaf6 72%);
  1200. }
  1201. .mw-tt td.col-case .tcell.clamped::after {
  1202. background: linear-gradient(rgba(250, 253, 252, 0), #fafdfc 72%);
  1203. }
  1204. .mw-tt tbody tr.tr-b td.col-case .tcell.clamped::after {
  1205. background: linear-gradient(rgba(246, 251, 250, 0), #f6fbfa 72%);
  1206. }
  1207. .mw-tt .tcell.open {
  1208. max-height: none;
  1209. cursor: zoom-out;
  1210. }
  1211. .mw-tt .tcell.open::after {
  1212. content: "";
  1213. height: 0;
  1214. }
  1215. /* ── 帖子详情弹层 ── */
  1216. dialog#post-dialog {
  1217. width: min(1100px, 94vw);
  1218. max-height: calc(100vh - 40px);
  1219. border: none;
  1220. border-radius: 14px;
  1221. padding: 0;
  1222. box-shadow: var(--shadow-lg);
  1223. overflow: hidden;
  1224. margin: auto; /* 全局 reset 清掉了 dialog 默认 margin:auto,这里补回才能居中 */
  1225. }
  1226. dialog#post-dialog::backdrop {
  1227. background: rgba(19, 30, 46, 0.5);
  1228. backdrop-filter: blur(2px);
  1229. }
  1230. /* 重新解构·编辑 Prompt 弹框 */
  1231. dialog#reextract-dlg {
  1232. border: none;
  1233. border-radius: 14px;
  1234. padding: 0;
  1235. width: min(680px, 94vw);
  1236. box-shadow: var(--shadow-lg);
  1237. margin: auto;
  1238. }
  1239. dialog#reextract-dlg::backdrop {
  1240. background: rgba(19, 30, 46, 0.42);
  1241. backdrop-filter: blur(2px);
  1242. }
  1243. .rx-wrap {
  1244. display: flex;
  1245. flex-direction: column;
  1246. max-height: calc(100vh - 48px);
  1247. }
  1248. .rx-head {
  1249. display: flex;
  1250. align-items: center;
  1251. justify-content: space-between;
  1252. padding: 14px 18px 12px;
  1253. border-bottom: 1px solid var(--line);
  1254. }
  1255. .rx-title {
  1256. font-weight: 700;
  1257. font-size: 15px;
  1258. color: var(--navy-deep);
  1259. }
  1260. .rx-sub {
  1261. padding: 12px 18px 0;
  1262. font-size: 12px;
  1263. color: var(--ink-faint);
  1264. line-height: 1.6;
  1265. }
  1266. .rx-model {
  1267. padding: 12px 18px 0;
  1268. display: flex;
  1269. align-items: center;
  1270. gap: 8px;
  1271. font-size: 13px;
  1272. }
  1273. .rx-model label {
  1274. font-weight: 600;
  1275. color: var(--ink);
  1276. }
  1277. .rx-prompt {
  1278. margin: 12px 18px;
  1279. flex: 1;
  1280. min-height: 300px;
  1281. resize: vertical;
  1282. font-family: "IBM Plex Mono", ui-monospace, monospace;
  1283. font-size: 12px;
  1284. line-height: 1.6;
  1285. color: var(--ink);
  1286. border: 1px solid var(--line-dark);
  1287. border-radius: 8px;
  1288. padding: 12px;
  1289. background: #fbfaf6;
  1290. }
  1291. .rx-foot {
  1292. display: flex;
  1293. justify-content: flex-end;
  1294. gap: 10px;
  1295. padding: 12px 18px 16px;
  1296. border-top: 1px solid var(--line);
  1297. }
  1298. #rx-save {
  1299. background: var(--green);
  1300. border-color: var(--green);
  1301. color: #fff;
  1302. }
  1303. #rx-save:hover {
  1304. background: #126b33;
  1305. color: #fff;
  1306. box-shadow: 0 4px 12px rgba(21, 128, 61, 0.3);
  1307. }
  1308. .pd-wrap {
  1309. display: flex;
  1310. flex-direction: column;
  1311. max-height: calc(100vh - 40px);
  1312. }
  1313. .pd-head {
  1314. display: flex;
  1315. justify-content: space-between;
  1316. gap: 14px;
  1317. align-items: flex-start;
  1318. padding: 16px 20px;
  1319. border-bottom: 1px solid var(--line);
  1320. background: #fff;
  1321. flex: none;
  1322. }
  1323. .pd-head h3 {
  1324. font-family: "Noto Serif SC", serif;
  1325. font-size: 18px;
  1326. line-height: 1.35;
  1327. margin-top: 6px;
  1328. }
  1329. .pd-meta {
  1330. display: flex;
  1331. gap: 8px;
  1332. flex-wrap: wrap;
  1333. align-items: center;
  1334. font-size: 12px;
  1335. color: var(--ink-soft);
  1336. }
  1337. .pd-close {
  1338. border: none;
  1339. background: #f1f0ea;
  1340. width: 30px;
  1341. height: 30px;
  1342. border-radius: 8px;
  1343. font-size: 14px;
  1344. color: var(--ink-soft);
  1345. flex: none;
  1346. transition: 0.15s;
  1347. }
  1348. .pd-close:hover {
  1349. background: var(--seal);
  1350. color: #fff;
  1351. }
  1352. .pd-body {
  1353. display: grid;
  1354. grid-template-columns: 1.05fr 0.95fr;
  1355. gap: 20px;
  1356. padding: 18px 20px;
  1357. overflow: auto;
  1358. }
  1359. @media (max-width: 920px) {
  1360. .pd-body {
  1361. grid-template-columns: 1fr;
  1362. }
  1363. }
  1364. .pd-body > section,
  1365. .pd-body > aside {
  1366. min-width: 0;
  1367. }
  1368. .pd-sec-title {
  1369. font-weight: 800;
  1370. margin: 16px 0 8px;
  1371. font-size: 13px;
  1372. }
  1373. .pd-sec-title:first-child {
  1374. margin-top: 0;
  1375. }
  1376. .pd-verdict {
  1377. background: #eaf6fb;
  1378. border-left: 4px solid #2c9ec7;
  1379. padding: 10px 12px;
  1380. color: #22566b;
  1381. border-radius: 6px;
  1382. font-size: 13px;
  1383. line-height: 1.6;
  1384. }
  1385. .pd-raw {
  1386. white-space: pre-wrap;
  1387. background: #faf9f5;
  1388. border: 1px solid var(--line);
  1389. border-radius: 10px;
  1390. padding: 12px;
  1391. max-height: 320px;
  1392. overflow: auto;
  1393. color: #3d3f44;
  1394. font-size: 13px;
  1395. line-height: 1.7;
  1396. }
  1397. .pd-images {
  1398. display: grid;
  1399. grid-template-columns: repeat(2, minmax(0, 1fr));
  1400. gap: 8px;
  1401. }
  1402. .pd-images img {
  1403. width: 100%;
  1404. max-height: 250px;
  1405. object-fit: contain;
  1406. border: 1px solid var(--line);
  1407. border-radius: 10px;
  1408. background: #f3f2ed;
  1409. cursor: zoom-in;
  1410. }
  1411. .pd-videos {
  1412. display: grid;
  1413. grid-template-columns: 1fr;
  1414. gap: 8px;
  1415. }
  1416. .pd-videos video {
  1417. width: 100%;
  1418. max-height: 320px;
  1419. border: 1px solid var(--line);
  1420. border-radius: 10px;
  1421. background: #000;
  1422. }
  1423. .pd-videos iframe {
  1424. width: 100%;
  1425. aspect-ratio: 16 / 9;
  1426. border: 1px solid var(--line);
  1427. border-radius: 10px;
  1428. background: #000;
  1429. }
  1430. .pd-videos .vid-fallback {
  1431. display: block;
  1432. padding: 10px 12px;
  1433. font-size: 12px;
  1434. color: var(--accent, #2d6cdf);
  1435. border: 1px dashed var(--line);
  1436. border-radius: 10px;
  1437. text-decoration: none;
  1438. }
  1439. /* ── 图片预览灯箱 ── */
  1440. dialog.lightbox {
  1441. position: fixed;
  1442. inset: 0;
  1443. width: 100%;
  1444. height: 100%;
  1445. max-width: 100%;
  1446. max-height: 100%;
  1447. margin: 0;
  1448. padding: 40px 72px;
  1449. border: none;
  1450. gap: 18px;
  1451. align-items: center;
  1452. justify-content: center;
  1453. background: rgba(20, 20, 22, 0.86);
  1454. backdrop-filter: blur(2px);
  1455. overflow: hidden;
  1456. }
  1457. dialog.lightbox[open] {
  1458. display: flex;
  1459. }
  1460. dialog.lightbox::backdrop {
  1461. background: rgba(20, 20, 22, 0.5);
  1462. }
  1463. .lb-stage {
  1464. margin: 0;
  1465. max-width: 100%;
  1466. max-height: 100%;
  1467. display: flex;
  1468. flex-direction: column;
  1469. align-items: center;
  1470. gap: 12px;
  1471. }
  1472. .lb-stage img {
  1473. max-width: min(1100px, 86vw);
  1474. max-height: 82vh;
  1475. object-fit: contain;
  1476. border-radius: 8px;
  1477. box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  1478. background: #2a2a2c;
  1479. }
  1480. .lb-stage figcaption {
  1481. color: rgba(255, 255, 255, 0.78);
  1482. font-size: 13px;
  1483. letter-spacing: 0.5px;
  1484. }
  1485. .lb-nav {
  1486. flex: 0 0 auto;
  1487. width: 46px;
  1488. height: 46px;
  1489. border-radius: 50%;
  1490. border: none;
  1491. background: rgba(255, 255, 255, 0.12);
  1492. color: #fff;
  1493. font-size: 28px;
  1494. line-height: 1;
  1495. cursor: pointer;
  1496. transition: 0.15s;
  1497. }
  1498. .lb-nav:hover {
  1499. background: rgba(255, 255, 255, 0.26);
  1500. }
  1501. .lb-close {
  1502. position: absolute;
  1503. top: 20px;
  1504. right: 24px;
  1505. width: 38px;
  1506. height: 38px;
  1507. border-radius: 50%;
  1508. border: none;
  1509. background: rgba(255, 255, 255, 0.12);
  1510. color: #fff;
  1511. font-size: 18px;
  1512. cursor: pointer;
  1513. transition: 0.15s;
  1514. }
  1515. .lb-close:hover {
  1516. background: rgba(255, 255, 255, 0.26);
  1517. }
  1518. /* ── 帖子列表缩略图 ── */
  1519. .post .thumb {
  1520. flex: 0 0 auto;
  1521. width: 44px;
  1522. height: 44px;
  1523. border-radius: 7px;
  1524. object-fit: cover;
  1525. background: #f0efe9;
  1526. border: 1px solid var(--line);
  1527. }
  1528. .post .thumb-ph {
  1529. flex: 0 0 auto;
  1530. width: 44px;
  1531. height: 44px;
  1532. border-radius: 7px;
  1533. background: #f0efe9;
  1534. border: 1px solid var(--line);
  1535. display: flex;
  1536. align-items: center;
  1537. justify-content: center;
  1538. color: var(--ink-faint);
  1539. font-size: 16px;
  1540. }
  1541. /* ── 原文卡片(可整体展开/收起;含标题、图片缩略图、正文) ── */
  1542. .src-block {
  1543. border: 1px solid var(--line);
  1544. border-radius: 10px;
  1545. margin-bottom: 14px;
  1546. background: #faf9f5;
  1547. overflow: hidden;
  1548. }
  1549. .src-head {
  1550. display: flex;
  1551. align-items: center;
  1552. gap: 8px;
  1553. padding: 9px 12px;
  1554. cursor: pointer;
  1555. user-select: none;
  1556. }
  1557. .src-head:hover {
  1558. background: #f3f2ed;
  1559. }
  1560. .src-caret {
  1561. flex: 0 0 auto;
  1562. color: var(--ink-faint);
  1563. font-size: 11px;
  1564. transition: transform 0.15s;
  1565. }
  1566. .src-block.open .src-caret {
  1567. transform: rotate(90deg);
  1568. }
  1569. .src-label {
  1570. flex: 0 0 auto;
  1571. font-size: 11px;
  1572. font-weight: 700;
  1573. color: var(--blue);
  1574. background: var(--blue-bg);
  1575. padding: 1px 7px;
  1576. border-radius: 4px;
  1577. }
  1578. .src-title {
  1579. flex: 1;
  1580. min-width: 0;
  1581. font-weight: 600;
  1582. font-size: 13px;
  1583. white-space: nowrap;
  1584. overflow: hidden;
  1585. text-overflow: ellipsis;
  1586. }
  1587. .src-link {
  1588. flex: 0 0 auto;
  1589. font-size: 12px;
  1590. color: var(--blue);
  1591. text-decoration: none;
  1592. }
  1593. .src-case {
  1594. flex: 0 0 auto;
  1595. font-size: 11px;
  1596. font-family: "IBM Plex Mono", ui-monospace, monospace;
  1597. color: var(--ink-faint);
  1598. background: var(--paper, #f3f2ed);
  1599. border: 1px solid var(--line);
  1600. padding: 1px 7px;
  1601. border-radius: 4px;
  1602. white-space: nowrap;
  1603. }
  1604. .src-body {
  1605. padding: 0 12px 12px;
  1606. }
  1607. .src-block:not(.open) .src-body {
  1608. display: none;
  1609. }
  1610. .src-thumbs {
  1611. display: flex;
  1612. gap: 8px;
  1613. overflow-x: auto;
  1614. padding: 4px 2px 10px;
  1615. scrollbar-width: thin;
  1616. }
  1617. .src-thumbs img {
  1618. flex: 0 0 auto;
  1619. height: 96px;
  1620. width: auto;
  1621. max-width: 150px;
  1622. border-radius: 8px;
  1623. border: 1px solid var(--line);
  1624. object-fit: cover;
  1625. background: #f0efe9;
  1626. cursor: zoom-in;
  1627. }
  1628. .src-text {
  1629. font-size: 13px;
  1630. line-height: 1.7;
  1631. color: #3d3f44;
  1632. white-space: pre-wrap;
  1633. }
  1634. .src-text.clamp {
  1635. max-height: 88px;
  1636. overflow: hidden;
  1637. -webkit-mask-image: linear-gradient(180deg, #000 62%, transparent);
  1638. mask-image: linear-gradient(180deg, #000 62%, transparent);
  1639. }
  1640. .src-text-toggle {
  1641. margin-top: 4px;
  1642. background: none;
  1643. border: none;
  1644. color: var(--blue);
  1645. cursor: pointer;
  1646. font-size: 12px;
  1647. padding: 2px 0;
  1648. }
  1649. .pd-tags {
  1650. display: flex;
  1651. gap: 6px;
  1652. flex-wrap: wrap;
  1653. margin-top: 12px;
  1654. }
  1655. .pd-score-head {
  1656. display: flex;
  1657. justify-content: space-between;
  1658. align-items: center;
  1659. margin-bottom: 10px;
  1660. }
  1661. .pd-score-head .t {
  1662. font-weight: 800;
  1663. font-size: 14px;
  1664. }
  1665. .pd-overall {
  1666. display: flex;
  1667. align-items: center;
  1668. gap: 6px;
  1669. font-size: 12.5px;
  1670. font-weight: 700;
  1671. color: var(--ink-soft);
  1672. background: #faf9f5;
  1673. border: 1px solid var(--line);
  1674. padding: 4px 12px;
  1675. border-radius: 8px;
  1676. }
  1677. .pd-overall b {
  1678. font-size: 20px;
  1679. color: var(--blue);
  1680. font-weight: 900;
  1681. line-height: 1;
  1682. }
  1683. .sc-card {
  1684. border: 1px solid var(--line);
  1685. border-radius: 10px;
  1686. background: #fff;
  1687. overflow: hidden;
  1688. margin-bottom: 12px;
  1689. }
  1690. .sc-card-head {
  1691. display: flex;
  1692. justify-content: space-between;
  1693. align-items: center;
  1694. gap: 10px;
  1695. padding: 10px 12px;
  1696. background: #faf9f5;
  1697. border-bottom: 1px solid var(--line);
  1698. font-size: 13px;
  1699. font-weight: 800;
  1700. }
  1701. .sc-card-head .badge {
  1702. display: inline-grid;
  1703. place-items: center;
  1704. width: 20px;
  1705. height: 20px;
  1706. border-radius: 5px;
  1707. background: var(--navy);
  1708. color: #fff;
  1709. font-size: 10px;
  1710. font-weight: 700;
  1711. margin-right: 7px;
  1712. }
  1713. .sc-card-head .avg {
  1714. font-size: 12px;
  1715. color: var(--ink-faint);
  1716. font-weight: 600;
  1717. }
  1718. .sc-card-head .avg b {
  1719. font-size: 17px;
  1720. color: var(--blue);
  1721. font-weight: 900;
  1722. }
  1723. .sc-card-body {
  1724. display: grid;
  1725. gap: 8px;
  1726. padding: 11px 12px;
  1727. }
  1728. /* 维度分组小标题:参考 mode_procedure —— 一级虚线大写,二级点线常规 */
  1729. .sc-sub {
  1730. font-size: 11px;
  1731. font-weight: 800;
  1732. letter-spacing: 0.8px;
  1733. color: var(--ink-faint);
  1734. text-transform: uppercase;
  1735. margin: 14px 0 8px;
  1736. padding-bottom: 5px;
  1737. border-bottom: 1px dashed var(--line-dark);
  1738. }
  1739. .sc-card-body > .sc-sub:first-child {
  1740. margin-top: 2px;
  1741. }
  1742. .sc-sub.lv2 {
  1743. font-size: 11px;
  1744. font-weight: 700;
  1745. letter-spacing: 0.3px;
  1746. text-transform: none;
  1747. color: var(--ink-soft);
  1748. margin: 11px 0 6px;
  1749. padding-bottom: 4px;
  1750. border-bottom: 1px dotted var(--line);
  1751. }
  1752. .sc-row {
  1753. display: grid;
  1754. grid-template-columns: 118px 1fr 30px 16px;
  1755. gap: 9px;
  1756. align-items: center;
  1757. font-size: 12.5px;
  1758. }
  1759. .sc-row .meter {
  1760. height: 8px;
  1761. border-radius: 99px;
  1762. background: #edebe4;
  1763. overflow: hidden;
  1764. }
  1765. .sc-row .meter span {
  1766. display: block;
  1767. height: 100%;
  1768. border-radius: 99px;
  1769. background: linear-gradient(90deg, #60a5fa, #2563eb);
  1770. }
  1771. .sc-row b {
  1772. font-weight: 700;
  1773. text-align: right;
  1774. }
  1775. .sc-row .info {
  1776. color: var(--ink-faint);
  1777. cursor: pointer;
  1778. font-size: 12px;
  1779. opacity: 0.75;
  1780. user-select: none;
  1781. }
  1782. .sc-row .info:hover {
  1783. color: var(--blue);
  1784. opacity: 1;
  1785. }
  1786. /* 判定理由弹层:点击 ⓘ 时浮现,挂在 dialog 顶层 */
  1787. .score-pop {
  1788. position: fixed;
  1789. z-index: 90;
  1790. width: 288px;
  1791. max-width: calc(100vw - 24px);
  1792. background: var(--card);
  1793. border: 1px solid var(--line-dark);
  1794. border-radius: 10px;
  1795. box-shadow: var(--shadow-lg);
  1796. padding: 12px 14px;
  1797. font-size: 12.5px;
  1798. line-height: 1.65;
  1799. color: var(--ink-soft);
  1800. animation: popIn 0.12s ease;
  1801. }
  1802. .score-pop .sp-head {
  1803. display: flex;
  1804. align-items: center;
  1805. gap: 8px;
  1806. margin-bottom: 8px;
  1807. padding-bottom: 8px;
  1808. border-bottom: 1px solid var(--line);
  1809. }
  1810. .score-pop .sp-tag {
  1811. font-size: 9px;
  1812. letter-spacing: 1.5px;
  1813. color: var(--ink-faint);
  1814. font-weight: 700;
  1815. border: 1px solid var(--line-dark);
  1816. border-radius: 5px;
  1817. padding: 2px 6px;
  1818. white-space: nowrap;
  1819. }
  1820. .score-pop .sp-name {
  1821. font-weight: 800;
  1822. font-size: 13px;
  1823. color: var(--ink);
  1824. }
  1825. .score-pop .sp-score {
  1826. margin-left: auto;
  1827. font-size: 16px;
  1828. font-weight: 900;
  1829. color: var(--blue);
  1830. }
  1831. .score-pop .sp-body {
  1832. white-space: pre-wrap;
  1833. }
  1834. @keyframes popIn {
  1835. from {
  1836. opacity: 0;
  1837. transform: translateY(-4px);
  1838. }
  1839. to {
  1840. opacity: 1;
  1841. transform: none;
  1842. }
  1843. }
  1844. /* 任务面板 */
  1845. #task-panel {
  1846. position: fixed;
  1847. right: 22px;
  1848. bottom: 22px;
  1849. width: 440px;
  1850. max-height: 55vh;
  1851. z-index: 130; /* 高于弹层(modal-bg 70/dialog 120),搜索进度日志始终可见 */
  1852. display: flex;
  1853. flex-direction: column;
  1854. border: 1px solid var(--line-dark);
  1855. border-radius: 12px;
  1856. background: var(--card);
  1857. box-shadow: var(--shadow-lg);
  1858. overflow: hidden;
  1859. }
  1860. #task-panel header {
  1861. all: unset;
  1862. display: flex;
  1863. align-items: center;
  1864. gap: 9px;
  1865. padding: 11px 14px;
  1866. background: var(--navy-deep);
  1867. color: #fff;
  1868. font-size: 13px;
  1869. font-weight: 700;
  1870. }
  1871. #task-panel header .dot {
  1872. width: 8px;
  1873. height: 8px;
  1874. border-radius: 50%;
  1875. background: #f5b942;
  1876. animation: blink 1s infinite;
  1877. }
  1878. #task-panel header .dot.done {
  1879. background: #3fb27f;
  1880. animation: none;
  1881. }
  1882. #task-panel header .dot.failed {
  1883. background: #e0492f;
  1884. animation: none;
  1885. }
  1886. @keyframes blink {
  1887. 50% {
  1888. opacity: 0.3;
  1889. }
  1890. }
  1891. #task-panel header button {
  1892. margin-left: auto;
  1893. background: none;
  1894. border: 0;
  1895. color: #9eb0c5;
  1896. font-size: 15px;
  1897. }
  1898. #task-panel header button:hover {
  1899. color: #fff;
  1900. }
  1901. #task-log {
  1902. font-family: "IBM Plex Mono", monospace;
  1903. font-size: 11px;
  1904. line-height: 1.65;
  1905. color: var(--ink-soft);
  1906. white-space: pre-wrap;
  1907. overflow: auto;
  1908. padding: 12px 14px;
  1909. background: #fafaf6;
  1910. flex: 1;
  1911. }
  1912. /* 弹窗(新建搜索) */
  1913. .modal-bg {
  1914. position: fixed;
  1915. inset: 0;
  1916. background: rgba(19, 30, 46, 0.5);
  1917. z-index: 70;
  1918. display: grid;
  1919. place-items: center;
  1920. backdrop-filter: blur(2px);
  1921. }
  1922. /* 不能 overflow:hidden,否则渠道下拉面板会被裁掉 */
  1923. .modal {
  1924. width: 460px;
  1925. background: var(--card);
  1926. border-radius: 14px;
  1927. box-shadow: var(--shadow-lg);
  1928. }
  1929. .modal h2 {
  1930. padding: 14px 18px;
  1931. background: var(--navy-deep);
  1932. color: #fff;
  1933. font-size: 15px;
  1934. letter-spacing: 2px;
  1935. border-radius: 14px 14px 0 0;
  1936. }
  1937. .modal .mb {
  1938. padding: 18px;
  1939. display: grid;
  1940. gap: 12px;
  1941. }
  1942. .modal label {
  1943. font-size: 12px;
  1944. color: var(--ink-soft);
  1945. display: grid;
  1946. gap: 5px;
  1947. }
  1948. .modal .mf {
  1949. display: flex;
  1950. justify-content: flex-end;
  1951. gap: 10px;
  1952. padding: 0 18px 18px;
  1953. }
  1954. /* 渠道下拉多选 */
  1955. .dd {
  1956. position: relative;
  1957. }
  1958. .dd-btn {
  1959. width: 100%;
  1960. display: flex;
  1961. justify-content: space-between;
  1962. align-items: center;
  1963. gap: 8px;
  1964. text-align: left;
  1965. padding: 7px 10px;
  1966. border: 1px solid var(--line-dark);
  1967. border-radius: 8px;
  1968. background: #fff;
  1969. font-size: 13px;
  1970. color: var(--ink);
  1971. }
  1972. .dd-btn .dd-arrow {
  1973. color: var(--ink-faint);
  1974. flex: none;
  1975. }
  1976. .dd-btn:focus {
  1977. border-color: var(--blue);
  1978. }
  1979. .dd-panel {
  1980. position: absolute;
  1981. left: 0;
  1982. right: 0;
  1983. top: calc(100% + 4px);
  1984. z-index: 10;
  1985. background: #fff;
  1986. border: 1px solid var(--line-dark);
  1987. border-radius: 10px;
  1988. box-shadow: var(--shadow-lg);
  1989. padding: 6px;
  1990. max-height: 220px;
  1991. overflow: auto;
  1992. }
  1993. .modal label.dd-opt {
  1994. display: flex;
  1995. flex-direction: row;
  1996. align-items: center;
  1997. gap: 8px;
  1998. padding: 7px 9px;
  1999. border-radius: 6px;
  2000. font-size: 13px;
  2001. color: var(--ink);
  2002. cursor: pointer;
  2003. }
  2004. .dd-opt:hover {
  2005. background: #f4f3ee;
  2006. }
  2007. .dd-opt input {
  2008. accent-color: var(--blue);
  2009. margin: 0;
  2010. cursor: pointer;
  2011. }
  2012. .dd-opt.sel {
  2013. background: var(--blue-bg);
  2014. font-weight: 500;
  2015. }
  2016. /* 聚类库占位 */
  2017. .cluster-empty {
  2018. display: grid;
  2019. place-items: center;
  2020. min-height: 60vh;
  2021. }
  2022. .cluster-empty .inner {
  2023. text-align: center;
  2024. color: var(--ink-faint);
  2025. }
  2026. .cluster-empty .stamp {
  2027. width: 120px;
  2028. height: 120px;
  2029. margin: 0 auto 18px;
  2030. border: 3px solid var(--line-dark);
  2031. border-radius: 50%;
  2032. display: grid;
  2033. place-items: center;
  2034. font-family: "Noto Serif SC", serif;
  2035. font-size: 30px;
  2036. font-weight: 900;
  2037. color: var(--line-dark);
  2038. transform: rotate(-8deg);
  2039. letter-spacing: 4px;
  2040. }
  2041. [hidden] {
  2042. display: none !important;
  2043. }
  2044. /* ── 页内提示(替代浏览器原生 alert) ── */
  2045. #toast-wrap {
  2046. position: fixed;
  2047. top: 18px;
  2048. left: 50%;
  2049. transform: translateX(-50%);
  2050. z-index: 120;
  2051. display: flex;
  2052. flex-direction: column;
  2053. align-items: center;
  2054. gap: 10px;
  2055. pointer-events: none;
  2056. }
  2057. .toast {
  2058. pointer-events: auto;
  2059. display: flex;
  2060. align-items: flex-start;
  2061. gap: 10px;
  2062. min-width: 240px;
  2063. max-width: min(440px, calc(100vw - 32px));
  2064. padding: 12px 14px 12px 13px;
  2065. background: var(--card);
  2066. color: var(--ink);
  2067. border: 1px solid var(--line-dark);
  2068. border-left: 4px solid var(--navy);
  2069. border-radius: 10px;
  2070. box-shadow: var(--shadow-lg);
  2071. font-size: 13px;
  2072. line-height: 1.55;
  2073. animation: toastIn 0.18s ease;
  2074. }
  2075. .toast.out {
  2076. animation: toastOut 0.16s ease forwards;
  2077. }
  2078. .toast .ic {
  2079. flex: none;
  2080. width: 18px;
  2081. height: 18px;
  2082. margin-top: 1px;
  2083. display: grid;
  2084. place-items: center;
  2085. border-radius: 50%;
  2086. font-size: 12px;
  2087. font-weight: 900;
  2088. color: #fff;
  2089. background: var(--navy);
  2090. }
  2091. .toast .msg {
  2092. flex: 1;
  2093. word-break: break-word;
  2094. }
  2095. .toast.error {
  2096. border-left-color: var(--seal);
  2097. }
  2098. .toast.error .ic {
  2099. background: var(--seal);
  2100. }
  2101. .toast.success {
  2102. border-left-color: var(--green);
  2103. }
  2104. .toast.success .ic {
  2105. background: var(--green);
  2106. }
  2107. .toast.warn {
  2108. border-left-color: var(--amber);
  2109. }
  2110. .toast.warn .ic {
  2111. background: var(--amber);
  2112. }
  2113. @keyframes toastIn {
  2114. from {
  2115. opacity: 0;
  2116. transform: translateY(-10px);
  2117. }
  2118. to {
  2119. opacity: 1;
  2120. transform: none;
  2121. }
  2122. }
  2123. @keyframes toastOut {
  2124. to {
  2125. opacity: 0;
  2126. transform: translateY(-8px);
  2127. }
  2128. }
  2129. /* Query 规则弹层 */
  2130. .qr-box { background:#fff; border-radius:14px; box-shadow:0 10px 44px rgba(0,0,0,.18);
  2131. width:96vw; max-width:1200px; max-height:92vh; display:flex; flex-direction:column; overflow:hidden; }
  2132. .qr-head { display:flex; align-items:center; padding:15px 20px; border-bottom:1px solid #eee; }
  2133. .qr-title { font-size:15px; font-weight:600; color:#1a1a1a; }
  2134. .qr-x { margin-left:auto; border:none; background:none; font-size:16px; color:#999; cursor:pointer; padding:4px 9px; border-radius:7px; line-height:1; }
  2135. .qr-x:hover { background:#f2f2f2; color:#333; }
  2136. .qr-bar { display:flex; align-items:center; gap:10px; padding:11px 20px; border-bottom:1px solid #f0f0f0; background:#fcfcfc; }
  2137. .qr-hint { color:#888; font-size:12px; margin-left:4px; }
  2138. .qr-thr-lab { color:#666; font-size:12px; }
  2139. .qr-thr { width:46px; padding:3px 5px; border:1px solid #ddd; border-radius:6px; font-size:12px; }
  2140. #qr-score:disabled { opacity:.6; cursor:wait; }
  2141. .ui-confirm-bg { position:fixed; inset:0; background:rgba(0,0,0,.38); z-index:200; display:flex; align-items:center; justify-content:center; }
  2142. .ui-confirm { background:#fff; border-radius:14px; box-shadow:0 14px 50px rgba(0,0,0,.28); width:400px; max-width:92vw; padding:22px 24px; }
  2143. .ui-confirm-msg { font-size:14px; color:#1a1a1a; line-height:1.6; white-space:pre-line; margin-bottom:18px; }
  2144. .ui-confirm-acts { display:flex; justify-content:flex-end; gap:10px; }
  2145. .qr-dims { padding:8px 20px 10px; max-height:32vh; overflow:auto; border-bottom:1px solid #f0f0f0; }
  2146. .qr-row { display:flex; align-items:flex-start; gap:10px; padding:4px 0; }
  2147. .qr-row + .qr-row { border-top:1px solid #f6f6f6; }
  2148. .qr-lab { min-width:64px; color:#999; font-size:12.5px; padding-top:5px; flex-shrink:0; }
  2149. .qr-chips { display:flex; flex-wrap:wrap; gap:6px; flex:1; }
  2150. .chip { padding:4px 13px; border-radius:16px; font-size:12.5px; cursor:pointer; border:1.5px solid #e2e2e2; background:#fff; color:#555; line-height:1.4; }
  2151. .chip:hover { border-color:#bbb; color:#222; }
  2152. .chip.on { background:#1a1a1a; border-color:#1a1a1a; color:#fff; font-weight:500; }
  2153. .chip.axis.on { background:#2563eb; border-color:#2563eb; }
  2154. .qr-table-wrap { overflow:auto; flex:1; }
  2155. .qr-tab { border-collapse:collapse; font-size:11px; }
  2156. .qr-tab th, .qr-tab td { border:1px solid #eee; padding:3px 7px; white-space:nowrap; }
  2157. .qr-tab thead th { position:sticky; top:0; background:#f7f7f7; z-index:2; }
  2158. .qr-corner { position:sticky; left:0; z-index:3; background:#eef0f3; font-weight:600; color:#555; }
  2159. .qr-th { position:sticky; left:0; background:#fafafa; z-index:1; text-align:left; color:#444; }
  2160. .qr-tl1 { background:#eef0f3; font-weight:600; color:#444; }
  2161. .qr-gh { background:#e8ebef; font-weight:600; color:#333; text-align:center; }
  2162. .qr-ah { background:#f3f4f6; color:#555; text-align:center; }
  2163. .qr-c.t0 { background:#fafafa; color:#bbb; } .qr-c.t1 { background:#f1f8f1; }
  2164. .qr-c.t2 { background:#d8ecd8; } .qr-c.t3 { background:#b9ddb9; }
  2165. .qr-c.dead { color:#ccc; }
  2166. .qr-c.keep { background:#fff3bf !important; box-shadow:inset 0 0 0 2px #f59e0b; color:#111; font-weight:700; cursor:pointer; }
  2167. .qr-c.keep:hover { background:#ffe066 !important; }
  2168. .qr-bd { display:inline-block; margin-left:5px; font-style:normal; font-size:11px; font-weight:800; color:#fff; background:#f59e0b; padding:0 6px; border-radius:9px; }
  2169. .qr-pop { position:fixed; z-index:60; width:300px; background:#fff; border:1px solid #e2e2e2;
  2170. border-radius:11px; box-shadow:0 8px 30px rgba(0,0,0,.18); padding:13px 15px; font-size:12.5px; color:#333; }
  2171. .qr-pop .q { font-size:13.5px; font-weight:600; color:#1a1a1a; margin-bottom:2px; word-break:break-all; }
  2172. .qr-pop .orig { font-size:11px; color:#aaa; margin-bottom:8px; }
  2173. .qr-pop .sc { display:flex; align-items:baseline; gap:8px; margin:6px 0; }
  2174. .qr-pop .sc b { font-size:22px; color:#2563eb; }
  2175. .qr-pop .dim { color:#888; font-size:11.5px; }
  2176. .qr-pop .rsn { color:#555; margin:7px 0 10px; line-height:1.5; }
  2177. .qr-pop .acts { display:flex; gap:8px; }
  2178. </style>
  2179. </head>
  2180. <body>
  2181. <div id="toast-wrap" aria-live="polite"></div>
  2182. <header>
  2183. <div class="logo">
  2184. <div class="seal">解</div>
  2185. <div><b>mode_workflow</b><small>解构工作台 · MODE WORKBENCH</small></div>
  2186. </div>
  2187. <nav id="nav">
  2188. <a
  2189. href="#dashboard"
  2190. data-tab="dashboard"
  2191. >Dashboard</a
  2192. >
  2193. <a
  2194. href="#dataset"
  2195. data-tab="dataset"
  2196. >Dataset</a
  2197. >
  2198. <a
  2199. href="#cluster"
  2200. data-tab="cluster"
  2201. >知识库</a
  2202. >
  2203. </nav>
  2204. <div class="spacer"></div>
  2205. <div class="hint">SEARCH · EXTRACT · ARCHIVE</div>
  2206. </header>
  2207. <main id="view-dashboard"></main>
  2208. <main id="view-dataset">
  2209. <div class="ds-top">
  2210. <div class="mode-switch">
  2211. <button
  2212. id="m-process"
  2213. class="on"
  2214. >
  2215. 工序
  2216. </button>
  2217. <button id="m-tools">工具</button>
  2218. </div>
  2219. <div style="flex: 1"></div>
  2220. <button
  2221. class="btn seal"
  2222. id="btn-new-search"
  2223. >
  2224. + 新建搜索
  2225. </button>
  2226. <button class="btn" id="btn-query-rule" style="margin-left:8px">Query 规则</button>
  2227. </div>
  2228. <div class="ds-grid">
  2229. <div class="card">
  2230. <div class="col-head">
  2231. QUERY
  2232. <span
  2233. class="n"
  2234. id="q-count"
  2235. ></span>
  2236. </div>
  2237. <div
  2238. class="qlist"
  2239. id="query-list"
  2240. >
  2241. <div class="empty">暂无 query</div>
  2242. </div>
  2243. </div>
  2244. <div class="card">
  2245. <div class="col-head posts-head">
  2246. <div class="ph-title">帖子 <span class="n" id="p-count"></span></div>
  2247. <div class="ph-actions">
  2248. <button class="btn sm" id="btn-batch" disabled hidden>批量解构</button>
  2249. <button class="btn sm" id="btn-extract-adopted" hidden>解构全部已采纳</button>
  2250. <button class="btn sm" id="btn-cat-adopted" hidden>归类全部已采纳</button>
  2251. </div>
  2252. </div>
  2253. <div
  2254. class="plat-tabs"
  2255. id="plat-tabs"
  2256. hidden
  2257. ></div>
  2258. <div
  2259. class="plist"
  2260. id="post-list"
  2261. >
  2262. <div class="empty"><span class="glyph">←</span>先选择左侧 query</div>
  2263. </div>
  2264. </div>
  2265. <div class="card xp">
  2266. <div
  2267. class="xp-head"
  2268. id="xp-head"
  2269. >
  2270. <span class="st">解构结果</span>
  2271. </div>
  2272. <div
  2273. class="xp-body"
  2274. id="xp-body"
  2275. >
  2276. <div class="empty"><span class="glyph">←</span>选择一个帖子查看解构结果</div>
  2277. </div>
  2278. </div>
  2279. </div>
  2280. </main>
  2281. <main id="view-cluster">
  2282. <iframe
  2283. id="cluster-frame"
  2284. title="知识检索"
  2285. loading="lazy"
  2286. ></iframe>
  2287. </main>
  2288. <div
  2289. id="task-panel"
  2290. hidden
  2291. >
  2292. <header>
  2293. <span
  2294. class="dot"
  2295. id="task-dot"
  2296. ></span
  2297. ><span id="task-title">任务</span> <button onclick="hideTask()">✕</button>
  2298. </header>
  2299. <div id="task-log"></div>
  2300. </div>
  2301. <!-- 帖子详情弹层(评分详情参考 fixed_query_eval) -->
  2302. <dialog id="post-dialog">
  2303. <div class="pd-wrap">
  2304. <div class="pd-head">
  2305. <div style="min-width: 0">
  2306. <div
  2307. class="pd-meta"
  2308. id="pd-meta"
  2309. ></div>
  2310. <h3 id="pd-title"></h3>
  2311. </div>
  2312. <button
  2313. class="pd-close"
  2314. onclick="document.getElementById('post-dialog').close()"
  2315. >
  2316. </button>
  2317. </div>
  2318. <div class="pd-body">
  2319. <section>
  2320. <div id="pd-verdict"></div>
  2321. <div class="pd-sec-title">抓取文本节选</div>
  2322. <div
  2323. class="pd-raw"
  2324. id="pd-text"
  2325. ></div>
  2326. <div class="pd-sec-title">图片预览</div>
  2327. <div
  2328. class="pd-images"
  2329. id="pd-images"
  2330. ></div>
  2331. <div
  2332. class="pd-sec-title"
  2333. id="pd-videos-title"
  2334. style="display: none"
  2335. >
  2336. 视频预览
  2337. </div>
  2338. <div
  2339. class="pd-videos"
  2340. id="pd-videos"
  2341. style="display: none"
  2342. ></div>
  2343. <div
  2344. class="pd-tags"
  2345. id="pd-tags"
  2346. ></div>
  2347. </section>
  2348. <aside>
  2349. <div class="pd-score-head">
  2350. <span class="t">评分详情</span>
  2351. <span class="pd-overall">综合评分 <b id="pd-overall">—</b></span>
  2352. </div>
  2353. <div id="pd-scores"></div>
  2354. </aside>
  2355. </div>
  2356. </div>
  2357. </dialog>
  2358. <!-- 重新解构 · 编辑解构 Prompt -->
  2359. <dialog id="reextract-dlg">
  2360. <div class="rx-wrap">
  2361. <div class="rx-head">
  2362. <div class="rx-title">重新解构 · 编辑解构 Prompt</div>
  2363. <button
  2364. class="btn sm"
  2365. onclick="document.getElementById('reextract-dlg').close()"
  2366. >
  2367. 关闭
  2368. </button>
  2369. </div>
  2370. <div class="rx-sub">
  2371. 修改下面的解构 Prompt 后,点「保存修改」将按最新 Prompt
  2372. 重新解构本帖(生成新版本,旧版本保留)。改动仅本次生效,不会改写默认 Prompt。
  2373. </div>
  2374. <div class="rx-model">
  2375. <label>模型:</label>
  2376. <select id="rx-model"></select>
  2377. </div>
  2378. <textarea
  2379. id="rx-prompt"
  2380. class="rx-prompt"
  2381. spellcheck="false"
  2382. ></textarea>
  2383. <div class="rx-foot">
  2384. <button
  2385. class="btn"
  2386. onclick="document.getElementById('reextract-dlg').close()"
  2387. >
  2388. 取消
  2389. </button>
  2390. <button
  2391. class="btn primary"
  2392. id="rx-save"
  2393. onclick="saveReextract()"
  2394. >
  2395. 保存修改
  2396. </button>
  2397. </div>
  2398. </div>
  2399. </dialog>
  2400. <!-- 图片预览灯箱(支持左右切换) -->
  2401. <dialog
  2402. class="lightbox"
  2403. id="lightbox"
  2404. onclick="if (event.target === this) closeLightbox();"
  2405. >
  2406. <button
  2407. class="lb-close"
  2408. onclick="closeLightbox()"
  2409. title="关闭 (Esc)"
  2410. >
  2411. </button>
  2412. <button
  2413. class="lb-nav lb-prev"
  2414. onclick="lbStep(-1)"
  2415. title="上一张 (←)"
  2416. >
  2417. </button>
  2418. <figure class="lb-stage">
  2419. <img
  2420. id="lb-img"
  2421. src=""
  2422. alt=""
  2423. />
  2424. <figcaption id="lb-count"></figcaption>
  2425. </figure>
  2426. <button
  2427. class="lb-nav lb-next"
  2428. onclick="lbStep(1)"
  2429. title="下一张 (→)"
  2430. >
  2431. </button>
  2432. </dialog>
  2433. <div
  2434. class="modal-bg"
  2435. id="search-modal"
  2436. hidden
  2437. >
  2438. <div class="modal">
  2439. <h2>新建搜索</h2>
  2440. <div class="mb">
  2441. <label
  2442. >Query(评估锚点,必填)<input
  2443. type="text"
  2444. id="s-query"
  2445. placeholder="如:AI 人像 图片 生成 怎么做"
  2446. /></label>
  2447. <label
  2448. >解构方向<select id="s-mode">
  2449. <option value="工序">工序</option>
  2450. <option value="工具">工具</option>
  2451. </select></label
  2452. >
  2453. <label
  2454. >同义措辞(可选,逗号分隔)<input
  2455. type="text"
  2456. id="s-syn"
  2457. placeholder="如:AI 人像生成 教程,AI 写真 怎么做"
  2458. /></label>
  2459. <label
  2460. >检索渠道(下拉多选)
  2461. <div
  2462. class="dd"
  2463. id="s-plat-dd"
  2464. >
  2465. <button
  2466. type="button"
  2467. class="dd-btn"
  2468. id="s-plat-btn"
  2469. >
  2470. 选择渠道 ▾
  2471. </button>
  2472. <div
  2473. class="dd-panel"
  2474. id="s-plat-panel"
  2475. hidden
  2476. ></div>
  2477. </div>
  2478. </label>
  2479. <label
  2480. >每措辞每渠道上限<input
  2481. type="number"
  2482. id="s-max"
  2483. value="10"
  2484. min="1"
  2485. max="50"
  2486. /></label>
  2487. </div>
  2488. <div class="mf">
  2489. <button
  2490. class="btn"
  2491. onclick="document.getElementById('search-modal').hidden = true"
  2492. >
  2493. 取消
  2494. </button>
  2495. <button
  2496. class="btn primary"
  2497. id="s-go"
  2498. >
  2499. 开始搜索
  2500. </button>
  2501. </div>
  2502. </div>
  2503. </div>
  2504. <!-- Query 规则组织器 弹层 -->
  2505. <div class="modal-bg" id="qr-modal" hidden>
  2506. <div class="qr-box">
  2507. <div class="qr-head">
  2508. <span class="qr-title">Query 词组织器</span>
  2509. <button class="qr-x" id="qr-close" title="关闭">✕</button>
  2510. </div>
  2511. <div class="qr-bar">
  2512. <button class="btn seal" id="qr-score">生成正交表</button>
  2513. <button class="btn" id="qr-search-all" hidden>搜全部达标</button>
  2514. <label class="qr-thr-lab">达标分 ≥ <input id="qr-thr" class="qr-thr" type="number" min="0" max="10" step="0.5" value="7"></label>
  2515. <span id="qr-hint" class="qr-hint"></span>
  2516. </div>
  2517. <div id="qr-dims" class="qr-dims"></div>
  2518. <div id="qr-table-wrap" class="qr-table-wrap"></div>
  2519. </div>
  2520. <div id="qr-pop" class="qr-pop" hidden></div>
  2521. </div>
  2522. <script>
  2523. /* ════ 基础 ════ */
  2524. const $ = (s) => document.querySelector(s);
  2525. /* 页内提示,替代浏览器原生 alert();type: info|error|success|warn */
  2526. function toast(msg, type = "info", ms = 3200) {
  2527. const wrap = $("#toast-wrap");
  2528. if (!wrap) return;
  2529. const ic = { info: "i", error: "!", success: "✓", warn: "!" }[type] || "i";
  2530. const el = document.createElement("div");
  2531. el.className = "toast " + type;
  2532. el.innerHTML = `<span class="ic">${ic}</span><span class="msg">${esc(msg)}</span>`;
  2533. const dismiss = () => {
  2534. el.classList.add("out");
  2535. el.addEventListener("animationend", () => el.remove(), { once: true });
  2536. };
  2537. el.addEventListener("click", dismiss);
  2538. wrap.appendChild(el);
  2539. setTimeout(dismiss, ms);
  2540. }
  2541. const api = (p, opt) =>
  2542. fetch(p, opt).then(async (r) => {
  2543. if (!r.ok)
  2544. throw Object.assign(new Error("api"), { status: r.status, body: await r.json().catch(() => ({})) });
  2545. return r.json();
  2546. });
  2547. const esc = (s) =>
  2548. String(s ?? "").replace(
  2549. /[&<>"']/g,
  2550. (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c],
  2551. );
  2552. /* 目的列: 把 intent 里的 {类别:值} 标记渲染成彩色胶囊 (口径同 procedure-dsl renderer.py:render_intent)。
  2553. 合法类别 5 个: effect/via/act/in-type/out-type; 其余落 ik-other(红删除线,当 lint 警告)。
  2554. 标记外的字面文字与值都做 HTML 转义。 */
  2555. const INTENT_KIND = {
  2556. effect: "ik-effect", via: "ik-via", act: "ik-act",
  2557. "in-type": "ik-in-type", "out-type": "ik-out-type",
  2558. };
  2559. const renderIntent = (text) => {
  2560. const s = String(text ?? "");
  2561. const re = /\{([\w-]+):([^}]+)\}/g;
  2562. let out = "", last = 0, m;
  2563. while ((m = re.exec(s))) {
  2564. out += esc(s.slice(last, m.index).replace(/`/g, ""));
  2565. const kc = INTENT_KIND[m[1]] || "ik-other";
  2566. out += `<span class="intent-tok ${kc}">${esc(m[2])}</span>`;
  2567. last = m.index + m[0].length;
  2568. }
  2569. return out + esc(s.slice(last).replace(/`/g, ""));
  2570. };
  2571. /* 外链图片走本服务同源反代,绕过公众号(mmbiz.qpic.cn)等防盗链 */
  2572. const imgProxy = (u) => (/^https?:\/\//.test(u || "") ? "/api/img?u=" + encodeURIComponent(u) : u || "");
  2573. /* 图片加载策略:优先「浏览器直连 CDN」(referrerpolicy=no-referrer 多数能绕防盗链),
  2574. 直连失败再回退到同源代理 /api/img。
  2575. 为什么:公网走 Cloudflare 快速隧道(trycloudflare),所有经 /api/img 的图片字节都要
  2576. 「上游CDN → 本机 → 隧道(受本机上行带宽限制)→ 客户」,一帖十几张图(每张 100~180KB)
  2577. 就把本机上行打满,于是「本地快、公网慢」。改为浏览器直连后,绝大多数图片字节不再过本机/
  2578. 隧道,只有少数仍被防盗链拦截的才回退代理。 */
  2579. const imgDirect = (u) => (/^https?:\/\//.test(u || "") ? u : imgProxy(u));
  2580. /* 视频走专用同源反代 /api/video:服务端按平台补 Referer(抖音 aweme/play 等必需)
  2581. + 透传 Range 头做边下边播/拖拽。不像 /api/img 那样整文件缓冲,避免慢 + BrokenPipe。 */
  2582. const vidProxy = (u) => (/^https?:\/\//.test(u || "") ? "/api/video?u=" + encodeURIComponent(u) : u || "");
  2583. /* 从各种 YouTube 链接里抠出 video_id(watch?v= / youtu.be/ / embed/) */
  2584. const ytId = (u) => {
  2585. const m =
  2586. (u || "").match(/[?&]v=([\w-]{6,})/) ||
  2587. (u || "").match(/youtu\.be\/([\w-]{6,})/) ||
  2588. (u || "").match(/embed\/([\w-]{6,})/);
  2589. return m ? m[1] : "";
  2590. };
  2591. /* 视频代理也失败时,把 <video> 换成「源站打开」链接(data-src 存原始 URL) */
  2592. function vidFallback(el) {
  2593. el.onerror = null;
  2594. const u = el.dataset.src || "";
  2595. if (u)
  2596. el.outerHTML =
  2597. '<a class="vid-fallback" href="' + u.replace(/"/g, "&quot;") +
  2598. '" target="_blank" rel="noopener">源站打开视频 ↗</a>';
  2599. }
  2600. function imgFallback(el, proxy) {
  2601. el.onerror = null; // 防止回调里再次触发自身造成死循环
  2602. if (!el.dataset.fb) {
  2603. el.dataset.fb = "1"; // 直连失败 → 回退同源代理(防盗链兜底)
  2604. el.onerror = () => imgFallback(el, proxy);
  2605. el.src = proxy;
  2606. return;
  2607. }
  2608. if (el.dataset.ph)
  2609. el.outerHTML = el.dataset.ph; // 代理也失败:换占位元素
  2610. else el.style.opacity = 0.25; // 无占位:淡化
  2611. }
  2612. function imgHtml(u, { cls = "", extra = "", ph = "" } = {}) {
  2613. const phAttr = ph ? ` data-ph="${esc(ph)}"` : "";
  2614. return `<img ${cls ? `class="${cls}" ` : ""}src="${esc(imgDirect(u))}" referrerpolicy="no-referrer" loading="lazy"${phAttr} ${extra} onerror="imgFallback(this,'${esc(imgProxy(u))}')">`;
  2615. }
  2616. const state = {
  2617. tab: "dashboard",
  2618. mode: "process",
  2619. queryId: null,
  2620. caseId: null,
  2621. post: null,
  2622. version: null,
  2623. platFilter: "all",
  2624. doneFilter: true,
  2625. selected: new Set(),
  2626. queries: [],
  2627. posts: [],
  2628. };
  2629. const PLAT_CLS = (p) =>
  2630. ({ xhs: "xhs", gzh: "gzh", zhihu: "zhihu", douyin: "douyin", sph: "sph", youtube: "youtube", x: "x" })[p] ||
  2631. "other";
  2632. const PLAT_NAME = (p) =>
  2633. ({
  2634. xhs: "小红书",
  2635. gzh: "公众号",
  2636. sph: "视频号",
  2637. github: "GitHub",
  2638. toutiao: "头条",
  2639. douyin: "抖音",
  2640. bili: "哔哩哔哩",
  2641. zhihu: "知乎",
  2642. weibo: "微博",
  2643. youtube: "YouTube",
  2644. x: "X",
  2645. })[p] ||
  2646. p ||
  2647. "?";
  2648. /* 渠道 logo 徽标(品牌色圆角方块,hover 显示渠道名) */
  2649. /* 有对应 SVG 图标的渠道(文件位于 /icons/<key>.svg) */
  2650. const PLAT_ICONS = new Set(["xhs", "gzh", "sph", "github", "douyin", "bili", "zhihu", "weibo", "youtube"]);
  2651. const PLAT_LOGO = (p, size = 18) =>
  2652. PLAT_ICONS.has(p)
  2653. ? `<span class="plat-logo" title="${PLAT_NAME(p)}"><img src="/icons/${p}.svg" width="${size}" height="${size}" alt="${PLAT_NAME(p)}" loading="lazy"></span>`
  2654. : `<span class="plat other">${esc(PLAT_NAME(p))}</span>`;
  2655. const MODELS_PROC = ["anthropic/claude-sonnet-4-6", "google/gemini-3.1-flash-lite"];
  2656. const MODELS_TOOL = ["google/gemini-3.1-flash-lite", "anthropic/claude-sonnet-4-6"];
  2657. const scoreCls = (v) => (v == null ? "s0" : v >= 9 ? "s9" : v >= 8 ? "s8" : v >= 6 ? "s6" : "s0");
  2658. /* ════ 路由 ════ */
  2659. function route() {
  2660. state.tab = (location.hash || "#dashboard").slice(1);
  2661. if (!["dashboard", "dataset", "cluster"].includes(state.tab)) state.tab = "dashboard";
  2662. document.querySelectorAll("nav a").forEach((a) => a.classList.toggle("on", a.dataset.tab === state.tab));
  2663. document.querySelectorAll("main").forEach((m) => m.classList.toggle("on", m.id === "view-" + state.tab));
  2664. if (state.tab === "dashboard") renderDashboard();
  2665. if (state.tab === "dataset" && !state.queries.length) loadQueries();
  2666. if (state.tab === "cluster") {
  2667. // 首次打开聚类库才加载内嵌检索页
  2668. const f = $("#cluster-frame");
  2669. if (f && !f.src) f.src = "/search.html";
  2670. }
  2671. }
  2672. window.addEventListener("hashchange", route);
  2673. /* ════ Dashboard ════ */
  2674. let chartRefs = [];
  2675. async function renderDashboard() {
  2676. const v = $("#view-dashboard");
  2677. let d;
  2678. try {
  2679. d = await api("/api/dashboard");
  2680. } catch (e) {
  2681. v.innerHTML = `<div class="card empty"><span class="glyph">!</span>Dashboard 加载失败:${esc(e.body?.error || e.status)}</div>`;
  2682. return;
  2683. }
  2684. const r = d.result,
  2685. p = d.process_data;
  2686. // 进度百分比向下取整:200/201=99.5% 显示 99%,未真正做完不会显示 100%
  2687. const pct = (a, b) => (b ? Math.floor((a / b) * 100) : 0);
  2688. const platBreak = (arr) =>
  2689. (arr || [])
  2690. .map(
  2691. ([k, n]) =>
  2692. `<span class="pb-item">${PLAT_LOGO(k, 15)}<b class="num">${n}</b></span>`,
  2693. )
  2694. .join("") || "—";
  2695. v.innerHTML = `
  2696. <div class="dash-section"><h2>结果数据</h2><div class="rule"></div><span class="tag">RESULTS</span></div>
  2697. <div class="cards">
  2698. <div class="card stat"><div class="lbl">采集帖子数量</div><div class="val num">${r.post_count}</div><div class="sub plat-break">${platBreak(r.collected_by_platform)}</div></div>
  2699. <div class="card stat t"><div class="lbl">解构帖子数量</div><div class="val num">${r.extracted_post_count}</div><div class="sub plat-break">${platBreak(r.extracted_by_platform)}</div></div>
  2700. <div class="card stat a"><div class="lbl">工具数量</div><div class="val num">${r.tool_count}</div><div class="sub">mode_tools 去重工具名</div></div>
  2701. <div class="card stat r"><div class="lbl">内容树覆盖节点</div><div class="val num">0</div>
  2702. <div class="sub">0%</div></div>
  2703. <div class="card stat"><div class="lbl">实质数量</div><div class="val num">${r.substance_count}</div><div class="sub">去重实质条目数</div></div>
  2704. <div class="card stat"><div class="lbl">形式数量</div><div class="val num">${r.form_count}</div><div class="sub">去重形式条目数</div></div>
  2705. </div>
  2706. <div class="dash-section"><h2>过程数据</h2><div class="rule"></div><span class="tag">PROCESS</span></div>
  2707. <div class="cards">
  2708. <div class="card stat a"><div class="lbl">解构成本</div><div class="val num">$${p.total_cost}</div><div class="sub">单条均值 $${p.avg_cost} · 共 ${p.run_count} 次</div></div>
  2709. <div class="card stat a"><div class="lbl">解构耗时</div><div class="val num">${(p.total_duration / 3600).toFixed(1)}<span style="font-size:14px">h</span></div><div class="sub">平均 ${p.avg_duration}s / 次</div></div>
  2710. <div class="card stat t"><div class="ring-row"><div class="ring" style="--p:${pct(p.process_progress.done, p.process_progress.total)}"><div>${pct(p.process_progress.done, p.process_progress.total)}%</div></div>
  2711. <div><div class="lbl">工序进度</div><div class="num" style="font-weight:700">${p.process_progress.done} / ${p.process_progress.total}</div><div class="sub">已解构 / 需解构</div></div></div></div>
  2712. <div class="card stat t"><div class="ring-row"><div class="ring" style="--p:${pct(p.tools_progress.done, p.tools_progress.total)}"><div>${pct(p.tools_progress.done, p.tools_progress.total)}%</div></div>
  2713. <div><div class="lbl">工具进度</div><div class="num" style="font-weight:700">${p.tools_progress.done} / ${p.tools_progress.total}</div><div class="sub">已解构 / 需解构</div></div></div></div>
  2714. </div>
  2715. <div class="charts">
  2716. <div class="card chart-card span6"><h3>工序提及工具 TOP10</h3><div class="chart" id="ch-via" style="height:300px"></div></div>
  2717. <div class="card chart-card span6"><h3>解构成本趋势</h3><div class="chart" id="ch-cost" style="height:300px"></div></div>
  2718. <div class="card chart-card span6"><h3>实质覆盖分布 <span class="num">${r.substance_count}</span></h3><div class="chart" id="ch-sub" style="height:320px"></div></div>
  2719. <div class="card chart-card span6"><h3>形式覆盖分布 <span class="num">${r.form_count}</span></h3><div class="chart" id="ch-form" style="height:320px"></div></div>
  2720. <div class="card chart-card span12"><h3>内容树覆盖热力图 <span class="num">${r.matrix_covered}/${r.matrix_valid}</span><span style="font-weight:400;color:var(--ink-faint)">· 27 动作 × 50 类型</span></h3><div class="chart" id="ch-matrix" style="height:560px"></div></div>
  2721. </div>`;
  2722. chartRefs.forEach((c) => c.dispose());
  2723. chartRefs = [];
  2724. const mk = (id, opt) => {
  2725. const c = echarts.init($(id));
  2726. c.setOption(opt);
  2727. chartRefs.push(c);
  2728. return c;
  2729. };
  2730. const ink = "#1c2433",
  2731. faint = "#9aa3b0",
  2732. grid = { left: 8, right: 16, top: 8, bottom: 8, containLabel: true };
  2733. /* 热力图 */
  2734. mk("#ch-matrix", {
  2735. tooltip: { formatter: (pr) => `${r.matrix_actions[pr.value[1]]} × ${r.matrix_types[pr.value[0]]}` },
  2736. grid: { left: 8, right: 16, top: 8, bottom: 60, containLabel: true },
  2737. xAxis: {
  2738. type: "category",
  2739. data: r.matrix_types,
  2740. axisLabel: { rotate: 60, fontSize: 9, color: faint },
  2741. splitArea: { show: true, areaStyle: { color: ["#fcfcf9", "#f5f4ef"] } },
  2742. },
  2743. yAxis: {
  2744. type: "category",
  2745. data: r.matrix_actions,
  2746. axisLabel: { fontSize: 10, color: ink },
  2747. splitArea: { show: true },
  2748. },
  2749. visualMap: { show: false, min: 0, max: 1, inRange: { color: ["#f0efe8", "#bb3a22"] } },
  2750. series: [
  2751. {
  2752. type: "heatmap",
  2753. data: r.matrix_cells.map(([a, t]) => [t, a, 1]),
  2754. itemStyle: { borderColor: "#fff", borderWidth: 1 },
  2755. },
  2756. ],
  2757. });
  2758. const bar = (data, color) => ({
  2759. tooltip: {},
  2760. grid,
  2761. xAxis: { type: "value", axisLabel: { color: faint } },
  2762. yAxis: {
  2763. type: "category",
  2764. data: data.map((x) => x[0]).reverse(),
  2765. axisLabel: { color: ink, fontSize: 11, width: 130, overflow: "truncate" },
  2766. },
  2767. series: [
  2768. {
  2769. type: "bar",
  2770. data: data.map((x) => x[1]).reverse(),
  2771. itemStyle: { color, borderRadius: [0, 3, 3, 0] },
  2772. barMaxWidth: 16,
  2773. label: { show: true, position: "right", color: faint, fontSize: 10 },
  2774. },
  2775. ],
  2776. });
  2777. mk("#ch-via", r.via_top10.length ? bar(r.via_top10, "#1e3a5f") : emptyOpt());
  2778. mk("#ch-sub", r.substance_top.length ? bar(r.substance_top, "#b45309") : emptyOpt());
  2779. mk("#ch-form", r.form_top.length ? bar(r.form_top, "#0f6b5c") : emptyOpt());
  2780. mk(
  2781. "#ch-cost",
  2782. p.cost_trend.length
  2783. ? {
  2784. tooltip: { trigger: "axis" },
  2785. grid,
  2786. xAxis: { type: "category", data: p.cost_trend.map((x) => x.date), axisLabel: { color: faint } },
  2787. yAxis: { type: "value", axisLabel: { color: faint, formatter: "${value}" } },
  2788. series: [
  2789. {
  2790. type: "line",
  2791. data: p.cost_trend.map((x) => x.cost),
  2792. smooth: true,
  2793. symbolSize: 7,
  2794. lineStyle: { color: "#bb3a22", width: 2.5 },
  2795. itemStyle: { color: "#bb3a22" },
  2796. areaStyle: { color: "rgba(187,58,34,.08)" },
  2797. },
  2798. ],
  2799. }
  2800. : emptyOpt(),
  2801. );
  2802. function emptyOpt() {
  2803. return {
  2804. title: {
  2805. text: "暂无数据",
  2806. left: "center",
  2807. top: "middle",
  2808. textStyle: { color: faint, fontSize: 12, fontWeight: 400 },
  2809. },
  2810. xAxis: { show: false },
  2811. yAxis: { show: false },
  2812. };
  2813. }
  2814. }
  2815. /* ════ Dataset:query 列表 ════ */
  2816. async function loadQueries() {
  2817. /* 工序/工具各自一张搜索表,query 列表按当前子模式拉取 */
  2818. try {
  2819. /* 接口按 query_id 升序返回;列表倒序显示(最新在上) */
  2820. state.queries = (await api("/api/queries?mode=" + state.mode)).reverse();
  2821. } catch (e) {
  2822. state.queries = [];
  2823. }
  2824. renderQueries();
  2825. /* 进入/切换子模式时默认选中第一个(即最新)query(进而联动第一帖与解构结果) */
  2826. if (!state.queryId && state.queries.length) await selectQuery(state.queries[0].query_id);
  2827. }
  2828. function renderQueries() {
  2829. const list = state.queries;
  2830. $("#q-count").textContent = list.length ? list.length + " 组" : "";
  2831. if (!list.length) {
  2832. $("#query-list").innerHTML = '<div class="empty">暂无 query<br>点右上「新建搜索」开始</div>';
  2833. return;
  2834. }
  2835. $("#query-list").innerHTML = list
  2836. .map((q) => {
  2837. const done = state.mode === "process" ? q.process_done : q.tools_done;
  2838. return `<div class="qitem ${q.query_id === state.queryId ? "on" : ""}" onclick="selectQuery('${q.query_id}')">
  2839. <div class="qid">${q.query_id}</div>
  2840. <div class="qt">${esc(q.query_text || "(未命名)")}</div>
  2841. <div class="qm">
  2842. <span>采纳/命中 <b class="num hit">${q.hit_count ?? 0}</b></span>
  2843. <span>总帖数 <b class="num">${q.post_count}</b></span>
  2844. <span>已解构 <b class="num">${done}</b></span>
  2845. </div>
  2846. </div>`;
  2847. })
  2848. .join("");
  2849. }
  2850. async function selectQuery(qid) {
  2851. state.queryId = qid;
  2852. state.caseId = null;
  2853. state.post = null;
  2854. state.platFilter = "all";
  2855. state.selected.clear();
  2856. renderQueries();
  2857. renderExtractEmpty();
  2858. $("#post-list").innerHTML = '<div class="empty">加载中…</div>';
  2859. try {
  2860. state.posts = await api("/api/posts?mode=" + state.mode + "&query_id=" + encodeURIComponent(qid));
  2861. } catch (e) {
  2862. state.posts = [];
  2863. }
  2864. renderPosts();
  2865. /* 默认选中「可见列表」第一帖(已解构筛选下即第一个已解构帖),无可见帖则退回全部第一帖 */
  2866. if (state.posts.length) {
  2867. const vis = visiblePosts();
  2868. await selectPost((vis[0] || state.posts[0]).case_id);
  2869. }
  2870. }
  2871. /* ════ Dataset:帖子列表(按渠道分 tab)════ */
  2872. function setPlatFilter(p) {
  2873. state.platFilter = p;
  2874. renderPosts();
  2875. }
  2876. function toggleDoneFilter() {
  2877. state.doneFilter = !state.doneFilter;
  2878. renderPosts();
  2879. renderPostsAutoSelect();
  2880. }
  2881. /* 当前可见帖(渠道 + 已解构筛选后),供列表渲染与「默认选中」共用 */
  2882. function visiblePosts() {
  2883. const isDone = (p) => (state.mode === "process" ? p.has_process : p.has_tools);
  2884. let list =
  2885. state.platFilter === "all"
  2886. ? state.posts
  2887. : state.posts.filter((p) => (p.platform || "other") === state.platFilter);
  2888. if (state.doneFilter) list = list.filter(isDone);
  2889. return list;
  2890. }
  2891. /* 切换筛选后,若当前选中帖已被筛掉,则改选可见列表的第一帖 */
  2892. async function renderPostsAutoSelect() {
  2893. const vis = visiblePosts();
  2894. if (vis.length && !vis.some((p) => p.case_id === state.caseId)) await selectPost(vis[0].case_id);
  2895. }
  2896. function renderPosts() {
  2897. const all = state.posts;
  2898. updateBatchBtn();
  2899. /* 渠道 tab + 已解构筛选 */
  2900. const counts = {};
  2901. all.forEach((p) => {
  2902. const k = p.platform || "other";
  2903. counts[k] = (counts[k] || 0) + 1;
  2904. });
  2905. const plats = Object.keys(counts);
  2906. if (state.platFilter !== "all" && !counts[state.platFilter]) state.platFilter = "all";
  2907. const isDone = (p) => (state.mode === "process" ? p.has_process : p.has_tools);
  2908. const platScoped =
  2909. state.platFilter === "all" ? all : all.filter((p) => (p.platform || "other") === state.platFilter);
  2910. const doneN = platScoped.filter(isDone).length;
  2911. const tabs = $("#plat-tabs");
  2912. if (all.length) {
  2913. tabs.hidden = false;
  2914. const btns =
  2915. plats.length > 1
  2916. ? [
  2917. `<button class="${state.platFilter === "all" ? "on" : ""}" onclick="setPlatFilter('all')">全部<span class="c">${all.length}</span></button>`,
  2918. ].concat(
  2919. plats.map(
  2920. (k) =>
  2921. `<button class="${state.platFilter === k ? "on" : ""}" onclick="setPlatFilter('${esc(k)}')">${PLAT_NAME(k)}<span class="c">${counts[k]}</span></button>`,
  2922. ),
  2923. )
  2924. : [];
  2925. btns.push(`<button class="done-filter ${state.doneFilter ? "on" : ""}" onclick="toggleDoneFilter()"
  2926. title="${state.doneFilter ? "当前只看已解构,点击显示全部" : "点击只看已解构"}"><span class="dot">●</span>已解构<span class="c">${doneN}</span></button>`);
  2927. tabs.innerHTML = btns.join("");
  2928. } else {
  2929. tabs.hidden = true;
  2930. }
  2931. const list = visiblePosts();
  2932. $("#p-count").textContent = all.length
  2933. ? state.platFilter === "all" && !state.doneFilter
  2934. ? `${all.length} 帖`
  2935. : `${list.length} / ${all.length} 帖`
  2936. : "";
  2937. if (!all.length) {
  2938. $("#post-list").innerHTML = '<div class="empty">该 query 暂无帖子</div>';
  2939. return;
  2940. }
  2941. if (!list.length) {
  2942. $("#post-list").innerHTML =
  2943. `<div class="empty">${state.doneFilter ? "该筛选下暂无已解构帖子" : "该渠道暂无帖子"}</div>`;
  2944. return;
  2945. }
  2946. $("#post-list").innerHTML = list
  2947. .map((p) => {
  2948. const done = state.mode === "process" ? p.has_process : p.has_tools;
  2949. const kt = (p.knowledge_type || []).map((k) => `<span class="pill">${esc(k)}</span>`).join("");
  2950. const sb =
  2951. p.overall_score != null
  2952. ? `<span class="score-badge ${scoreCls(p.overall_score)} num"
  2953. onclick="event.stopPropagation();openPostDetail('${esc(p.case_id)}')">${p.overall_score}</span>`
  2954. : "";
  2955. const thumbSrc = (p.images || []).filter(Boolean)[0];
  2956. const thumb = thumbSrc
  2957. ? imgHtml(thumbSrc, { cls: "thumb", ph: "<div class='thumb-ph'>🖼️</div>" })
  2958. : `<div class="thumb-ph" title="暂无图片">🖼️</div>`;
  2959. return `<div class="post ${p.case_id === state.caseId ? "on" : ""}" onclick="selectPost('${esc(p.case_id)}')">
  2960. ${thumb}
  2961. <div style="flex:1;min-width:0">
  2962. <div class="pt">${esc(p.title || "(无标题)")}</div>
  2963. <div class="pm">
  2964. ${PLAT_LOGO(p.platform)}
  2965. ${p.adopted ? '<span class="pill green">采纳</span>' : ""}
  2966. ${kt}
  2967. ${done ? '<span class="done-dot">● 已解构</span>' : ""}
  2968. </div>
  2969. </div>
  2970. ${sb}
  2971. </div>`;
  2972. })
  2973. .join("");
  2974. }
  2975. function toggleSel(cid, on) {
  2976. on ? state.selected.add(cid) : state.selected.delete(cid);
  2977. updateBatchBtn();
  2978. }
  2979. function updateBatchBtn() {
  2980. const b = $("#btn-batch");
  2981. b.disabled = !state.selected.size;
  2982. b.textContent = state.selected.size ? `批量解构(${state.selected.size})` : "批量解构";
  2983. // 解构全部(未解构/已采纳总数):未解构=已采纳但本方向未解构;A 灰 B 绿
  2984. const adopted = (state.posts || []).filter((p) => p.adopted);
  2985. const adoptedN = adopted.length;
  2986. const doneKey = state.mode === "process" ? "has_process" : "has_tools";
  2987. const undoneN = adopted.filter((p) => !p[doneKey]).length;
  2988. const ea = $("#btn-extract-adopted");
  2989. ea.hidden = !adoptedN;
  2990. ea.innerHTML = `解构全部(<span class="cnt-rest">${undoneN}</span>/<span class="cnt-total">${adoptedN}</span>)`;
  2991. // 归类全部(未归类/已采纳总数):仅工序方向 + 有已采纳已解构帖才显示;未归类=已采纳未归类
  2992. const hasCatTarget = adopted.some((p) => p.has_process);
  2993. const unCatN = adopted.filter((p) => !p.has_category).length;
  2994. const ca = $("#btn-cat-adopted");
  2995. ca.hidden = state.mode !== "process" || !hasCatTarget;
  2996. ca.innerHTML = `归类全部(<span class="cnt-rest">${unCatN}</span>/<span class="cnt-total">${adoptedN}</span>)`;
  2997. }
  2998. $("#btn-batch").onclick = () => state.selected.size && startExtract([...state.selected]);
  2999. $("#btn-extract-adopted").onclick = async () => {
  3000. const adopted = (state.posts || []).filter((p) => p.adopted);
  3001. const cids = adopted.map((p) => p.case_id);
  3002. if (!cids.length) return toast("当前 query 下没有已采纳的帖子", "warn");
  3003. const dir = state.mode === "process" ? "工序" : "工具";
  3004. const doneKey = state.mode === "process" ? "has_process" : "has_tools";
  3005. const undoneN = adopted.filter((p) => !p[doneKey]).length;
  3006. const allDone = undoneN === 0; // 已采纳帖全部已解构
  3007. const msg = allDone
  3008. ? `这 ${cids.length} 个已采纳帖都已${dir}解构。是否重新解构?\n重新解构会消耗 LLM、生成新版本并覆盖当前展示。`
  3009. : `对该 query 下全部 ${cids.length} 个已采纳帖做${dir}解构(其中 ${undoneN} 个未解构)。\n已解构过的会自动跳过/复用,不重复花钱。`;
  3010. if (!(await uiConfirm(msg))) return;
  3011. // 全部已解构时,确认重做须 force(否则按 case 去重会全部跳过、白点一次)
  3012. startExtract(cids, allDone ? { force: true } : {});
  3013. };
  3014. $("#btn-cat-adopted").onclick = async () => {
  3015. // 只归类「已采纳且已解构」的帖(只有已解构才有 steps 可归类);has_category 来自 fetch_posts
  3016. const adoptedProc = (state.posts || []).filter((p) => p.adopted && p.has_process);
  3017. const cids = adoptedProc.map((p) => p.case_id);
  3018. if (!cids.length) return toast("当前 query 下没有「已采纳且已解构」的帖子", "warn");
  3019. const rest = adoptedProc.filter((p) => !p.has_category).map((p) => p.case_id); // 未归类
  3020. const catN = cids.length - rest.length;
  3021. let action; // "all"=归类全部(覆盖) / "rest"=只归类剩余 / null=取消
  3022. if (rest.length === 0) {
  3023. // 全部已归类:只能重新归类全部
  3024. action = (await uiConfirm(`这 ${cids.length} 个帖的工序都已归类。是否重新归类?\n重新归类会用最新分类结果覆盖原有实质/形式 tag。`)) ? "all" : null;
  3025. } else if (catN === 0) {
  3026. // 都没归类:归类全部 = 归类剩余,两按钮即可
  3027. action = (await uiConfirm(`对该 query 下 ${cids.length} 个已采纳且已解构的帖做工序归类?\n将把命中的分类回写进各工序的实质/形式。`)) ? "all" : null;
  3028. } else {
  3029. // 部分已归类:归类剩余(只处理未归类) / 归类全部(覆盖) / 取消
  3030. action = await uiChoose(
  3031. `该 query 下 ${cids.length} 个已采纳且已解构的帖,其中 ${catN} 个已归类、${rest.length} 个未归类。\n「归类剩余」只处理未归类的 ${rest.length} 个;「归类全部」会重跑并覆盖已归类的。`,
  3032. [
  3033. { key: "rest", text: `归类剩余(${rest.length})` },
  3034. { key: "all", text: "归类全部(覆盖)", primary: true },
  3035. ]);
  3036. }
  3037. if (!action) return;
  3038. startCategorize(action === "rest" ? rest : cids); // 归类即覆盖写,无需 force
  3039. };
  3040. /* ════ 帖子详情弹层 ════ */
  3041. /* 得分可能是字符串("1")或数字(10),统一解析;非数值返回 null */
  3042. const scoreNum = (v) => {
  3043. const n = typeof v === "number" || (typeof v === "string" && v.trim() !== "") ? Number(v) : NaN;
  3044. return Number.isFinite(n) ? n : null;
  3045. };
  3046. function collectScores(node) {
  3047. let out = [];
  3048. if (Array.isArray(node)) node.forEach((v) => (out = out.concat(collectScores(v))));
  3049. else if (node && typeof node === "object") {
  3050. for (const [k, v] of Object.entries(node)) {
  3051. if (k === "得分") {
  3052. const n = scoreNum(v);
  3053. if (n !== null) out.push(n);
  3054. } else out = out.concat(collectScores(v));
  3055. }
  3056. }
  3057. return out;
  3058. }
  3059. function scRow(label, v, reason) {
  3060. const n = scoreNum(v);
  3061. const has = n !== null;
  3062. return `<div class="sc-row">
  3063. <span style="color:${has ? "inherit" : "var(--ink-faint)"}">${esc(label)}</span>
  3064. <div class="meter"><span style="width:${has ? Math.min(n, 10) * 10 : 0}%"></span></div>
  3065. <b class="num">${has ? n : "—"}</b>
  3066. ${reason ? `<span class="info" data-label="${esc(label)}" data-reason="${esc(reason)}" data-score="${has ? n : ""}" onclick="showScorePop(this)">ⓘ</span>` : "<span></span>"}
  3067. </div>`;
  3068. }
  3069. /* 递归渲染评分;depth>0 的分组标题用二级样式,形成层级 */
  3070. function walkScores(node, depth) {
  3071. depth = depth || 0;
  3072. let html = "";
  3073. for (const [k, v] of Object.entries(node || {})) {
  3074. if (v && typeof v === "object" && !Array.isArray(v) && "得分" in v) {
  3075. html += scRow(k, v["得分"], v["理由"]);
  3076. } else if (scoreNum(v) !== null) {
  3077. html += scRow(k, v);
  3078. } else if (v && typeof v === "object" && !Array.isArray(v)) {
  3079. const inner = walkScores(v, depth + 1);
  3080. if (inner) html += `<div class="sc-sub${depth > 0 ? " lv2" : ""}">${esc(k)}</div>` + inner;
  3081. }
  3082. }
  3083. return html;
  3084. }
  3085. /* ── 质量评分:不跟随原始 JSON 嵌套,改用 mode_procedure 的规范分组与顺序 ──
  3086. 固定维度 → 用例 → 工序 → 能力 → 工具;丢弃「字段完整性」「动态维度」等中间表头 */
  3087. const QUALITY_ORDER = {
  3088. 工序: ["流程完整性", "输入完整性", "实现完整性", "输出完整性", "泛化性"],
  3089. 能力: ["输入完整性", "实现完整性", "输出完整性", "泛化性"],
  3090. 工具: ["能力边界覆盖", "有效比较", "参数/接口具体性", "实操示例", "版本&限制"],
  3091. };
  3092. /* DFS 找到名为 name 的容器节点(工序/能力/工具) */
  3093. function findScoreNode(n, name) {
  3094. if (!n || typeof n !== "object" || Array.isArray(n)) return null;
  3095. if (name in n && n[name] && typeof n[name] === "object" && !Array.isArray(n[name])) return n[name];
  3096. for (const v of Object.values(n)) {
  3097. if (v && typeof v === "object" && !Array.isArray(v)) {
  3098. const r = findScoreNode(v, name);
  3099. if (r) return r;
  3100. }
  3101. }
  3102. return null;
  3103. }
  3104. /* 递归收集子树叶子评分 [name,{得分,理由}],打平中间分组头 */
  3105. function collectLeaves(node) {
  3106. let out = [];
  3107. for (const [k, v] of Object.entries(node || {})) {
  3108. if (v && typeof v === "object" && !Array.isArray(v) && "得分" in v) out.push([k, v]);
  3109. else if (scoreNum(v) !== null) out.push([k, { 得分: v }]);
  3110. else if (v && typeof v === "object" && !Array.isArray(v)) out = out.concat(collectLeaves(v));
  3111. }
  3112. return out;
  3113. }
  3114. function renderQuality(qnode) {
  3115. /* 固定维度/用例 的维度名全局唯一,扁平索引即可取 */
  3116. const flat = {};
  3117. (function collect(n) {
  3118. for (const [k, v] of Object.entries(n || {})) {
  3119. if (v && typeof v === "object" && !Array.isArray(v)) {
  3120. if ("得分" in v) flat[k] = v;
  3121. else collect(v);
  3122. } else if (scoreNum(v) !== null) flat[k] = { 得分: v };
  3123. }
  3124. })(qnode);
  3125. const sub = (t) => `<div class="sc-sub">${esc(t)}</div>`;
  3126. const rows = (pairs) => pairs.map(([n, o]) => scRow(n, o["得分"], o["理由"])).join("");
  3127. const pick = (names) => names.filter((n) => flat[n]).map((n) => [n, flat[n]]);
  3128. let html = "";
  3129. let p = pick(["时效性", "热度性", "评论反馈", "可复现性", "意图可控性"]); // ① 固定维度(置顶)
  3130. if (p.length) html += sub("固定维度") + rows(p);
  3131. p = pick(["真实感", "真实感 (非AI)", "真实感(非AI)", "表现力"]); // ② 用例
  3132. if (p.length) html += sub("用例") + rows(p);
  3133. for (const name of ["工序", "能力", "工具"]) {
  3134. // ③ 动态维度(按方向命名,内部规范排序)
  3135. const node = findScoreNode(qnode, name);
  3136. if (!node) continue;
  3137. const leaves = collectLeaves(node);
  3138. if (!leaves.length) continue;
  3139. const order = QUALITY_ORDER[name] || [];
  3140. leaves.sort((a, b) => (order.indexOf(a[0]) + 1 || 99) - (order.indexOf(b[0]) + 1 || 99));
  3141. html += sub(name) + rows(leaves);
  3142. }
  3143. return html || '<span style="color:var(--ink-faint)">无评分</span>';
  3144. }
  3145. /* ── 判定理由弹层:点击 ⓘ 浮现,符合当前页面样式 ── */
  3146. let _scorePop = null;
  3147. function closeScorePop() {
  3148. if (_scorePop) {
  3149. _scorePop.remove();
  3150. _scorePop = null;
  3151. }
  3152. document.removeEventListener("mousedown", _scorePopOutside, true);
  3153. }
  3154. function _scorePopOutside(e) {
  3155. if (_scorePop && !_scorePop.contains(e.target) && !e.target.classList.contains("info")) closeScorePop();
  3156. }
  3157. function showScorePop(el) {
  3158. const reopen = _scorePop && _scorePop._anchor === el;
  3159. closeScorePop();
  3160. if (reopen) return; // 再次点击同一图标 → 收起
  3161. const score = el.dataset.score;
  3162. const pop = document.createElement("div");
  3163. pop.className = "score-pop";
  3164. pop._anchor = el;
  3165. pop.innerHTML = `<div class="sp-head">
  3166. <span class="sp-tag">判定理由</span>
  3167. <span class="sp-name">${esc(el.dataset.label || "")}</span>
  3168. ${score !== "" && score != null ? `<span class="sp-score">${esc(score)}</span>` : ""}
  3169. </div>
  3170. <div class="sp-body">${esc(el.dataset.reason || "")}</div>`;
  3171. // 挂在 dialog 内,确保位于 showModal 顶层之上
  3172. (document.getElementById("post-dialog") || document.body).appendChild(pop);
  3173. _scorePop = pop;
  3174. // 定位:图标下方右对齐;越界则上翻 / 收边
  3175. const r = el.getBoundingClientRect();
  3176. let top = r.bottom + 8,
  3177. left = r.right - pop.offsetWidth;
  3178. if (left < 12) left = 12;
  3179. if (top + pop.offsetHeight > window.innerHeight - 12) top = r.top - pop.offsetHeight - 8;
  3180. if (top < 12) top = 12;
  3181. pop.style.top = top + "px";
  3182. pop.style.left = left + "px";
  3183. setTimeout(() => document.addEventListener("mousedown", _scorePopOutside, true), 0);
  3184. }
  3185. document.getElementById("post-dialog")?.addEventListener("close", closeScorePop);
  3186. /* ── 图片预览灯箱 ── */
  3187. const lb = { imgs: [], i: 0 };
  3188. function openLightbox(i) {
  3189. if (!lb.imgs.length) return;
  3190. lb.i = (i + lb.imgs.length) % lb.imgs.length;
  3191. renderLightbox();
  3192. const d = $("#lightbox");
  3193. if (!d.open) d.showModal();
  3194. }
  3195. function closeLightbox() {
  3196. const d = $("#lightbox");
  3197. if (d.open) d.close();
  3198. }
  3199. function lbStep(d) {
  3200. if (!lb.imgs.length) return;
  3201. lb.i = (lb.i + d + lb.imgs.length) % lb.imgs.length;
  3202. renderLightbox();
  3203. }
  3204. function renderLightbox() {
  3205. const url = lb.imgs[lb.i];
  3206. const el = $("#lb-img");
  3207. delete el.dataset.fb; // 切换图片前清除上一张的回退标记
  3208. el.onerror = () => imgFallback(el, imgProxy(url));
  3209. el.src = imgDirect(url); // 大图同样优先直连,失败回退代理
  3210. $("#lb-count").textContent = `${lb.i + 1} / ${lb.imgs.length}`;
  3211. const multi = lb.imgs.length > 1;
  3212. document.querySelector(".lb-prev").style.visibility = multi ? "visible" : "hidden";
  3213. document.querySelector(".lb-next").style.visibility = multi ? "visible" : "hidden";
  3214. }
  3215. document.addEventListener("keydown", (e) => {
  3216. if (!$("#lightbox").open) return;
  3217. if (e.key === "ArrowLeft") lbStep(-1);
  3218. else if (e.key === "ArrowRight") lbStep(1);
  3219. // Esc 由 <dialog> 原生处理(触发 close)
  3220. });
  3221. async function openPostDetail(cid) {
  3222. const p = state.posts.find((x) => x.case_id === cid);
  3223. if (!p) return;
  3224. await ensurePostDetail(p); // 列表瘦身,弹框前补全正文/评估
  3225. const e = p.llm_evaluation || {};
  3226. const meta = [];
  3227. meta.push(`${PLAT_LOGO(p.platform)}<span style="font-weight:600">${esc(PLAT_NAME(p.platform))}</span>`);
  3228. meta.push(p.adopted ? '<span class="pill green">采纳/命中</span>' : '<span class="pill">未采纳</span>');
  3229. if (p.publish_time) meta.push(`<span>${esc(String(p.publish_time).slice(0, 16))}</span>`);
  3230. if (p.like_count != null) meta.push(`<span>👍 ${p.like_count}</span>`);
  3231. if (p.quality_grade) meta.push(`<span>质量 ${esc(p.quality_grade)} ${p.quality_score ?? ""}</span>`);
  3232. if (p.url) meta.push(`<a href="${esc(p.url)}" target="_blank">原文 ↗</a>`);
  3233. meta.push(`<span class="pill" title="case_id" style="font-family:'IBM Plex Mono',ui-monospace,monospace">${esc(p.case_id || cid)}</span>`);
  3234. $("#pd-meta").innerHTML = meta.join("");
  3235. $("#pd-title").textContent = p.title || "(无标题)";
  3236. const verdict = e["判定理由"] || e["理由"] || "";
  3237. $("#pd-verdict").innerHTML = verdict ? `<div class="pd-verdict">${esc(verdict)}</div>` : "";
  3238. $("#pd-text").textContent = p.body || "(无正文)";
  3239. const imgs = (p.images || []).filter(Boolean);
  3240. $("#pd-images").innerHTML = imgs.length
  3241. ? imgs
  3242. .map(
  3243. (s, i) => imgHtml(s, { extra: `onclick="openLightbox(${i})"` }),
  3244. )
  3245. .join("")
  3246. : '<p style="color:var(--ink-faint);font-size:12px">搜索详情未返回图片。</p>';
  3247. lb.imgs = imgs;
  3248. // 视频预览:仅当 videos 有值时显示模块
  3249. const vids = (p.videos || []).filter(Boolean);
  3250. const showVids = vids.length > 0;
  3251. $("#pd-videos-title").style.display = showVids ? "" : "none";
  3252. const pdVideos = $("#pd-videos");
  3253. pdVideos.style.display = showVids ? "" : "none";
  3254. pdVideos.innerHTML = showVids
  3255. ? vids
  3256. .map((s) => {
  3257. // YouTube 的 videos[0] 是 watch 页 URL,<video> 播不了 → 用 iframe embed
  3258. const isYt = p.platform === "youtube" || /youtube\.com|youtu\.be/.test(s);
  3259. if (isYt) {
  3260. const id = p.video_id || ytId(s);
  3261. return id
  3262. ? `<iframe src="https://www.youtube.com/embed/${esc(id)}" loading="lazy" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`
  3263. : `<a class="vid-fallback" href="${esc(s)}" target="_blank" rel="noopener">在 YouTube 打开视频 ↗</a>`;
  3264. }
  3265. // 其他平台(抖音等)走同源视频代理:补 Referer + Range 流式,失败兜底源站链接
  3266. return `<video src="${esc(vidProxy(s))}" data-src="${esc(s)}" controls preload="metadata" playsinline onerror="vidFallback(this)"></video>`;
  3267. })
  3268. .join("")
  3269. : "";
  3270. $("#pd-tags").innerHTML = [
  3271. ...(p.knowledge_type || []).map((t) => "类型:" + t),
  3272. ...(p.found_by || []).map((q) => "命中:" + q),
  3273. ]
  3274. .map((t) => `<span class="pill">${esc(t)}</span>`)
  3275. .join("");
  3276. $("#pd-overall").innerHTML =
  3277. p.overall_score != null
  3278. ? `${p.overall_score}<span style="font-size:11px;color:var(--ink-faint);font-weight:500"> /10</span>`
  3279. : "—";
  3280. /* 评分卡:相关性 + 质量(均分 + 各维度,ⓘ hover 看理由) */
  3281. $("#pd-scores").innerHTML =
  3282. [
  3283. ["01", "相关性"],
  3284. ["02", "质量"],
  3285. ]
  3286. .map(([no, key], i) => {
  3287. const node = e[key];
  3288. if (!node) return "";
  3289. const vs = collectScores(node);
  3290. const avg = vs.length ? (vs.reduce((a, b) => a + b, 0) / vs.length).toFixed(1) : "N/A";
  3291. return `<div class="sc-card">
  3292. <div class="sc-card-head">
  3293. <span><span class="badge">${no}</span>${esc(key)}</span>
  3294. <span class="avg">均分 <b>${avg}</b>/10</span>
  3295. </div>
  3296. <div class="sc-card-body">${(key === "质量" ? renderQuality(node) : walkScores(node)) || '<span style="color:var(--ink-faint)">无评分</span>'}</div>
  3297. </div>`;
  3298. })
  3299. .join("") || '<div class="empty">无评估数据</div>';
  3300. $("#post-dialog").showModal();
  3301. }
  3302. /* ════ Dataset:右栏解构结果 ════ */
  3303. function renderExtractEmpty() {
  3304. $("#xp-head").innerHTML = '<span class="st">解构结果</span>';
  3305. $("#xp-body").innerHTML = '<div class="empty"><span class="glyph">←</span>选择一个帖子查看解构结果</div>';
  3306. }
  3307. async function selectPost(cid) {
  3308. state.caseId = cid;
  3309. state.version = null;
  3310. state.post = state.posts.find((p) => p.case_id === cid) || null;
  3311. renderPosts();
  3312. await ensurePostDetail(state.post); // 列表瘦身,补全正文/评估再渲染右侧详情
  3313. await loadExtract();
  3314. }
  3315. // 列表是瘦身数据(无 body/llm_evaluation/videos);详情按需取单帖并合并到对象上(合并后再点 0 往返)
  3316. async function ensurePostDetail(p) {
  3317. if (!p || p.body !== undefined) return p;
  3318. try {
  3319. const full = await api(`/api/post?mode=${state.mode}&query_id=`
  3320. + encodeURIComponent(state.queryId) + "&case_id=" + encodeURIComponent(p.case_id));
  3321. if (full) Object.assign(p, full);
  3322. } catch (e) { /* 详情取不到不阻断,正文/评分留空 */ }
  3323. return p;
  3324. }
  3325. /* ── 解构结果:客户端缓存 + 请求竞态守卫(解决「多次点击卡顿 / 残留上一帖」)──
  3326. · _extractCache:解构数据只在「重新解构」时变(由本页 startExtract 触发,届时清缓存),
  3327. 故缓存可长留——再次点开看过的帖 0 往返、瞬时渲染。
  3328. · _extractSeq:每次发起 +1;晚到的旧响应据 seq 丢弃,杜绝快速连点时旧响应覆盖新选中。 */
  3329. const _extractCache = new Map(); // key: mode|case_id|version → {versions,data,missing}
  3330. const _extractKey = (cid, ver) => `${state.mode}|${cid}|${ver || ""}`;
  3331. let _extractSeq = 0;
  3332. function invalidateExtractCache(cid) {
  3333. for (const k of [..._extractCache.keys()]) if (k.includes(`|${cid}|`)) _extractCache.delete(k);
  3334. }
  3335. async function loadExtract() {
  3336. if (!state.caseId) return renderExtractEmpty();
  3337. const isProc = state.mode === "process";
  3338. const seq = ++_extractSeq; // 本次请求序号
  3339. const key = _extractKey(state.caseId, state.version);
  3340. // 1) 命中缓存:瞬时渲染,0 往返
  3341. const cached = _extractCache.get(key);
  3342. if (cached) return paintExtract(cached, seq);
  3343. // 2) 未命中:立即显示「原文 + loading」。关键:重写 #xp-body 会移除上一帖的 <img>,
  3344. // 浏览器随即取消其 /api/img 下载,腾出每域 ~6 条连接额度,新的 /api/extract 不再
  3345. // 排在旧图片请求后面等待——这是「多次点击要等很久」的根因。同时给出加载态,
  3346. // 不再停留在上一帖的解构结果。
  3347. renderExtractHead([], null, false, true);
  3348. $("#xp-body").innerHTML =
  3349. renderSourceBlock() +
  3350. `<div class="empty"><span class="spinner"></span>正在加载${isProc ? "工序" : "工具"}解构…</div>`;
  3351. // 版本列表 + 解构详情合一,一个请求拿全(服务端同连接两查,ETag 命中可走 304)
  3352. const url =
  3353. `/api/extract?mode=${state.mode}&case_id=` +
  3354. encodeURIComponent(state.caseId) +
  3355. (state.version ? "&version=" + encodeURIComponent(state.version) : "");
  3356. let res;
  3357. try {
  3358. res = await api(url);
  3359. } catch (e) {
  3360. if (seq !== _extractSeq) return; // 已切到别的帖,丢弃本响应
  3361. $("#xp-body").innerHTML = renderSourceBlock() + '<div class="empty">解构数据加载失败,请重试</div>';
  3362. return;
  3363. }
  3364. if (seq !== _extractSeq) return; // 晚到的旧响应:不覆盖新选中
  3365. const payload = { versions: res.versions || [], data: res.data, missing: res.missing || !res.data };
  3366. _extractCache.set(key, payload);
  3367. paintExtract(payload, seq);
  3368. }
  3369. function paintExtract({ versions, data, missing }, seq) {
  3370. if (seq !== _extractSeq) return; // 渲染前再校验(缓存命中路径也经此)
  3371. const isProc = state.mode === "process";
  3372. renderExtractHead(versions, data, missing);
  3373. const body = $("#xp-body");
  3374. if (missing || !data) {
  3375. body.innerHTML =
  3376. renderSourceBlock() +
  3377. `<div class="empty">该帖暂无${isProc ? "工序" : "工具"}解构<br><br>
  3378. <button class="btn primary" onclick="startExtract(['${esc(state.caseId)}'])">开始解构</button></div>`;
  3379. return;
  3380. }
  3381. state.version = data.version;
  3382. // 以「具体 version」补一条缓存别名,版本下拉切回时也能命中
  3383. _extractCache.set(_extractKey(state.caseId, data.version), { versions, data, missing });
  3384. syncVersionSelect();
  3385. body.innerHTML = isProc ? renderProcedures(data) : renderTools(data);
  3386. requestAnimationFrame(markSrcTextClamp);
  3387. if (isProc) requestAnimationFrame(markStepClamps);
  3388. else requestAnimationFrame(markClampedCells);
  3389. }
  3390. function renderExtractHead(versions, data, missing, loading) {
  3391. const isProc = state.mode === "process";
  3392. const title = state.post ? esc(state.post.title || state.caseId) : esc(state.caseId || "");
  3393. const opts = versions
  3394. .map(
  3395. (v, i) =>
  3396. `<option value="${esc(v.version)}">${esc(v.version)}${i === 0 ? " (最新)" : ""} · ${v.n}${isProc ? "工序" : "工具"}</option>`,
  3397. )
  3398. .join("");
  3399. const stat = loading ? "加载中…" : missing ? "未提取" : "已提取";
  3400. $("#xp-head").innerHTML = `
  3401. <span class="st">大模型${isProc ? "工序" : "工具"}:<em>${stat}</em></span>
  3402. <span style="font-size:12px;color:var(--ink-faint);max-width:330px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${title}">${title}</span>
  3403. <span class="spacer"></span>
  3404. ${versions.length ? `<select id="ver-sel">${opts}</select>` : ""}
  3405. <button class="btn sm primary" onclick="openReextractDialog()">${missing ? "提取" : "♻ 重新生成"}</button>
  3406. ${isProc && !missing ? `<button class="btn sm" onclick="categorizeCurrent()" title="对本帖工序做分类归纳,把命中分类回写到实质/形式">🏷 归纳</button>` : ""}
  3407. <button class="btn sm" onclick="showTaskPanel()" title="重新打开任务日志面板">📋 操作日志</button>`;
  3408. const vs = $("#ver-sel");
  3409. if (vs)
  3410. vs.onchange = () => {
  3411. state.version = vs.value;
  3412. loadExtract();
  3413. };
  3414. }
  3415. function syncVersionSelect() {
  3416. const vs = $("#ver-sel");
  3417. if (vs && state.version) vs.value = state.version;
  3418. }
  3419. /* ── 原文卡片:标题 + 图片缩略图(横滑、可灯箱预览)+ 正文(定高可展开),整体可收起 ── */
  3420. let srcOpen = true,
  3421. srcTextOpen = false;
  3422. function renderSourceBlock() {
  3423. const p = state.post;
  3424. if (!p || !(p.title || (p.images || []).length || p.body)) return "";
  3425. const imgs = (p.images || []).filter(Boolean);
  3426. const thumbs = imgs.length
  3427. ? `<div class="src-thumbs">${imgs
  3428. .map(
  3429. (s, i) =>
  3430. imgHtml(s, { extra: `onclick="openSrcLightbox(${i})"` }),
  3431. )
  3432. .join("")}</div>`
  3433. : "";
  3434. const body = p.body
  3435. ? `<div class="src-text${srcTextOpen ? "" : " clamp"}" id="src-text">${esc(p.body)}</div>
  3436. <button class="src-text-toggle" id="src-text-toggle" onclick="toggleSrcText()" hidden>${srcTextOpen ? "收起 ▲" : "展开 ▼"}</button>`
  3437. : "";
  3438. const link = p.url
  3439. ? `<a class="src-link" href="${esc(p.url)}" target="_blank" rel="noreferrer" onclick="event.stopPropagation()">原文 ↗</a>`
  3440. : "";
  3441. return `<div class="src-block${srcOpen ? " open" : ""}" id="src-block">
  3442. <div class="src-head" onclick="toggleSrc()">
  3443. <span class="src-caret">▸</span>
  3444. <span class="src-label">原文</span>
  3445. <span class="src-title">${esc(p.title || "(无标题)")}</span>
  3446. ${link}
  3447. <span class="src-case" title="case_id" onclick="event.stopPropagation()">${esc(p.case_id || "")}</span>
  3448. </div>
  3449. <div class="src-body">${thumbs}${body}</div>
  3450. </div>`;
  3451. }
  3452. function toggleSrc() {
  3453. srcOpen = !srcOpen;
  3454. const b = $("#src-block");
  3455. if (b) b.classList.toggle("open", srcOpen);
  3456. requestAnimationFrame(markSrcTextClamp);
  3457. }
  3458. function toggleSrcText() {
  3459. srcTextOpen = !srcTextOpen;
  3460. const t = $("#src-text"),
  3461. btn = $("#src-text-toggle");
  3462. if (t) t.classList.toggle("clamp", !srcTextOpen);
  3463. if (btn) btn.textContent = srcTextOpen ? "收起 ▲" : "展开 ▼";
  3464. }
  3465. function openSrcLightbox(i) {
  3466. lb.imgs = ((state.post && state.post.images) || []).filter(Boolean);
  3467. openLightbox(i);
  3468. }
  3469. /* 仅当正文在定高下溢出时才显示「展开」按钮(需在可见、未展开态测量) */
  3470. function markSrcTextClamp() {
  3471. const t = $("#src-text"),
  3472. btn = $("#src-text-toggle");
  3473. if (!t || !btn) return;
  3474. if (srcTextOpen) {
  3475. btn.hidden = false;
  3476. return;
  3477. }
  3478. btn.hidden = !(t.scrollHeight > t.clientHeight + 2);
  3479. }
  3480. /* ── 工序渲染 ── */
  3481. function renderProcedures(data) {
  3482. const src = data.source || {};
  3483. return (
  3484. renderSourceBlock() +
  3485. (data.procedures || [])
  3486. .map((p) => {
  3487. const d = p.declarations || {};
  3488. const ins =
  3489. (d.inputs || [])
  3490. .map(
  3491. (x) =>
  3492. `<span class="pill amber">${esc(x.type || "")}</span> ${x.name ? `<b>${esc(x.name)}</b>` : ""} ${x.desc ? `<span style="color:var(--ink-faint)">— ${esc(x.desc)}</span>` : ""}`,
  3493. )
  3494. .join("<br>") || '<span style="color:var(--ink-faint)">无</span>';
  3495. const ret = d.returns
  3496. ? `<span class="pill teal">${esc(d.returns.type || "")}</span>`
  3497. : '<span style="color:var(--ink-faint)">无</span>';
  3498. return `<div class="proc">
  3499. <div class="proc-head">
  3500. <div class="nm"><span class="pid">工序 ${esc(p.id || "")}</span>${esc(p.name || "")}</div>
  3501. ${p.purpose ? `<div class="pp">#目的:${esc(p.purpose)}</div>` : ""}
  3502. <div class="meta">
  3503. ${p.category ? `<span class="pill red">类别:${esc(p.category)}</span>` : ""}
  3504. ${src.platform ? `<span class="pill">#平台:${esc(src.platform)}</span>` : ""}
  3505. ${src.author ? `<span class="pill">#作者:${esc(src.author)}</span>` : ""}
  3506. <span class="pill">case:${esc(data.case_id)}</span>
  3507. ${(p.tools_used || []).map((t) => `<span class="pill teal">${esc(t)}</span>`).join("")}
  3508. </div>
  3509. </div>
  3510. <div class="decl">
  3511. <div><div class="dl">输入</div><div class="di">${ins}</div></div>
  3512. <div><div class="dl">返回</div><div class="di">${ret}</div></div>
  3513. </div>
  3514. ${renderSteps(p.steps || [])}
  3515. </div>`;
  3516. })
  3517. .join("") || '<div class="empty">本版本无工序</div>'
  3518. );
  3519. }
  3520. function renderSteps(steps) {
  3521. if (!steps.length) return '<div class="empty">无步骤</div>';
  3522. let rows = "";
  3523. for (const s of steps) {
  3524. const ins = s.inputs && s.inputs.length ? s.inputs : [null];
  3525. const outs = s.outputs && s.outputs.length ? s.outputs : [null];
  3526. const n = Math.max(ins.length, outs.length);
  3527. for (let i = 0; i < n; i++) {
  3528. rows += "<tr>";
  3529. if (i === 0) {
  3530. rows += `<td rowspan="${n}" class="sid">${esc(s.id || "")}</td>
  3531. <td rowspan="${n}"><div class="intent-text">${renderIntent(s.intent || s.directive || "")}</div></td>
  3532. <td rowspan="${n}">${s.effect ? `<span class="pill navy">${esc(s.effect)}</span>` : ""}</td>
  3533. <td rowspan="${n}">${renderSF(s.substance, s.substanceMatch)}</td>
  3534. <td rowspan="${n}">${renderSF(s.form, s.formMatch)}</td>`;
  3535. }
  3536. rows += ioCell(ins[i], "in");
  3537. if (i === 0) {
  3538. rows += `<td rowspan="${n}">${s.via ? `<span class="pill teal">${esc(s.via)}</span>` : ""}</td>
  3539. <td rowspan="${n}" class="vtxt">${esc(s.action || "")}</td>`;
  3540. }
  3541. rows += ioCell(outs[i], "out");
  3542. rows += "</tr>";
  3543. }
  3544. }
  3545. return `<div style="overflow-x:auto"><table class="steps">
  3546. <colgroup>
  3547. <col style="width:44px"><col style="width:200px"><col style="width:92px">
  3548. <col style="width:180px"><col style="width:168px">
  3549. <col style="width:112px"><col style="width:330px"><col style="width:92px">
  3550. <col style="width:118px"><col style="width:130px">
  3551. <col style="width:112px"><col style="width:360px"><col style="width:110px">
  3552. </colgroup>
  3553. <thead>
  3554. <tr><th class="h-req" colspan="5">需 求</th><th class="h-in" colspan="3">输 入</th><th class="h-im" colspan="2">实 现</th><th class="h-out" colspan="3">输 出</th></tr>
  3555. <tr>
  3556. <th class="h-req2">#</th><th class="h-req2">目的</th><th class="h-req2">作用</th><th class="h-req2">实质</th><th class="h-req2">形式</th>
  3557. <th class="h-in2">类型</th><th class="h-in2">值</th><th class="h-in2">来源</th>
  3558. <th class="h-im2">外部工具</th><th class="h-im2">动作</th>
  3559. <th class="h-out2">类型</th><th class="h-out2">值</th><th class="h-out2">去处</th>
  3560. </tr>
  3561. </thead><tbody>${rows}</tbody></table></div>`;
  3562. }
  3563. function fmtSF(v) {
  3564. return v == null ? "" : Array.isArray(v) ? v.join("、") : v;
  3565. }
  3566. const SF_ARROW =
  3567. '<svg class="sf-arrow" viewBox="0 0 24 24" width="13" height="13" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
  3568. const SF_NO_MATCH = "无"; // 后端未命中占位符(与 category_match.py NO_MATCH 一致)
  3569. /* 原值拆分:与后端 _split_values 完全一致 —— 括号内的「、」不拆、去重保序,
  3570. 保证原值子项与 *Match 子项「等长等序」可按下标配对 */
  3571. function _splitParts(raw) {
  3572. if (raw == null) return [];
  3573. if (Array.isArray(raw)) {
  3574. const out = [],
  3575. seen = new Set();
  3576. for (const x of raw) {
  3577. const p = String(x).trim();
  3578. if (p && !seen.has(p)) {
  3579. seen.add(p);
  3580. out.push(p);
  3581. }
  3582. }
  3583. return out;
  3584. }
  3585. const parts = [];
  3586. let cur = "",
  3587. depth = 0;
  3588. for (const ch of String(raw)) {
  3589. if (ch === "(" || ch === "(") {
  3590. depth++;
  3591. cur += ch;
  3592. } else if (ch === ")" || ch === ")") {
  3593. depth--;
  3594. cur += ch;
  3595. } else if (ch === "、" && depth === 0) {
  3596. const p = cur.trim();
  3597. if (p) parts.push(p);
  3598. cur = "";
  3599. } else {
  3600. cur += ch;
  3601. }
  3602. }
  3603. const last = cur.trim();
  3604. if (last) parts.push(last);
  3605. const out = [],
  3606. seen = new Set();
  3607. for (const p of parts)
  3608. if (!seen.has(p)) {
  3609. seen.add(p);
  3610. out.push(p);
  3611. }
  3612. return out;
  3613. }
  3614. /* *Match 拆分:按下标对齐,**不去重不滤空**,保留「无」占位 */
  3615. function _matchParts(v) {
  3616. return v == null ? [] : String(v).split("、").map((x) => x.trim());
  3617. }
  3618. /* 实质/形式单元格:逐子项「原值 → 命中值」配对。
  3619. 命中 → 原值灰色划除 + 箭头 + 绿色命中值;
  3620. 未命中(占位「无」/缺失)→ 只显原值,黑色正常(无划除无箭头) */
  3621. function renderSF(value, match) {
  3622. const olds = _splitParts(value);
  3623. const news = _matchParts(match);
  3624. if (!news.length) return esc(fmtSF(value)); // 整格未归类 → 原值黑色
  3625. const n = Math.max(olds.length, news.length);
  3626. let rows = "";
  3627. for (let i = 0; i < n; i++) {
  3628. const a = olds[i],
  3629. b = news[i];
  3630. const matched = b != null && b !== "" && b !== SF_NO_MATCH;
  3631. if (matched) {
  3632. rows += `<div class="sf-pair">${
  3633. a != null ? `<span class="sf-old">${esc(a)}</span>${SF_ARROW}` : ""
  3634. }<span class="sf-new">${esc(b)}</span></div>`;
  3635. } else if (a != null) {
  3636. rows += `<div class="sf-pair"><span class="sf-plain">${esc(a)}</span></div>`;
  3637. }
  3638. }
  3639. return `<div class="sf-map">${rows}</div>`;
  3640. }
  3641. function ioCell(x, kind) {
  3642. const cls = kind === "in" ? "c-in" : "c-out";
  3643. if (!x) return `<td class="${cls}"></td><td class="${cls}"></td><td class="${cls}"></td>`;
  3644. const inf = x.inferred ? ` inf" title="推断理由:${esc(x.inferred_reason || "模型推断补全")}` : "";
  3645. const badge = x.inferred ? '<span class="ib">推</span>' : "";
  3646. return `<td class="${cls}"><span class="pill ${kind === "in" ? "amber" : "blue"}">${esc(x.type || "")}</span></td>
  3647. <td class="${cls}${inf}">${badge}<div class="clamp-val" onclick="toggleClampVal(this)"><span class="vtxt">${esc(x.value || "")}</span></div></td>
  3648. <td class="${cls}"><span class="anchor">${esc(x.anchor || "")}</span></td>`;
  3649. }
  3650. /* 点击「值」单元格展开/收起(仅在内容溢出、已标记 clampable 时生效) */
  3651. function toggleClampVal(el) {
  3652. if (!el.classList.contains("clampable") && !el.classList.contains("open")) return;
  3653. el.classList.toggle("open");
  3654. }
  3655. /* 渲染后标记真正溢出 4 行的「值」单元格:先套限高再测量,溢出才保留 clampable */
  3656. function markStepClamps() {
  3657. document.querySelectorAll("#xp-body .steps .clamp-val").forEach((el) => {
  3658. if (el.classList.contains("open")) return;
  3659. el.classList.add("clampable");
  3660. if (el.scrollHeight <= el.clientHeight + 2) el.classList.remove("clampable");
  3661. });
  3662. }
  3663. /* ── 工具渲染(表格,移植自 fixed_query_eval renderToolTable)── */
  3664. const DASH = '<span class="dash">—</span>';
  3665. function _toolCell(v) {
  3666. if (v === null || v === undefined || v === "" || (Array.isArray(v) && !v.length)) return DASH;
  3667. if (Array.isArray(v)) return "<ul>" + v.map((x) => `<li>${esc(String(x))}</li>`).join("") + "</ul>";
  3668. return esc(String(v));
  3669. }
  3670. function _scopeCell(v) {
  3671. /* 作用域是 JSON 数组:按「、」拼接成短语,不出列表 */
  3672. if (v === null || v === undefined || (Array.isArray(v) && !v.length) || v === "") return DASH;
  3673. return esc(Array.isArray(v) ? v.join("、") : String(v));
  3674. }
  3675. function _ttCell(inner, clampable) {
  3676. return clampable ? `<div class="tcell" onclick="this.classList.toggle('open')">${inner}</div>` : inner;
  3677. }
  3678. function _toolCellContent(c, t) {
  3679. let inner,
  3680. cls = "",
  3681. clampable = true,
  3682. style = "";
  3683. if (c === "工具名称") {
  3684. cls = "col-tool";
  3685. clampable = false;
  3686. inner = `🔧 ${esc(t[c] || "(未命名)")}`;
  3687. } else if (c === "来源链接") {
  3688. clampable = false;
  3689. inner = t[c]
  3690. ? `<a href="${esc(t[c])}" target="_blank" style="color:#176d64;font-weight:600;">🔗 打开</a>`
  3691. : DASH;
  3692. } else if (c === "创作层级") {
  3693. clampable = false;
  3694. inner = t[c]
  3695. ? `<span class="layer-badge ${t[c] === "制作层" ? "make" : "create"}">${esc(t[c])}</span>`
  3696. : DASH;
  3697. } else if (c === "实质作用域" || c === "形式作用域") {
  3698. inner = _scopeCell(t[c]);
  3699. } else {
  3700. inner = _toolCell(t[c]);
  3701. }
  3702. if (["输入", "输出", "用法", "缺点"].includes(c)) style = "max-width:240px;";
  3703. else if (c === "实质作用域" || c === "形式作用域") style = "max-width:170px;";
  3704. else if (!clampable) style = "white-space:nowrap;";
  3705. return { inner, cls, clampable, style };
  3706. }
  3707. function _td(c, t, rowspan) {
  3708. const { inner, cls, clampable, style } = _toolCellContent(c, t);
  3709. const rs = rowspan > 1 ? ` rowspan="${rowspan}"` : "";
  3710. return `<td class="${cls}" style="${style}"${rs}>${_ttCell(inner, clampable)}</td>`;
  3711. }
  3712. function _caseTd(cse, key) {
  3713. const v = cse && cse[key] != null && cse[key] !== "" ? esc(String(cse[key])) : DASH;
  3714. return `<td class="col-case" style="max-width:210px;">${_ttCell(v, true)}</td>`;
  3715. }
  3716. function renderTools(data) {
  3717. const tools = data.tools || [];
  3718. if (!tools.length) return renderSourceBlock() + '<div class="empty">本版本无工具</div>';
  3719. /* 案例 group(输入/输出/效果)放在 用法 后、缺点 前;用 colspan/rowspan 做两层表头 */
  3720. const before = ["工具名称", "创作层级", "实质作用域", "形式作用域", "输入", "输出", "用法"];
  3721. const after = ["缺点", "来源链接", "最新更新时间"];
  3722. const thead = `<thead>
  3723. <tr>
  3724. ${before.map((c) => `<th rowspan="2">${c}</th>`).join("")}
  3725. <th colspan="3" class="th-group">案例</th>
  3726. ${after.map((c) => `<th rowspan="2">${c}</th>`).join("")}
  3727. </tr>
  3728. <tr>${["输入", "输出", "效果"].map((c) => `<th class="th-sub">${c}</th>`).join("")}</tr>
  3729. </thead>`;
  3730. const rows = tools
  3731. .map((t, ti) => {
  3732. const cases = Array.isArray(t["案例"]) && t["案例"].length ? t["案例"] : [null];
  3733. const K = cases.length;
  3734. const par = ti % 2 ? "tr-b" : "tr-a";
  3735. return cases
  3736. .map((cse, i) => {
  3737. const caseTds = `${_caseTd(cse, "输入")}${_caseTd(cse, "输出")}${_caseTd(cse, "效果")}`;
  3738. if (i === 0) {
  3739. return `<tr class="${par}">${before.map((c) => _td(c, t, K)).join("")}${caseTds}${after.map((c) => _td(c, t, K)).join("")}</tr>`;
  3740. }
  3741. return `<tr class="${par}">${caseTds}</tr>`;
  3742. })
  3743. .join("");
  3744. })
  3745. .join("");
  3746. return (
  3747. renderSourceBlock() +
  3748. `<div class="mw-ttwrap"><table class="mw-tt">${thead}<tbody>${rows}</tbody></table></div>`
  3749. );
  3750. }
  3751. /* 渲染后标记真正溢出的单元格(才显示蒙版+可点击) */
  3752. function markClampedCells() {
  3753. document.querySelectorAll("#xp-body .mw-tt .tcell").forEach((el) => {
  3754. if (!el.classList.contains("open") && el.scrollHeight > el.clientHeight + 2) el.classList.add("clamped");
  3755. else if (el.scrollHeight <= el.clientHeight + 2) el.classList.remove("clamped");
  3756. });
  3757. }
  3758. /* ════ 重新解构 · 编辑 Prompt 弹框 ════ */
  3759. async function openReextractDialog() {
  3760. if (!state.caseId) {
  3761. toast("请先选择帖子", "info");
  3762. return;
  3763. }
  3764. const isProc = state.mode === "process";
  3765. const dlg = $("#reextract-dlg"),
  3766. sel = $("#rx-model"),
  3767. ta = $("#rx-prompt"),
  3768. save = $("#rx-save");
  3769. sel.innerHTML = (isProc ? MODELS_PROC : MODELS_TOOL)
  3770. .map((m) => `<option>${m}</option>`)
  3771. .join("");
  3772. ta.value = "加载中…";
  3773. ta.disabled = save.disabled = true;
  3774. dlg.showModal();
  3775. try {
  3776. const r = await api(`/api/extract_prompt?mode=${state.mode}`);
  3777. ta.value = r.prompt || "";
  3778. } catch (e) {
  3779. ta.value = "";
  3780. toast("加载 Prompt 失败:" + (e.body?.error || e.status), "error");
  3781. } finally {
  3782. ta.disabled = save.disabled = false;
  3783. }
  3784. }
  3785. async function saveReextract() {
  3786. const cid = state.caseId;
  3787. if (!cid) return;
  3788. const model = $("#rx-model").value,
  3789. prompt = $("#rx-prompt").value;
  3790. $("#reextract-dlg").close();
  3791. // 临时 prompt 覆盖 + force 重解构(仅本次生效,不改默认 Prompt)
  3792. await startExtract([cid], { model, prompt, force: true });
  3793. }
  3794. /* ════ 解构任务 ════ */
  3795. async function startExtract(caseIds, opts = {}) {
  3796. if (!state.queryId || !caseIds.length) return;
  3797. const isProc = state.mode === "process";
  3798. const model = opts.model || (isProc ? MODELS_PROC[0] : MODELS_TOOL[0]);
  3799. try {
  3800. const body = { query_id: state.queryId, case_ids: caseIds, model };
  3801. if (opts.prompt != null) body.prompt = opts.prompt; // 临时 prompt 覆盖(仅本次)
  3802. if (opts.force) body.force = true; // 换 prompt/模型重解构需跳过去重
  3803. const r = await api(`/api/extract_${isProc ? "process" : "tools"}`, {
  3804. method: "POST",
  3805. body: JSON.stringify(body),
  3806. });
  3807. // 全部正在解构中(被认领跳过):没有 task_id,提示一下即可,别去轮询空任务
  3808. if (!r.task_id) {
  3809. toast(r.note || "所选帖子正在解构中,已跳过", "info");
  3810. return;
  3811. }
  3812. if ((r.skipped || []).length) toast(`${r.skipped.length} 帖正在解构中,已跳过`, "info");
  3813. showTask(`${isProc ? "工序" : "工具"}解构 · ${caseIds.length} 帖`, r.task_id, async () => {
  3814. state.selected.clear();
  3815. caseIds.forEach(invalidateExtractCache); // 重新解构后数据已变,清这些帖的缓存
  3816. await selectQuery(state.queryId);
  3817. if (caseIds.includes(state.caseId)) {
  3818. /* selectQuery 清了 caseId,恢复选中 */
  3819. }
  3820. if (caseIds.length === 1) {
  3821. state.caseId = caseIds[0];
  3822. state.version = null;
  3823. renderPosts();
  3824. await loadExtract();
  3825. }
  3826. // 需求3:工序解构完成 → 自动归类(工具方向无 substance/form,不归类)
  3827. if (isProc) startCategorize(caseIds, { auto: true });
  3828. });
  3829. } catch (e) {
  3830. toast("任务启动失败:" + (e.body?.error || e.status), "error");
  3831. }
  3832. }
  3833. /* ════ 工序归类(category-match)════
  3834. 起 /api/categorize 子进程任务,完成后清缓存并刷新当前帖解构,实质/形式单元格出 tag。
  3835. auto=true 为「工序解构完成后自动归类」,文案略不同。 */
  3836. async function startCategorize(caseIds, opts = {}) {
  3837. if (state.mode !== "process") return; // 仅工序方向有 substance/form 可归类
  3838. if (!state.queryId || !caseIds.length) return;
  3839. try {
  3840. const r = await api("/api/categorize", {
  3841. method: "POST",
  3842. body: JSON.stringify({ query_id: state.queryId, case_ids: caseIds }),
  3843. });
  3844. if (!r.task_id) return toast(r.note || "无可归类帖", "info");
  3845. showTask(`工序归类 · ${caseIds.length} 帖${opts.auto ? "(自动)" : ""}`, r.task_id, async () => {
  3846. caseIds.forEach(invalidateExtractCache); // 归类改了 steps,清缓存才能拿到新 match
  3847. // 乐观更新:归类成功的帖标记已归类,刷新「归类全部(未归类/已采纳)」计数
  3848. const done = new Set(caseIds);
  3849. (state.posts || []).forEach((p) => { if (done.has(p.case_id)) p.has_category = true; });
  3850. updateBatchBtn();
  3851. // 当前正看的帖在本批里 → 重载解构,实质/形式立即出 tag
  3852. if (caseIds.includes(state.caseId)) {
  3853. state.version = null;
  3854. await loadExtract();
  3855. }
  3856. toast(opts.auto ? "解构完成,已自动归类" : "归类完成", "success");
  3857. });
  3858. } catch (e) {
  3859. toast("归类启动失败:" + (e.body?.error || e.status), "error");
  3860. }
  3861. }
  3862. function categorizeCurrent() {
  3863. if (!state.caseId) return toast("请先选择帖子", "warn");
  3864. startCategorize([state.caseId]);
  3865. }
  3866. /* ════ 任务面板(✕ 只隐藏;「操作日志」按钮可随时唤回)════ */
  3867. let pollTimer = null,
  3868. hasTask = false;
  3869. // 自建确认弹框(替代浏览器原生 confirm):返回 Promise<bool>。Enter=确定 / Esc=取消 / 点遮罩=取消
  3870. function uiConfirm(message, opt = {}) {
  3871. const { okText = "确定", cancelText = "取消" } = opt;
  3872. return new Promise((resolve) => {
  3873. const bg = document.createElement("div");
  3874. bg.className = "ui-confirm-bg";
  3875. bg.innerHTML =
  3876. '<div class="ui-confirm"><div class="ui-confirm-msg"></div>'
  3877. + '<div class="ui-confirm-acts">'
  3878. + '<button class="btn" data-act="cancel"></button>'
  3879. + '<button class="btn seal" data-act="ok"></button></div></div>';
  3880. bg.querySelector(".ui-confirm-msg").textContent = message;
  3881. bg.querySelector('[data-act="cancel"]').textContent = cancelText;
  3882. bg.querySelector('[data-act="ok"]').textContent = okText;
  3883. document.body.appendChild(bg);
  3884. const done = (v) => { bg.remove(); document.removeEventListener("keydown", onKey, true); resolve(v); };
  3885. bg.addEventListener("click", (e) => {
  3886. if (e.target === bg) return done(false);
  3887. const a = e.target.closest("[data-act]");
  3888. if (a) done(a.dataset.act === "ok");
  3889. });
  3890. const onKey = (e) => {
  3891. if (e.key === "Escape") { e.preventDefault(); done(false); }
  3892. else if (e.key === "Enter") { e.preventDefault(); done(true); }
  3893. };
  3894. document.addEventListener("keydown", onKey, true);
  3895. bg.querySelector('[data-act="ok"]').focus();
  3896. });
  3897. }
  3898. /* 多按钮选择弹框(uiConfirm 的多选版):buttons=[{key,text,primary?}]。
  3899. 点业务按钮返回其 key;取消/Esc/点遮罩返回 null;Enter=primary(或第一个)按钮。 */
  3900. function uiChoose(message, buttons, opt = {}) {
  3901. const { cancelText = "取消" } = opt;
  3902. return new Promise((resolve) => {
  3903. const bg = document.createElement("div");
  3904. bg.className = "ui-confirm-bg";
  3905. const btns = buttons
  3906. .map((b) => `<button class="btn ${b.primary ? "seal" : ""}" data-key="${esc(b.key)}">${esc(b.text)}</button>`)
  3907. .join("");
  3908. bg.innerHTML =
  3909. '<div class="ui-confirm"><div class="ui-confirm-msg"></div>'
  3910. + '<div class="ui-confirm-acts">'
  3911. + `<button class="btn" data-key="">${esc(cancelText)}</button>`
  3912. + btns + "</div></div>";
  3913. bg.querySelector(".ui-confirm-msg").textContent = message;
  3914. document.body.appendChild(bg);
  3915. const done = (v) => { bg.remove(); document.removeEventListener("keydown", onKey, true); resolve(v); };
  3916. bg.addEventListener("click", (e) => {
  3917. if (e.target === bg) return done(null);
  3918. const a = e.target.closest("[data-key]");
  3919. if (a) done(a.dataset.key || null); // data-key="" → 取消 → null
  3920. });
  3921. const onKey = (e) => {
  3922. if (e.key === "Escape") { e.preventDefault(); done(null); }
  3923. else if (e.key === "Enter") {
  3924. e.preventDefault();
  3925. const p = buttons.find((b) => b.primary) || buttons[0];
  3926. done(p ? p.key : null);
  3927. }
  3928. };
  3929. document.addEventListener("keydown", onKey, true);
  3930. (bg.querySelector(".ui-confirm-acts .seal") || bg.querySelector(".ui-confirm-acts .btn:last-child")).focus();
  3931. });
  3932. }
  3933. function showTask(title, taskId, onDone, onSettled) {
  3934. hasTask = true;
  3935. $("#task-panel").hidden = false;
  3936. $("#task-title").textContent = title;
  3937. $("#task-dot").className = "dot";
  3938. $("#task-log").textContent = "启动中…";
  3939. clearTimeout(pollTimer);
  3940. const poll = async () => {
  3941. let t;
  3942. try {
  3943. t = await api("/api/task_status?task_id=" + encodeURIComponent(taskId));
  3944. } catch (e) {
  3945. $("#task-log").textContent = "状态查询失败";
  3946. if (onSettled) onSettled("error"); // 轮询出错也算结束,让调用方恢复按钮等
  3947. return;
  3948. }
  3949. const log = $("#task-log");
  3950. log.textContent = t.log_tail || "(暂无日志)";
  3951. log.scrollTop = log.scrollHeight;
  3952. if (t.status === "running") {
  3953. pollTimer = setTimeout(poll, 2000);
  3954. return;
  3955. }
  3956. $("#task-dot").className = "dot " + t.status;
  3957. $("#task-title").textContent = title + (t.status === "done" ? " · 完成" : " · 失败");
  3958. if (t.status === "done" && onDone) onDone();
  3959. if (onSettled) onSettled(t.status); // done / failed 都触发
  3960. };
  3961. poll();
  3962. }
  3963. /* ✕ 只隐藏面板,轮询照跑(任务完成后回调依然触发) */
  3964. function hideTask() {
  3965. $("#task-panel").hidden = true;
  3966. }
  3967. function showTaskPanel() {
  3968. if (!hasTask) return toast("本次会话还没有任务日志", "warn");
  3969. $("#task-panel").hidden = false;
  3970. const log = $("#task-log");
  3971. log.scrollTop = log.scrollHeight;
  3972. }
  3973. /* ════ Query 规则组织器 ════ */
  3974. // 扁平维度词表(移植自 query-builder.html DIMS);实质/形式 改为接口下钻,不在此。
  3975. const QR_FLAT = [
  3976. { id: "tool_type", label: "工具类型", items: ["AI", "桌面 APP", "云端 Web", "API·CLI", "插件扩展"] },
  3977. { id: "modality", label: "模态", items: ["图片", "视频"] },
  3978. { id: "suffix", label: "后缀", items: ["怎么做"] },
  3979. ];
  3980. const QR_TREE = [
  3981. { id: "substance", label: "实质", source: "实质" },
  3982. { id: "form", label: "形式", source: "形式" },
  3983. ];
  3984. const qrState = {
  3985. flat: { tool_type: null, modality: null, suffix: null },
  3986. treePath: { substance: [], form: [] }, // 实质/形式 选中 name 路径(仅作 Sonnet 上下文)
  3987. treeData: { substance: null, form: null },
  3988. axisPath: { action: [], type: [] }, // 动作/类型 筛选路径(l1/l2/叶子,来自 matrix,筛表显示)
  3989. matrix: null, // /api/query_matrix
  3990. scores: null, // 最近一次评分结果 cells
  3991. threshold: 7, // 达标 = keep 且 综合分≥此值(可在弹层调)
  3992. lastCost: null,
  3993. };
  3994. function qrChip(label, active, on, cls) {
  3995. const b = document.createElement("button");
  3996. b.className = "chip" + (cls ? " " + cls : "") + (active ? " on" : "");
  3997. b.textContent = label;
  3998. b.onclick = on;
  3999. return b;
  4000. }
  4001. function qrRow(root, labtxt) {
  4002. const row = document.createElement("div");
  4003. row.className = "qr-row";
  4004. row.innerHTML = `<span class="qr-lab">${labtxt}</span>`;
  4005. const wrap = document.createElement("span");
  4006. wrap.className = "qr-chips";
  4007. row.appendChild(wrap);
  4008. root.appendChild(row);
  4009. return wrap;
  4010. }
  4011. // 动作/类型 三级(l1/l2/叶子)取自 matrix items 的 l1/l2/name
  4012. function qrAxisLevelOptions(items, prefix) {
  4013. if (prefix.length === 0) return [...new Set(items.map((x) => x.l1))];
  4014. if (prefix.length === 1) return [...new Set(items.filter((x) => x.l1 === prefix[0]).map((x) => x.l2))];
  4015. return items.filter((x) => x.l1 === prefix[0] && x.l2 === prefix[1]).map((x) => x.name);
  4016. }
  4017. function qrAxisMatch(item, path) {
  4018. if (path[0] && item.l1 !== path[0]) return false;
  4019. if (path[1] && item.l2 !== path[1]) return false;
  4020. if (path[2] && item.name !== path[2]) return false;
  4021. return true;
  4022. }
  4023. function renderQrDims() {
  4024. const root = $("#qr-dims");
  4025. root.innerHTML = "";
  4026. // 扁平维度(工具类型/模态/后缀):拼词上下文
  4027. QR_FLAT.forEach((d) => {
  4028. const wrap = qrRow(root, `· ${d.label}`);
  4029. wrap.appendChild(qrChip("无", qrState.flat[d.id] == null, () => { qrState.flat[d.id] = null; renderQrDims(); renderQrTable(); }));
  4030. d.items.forEach((it) =>
  4031. wrap.appendChild(qrChip(it, qrState.flat[d.id] === it, () => { qrState.flat[d.id] = it; renderQrDims(); renderQrTable(); })));
  4032. });
  4033. // 实质/形式 接口下钻:仅作 Sonnet 上下文,不拼词、不筛表
  4034. QR_TREE.forEach((d) => {
  4035. const path = qrState.treePath[d.id];
  4036. let level = qrState.treeData[d.id] ? qrState.treeData[d.id].tree : [];
  4037. for (let depth = 0; ; depth++) {
  4038. const wrap = qrRow(root, depth === 0 ? `· ${d.label}` : "");
  4039. wrap.appendChild(qrChip("无", path.length === depth, () => { qrState.treePath[d.id] = path.slice(0, depth); renderQrDims(); }));
  4040. (level || []).forEach((node) =>
  4041. wrap.appendChild(qrChip(node.name, path[depth] === node.name,
  4042. () => { qrState.treePath[d.id] = [...path.slice(0, depth), node.name]; renderQrDims(); })));
  4043. const sel = (level || []).find((n) => n.name === path[depth]);
  4044. if (!sel || !(sel.children && sel.children.length)) break;
  4045. level = sel.children;
  4046. }
  4047. });
  4048. // 动作/类型 下钻(来自 matrix l1/l2):筛选表格显示
  4049. if (qrState.matrix) {
  4050. [{ id: "action", label: "动作", items: qrState.matrix.actions },
  4051. { id: "type", label: "类型", items: qrState.matrix.types }].forEach((d) => {
  4052. const path = qrState.axisPath[d.id];
  4053. for (let depth = 0; depth <= 2; depth++) {
  4054. const opts = qrAxisLevelOptions(d.items, path.slice(0, depth));
  4055. if (!opts.length) break;
  4056. const wrap = qrRow(root, depth === 0 ? `· ${d.label}` : "");
  4057. wrap.appendChild(qrChip("无", path.length === depth,
  4058. () => { qrState.axisPath[d.id] = path.slice(0, depth); renderQrDims(); renderQrTable(); }, "axis"));
  4059. opts.forEach((name) =>
  4060. wrap.appendChild(qrChip(name, path[depth] === name,
  4061. () => { qrState.axisPath[d.id] = [...path.slice(0, depth), name]; renderQrDims(); renderQrTable(); }, "axis")));
  4062. if (path[depth] == null) break; // 未选中本层 → 不展开下一层
  4063. }
  4064. });
  4065. }
  4066. }
  4067. async function qrOpen() {
  4068. qrClosePop();
  4069. renderQrDims();
  4070. // 并行拉矩阵 + 两棵分类树(接口挂则该维度降级:提示不可选)
  4071. try { qrState.matrix = qrState.matrix || await api("/api/query_matrix"); }
  4072. catch (e) { return toast("内容树矩阵加载失败", "error"); }
  4073. for (const d of QR_TREE) {
  4074. if (qrState.treeData[d.id]) continue;
  4075. try { qrState.treeData[d.id] = await api("/api/category_tree?source_type=" + encodeURIComponent(d.source)); }
  4076. catch (e) { toast(`${d.label} 接口不可达,该维度暂不可选`, "warn"); }
  4077. }
  4078. renderQrDims();
  4079. renderQrTable();
  4080. }
  4081. // 单格 query = [工具类型] 动作叶 类型叶 [模态] [后缀](与后端 query_score._build_cells 一致)
  4082. function qrCellQuery(action, type) {
  4083. const f = qrState.flat;
  4084. return [f.tool_type, action, type, f.modality, f.suffix].filter((x) => x && x !== "无").join(" ");
  4085. }
  4086. function renderQrTable() {
  4087. const m = qrState.matrix;
  4088. if (!m) return;
  4089. const { actions, types, matrix } = m;
  4090. const sc = qrState.scores; // {"ai_ti":{keep,score,rewrite,...}}
  4091. // 按 动作/类型 筛选路径过滤可见行列(保留原始索引 ai/ti 供评分键 ai_ti)
  4092. const aIdx = actions.map((_, i) => i).filter((i) => qrAxisMatch(actions[i], qrState.axisPath.action));
  4093. const tIdx = types.map((_, i) => i).filter((i) => qrAxisMatch(types[i], qrState.axisPath.type));
  4094. let html = '<table class="qr-tab"><thead>';
  4095. html += '<tr><th class="qr-corner" rowspan="2">类型 \\ 动作</th>';
  4096. const groups = [];
  4097. aIdx.forEach((ai) => {
  4098. const l1 = actions[ai].l1;
  4099. const last = groups[groups.length - 1];
  4100. if (last && last.l1 === l1) last.span++;
  4101. else groups.push({ l1, span: 1 });
  4102. });
  4103. groups.forEach((g) => { html += `<th colspan="${g.span}" class="qr-gh">${g.l1}</th>`; });
  4104. html += "</tr><tr>";
  4105. aIdx.forEach((ai) => { html += `<th class="qr-ah">${actions[ai].name}</th>`; });
  4106. html += "</tr></thead><tbody>";
  4107. let curL1 = null;
  4108. tIdx.forEach((ti) => {
  4109. const t = types[ti];
  4110. if (t.l1 !== curL1) {
  4111. curL1 = t.l1;
  4112. html += `<tr><td class="qr-tl1" colspan="${aIdx.length + 1}">${t.l1}</td></tr>`;
  4113. }
  4114. html += `<tr><th class="qr-th">${t.name}</th>`;
  4115. aIdx.forEach((ai) => {
  4116. const tier = (matrix[ai][ti] || {}).tier || 0;
  4117. const q = qrCellQuery(actions[ai].name, t.name);
  4118. const v = sc ? sc[`${ai}_${ti}`] : null;
  4119. const keep = qrKeep(v);
  4120. const cls = `qr-c t${tier}` + (tier === 0 ? " dead" : "") + (keep ? " keep" : "");
  4121. const badge = keep && v.score != null ? `<i class="qr-bd">${v.score}</i>` : "";
  4122. html += `<td class="${cls}" data-ai="${ai}" data-ti="${ti}">${q}${badge}</td>`;
  4123. });
  4124. html += "</tr>";
  4125. });
  4126. html += "</tbody></table>";
  4127. $("#qr-table-wrap").innerHTML = html;
  4128. }
  4129. function qrSelBody() {
  4130. return {
  4131. tool_type: qrState.flat.tool_type || "",
  4132. modality: qrState.flat.modality || "",
  4133. suffix: qrState.flat.suffix || "",
  4134. substance_path: qrState.treePath.substance,
  4135. form_path: qrState.treePath.form,
  4136. };
  4137. }
  4138. async function qrLoadScores(sel) {
  4139. const r = await api("/api/query_score?sel=" + encodeURIComponent(sel));
  4140. if (r && r.pending) return false;
  4141. qrState.scores = r.cells || {};
  4142. qrState.lastCost = r.cost_usd;
  4143. renderQrTable();
  4144. qrRefreshKeep();
  4145. return true;
  4146. }
  4147. // 达标 = Sonnet keep 且 综合分≥阈值;高亮/计数/搜全部达标 统一口径
  4148. function qrKeep(v) { return !!(v && v.keep && v.score != null && v.score >= qrState.threshold); }
  4149. function qrRefreshKeep() {
  4150. if (!qrState.scores) return;
  4151. const k = Object.values(qrState.scores).filter(qrKeep).length;
  4152. $("#qr-hint").textContent = `达标(keep 且 ≥${qrState.threshold}):${k} 格`
  4153. + (qrState.lastCost != null ? ` · 评分 $${qrState.lastCost}` : "");
  4154. $("#qr-search-all").hidden = k === 0;
  4155. }
  4156. $("#qr-thr").addEventListener("input", () => {
  4157. const x = parseFloat($("#qr-thr").value);
  4158. qrState.threshold = isNaN(x) ? 0 : x;
  4159. if (qrState.scores) { qrClosePop(); renderQrTable(); qrRefreshKeep(); }
  4160. });
  4161. $("#qr-score").onclick = async () => {
  4162. const btn = $("#qr-score");
  4163. if (btn.disabled) return; // 评分进行中:防重复点击(避免重复起任务/花钱)
  4164. const orig = btn.textContent;
  4165. btn.disabled = true; btn.textContent = "评估中…";
  4166. const restore = () => { btn.disabled = false; btn.textContent = orig; };
  4167. renderQrTable(); // 先按当前 chips 刷新拼词
  4168. $("#qr-hint").textContent = "提交评分…";
  4169. let r;
  4170. try { r = await api("/api/query_score", { method: "POST", body: JSON.stringify(qrSelBody()) }); }
  4171. catch (e) { toast("评分启动失败:" + (e.body?.error || e.status), "error"); return restore(); }
  4172. if (r.cached) { try { await qrLoadScores(r.sel); } finally { restore(); } return; }
  4173. // 后台任务:完成→载入结果;成功/失败/查询出错 都恢复按钮(onSettled)
  4174. showTask("Query 评分 · 643 格", r.task_id,
  4175. async () => { await qrLoadScores(r.sel); },
  4176. (status) => { if (status !== "done") toast("评分任务" + (status === "failed" ? "失败" : "状态异常") + ",可重试", "warn"); restore(); });
  4177. };
  4178. async function qrRunSearch(query, label) {
  4179. const body = { query, platforms: "xhs,gzh", max_count: 20 }; // 用改写词搜索,方向无关
  4180. if (label && label !== query) body.query_text = label; // query 列表存原始组合词
  4181. const r = await api("/api/run_search", { method: "POST", body: JSON.stringify(body) });
  4182. return r; // {task_id, query_id}
  4183. }
  4184. // 点高亮格 → 气泡显示评分/理由 + 发起搜索/复制(不再用浏览器原生 confirm)
  4185. function qrClosePop() { $("#qr-pop").hidden = true; }
  4186. function qrShowPop(td, v) {
  4187. const pop = $("#qr-pop");
  4188. const query = v.rewrite || v.query;
  4189. const orig = v.rewrite && v.rewrite !== v.query ? `<div class="orig">原: ${v.query}</div>` : "";
  4190. const tier = td.classList.contains("t3") ? 3 : td.classList.contains("t2") ? 2 : td.classList.contains("t1") ? 1 : 0;
  4191. pop.innerHTML =
  4192. `<div class="q">${query}</div>${orig}` +
  4193. `<div class="sc"><b>${v.score ?? "?"}</b><span class="dim">综合分 = 人话 ${v.natural ?? "?"}×.4 + 可搜 ${v.findable ?? "?"}×.3 + 价值 ${v.useful ?? "?"}×.3</span></div>` +
  4194. `<div class="dim" style="margin:0 0 7px">内容树 tier ${tier}(人工预判可检索度,仅参考,不计入综合分)</div>` +
  4195. `<div class="rsn">${v.reason || "(无理由)"}</div>` +
  4196. `<div class="acts"><button class="btn seal" id="qr-pop-go">发起搜索</button><button class="btn" id="qr-pop-copy">复制</button></div>`;
  4197. pop.hidden = false;
  4198. const r = td.getBoundingClientRect(), pw = 300, ph = pop.offsetHeight || 150;
  4199. let left = r.left, top = r.bottom + 6;
  4200. if (left + pw > window.innerWidth - 10) left = window.innerWidth - pw - 10;
  4201. if (top + ph > window.innerHeight - 10) top = r.top - ph - 6;
  4202. pop.style.left = Math.max(10, left) + "px";
  4203. pop.style.top = Math.max(10, top) + "px";
  4204. $("#qr-pop-go").onclick = async () => {
  4205. qrClosePop();
  4206. try { const rr = await qrRunSearch(query, v.query); showTask(`搜索 · ${rr.query_id} ${query}`, rr.task_id, null); }
  4207. catch (err) { toast("搜索启动失败:" + (err.body?.error || err.status), "error"); }
  4208. };
  4209. $("#qr-pop-copy").onclick = () => { navigator.clipboard && navigator.clipboard.writeText(query); toast("已复制", "info", 1200); };
  4210. }
  4211. $("#qr-table-wrap").onclick = (e) => {
  4212. const td = e.target.closest("td.qr-c.keep");
  4213. if (!td) return;
  4214. const v = qrState.scores && qrState.scores[`${td.dataset.ai}_${td.dataset.ti}`];
  4215. if (v) qrShowPop(td, v);
  4216. };
  4217. // 点气泡外/表格空白处 关闭气泡
  4218. $("#qr-modal").addEventListener("click", (e) => {
  4219. if (!e.target.closest("#qr-pop") && !e.target.closest("td.qr-c.keep")) qrClosePop();
  4220. });
  4221. // 搜全部达标:逐格起任务(朴素循环,失败不阻断)
  4222. // 批量进度面板:任务面板里列出每个搜索的实时状态(轮询各 task_id)
  4223. function showQrBatch(items) {
  4224. hasTask = true;
  4225. $("#task-panel").hidden = false;
  4226. $("#task-title").textContent = `搜全部达标 · ${items.length} 个`;
  4227. $("#task-dot").className = "dot";
  4228. clearTimeout(pollTimer);
  4229. const st = {};
  4230. const poll = async () => {
  4231. await Promise.all(items.map(async (it) => {
  4232. if (st[it.task_id] && st[it.task_id] !== "running") return;
  4233. try { const t = await api("/api/task_status?task_id=" + encodeURIComponent(it.task_id)); st[it.task_id] = t.status; }
  4234. catch (e) { st[it.task_id] = st[it.task_id] || "running"; }
  4235. }));
  4236. const done = items.filter((it) => st[it.task_id] && st[it.task_id] !== "running").length;
  4237. $("#task-title").textContent = `搜全部达标 · ${done}/${items.length} 完成`;
  4238. $("#task-log").textContent = items.map((it) => {
  4239. const s = st[it.task_id] || "running";
  4240. return `${s === "done" ? "✅" : s === "failed" ? "❌" : "⏳"} ${it.query_id} ${it.query}`;
  4241. }).join("\n");
  4242. if (done < items.length) pollTimer = setTimeout(poll, 2000);
  4243. else $("#task-dot").className = "dot done";
  4244. };
  4245. poll();
  4246. }
  4247. $("#qr-search-all").onclick = async () => {
  4248. const keeps = Object.entries(qrState.scores || {}).filter(([, v]) => qrKeep(v));
  4249. if (!keeps.length) return;
  4250. if (!(await uiConfirm(`将对 ${keeps.length} 个达标 query 各起一次搜索(小红书+公众号 各20),确认?`))) return;
  4251. qrClosePop();
  4252. const items = [];
  4253. for (const [, v] of keeps) {
  4254. const q = v.rewrite || v.query;
  4255. try { const r = await qrRunSearch(q, v.query); if (r.task_id) items.push({ query: q, query_id: r.query_id, task_id: r.task_id }); }
  4256. catch (e) { /* 单格失败不阻断 */ }
  4257. }
  4258. if (!items.length) return toast("全部发起失败", "error");
  4259. toast(`已发起 ${items.length}/${keeps.length} 个搜索`, "info");
  4260. showQrBatch(items);
  4261. };
  4262. /* ════ 新建搜索 ════ */
  4263. /* 渠道下拉多选(选项同 search_eval:小红书/知乎/公众号/抖音/视频号/YouTube) */
  4264. const CHANNELS = [
  4265. { key: "xhs", name: "小红书", on: true },
  4266. { key: "zhihu", name: "知乎", on: true },
  4267. { key: "gzh", name: "公众号" },
  4268. { key: "douyin", name: "抖音" },
  4269. { key: "sph", name: "视频号" },
  4270. { key: "youtube", name: "YouTube" },
  4271. ];
  4272. $("#s-plat-panel").innerHTML = CHANNELS.map(
  4273. (c) => `
  4274. <label class="dd-opt ${c.on ? "sel" : ""}">
  4275. <input type="checkbox" value="${c.key}" ${c.on ? "checked" : ""}>${c.name}
  4276. </label>`,
  4277. ).join("");
  4278. function selectedPlatforms() {
  4279. return [...document.querySelectorAll("#s-plat-panel input:checked")].map((x) => x.value);
  4280. }
  4281. function syncPlatBtn() {
  4282. const names = [...document.querySelectorAll("#s-plat-panel input:checked")].map(
  4283. (x) => CHANNELS.find((c) => c.key === x.value).name,
  4284. );
  4285. $("#s-plat-btn").innerHTML =
  4286. `<span>${names.length ? esc(names.join("、")) : "选择渠道"}</span><span class="dd-arrow">▾</span>`;
  4287. }
  4288. $("#s-plat-btn").onclick = (e) => {
  4289. e.stopPropagation();
  4290. $("#s-plat-panel").hidden = !$("#s-plat-panel").hidden;
  4291. };
  4292. $("#s-plat-panel").onclick = (e) => e.stopPropagation();
  4293. $("#s-plat-panel").addEventListener("change", (e) => {
  4294. e.target.closest(".dd-opt").classList.toggle("sel", e.target.checked);
  4295. syncPlatBtn();
  4296. });
  4297. document.addEventListener("click", () => {
  4298. $("#s-plat-panel").hidden = true;
  4299. });
  4300. syncPlatBtn();
  4301. $("#btn-new-search").onclick = () => {
  4302. $("#s-mode").value = state.mode === "process" ? "工序" : "工具"; // 默认跟随当前子模式
  4303. $("#search-modal").hidden = false;
  4304. $("#s-query").focus();
  4305. };
  4306. $("#search-modal").onclick = (e) => {
  4307. if (e.target === $("#search-modal")) $("#search-modal").hidden = true;
  4308. };
  4309. $("#s-go").onclick = async () => {
  4310. const query = $("#s-query").value.trim();
  4311. if (!query) return toast("请填写 query", "warn");
  4312. const plats = selectedPlatforms();
  4313. if (!plats.length) return toast("请至少选择一个检索渠道", "warn");
  4314. const body = {
  4315. query,
  4316. synonyms: $("#s-syn").value.trim(),
  4317. mode_type: $("#s-mode").value,
  4318. platforms: plats.join(","),
  4319. max_count: parseInt($("#s-max").value) || 10,
  4320. };
  4321. try {
  4322. const r = await api("/api/run_search", { method: "POST", body: JSON.stringify(body) });
  4323. $("#search-modal").hidden = true;
  4324. showTask(`搜索 · ${r.query_id} ${query}`, r.task_id, async () => {
  4325. /* 搜索结果落在 s-mode 对应的表,完成后切到对应子模式再选中 */
  4326. const m = body.mode_type === "工具" ? "tools" : "process";
  4327. if (state.mode !== m) {
  4328. state.mode = m;
  4329. $("#m-process").classList.toggle("on", m === "process");
  4330. $("#m-tools").classList.toggle("on", m === "tools");
  4331. }
  4332. await loadQueries();
  4333. selectQuery(r.query_id);
  4334. });
  4335. } catch (e) {
  4336. toast("搜索启动失败:" + (e.body?.error || e.status), "error");
  4337. }
  4338. };
  4339. /* ════ 工序/工具子模式 ════ */
  4340. $("#m-process").onclick = () => setMode("process");
  4341. $("#m-tools").onclick = () => setMode("tools");
  4342. function setMode(m) {
  4343. if (state.mode === m) return;
  4344. state.mode = m;
  4345. state.version = null;
  4346. /* 工序/工具是两张独立搜索表,切换时整体重置三栏 */
  4347. state.queryId = null;
  4348. state.caseId = null;
  4349. state.post = null;
  4350. state.posts = [];
  4351. state.selected.clear();
  4352. state.platFilter = "all";
  4353. $("#m-process").classList.toggle("on", m === "process");
  4354. $("#m-tools").classList.toggle("on", m === "tools");
  4355. $("#plat-tabs").hidden = true;
  4356. $("#p-count").textContent = "";
  4357. $("#post-list").innerHTML = '<div class="empty"><span class="glyph">←</span>先选择左侧 query</div>';
  4358. renderExtractEmpty();
  4359. loadQueries();
  4360. }
  4361. $("#btn-query-rule").onclick = () => { $("#qr-modal").hidden = false; qrOpen(); };
  4362. $("#qr-close").onclick = () => { $("#qr-modal").hidden = true; };
  4363. $("#qr-modal").onclick = (e) => { if (e.target === $("#qr-modal")) $("#qr-modal").hidden = true; };
  4364. window.addEventListener("resize", () => chartRefs.forEach((c) => c.resize()));
  4365. route();
  4366. </script>
  4367. </body>
  4368. </html>