reports.html
5.32 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
{% extends "base.html" %}
{% set page_type = page_type|default('digest') %}
{% if page_type == 'summary' %}
{% set request_path = "/summaries" %}
{% elif page_type == 'learn' %}
{% set request_path = "/learn-records" %}
{% else %}
{% set request_path = "/reports" %}
{% endif %}
{% block body %}
<style>
body{overflow-y:auto!important;height:auto!important;}
.fbar{display:flex;gap:6px;margin-bottom:14px;flex-wrap:wrap;align-items:center;}
.fbar input{flex:1;min-width:120px;padding:10px;border:1px solid #ddd;border-radius:8px;font-size:14px;}
.fbar button{padding:8px 14px;border:1px solid #ddd;border-radius:8px;font-size:12px;background:white;cursor:pointer;white-space:nowrap;}
.fbar button.on{background:#2c3e50;color:white;border-color:#2c3e50;}
.badge{font-size:10px;padding:2px 8px;border-radius:10px;font-weight:600;}
.badge.digest{background:#2c3e50;color:white;}
.badge.summary{background:#3498db;color:white;}
.badge.learn{background:#9b59b6;color:white;}
</style>
<div style="max-width:700px;margin:0 auto;padding:20px;">
{% if page_type == 'summary' %}
<h2 style="margin-bottom:10px;">📝 文章摘要</h2>
{% elif page_type == 'learn' %}
<h2 style="margin-bottom:10px;">📚 学习记录</h2>
{% else %}
<h2 style="margin-bottom:10px;">📋 日报列表</h2>
{% endif %}
<div class="fbar">
<input type="text" id="searchInput" placeholder="搜索标题..." oninput="render()">
<button onclick="setSort()" id="btnSort" style="font-size:12px;">时间↓</button>
</div>
<div style="font-size:12px;color:#999;margin-bottom:12px;" id="infoBar">加载中...</div>
<div id="reportList"><div class="loading"><div class="spinner"></div></div></div>
</div>
<script>
var allData=[],sortAsc=false;
var PAGE_TYPE='{{ page_type }}';
function getType(r){
var d=r.report_date||'';
if(d==='summary')return'summary';
if(d==='learn')return'learn';
if(/^\d{4}-\d{2}-\d{2}$/.test(d))return'digest';
return'digest';
}
async function load(){
var list=document.getElementById('reportList');
try{
var apiUrl='/api/reports';
if(PAGE_TYPE==='summary'){apiUrl+='?type=summary';}
else if(PAGE_TYPE==='learn'){apiUrl+='?type=learn';}
var r=await fetch(apiUrl);var j=await r.json();
if(!j.ok||!j.data.length){list.innerHTML='<div class="empty-state">暂无记录</div>';return;}
allData=j.data;
render();
}catch(e){list.innerHTML='<div class="empty-state">加载失败</div>';}
}
function setSort(){sortAsc=!sortAsc;document.getElementById('btnSort').textContent=sortAsc?'时间↑':'时间↓';render();}
function render(){
var q=(document.getElementById('searchInput').value||'').trim().toLowerCase();
var filtered=[];
for(var i=0;i<allData.length;i++){
var a=allData[i];
if(q&&(a.chatroom_name||'').toLowerCase().indexOf(q)<0)continue;
filtered.push(a);
}
filtered.sort(function(a,b){return sortAsc?(a.id||0)-(b.id||0):(b.id||0)-(a.id||0);});
document.getElementById('infoBar').textContent='共 '+filtered.length+' 条'+(q?'(筛选自 '+allData.length+' 条)':'');
var html='';
for(var i=0;i<filtered.length;i++){
var rp=filtered[i],type=getType(rp);
var badge='';
if(type==='digest')badge='<span class="badge digest">群日报</span>';
else if(type==='summary')badge='<span class="badge summary">文章摘要</span>';
else badge='<span class="badge learn">学习记录</span>';
html+='<div style="background:white;border-radius:8px;padding:16px;margin-bottom:12px;box-shadow:0 1px 2px rgba(0,0,0,0.05);">';
html+='<div style="display:flex;align-items:center;gap:8px;margin-bottom:6px;">'+badge;
html+='<a href="/report/'+rp.id+'" style="text-decoration:none;color:#2c3e50;flex:1;min-width:0;"><div style="font-size:15px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">'+esc(rp.chatroom_name)+' — '+rp.report_date+'</div></a>';
html+='</div>';
html+='<span style="font-size:11px;color:#999;white-space:nowrap;">'+(rp.created_at||'').slice(0,16)+'</span>';
html+='<div style="font-size:12px;color:#666;margin:6px 0;">'+esc(rp.summary||'').slice(0,120)+'...</div>';
html+='<div style="display:flex;gap:8px;margin-top:10px;">';
if(type==='digest'){
html+='<button onclick="event.preventDefault();genImg('+rp.id+',event)" style="flex:1;padding:12px;border:1px solid #3498db;border-radius:8px;background:white;color:#3498db;font-size:14px;cursor:pointer;">生成图片</button>';
}
html+='<button onclick="event.preventDefault();del('+rp.id+')" style="flex:1;padding:12px;border:1px solid #e74c3c;border-radius:8px;background:white;color:#e74c3c;font-size:14px;cursor:pointer;">删除</button>';
html+='</div></div>';
}
document.getElementById('reportList').innerHTML=html||'<div class="empty-state">无匹配记录</div>';
}
async function genImg(id,evt){evt.stopPropagation();if(!confirm('为这份日报生成复古铜版画风格图片?'))return;try{var r=await fetch('/api/reports/'+id+'/generate-image',{method:'POST'});var j=await r.json();if(j.ok){alert('图片生成任务已提交!');}else{alert('失败: '+(j.error||''));}}catch(e){alert('错误: '+e.message);}}
async function del(id){if(!confirm('确认删除?'))return;await fetch('/api/report/'+id+'/delete',{method:'POST'});load();}
function esc(s){return String(s||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');}
load();
</script>
{% endblock %}