(() => { 'use strict'; let api,esc,formatDate,user; const statuses={healthy:['上次正常','green'],error:['上次失败','red'],pending:['待检查','yellow'],disabled:['已停用','secondary'],paused:['已暂停','secondary'],running:['执行中','blue'],unknown:['状态未知','orange'],stale:['记录已过期','yellow'],healthy_stale:['成功记录已过期','yellow'],unconfigured:['未配置','secondary']}; const guards={running:['守护正常','green'],starting:['启动中','blue'],backoff:['等待恢复','orange'],cooldown:['恢复冷却中','orange'],stale:['守护心跳过期','red'],unmanaged:['未通过守护启动','yellow'],stopped:['已停止','secondary'],stopping:['停止中','secondary']}; const reasons={healthy:'两个服务端口心跳正常',initial_start:'首次启动',unexpected_exit:'业务进程意外退出',health_timeout:'服务持续无响应',manual_restart:'手动重启',manual_stop:'手动停止',port_conflict:'服务端口已被占用',spawn_failed:'进程启动失败',startup_failed:'启动失败'}; const events={guard_started:'守护启动',child_exit:'业务进程退出',unresponsive:'服务持续无响应',restarting:'准备自动恢复',cooldown:'多次失败,进入冷却',manual_restart:'手动重启',guard_stopped:'守护停止',monitor_error:'守护检查异常',spawn_failed:'业务进程启动失败',autostart_installed:'启用 Windows 登录自启',autostart_removed:'移除 Windows 登录自启'}; function duration(seconds){seconds=Math.max(0,Math.floor(seconds));const days=Math.floor(seconds/86400),hours=Math.floor(seconds%86400/3600),minutes=Math.floor(seconds%3600/60);return (days?days+' 天 ':'')+(hours?hours+' 小时 ':'')+(minutes?minutes+' 分钟 ':seconds%60+' 秒');} function badge(status,map=statuses){const [label,color]=map[status]||['状态未知','secondary'];return `${label}`;} async function render(container,isActive=()=>true){ const live=()=>isActive()&&container.isConnected;let pending=false; container.innerHTML=`
默认永久保留;会话归档及异常退役保留原证据。
状态数据 '+(d.state.bytes/1048576).toFixed(2)+' MiB · PDF '+d.pdf.files+' 份 / '+(d.pdf.bytes/1048576).toFixed(2)+' MiB · 导出台账 '+d.jobs.total+' 条
导出 PDF 历史备份与恢复按停服操作指南执行;只恢复到新空目录。
';}catch(e){if(live())container.querySelector('#capacity-content').textContent=e.message;}finally{if(live())b.disabled=false;}};container.querySelector('#capacity-refresh').onclick=load;void load();} const failed=error=>{if(!live())return;const access=container.querySelector('#health-access');if(access){access.className='badge bg-red-lt ms-auto';access.textContent='连接中断';}notice.className='card-footer small text-danger';notice.textContent='状态读取失败:'+error.message+';保留上次状态,请刷新重试。';}; let initial,initialError;try{initial=await window.PageLifecycle.validateRegion('health');}catch(error){initialError=error;} await refresh(new AbortController().signal).catch(failed); const polling=window.PageLifecycle.regionPoll('health',{refresh,onError:failed},10000,{isActive:live,initial});button.onclick=()=>polling.refresh().catch(()=>{});if(initialError)failed(initialError);await polling.run().catch(()=>{}); } window.HealthViews={configure:options=>({api,esc,formatDate,user}=options),render}; })();