feat(health): cron列表加消息通道列+可切换API(toggle_delivery)

This commit is contained in:
xxm
2026-08-21 20:23:33 +08:00
parent 6577534130
commit d6e101c4df
2 changed files with 57 additions and 1 deletions
+23 -1
View File
@@ -390,7 +390,7 @@ function renderPipelineTable(pipelines) {
const layerColor = {collect:'#3fb950', process:'#d29922', use:'#58a6ff', monitor:'#bc8cff'}[layer];
html += `<div style="margin:14px 0 6px;padding:8px 12px;background:#161b22;border-left:3px solid ${layerColor};border-radius:4px">`;
html += `<strong style="color:${layerColor}">${title}</strong> <span style="color:#8b949e;font-size:11px">${desc} · ${group.length}任务 ✅${ok}${err}</span></div>`;
html += '<table><thead><tr><th>名称</th><th>来源</th><th>脚本/LLM</th><th>类型</th><th>调度</th><th>状态</th><th>最后运行</th><th>最后十次</th></tr></thead><tbody>';
html += '<table><thead><tr><th>名称</th><th>来源</th><th>脚本/LLM</th><th>类型</th><th>调度</th><th>消息通道</th><th>状态</th><th>最后运行</th><th>最后十次</th></tr></thead><tbody>';
group.forEach((p) => {
const tagCls = p.status==='ok'?'ok':p.status==='error'?'error':'warn';
const statusDisplay = p.last_run ? p.status : '待首次运行';
@@ -408,6 +408,9 @@ function renderPipelineTable(pipelines) {
html += `<td style="font-size:11px">${p.script||'LLM'}</td>`;
html += `<td><span class="cron-tag ${tagCls}">${p.type||'cron'}</span></td>`;
html += `<td style="font-size:11px">${p.schedule||'-'}</td>`;
const delColor = p.delivery==='xmpp'?'#3fb950':p.delivery==='both'?'#d29922':'#8b949e';
const delLabel = p.delivery==='xmpp'?'📣 xmpp':p.delivery==='both'?'🔄 both':'📡 broadcast';
html += `<td style="font-size:11px"><span style="color:${delColor};cursor:pointer;border:1px solid ${delColor};padding:1px 6px;border-radius:4px" onclick="cycDelivery('${encName}')" title="点击切换通道(broadcast/xmpp/both)">${delLabel}</span></td>`;
html += `<td class="pipeline-${tagCls}">${statusDisplay}</td>`;
html += `<td style="font-size:11px">${p.last_run||'-'}</td>`;
html += `<td><button class="pipe-reports-btn" data-cron="${encName}" data-script="${encScript}" data-name="${(p.name||'').replace(/"/g,'&quot;')}" onclick="openLastReports(this)">最后十次</button></td></tr>`;
@@ -581,5 +584,24 @@ function viewReportDetail(reportId) {
list.innerHTML = '<div style="color:#f85149">加载失败: ' + e.message + '</div>';
});
}
function cycDelivery(jobName) {
var uname = decodeURIComponent(jobName);
var row = document.querySelector('[data-name="'+uname.toLowerCase()+'"]');
if (!row) { alert('job not found'); return; }
var cur = row.querySelector('.pipe-row span') ? row.querySelector('.pipe-row span').textContent : '';
// 找到该行的delivery span
var spans = row.querySelectorAll('td:nth-child(6) span');
var curDel = spans[0] ? spans[0].textContent.replace(/[^-]/g,'').trim() : '';
// 简化:点击后调API toggle
fetch('/api/broadcast/toggle_delivery', {
method:'POST',
headers:{'Content-Type':'application/json'},
body: JSON.stringify({name: uname})
}).then(r=>r.json()).then(d=>{
location.reload();
}).catch(e=>alert('切换失败:'+e.message));
}
</script>
</body></html>