Files
news-tracker/templates/sources.html
T

63 lines
2.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{% extends "base.html" %}
{% set active = 'sources' %}
{% block title %}数据源 - 新闻智能跟踪{% endblock %}
{% block content %}
<div class="page-head">
<h1>📡 数据源管理</h1>
<button class="btn accent" onclick="toggleAdd()"> 新增数据源</button>
</div>
<div class="card" id="add-box" style="display:none;">
<h3>新增数据源</h3>
<div class="form-row">
<input id="f_name" placeholder="名称(如:36氪 AI频道)">
<input id="f_type" placeholder="类型(科技媒体/公司动态/学术/政策...)">
<input id="f_url" placeholder="URL / RSS 地址">
<input id="f_weight" type="number" step="0.1" value="0.8" placeholder="权重">
</div>
<textarea id="f_desc" placeholder="描述(该源提供哪些内容)" rows="2"></textarea>
<div class="form-row"><button class="btn" onclick="saveSource()">保存</button></div>
</div>
<div class="card">
<table>
<thead><tr><th>ID</th><th>名称</th><th>类型</th><th>权重</th><th>状态</th><th>最近采集</th><th>新增条数</th><th>操作</th></tr></thead>
<tbody>
{% for s in sources %}
<tr>
<td>{{ s.id }}</td>
<td><b>{{ s.name }}</b><br><span class="muted small">{{ s.description }}</span></td>
<td>{{ s.type }}</td>
<td>{{ s.weight }}</td>
<td>{% if s.enabled %}<span class="tag ok">启用</span>{% else %}<span class="tag">停用</span>{% endif %}</td>
<td>{{ s.last_fetch or '—' }}</td>
<td>{{ s.last_count }}</td>
<td>
<button class="btn mini" onclick="toggleSource({{ s.id }})">{{ '停用' if s.enabled else '启用' }}</button>
<button class="btn mini danger" onclick="delSource({{ s.id }})">删除</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
{% block script %}
<script>
function toggleAdd(){ document.getElementById('add-box').style.display = document.getElementById('add-box').style.display==='none' ? 'block' : 'none'; }
async function saveSource(){
const r = await API.json('/api/sources', {
action:'add', name:val('f_name'), type:val('f_type'), url:val('f_url'),
weight:parseFloat(val('f_weight')||'1'), description:val('f_desc')
});
if (r.ok) { toast('✅ 已添加'); setTimeout(()=>location.reload(), 600); } else toast('❌ 添加失败', false);
}
async function toggleSource(id){ await API.json('/api/sources', {action:'toggle', id}); location.reload(); }
async function delSource(id){
if (!confirm('确认删除该数据源?')) return;
await API.json('/api/sources', {action:'delete', id}); toast('✅ 已删除'); setTimeout(()=>location.reload(), 400);
}
function val(id){ return document.getElementById(id).value; }
</script>
{% endblock %}