learn.html
22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
{% extends "base.html" %}
{% block title %}学习管线 - WeChat Viewer{% endblock %}
{% block body %}
<style>
body{overflow-y:auto!important;height:auto!important;}
.learn-container{max-width:1000px;margin:0 auto;padding:16px;}
.learn-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px;flex-wrap:wrap;gap:8px;}
.learn-header h1{font-size:20px;color:#2c3e50;}
/* Pipeline flow */
.pipeline{display:flex;align-items:center;gap:6px;margin-bottom:16px;flex-wrap:wrap;font-size:12px;}
.pipe-step{background:white;padding:8px 12px;border-radius:8px;text-align:center;min-width:70px;box-shadow:0 1px 2px rgba(0,0,0,0.05);cursor:pointer;transition:.15s;border:2px solid transparent;}
.pipe-step:hover{border-color:#3498db;}
.pipe-step .n{font-size:18px;font-weight:bold;}
.pipe-step .l{font-size:10px;color:#999;}
.pipe-step.s1 .n{color:#9b59b6}.pipe-step.s2 .n{color:#f39c12}
.pipe-step.s3 .n{color:#e67e22}.pipe-step.s4 .n{color:#27ae60}
.pipe-step.s5 .n{color:#8e44ad}.pipe-step.s6 .n{color:#e74c3c}
.pipe-arrow{color:#ccc;font-size:14px;}
/* Tabs */
.tabs{display:flex;gap:4px;margin-bottom:10px;flex-wrap:wrap;}
.tab{padding:6px 12px;border-radius:6px;cursor:pointer;font-size:12px;border:1px solid #ddd;background:white;color:#666;}
.tab.active{background:#2c3e50;color:white;border-color:#2c3e50;}
.tab .count{font-size:10px;margin-left:4px;opacity:.7;}
/* Date filter */
.date-bar{display:flex;align-items:center;gap:8px;margin-bottom:12px;font-size:12px;flex-wrap:wrap;}
.date-bar input[type=date]{border:1px solid #cfd8e3;border-radius:6px;padding:5px 8px;font-size:12px;}
.date-bar .btn-sm{padding:4px 10px;border:1px solid #ddd;border-radius:6px;background:white;cursor:pointer;font-size:11px;color:#555;}
.date-bar .btn-sm.active{background:#2c3e50;color:white;border-color:#2c3e50;}
.date-bar .btn-sm:hover{border-color:#3498db;}
.date-bar .filtered-count{color:#888;font-size:11px;}
/* Cards */
.card{background:white;border-radius:8px;padding:12px 16px;margin-bottom:8px;box-shadow:0 1px 2px rgba(0,0,0,0.04);}
.card.skill{border-left:3px solid #1e8449}.card.memory{border-left:3px solid #1a5276}
.card.reference{border-left:3px solid #6c3483}.card.todo{border-left:3px solid #b9770e}
.card.failed{border-left-color:#e74c3c;opacity:.85;}
.card .row{display:flex;align-items:center;gap:8px;margin-bottom:6px;flex-wrap:wrap;}
.card .title{font-size:13px;font-weight:600;flex:1;min-width:120px;}
.card .meta{font-size:11px;color:#888;}
.card .content{font-size:12px;color:#555;line-height:1.5;white-space:pre-wrap;max-height:60px;overflow:hidden;}
.card .content.open{max-height:none;}
.card .expand{font-size:10px;color:#3498db;cursor:pointer;margin-top:4px;}
.card .actions{margin-top:8px;display:flex;gap:6px;}
.badge{font-size:9px;padding:2px 7px;border-radius:8px;font-weight:600;white-space:nowrap;}
.badge.skill{background:#d5f5e3;color:#1e8449}.badge.memory{background:#d6eaf8;color:#1a5276}
.badge.reference{background:#e8daef;color:#6c3483}.badge.todo{background:#fdebd0;color:#b9770e}
.badge.high{background:#fadbd8;color:#922b21}.badge.medium{background:#fef9e7;color:#7d6608}.badge.low{background:#f2f3f4;color:#999}
.badge.auto{background:#e8daef;color:#6c3483}
.badge.score{font-weight:bold;font-size:11px;}
.badge.time{background:#f0f0f0;color:#888;}
.btn{padding:5px 12px;border:none;border-radius:5px;cursor:pointer;font-size:12px;color:white;}
.btn.green{background:#27ae60}.btn.green:hover{background:#219a52}
.btn.red{background:#e74c3c}.btn.red:hover{background:#c0392b}
.btn.orange{background:#f39c12}.btn.orange:hover{background:#d68910}
.btn.purple{background:#9b59b6}.btn.purple:hover{background:#8e44ad}
.btn:disabled{opacity:.5;cursor:not-allowed}
.empty-state{text-align:center;padding:40px 20px;color:#999;}
.loading{text-align:center;padding:30px;color:#999;}
.result-detail{font-size:11px;color:#888;margin-top:6px;line-height:1.6;}
.result-detail b{color:#555;}
.fb-box{border-top:1px solid #eee;margin-top:8px;padding-top:6px;}
.fb-input{width:100%;padding:5px 8px;border:1px solid #ddd;border-radius:4px;font-size:11px;box-sizing:border-box;}
.fb-btn{background:#3498db;color:white;border:none;padding:3px 8px;border-radius:4px;cursor:pointer;font-size:10px;margin-top:3px;}
.fb-done{font-size:10px;color:#8e44ad;padding:3px 6px;background:#f4ecf7;border-radius:4px;}
</style>
<div class="learn-container">
<div class="learn-header">
<h1>📚 学习管线</h1>
<div style="display:flex;gap:6px;">
<button class="btn purple" id="btnClassify" onclick="runClassify()">🤖 运行分类器</button>
<button class="btn" style="background:#7f8c8d;color:white;" onclick="refresh()">🔄 刷新</button>
</div>
</div>
<!-- Pipeline flow -->
<div class="pipeline" id="pipeline"></div>
<!-- Tabs -->
<div class="tabs" id="tabs">
<div class="tab active" data-tab="articles">📰 文章列表<span class="count"></span></div>
<div class="tab" data-tab="pending_review">待审核<span class="count"></span></div>
<div class="tab" data-tab="pending_learn">待学习<span class="count"></span></div>
<div class="tab" data-tab="applied">已吸收<span class="count"></span></div>
<div class="tab" data-tab="results">学习报告<span class="count"></span></div>
<div class="tab" data-tab="failed">失败<span class="count"></span></div>
</div>
<!-- Date filter -->
<div class="date-bar" id="dateBar">
<span style="color:#999;">📅</span>
<input type="date" id="dateFrom" onchange="applyDateFilter()" style="width:130px;">
<span style="color:#999;">至</span>
<input type="date" id="dateTo" onchange="applyDateFilter()" style="width:130px;">
<button class="btn-sm active" data-range="all" onclick="setDateRange('all')">全部</button>
<button class="btn-sm" data-range="today" onclick="setDateRange('today')">今天</button>
<button class="btn-sm" data-range="7d" onclick="setDateRange('7d')">近7天</button>
<button class="btn-sm" data-range="30d" onclick="setDateRange('30d')">近30天</button>
<input type="text" id="searchInput" placeholder="搜索文章标题..." oninput="renderContent()" style="padding:5px 10px;border:1px solid #cfd8e3;border-radius:6px;font-size:12px;min-width:140px;">
<select id="dateFilter" onchange="applyDateFilter()" style="padding:5px 10px;border:1px solid #cfd8e3;border-radius:6px;font-size:12px;background:white;cursor:pointer;min-width:120px;">
<option value="">全部日期</option>
<option value="today">今天</option>
<option value="7d">近7天</option>
<option value="30d">近30天</option>
</select>
<select id="sortBy" onchange="renderContent()" style="padding:5px 10px;border:1px solid #cfd8e3;border-radius:6px;font-size:12px;background:white;cursor:pointer;">
<option value="score">按评分↓</option>
<option value="time">按时间↓</option>
<option value="title">按标题</option>
</select>
<span class="filtered-count" id="filteredCount"></span>
</div>
<div id="content"></div>
</div>
<script>
var TAB = 'articles';
var stats = {};
var dateFrom = null;
var dateTo = null;
var allData = []; // cached full dataset for client-side filtering
function esc(s){return String(s||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');}
var TN={skill:'🛠 Skill',memory:'🧠 记忆',todo:'📋 待办',reference:'📖 参考'};
var CN={high:'高',medium:'中',low:'低'};
function fmtDate(d){if(!d)return'-'; return d.substring(0,16);}
function fmtDateShort(d){if(!d)return'-'; return d.substring(5,16);}
function setDateRange(range){
document.querySelectorAll('.btn-sm[data-range]').forEach(function(b){b.classList.remove('active');});
document.querySelector('.btn-sm[data-range='+range+']').classList.add('active');
var now=new Date();
if(range==='all'){dateFrom=null;dateTo=null;}
else if(range==='today'){var s=now.toISOString().substring(0,10); dateFrom=s; dateTo=s;}
else{var d=new Date(now.getTime()-(parseInt(range)*24*3600*1000)); dateFrom=d.toISOString().substring(0,10); dateTo=now.toISOString().substring(0,10);}
document.getElementById('dateFrom').value=dateFrom||'';
document.getElementById('dateTo').value=dateTo||'';
applyDateFilter();
}
function applyDateFilter(){
var fv=document.getElementById('dateFrom').value;
var tv=document.getElementById('dateTo').value;
dateFrom=fv||null;
dateTo=tv||null;
var df = document.getElementById('dateFilter').value;
if (df) { setDateRange(df); return; }
// highlight active range button if matches
document.querySelectorAll('.btn-sm[data-range]').forEach(function(b){b.classList.remove('active');});
if(!dateFrom&&!dateTo) document.querySelector('.btn-sm[data-range=all]').classList.add('active');
renderContent();
}
function filterByDate(data){
if(!dateFrom&&!dateTo) return data;
// use reviewed_at if available, else created_at
return data.filter(function(d){
var t=d.reviewed_at||d.created_at||'';
if(!t) return false;
var day=t.substring(0,10);
if(dateFrom&&day<dateFrom) return false;
if(dateTo&&day>dateTo) return false;
return true;
});
}
function refresh(){loadStats().then(function(){loadContent();});}
function loadStats(){
return fetch('/api/learn/stats').then(function(r){return r.json()}).then(function(j){
if(!j.ok)return;
stats = j.data;
renderPipeline();
renderTabs();
});
}
function renderPipeline(){
var s=stats;
var h='';
h+='<div style="display:flex;align-items:center;gap:8px;margin-bottom:6px;flex-wrap:wrap;font-size:12px;">';
h+=pipeStep('s1','未分类',s.unclassified||0);
h+='<span style="color:#999;font-size:11px;">→ 分类器 →</span>';
h+=pipeStep('s2','≥7 待学习',s.pending_learn||0)+arrow();
h+=pipeStep('s4','已吸收',s.applied||0)+arrow();
h+=pipeStep('s5','学习报告',s.results_count||0);
h+=arrow()+pipeStep('s6','失败',s.failed||0);
h+='</div>';
h+='<div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;font-size:12px;">';
h+='<span style="display:inline-block;width:68px;"></span>';
h+='<span style="color:#999;font-size:11px;">↘ 4-6</span>';
h+=pipeStep('s3','待审核',s.pending||0);
h+='<span style="color:#999;font-size:10px;">(人工审批)</span>';
h+='</div>';
document.getElementById('pipeline').innerHTML=h;
}
function pipeStep(cls,label,n){
return '<div class="pipe-step '+cls+'" onclick="switchTab(\''+(label==='待审核'?'pending_review':label==='待学习'?'pending_learn':label==='已吸收'?'applied':label==='学习报告'?'results':'failed')+'\')"><div class="n">'+n+'</div><div class="l">'+label+'</div></div>';
}
function arrow(){return '<span class="pipe-arrow">→</span>';}
function renderTabs(){
var s=stats;
var counts={articles:(s.unclassified||0)+(s.pending||0)+(s.pending_learn||0)+(s.applied||0)+(s.failed||0)+(s.rejected||0), pending_review:s.pending||0, pending_learn:s.pending_learn||0, applied:s.applied||0, results:s.results_count||0, failed:s.failed||0};
document.querySelectorAll('.tab').forEach(function(t){
var key=t.getAttribute('data-tab');
var c=t.querySelector('.count');
if(c)c.textContent=counts[key]?'('+counts[key]+')':'';
t.classList.toggle('active',key===TAB);
});
}
function switchTab(tab){
TAB=tab;
renderTabs();
loadContent();
}
function loadContent(){
allData=[];
var el=document.getElementById('content');
el.innerHTML='<div class="loading">加载中...</div>';
if(TAB==='articles'){ loadArticles(el); }
else if(TAB==='results'){ loadResults(el); }
else{ loadQueue(el,TAB); }
}
function renderContent(){
// re-render with current filter
var q = (document.getElementById('searchInput').value || '').trim().toLowerCase();
var sb = document.getElementById('sortBy').value;
if (q) {
allData = allData.filter(function(d){
return ((d.title || '') + ' ' + (d.result_summary || '') + ' ' + (d.error_msg || '')).toLowerCase().indexOf(q) >= 0;
});
}
if (sb === 'title') allData.sort(function(a,b){return (a.title||'').localeCompare(b.title||'')});
else if (sb === 'time') allData.sort(function(a,b){return (b.created_at||'').localeCompare(a.created_at||'')});
else allData.sort(function(a,b){return (b.score||0)-(a.score||0)});
if(TAB==='articles'){ loadArticles(document.getElementById('content'), allData); }
else if(TAB==='results'){ loadResults(document.getElementById('content'), allData); }
else{ renderQueueCards(allData); }
}
function loadArticles(el, cached){
if(cached&&cached.length){ renderArticlesTable(cached,el); return; }
fetch('/api/learn/articles').then(function(r){return r.json()}).then(function(j){
if(!j.ok||!j.data.length){el.innerHTML='<div class="empty-state"><p>暂无文章</p><small>运行分类器后出现</small></div>';return;}
allData=j.data;
renderArticlesTable(allData,el);
}).catch(function(e){el.innerHTML='<div class="empty-state">加载失败: '+e.message+'</div>';});
}
function renderArticlesTable(data,el){
var filtered=filterByDate(data);
document.getElementById('filteredCount').textContent=filtered.length!==data.length?'筛选 '+filtered.length+'/'+data.length+' 篇':'';
if(!filtered.length){el.innerHTML='<div class="empty-state">该时间范围内无数据</div>';return;}
var h='<div style="font-size:11px;color:#999;margin-bottom:10px;">共 '+filtered.length+' 篇,按评分↓</div>';
h+='<table style="width:100%;border-collapse:collapse;font-size:12px;">';
h+='<thead><tr style="background:#f8f9fa;text-align:left;">';
h+='<th style="padding:8px;border-bottom:2px solid #ddd;">评分</th>';
h+='<th style="padding:8px;border-bottom:2px solid #ddd;">文章</th>';
h+='<th style="padding:8px;border-bottom:2px solid #ddd;">类型</th>';
h+='<th style="padding:8px;border-bottom:2px solid #ddd;">状态</th>';
h+='<th style="padding:8px;border-bottom:2px solid #ddd;">吸收时间</th>';
h+='<th style="padding:8px;border-bottom:2px solid #ddd;">结果</th>';
h+='</tr></thead><tbody>';
for(var i=0;i<filtered.length;i++){
var t=filtered[i];
var sc=t.score||0;
var scColor=sc>=7?'#27ae60':sc>=4?'#f39c12':'#95a5a6';
var stLabel={'pending_review':'待审核','pending_learn':'待学习','applied':'已吸收','approved':'已通过','failed':'失败','rejected':'已拒绝'};
var st=t.status||'?';
var stColor=st==='applied'?'#27ae60':st==='failed'?'#e74c3c':st==='pending_learn'?'#f39c12':'#666';
var result=t.result_summary||t.error_msg||'';
if(t.created_skill)result='🛠 '+esc(t.created_skill);
var time=t.status==='applied'?(t.reviewed_at||t.created_at||''):(t.created_at||'');
h+='<tr onclick="location=\'/learn/'+t.id+'\'" style="cursor:pointer;border-bottom:1px solid #eee;'+(i%2?'background:#fafafa':'')+'">';
h+='<td style="padding:8px;font-weight:bold;color:'+scColor+';white-space:nowrap;">⭐'+sc+'</td>';
h+='<td style="padding:8px;">'+esc((t.title||'?').substring(0,60))+'</td>';
h+='<td style="padding:8px;white-space:nowrap;">'+esc({skill:'Skill',memory:'记忆',reference:'参考',todo:'待办'}[t.learn_type]||t.learn_type||'')+'</td>';
h+='<td style="padding:8px;color:'+stColor+';font-weight:600;white-space:nowrap;">'+(stLabel[st]||st)+'</td>';
h+='<td style="padding:8px;font-size:11px;color:#888;white-space:nowrap;">'+fmtDateShort(time)+'</td>';
h+='<td style="padding:8px;font-size:11px;color:#888;">'+(result?esc(result).substring(0,40):'-')+'</td>';
h+='</tr>';
}
h+='</tbody></table>';
el.innerHTML=h;
}
function loadQueue(el,status){
fetch('/api/learn-queue?status='+status).then(function(r){return r.json()}).then(function(j){
if(!j.ok||!j.data.length){el.innerHTML='<div class="empty-state">暂无数据</div>';return;}
allData=j.data.slice().sort(function(a,b){return(b.score||0)-(a.score||0);});
renderQueueCards(allData);
}).catch(function(e){el.innerHTML='<div class="empty-state">加载失败: '+e.message+'</div>';});
}
function renderQueueCards(data){
var filtered=filterByDate(data);
document.getElementById('filteredCount').textContent=filtered.length!==data.length?'筛选 '+filtered.length+'/'+data.length+' 篇':'';
var el=document.getElementById('content');
if(!filtered.length){el.innerHTML='<div class="empty-state">该时间范围内无数据</div>';return;}
var h='';
for(var i=0;i<filtered.length;i++){
var t=filtered[i];
var typeCls=t.learn_type||'';
var failedCls=t.status==='failed'?' failed':'';
var scoreColor=t.score>=7?'#27ae60':t.score>=4?'#f39c12':'#95a5a6';
var time=t.status==='applied'?(t.reviewed_at||t.created_at||''):(t.created_at||'');
h+='<div class="card '+typeCls+failedCls+'" onclick="location=\'/learn/'+t.id+'\'" style="cursor:pointer;">';
h+='<div class="row">';
h+='<span class="badge '+typeCls+'">'+(TN[typeCls]||typeCls)+'</span>';
if(t.score)h+='<span class="badge score" style="color:'+scoreColor+'">⭐'+t.score+'</span>';
h+='<span class="badge '+t.confidence+'">'+(CN[t.confidence]||t.confidence)+'</span>';
h+='<span class="title">'+esc(t.title||'未命名')+'</span>';
if(t.status==='applied')h+='<span style="font-size:10px;color:#27ae60;">✓</span>';
if(t.status==='failed')h+='<span style="font-size:10px;color:#e74c3c;">❌</span>';
h+='<span class="badge time">'+fmtDateShort(time)+'</span>';
h+='</div>';
if(t.learn_target)h+='<div class="meta">目标: '+esc(t.learn_target)+'</div>';
if(t.learn_content){
var cid='q'+i; var txt=String(t.learn_content);
h+='<div class="content" id="'+cid+'">'+esc(txt.substring(0,200))+'</div>';
if(txt.length>200)h+='<div class="expand" data-cid="'+cid+'" data-full="'+esc(txt)+'" onclick="toggleCard(this)">▶ 展开</div>';
}
if(t.error_msg)h+='<div style="font-size:10px;color:#e74c3c;margin-top:4px;">'+esc(t.error_msg)+'</div>';
if(t.status==='pending_review'||t.status==='pending_learn'){
h+='<div class="actions" onclick="event.stopPropagation();">';
h+='<button class="btn green" onclick="approve('+t.id+')">✅ 吸收</button>';
h+='<button class="btn orange" onclick="reject('+t.id+')">🗑 跳过</button>';
h+='</div>';
}
if(t.status==='failed'){
h+='<div class="actions" onclick="event.stopPropagation();">';
h+='<button class="btn orange" onclick="retry('+t.id+')">🔄 重试</button>';
h+='</div>';
}
h+='</div>';
}
el.innerHTML=h;
}
function loadResults(el, cached){
if(cached&&cached.length){ renderResultsCards(cached,el); return; }
fetch('/api/learn-results').then(function(r){return r.json()}).then(function(j){
if(!j.ok||!j.data.length){el.innerHTML='<div class="empty-state"><p>暂无学习报告</p><small>吸收完成后自动生成</small></div>';return;}
allData=j.data;
renderResultsCards(allData,el);
}).catch(function(e){el.innerHTML='<div class="empty-state">加载失败: '+e.message+'</div>';});
}
function renderResultsCards(data,el){
var filtered=filterByDate(data);
document.getElementById('filteredCount').textContent=filtered.length!==data.length?'筛选 '+filtered.length+'/'+data.length+' 篇':'';
if(!filtered.length){el.innerHTML='<div class="empty-state">该时间范围内无数据</div>';return;}
var h='';
for(var i=0;i<filtered.length;i++){
var t=filtered[i];
h+='<div class="card '+t.result_type+'" onclick="location=\'/learn/'+(t.learn_queue_id||t.id)+'\'" style="cursor:pointer;">';
h+='<div class="row">';
h+='<span class="badge '+t.result_type+'">'+(TN[t.result_type]||t.result_type)+'</span>';
if(t.auto_applied)h+='<span class="badge auto">🤖 自动</span>';
h+='<span class="title">'+esc(t.article_title||'未命名')+'</span>';
h+='<span style="font-size:10px;color:#999;">'+fmtDate(t.created_at)+'</span>';
h+='</div>';
if(t.result_summary)h+='<div class="content">'+esc(t.result_summary).substring(0,300)+'</div>';
h+='<div class="result-detail">';
if(t.created_skill)h+='<div>🛠 创建 skill: <b>'+esc(t.created_skill)+'</b></div>';
if(t.updated_skill)h+='<div>📝 更新 skill: <b>'+esc(t.updated_skill)+'</b></div>';
if(t.learned_methodology)h+='<div>💡 方法论: '+esc(t.learned_methodology).substring(0,100)+'</div>';
if(t.verification_result)h+='<div>✅ 验证: '+esc(t.verification_result).substring(0,100)+'</div>';
if(t.architecture_change)h+='<div>🔧 架构: '+esc(t.architecture_change).substring(0,100)+'</div>';
h+='</div>';
h+='<div class="fb-box" onclick="event.stopPropagation();">';
if(t.human_feedback){
h+='<div class="fb-done">💬 '+esc(t.human_feedback)+'</div>';
}else{
h+='<input class="fb-input" id="fb_'+t.id+'" placeholder="输入反馈..."><button class="fb-btn" onclick="sendFb('+t.id+')">发送</button>';
}
h+='</div>';
h+='</div>';
}
el.innerHTML=h;
}
function toggleCard(el){
var cid=el.getAttribute('data-cid');var txt=el.getAttribute('data-full');
var d=document.getElementById(cid);if(!d)return;
if(d.classList.contains('open')){
d.classList.remove('open');d.textContent=txt.substring(0,200);
el.textContent='▶ 展开';
}else{
d.classList.add('open');d.innerHTML=txt.replace(/\\n/g,'<br>');
el.textContent='▲ 收起';
}
}
function approve(id){fetch('/api/learn/'+id+'/approve',{method:'POST'}).then(function(r){return r.json()}).then(function(j){if(j.ok)refresh();else alert(j.error);});}
function reject(id){fetch('/api/learn/'+id+'/reject',{method:'POST'}).then(function(r){return r.json()}).then(function(j){if(j.ok)refresh();else alert(j.error);});}
function retry(id){approve(id);}
function sendFb(id){
var inp=document.getElementById('fb_'+id);if(!inp||!inp.value.trim())return;
fetch('/api/learn-result/'+id+'/feedback',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({feedback:inp.value.trim()})}).then(function(r){return r.json()}).then(function(j){if(j.ok)refresh();else alert(j.error);});
}
function runClassify(){
var btn=document.getElementById('btnClassify');btn.disabled=true;btn.textContent='分类中...';
fetch('/api/learn/classify',{method:'POST'}).then(function(r){return r.json()}).then(function(j){
if(j.ok){alert('已启动: '+j.data.classified+' 篇');refresh();}else{alert(j.error);}
btn.disabled=false;btn.textContent='🤖 运行分类器';
});
}
// Init
document.querySelectorAll('.tab').forEach(function(t){
t.addEventListener('click',function(){switchTab(this.getAttribute('data-tab'));});
});
refresh();
</script>
{% endblock %}