Fix Web 2.0.3 log panel layout
This commit is contained in:
+46
-31
@@ -3,7 +3,7 @@ import {apiPath, webPath} from './paths.js';
|
||||
import {el, $, $$, clone, getPath, setPath, pathKey, textValue, number, chinaTime, download, csvBlob, optionsList, detailsList, tabKeys} from './dom.js';
|
||||
import {PageView, PAGES} from './pages.js';
|
||||
import {notice, dialog, confirm, filePicker, fileBase64} from './ui.js';
|
||||
import {createLogState, mergeLogs, visibleLogs, syncLogLines, logText, attachTaskLog} from './task-logs.js';
|
||||
import {createLogState, logView, mergeLogs, visibleLogs, syncLogLines, logText} from './task-logs.js';
|
||||
|
||||
const state = {accounts:new Map(),active:null,schema:null,meta:null,ready:false,polling:false,seq:0,redirecting:false,webStatusError:null,statusMessage:'连接中'};
|
||||
const current = () => state.accounts.get(state.active);
|
||||
@@ -174,7 +174,7 @@ function editConfig(account,path,value,field={},row) {
|
||||
syncSaveStatus(account);
|
||||
// Update other controls, while every control protects its own focused input.
|
||||
account.pages.forEach(page=>page.data&&page.render(page.data));
|
||||
if (path[0]==='log_visible'||path[0]==='log_sizes') applyLogLayout(account);
|
||||
if (path[0]==='log_sizes') applyLogLayout(account);
|
||||
}
|
||||
|
||||
async function flushConfig(account=current()) {
|
||||
@@ -261,8 +261,8 @@ async function perform(account,operation,payload={},options={}) {
|
||||
const page=options.page || account.pages.get(account.page);if(page)await loadPage(page,true);
|
||||
if(operation==='login'&&result)account.pages.get('login')?.login?.update(result);
|
||||
const message=loginOperations.has(operation)?account.summary.running?'已读取角色,已自动开启策略,执行已配置且已勾选的功能;可在顶部“停止”。':'已读取角色。策略已停止,可在顶部“开启”继续执行已勾选功能。':result?.message;
|
||||
if(message)notice(message);
|
||||
setStatus(message || `${operationLabels[operation] || '操作'}已完成`);
|
||||
if(message && operation!=='refresh')notice(message);
|
||||
setStatus(operation==='refresh'?'状态已刷新':message || `${operationLabels[operation] || '操作'}已完成`);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -271,7 +271,6 @@ function getPage(account,key) {
|
||||
const page=new PageView(account,key,{edit:editConfig,perform,load:loadPage,action:pageAction,command,
|
||||
schema:pageKey=>state.schema?.pages?.find(page=>page.key===pageKey)?.form || []});
|
||||
account.pages.set(key,page);$('#page-host').append(page.root);
|
||||
attachTaskLog(page);
|
||||
}
|
||||
return account.pages.get(key);
|
||||
}
|
||||
@@ -292,18 +291,19 @@ async function loadPage(page,force=false) {
|
||||
|
||||
function selectPage(key) {
|
||||
const account=current();if(!account)return;
|
||||
saveLogScroll(account);
|
||||
if(account.page!==key)account.pages.get(account.page)?.login?.clearPassword();
|
||||
account.page=key;
|
||||
state.accounts.forEach(other=>other.pages.forEach(page=>{page.root.hidden=other.id!==account.id||page.key!==key;}));
|
||||
const page=getPage(account,key);page.root.hidden=false;
|
||||
page.taskLog?.render();
|
||||
renderLogs();
|
||||
$$('.page-tab').forEach(tab=>{const selected=tab.dataset.page===key;tab.setAttribute('aria-selected',String(selected));tab.tabIndex=selected?0:-1;});
|
||||
loadPage(page,true);
|
||||
}
|
||||
|
||||
async function selectAccount(id) {
|
||||
const previous=current();previous?.pages.get('login')?.login?.clearPassword();
|
||||
if(previous && !$('#log-panel').hidden && $('#log-lines').dataset.account===previous.id)previous.logs.total.scrollTop=$('#log-lines').scrollTop;
|
||||
saveLogScroll(previous);
|
||||
if(previous?.edits.size)flushConfig(previous).catch(error);
|
||||
state.active=id;const account=current();if(!account)return;
|
||||
$('#page-host').querySelector('.initial-state')?.remove();
|
||||
@@ -378,11 +378,11 @@ async function exportYields(account=current()) {
|
||||
async function command(name,account=current()) {
|
||||
try {
|
||||
if(name==='add-account'||name==='add-demo')return await addAccount(name==='add-demo');
|
||||
if(name==='about')return dialog('关于牧场助手',el('div',{},el('p',{text:`牧羊人之心牧场助手 Web ${state.meta?.version || '2.0.2'}`}),el('p',{text:`游戏数据版本 ${state.meta?.gameVersion || '1.9.68'}`}),el('p',{class:'info-note',text:'与桌面助手共用核心策略。配置在服务端自动保存;每次成功登录后自动执行已勾选功能,可在顶部“停止”。服务重启后须先成功登录才执行。'})),{info:true});
|
||||
if(name==='about')return dialog('关于牧场助手',el('div',{},el('p',{text:`牧羊人之心牧场助手 Web ${state.meta?.version || '2.0.3'}`}),el('p',{text:`游戏数据版本 ${state.meta?.gameVersion || '1.9.68'}`}),el('p',{class:'info-note',text:'与桌面助手共用核心策略。配置在服务端自动保存;每次成功登录后自动执行已勾选功能,可在顶部“停止”。服务重启后须先成功登录才执行。'})),{info:true});
|
||||
if(name==='updates')return await showUpdates();
|
||||
if(name==='admin-logout'){hideWorkbench();try{await api.logout();}finally{requireAuth();}return;}
|
||||
if(!account)throw new Error('请先新增或选择账号。');
|
||||
if(name==='debug'){account.logs.debug=!account.logs.debug;account.logs.next=0;account.logs.generation=(account.logs.generation || 0)+1;$('#debug-log').checked=account.logs.debug;setLogVisible(true);renderLogs(true);currentPage()?.taskLog?.render();await fetchLogs(account);return;}
|
||||
if(name==='debug'){account.logs.debug=!account.logs.debug;account.logs.next=0;account.logs.generation=(account.logs.generation || 0)+1;$('#debug-log').checked=account.logs.debug;renderLogs(true);await fetchLogs(account);return;}
|
||||
if(name==='save'){await flushConfig(account);notice('策略已保存。');return;}
|
||||
if(name==='stop'||name==='start')return await perform(account,name);
|
||||
if(name==='start-all'||name==='stop-all'){
|
||||
@@ -475,17 +475,24 @@ async function showUpdates() {
|
||||
}
|
||||
|
||||
function setLogVisible(visible) {
|
||||
const account=current();if(account?.config)editConfig(account,['log_visible'],visible);
|
||||
else applyLogLayout(null,visible);
|
||||
const account=current();if(!account)return;
|
||||
saveLogScroll(account);
|
||||
account.logs.visible=Boolean(visible);
|
||||
applyLogLayout(account);
|
||||
}
|
||||
|
||||
function applyLogLayout(account=current(),visibleOverride) {
|
||||
function saveLogScroll(account=current()) {
|
||||
const root=$('#log-lines');
|
||||
if(account && !$('#log-panel').hidden && root.dataset.account===account.id && root.dataset.page===account.page)
|
||||
logView(account.logs,account.page).scrollTop=root.scrollTop;
|
||||
}
|
||||
|
||||
function applyLogLayout(account=current()) {
|
||||
if(account&&account.id!==state.active)return;
|
||||
const visible=visibleOverride ?? account?.config?.log_visible ?? true;
|
||||
if(!visible && account && !$('#log-panel').hidden && $('#log-lines').dataset.account===account.id)account.logs.total.scrollTop=$('#log-lines').scrollTop;
|
||||
$('#log-panel').hidden=!visible;$('#log-resizer').hidden=!visible;$('#log-toggle').textContent=visible?'隐藏总日志':'显示总日志';$('#log-toggle').setAttribute('aria-expanded',String(visible));
|
||||
const visible=Boolean(account?.logs.visible);
|
||||
$('#log-panel').hidden=!visible;$('#log-resizer').hidden=!visible;$('#log-toggle').textContent=visible?'隐藏日志':'显示日志';$('#log-toggle').setAttribute('aria-expanded',String(visible));
|
||||
const size=account?.config?.log_sizes?.[1];if(size)setLogHeight(size);
|
||||
if(visible)renderLogs();
|
||||
renderLogs();
|
||||
}
|
||||
|
||||
function setLogHeight(height) {
|
||||
@@ -494,28 +501,32 @@ function setLogHeight(height) {
|
||||
}
|
||||
|
||||
function renderLogs(reset=false) {
|
||||
const account=current(),root=$('#log-lines');if(!account){root.replaceChildren();return;}
|
||||
const account=current(),root=$('#log-lines');
|
||||
const title=`${PAGES.find(([key])=>key===account?.page)?.[1] || ''}日志`;
|
||||
$('#log-heading').textContent=title;$('#log-panel').setAttribute('aria-label',title);root.setAttribute('aria-label',`${title}内容`);
|
||||
$('#log-search').setAttribute('aria-label',`${title}搜索`);
|
||||
if(!account){root.replaceChildren();delete root.dataset.account;delete root.dataset.page;$('#log-count').textContent='';return;}
|
||||
const log=account.logs,view=logView(log,account.page);
|
||||
$('#log-follow').checked=view.follow;$('#debug-log').checked=log.debug;
|
||||
if($('#log-search').value!==view.search)$('#log-search').value=view.search;
|
||||
if($('#log-panel').hidden)return;
|
||||
const log=account.logs,view=log.total;
|
||||
const switching=root.dataset.account!==account.id;
|
||||
const switching=root.dataset.account!==account.id || root.dataset.page!==account.page;
|
||||
const scrollTop=switching?view.scrollTop:root.scrollTop;
|
||||
reset=reset || switching;
|
||||
const token=JSON.stringify([log.revision,view.clearedThrough,log.debug]);
|
||||
const token=JSON.stringify([log.revision,view.clearedThrough,log.debug,view.search]);
|
||||
if(!reset && view.rendered===token)return;
|
||||
const entries=visibleLogs(log,view);
|
||||
const entries=visibleLogs(log,view,account.page);
|
||||
syncLogLines(root,entries,{reset,follow:view.follow,scrollTop:reset?scrollTop:undefined,inspect:log.debug?entry=>showDebugEntry(account,entry):null});
|
||||
root.dataset.account=account.id;view.rendered=token;
|
||||
$('#log-follow').checked=view.follow;
|
||||
root.dataset.account=account.id;root.dataset.page=account.page;view.rendered=token;
|
||||
const count=`${Math.min(600,entries.length)} 条`;
|
||||
if($('#log-count').textContent!==count)$('#log-count').textContent=count;
|
||||
$('#debug-log').checked=log.debug;$('#log-heading').textContent=log.debug?'总日志(调试 / 已脱敏)':'总日志';
|
||||
}
|
||||
|
||||
async function fetchLogs(account) {
|
||||
if(account.logs.loading)return;account.logs.loading=true;const generation=account.logs.generation || 0;
|
||||
try{const response=await api.logs(account.id,account.logs.next,account.logs.debug);if(generation!==(account.logs.generation || 0))return;
|
||||
mergeLogs(account.logs,response.entries || [],response.next);
|
||||
if(account.id===state.active){renderLogs();currentPage()?.taskLog?.render();}
|
||||
if(account.id===state.active)renderLogs();
|
||||
transportError(account,'logs','日志',null);
|
||||
}catch(failure){if(generation===(account.logs.generation || 0))transportError(account,'logs','日志',failure);}finally{account.logs.loading=false;}
|
||||
}
|
||||
@@ -533,7 +544,7 @@ async function showDebugEntry(account,entry) {
|
||||
|
||||
function showNoAccounts() {
|
||||
state.active=null;$('#page-host').replaceChildren(el('div',{class:'initial-state'},el('p',{text:'尚未添加账号。新增账号后登录游戏,或使用离线演示查看工作台。'}),el('div',{class:'page-toolbar'},el('button',{text:'新增账号…',onClick:()=>command('add-account')}),el('button',{text:'新增离线演示账号',onClick:()=>command('add-demo')}))));
|
||||
renderAccountTabs();renderSummary();renderLogs(true);setStatus('等待新增账号');
|
||||
renderAccountTabs();renderSummary();applyLogLayout();setStatus('等待新增账号');
|
||||
}
|
||||
|
||||
async function syncAccounts() {
|
||||
@@ -562,6 +573,9 @@ async function tick() {
|
||||
}
|
||||
|
||||
function hideWorkbench() {
|
||||
saveLogScroll();
|
||||
state.accounts.forEach(account=>account.logs.visible=false);
|
||||
applyLogLayout();
|
||||
state.ready=false;
|
||||
$('#app').hidden=true;$('#notice').hidden=true;
|
||||
$$('dialog[open]').forEach(root=>root.close());
|
||||
@@ -581,7 +595,7 @@ async function bootstrap() {
|
||||
$('#app').hidden=false;
|
||||
const [meta,schema]=await Promise.all([api.meta(),api.schema()]);state.meta=meta;state.schema=schema;
|
||||
if(state.redirecting)return;
|
||||
$('#app-version').textContent=meta.version || '2.0.2';$('#game-version').textContent=meta.gameVersion || '1.9.68';$('#access-mode').textContent=auth.access_mode==='local'||auth.access_mode==='loopback'?'本机工作台':auth.required?'管理工作台':'本机工作台';
|
||||
$('#app-version').textContent=meta.version || '2.0.3';$('#game-version').textContent=meta.gameVersion || '1.9.68';$('#access-mode').textContent=auth.access_mode==='local'||auth.access_mode==='loopback'?'本机工作台':auth.required?'管理工作台':'本机工作台';
|
||||
await syncAccounts();if(state.redirecting)return;state.ready=true;setStatus('工作台已连接');
|
||||
}catch(failure){if(failure.status===401||$('#app').hidden){requireAuth();return;}if(state.redirecting)return;setStatus(failure.message);$('#page-host').replaceChildren(el('div',{class:'initial-state'},el('p',{text:failure.message}),el('button',{text:'重新连接',onClick:bootstrap})));}
|
||||
}
|
||||
@@ -599,10 +613,11 @@ $('#refresh-interval').addEventListener('change',event=>{if(current())editConfig
|
||||
$('#save-status').tabIndex=0;$('#save-status').addEventListener('click',()=>command('save'));$('#save-status').addEventListener('keydown',event=>{if(event.key==='Enter')command('save');});
|
||||
$('#debug-toggle').addEventListener('click',()=>command('debug'));$('#debug-log').addEventListener('change',()=>command('debug'));
|
||||
$('#log-toggle').addEventListener('click',()=>setLogVisible($('#log-panel').hidden));
|
||||
$('#clear-log').addEventListener('click',()=>{const log=current()?.logs;if(log){log.total.clearedThrough=log.highWater;renderLogs();}});
|
||||
$('#download-log').addEventListener('click',()=>{const log=current()?.logs;if(log)download(new Blob([logText(visibleLogs(log,log.total))],{type:'text/plain;charset=utf-8'}),'牧场日志.txt');});
|
||||
$('#log-lines').addEventListener('scroll',()=>{const node=$('#log-lines'),account=current();if(!account || $('#log-panel').hidden || node.dataset.account!==account.id)return;account.logs.total.scrollTop=node.scrollTop;if(node.scrollHeight-node.scrollTop-node.clientHeight>55){$('#log-follow').checked=false;account.logs.total.follow=false;}});
|
||||
$('#log-follow').addEventListener('change',()=>{const account=current(),node=$('#log-lines');if(!account || $('#log-panel').hidden || node.dataset.account!==account.id)return;account.logs.total.follow=$('#log-follow').checked;if($('#log-follow').checked)node.scrollTop=node.scrollHeight;});
|
||||
$('#clear-log').addEventListener('click',()=>{const account=current();if(account){logView(account.logs,account.page).clearedThrough=account.logs.highWater;renderLogs();}});
|
||||
$('#download-log').addEventListener('click',()=>{const account=current();if(account)download(new Blob([logText(visibleLogs(account.logs,logView(account.logs,account.page),account.page))],{type:'text/plain;charset=utf-8'}),`${$('#log-heading').textContent}.txt`);});
|
||||
$('#log-search').addEventListener('input',event=>{const account=current();if(account){logView(account.logs,account.page).search=event.target.value;renderLogs();}});
|
||||
$('#log-lines').addEventListener('scroll',()=>{const node=$('#log-lines'),account=current();if(!account || $('#log-panel').hidden || node.dataset.account!==account.id || node.dataset.page!==account.page)return;const view=logView(account.logs,account.page);view.scrollTop=node.scrollTop;if(node.scrollHeight-node.scrollTop-node.clientHeight>55){$('#log-follow').checked=false;view.follow=false;}});
|
||||
$('#log-follow').addEventListener('change',()=>{const account=current(),node=$('#log-lines');if(!account || $('#log-panel').hidden || node.dataset.account!==account.id || node.dataset.page!==account.page)return;const view=logView(account.logs,account.page);view.follow=$('#log-follow').checked;if(view.follow)node.scrollTop=node.scrollHeight;view.scrollTop=node.scrollTop;});
|
||||
let resize;
|
||||
$('#log-resizer').addEventListener('pointerdown',event=>{resize={y:event.clientY,height:$('#log-panel').getBoundingClientRect().height};event.currentTarget.setPointerCapture(event.pointerId);event.preventDefault();});
|
||||
$('#log-resizer').addEventListener('pointermove',event=>{if(resize)setLogHeight(resize.height+resize.y-event.clientY);});
|
||||
|
||||
@@ -26,21 +26,21 @@
|
||||
</div></details>
|
||||
<details class="menu"><summary accesskey="h">帮助<span class="access-key">(H)</span></summary><div class="menu-popup"><button data-command="updates">检查版本更新…</button><button data-command="debug">调试日志</button><button data-command="about">关于…</button></div></details>
|
||||
</nav>
|
||||
<span class="window-title">牧羊人之心牧场助手 <span id="app-version">2.0.2</span></span>
|
||||
<span class="window-title">牧羊人之心牧场助手 <span id="app-version">2.0.3</span></span>
|
||||
<span id="access-mode" class="muted">正在连接本地服务</span>
|
||||
</header>
|
||||
<div class="account-bar"><div id="account-tabs" class="account-tabs" role="tablist" aria-label="账号"></div><button id="add-account" class="compact" title="新增账号">+ 新增账号</button></div>
|
||||
<div class="toolbar" aria-label="角色状态和运行控制">
|
||||
<div class="player-line"><span id="connection" class="connection">未登录</span><strong id="player-name">—</strong><span>等级 <b id="player-level">—</b></span><span class="experience">经验 <b id="player-exp">—</b><progress id="experience-progress" max="1" value="0" aria-label="角色经验"></progress></span><span>金币 <b id="player-money">—</b></span><span>氪金 <b id="player-ke">—</b></span><span>体力 <b id="player-ti">—</b></span></div>
|
||||
<div class="run-controls"><label>刷新 <select id="refresh-interval" aria-label="随机刷新间隔" title="整体刷新完成后,从 0 到所选上限随机等待;空坑装填与到期同步独立执行"><option value="30">随机30秒</option><option value="60">随机60秒</option><option value="120">随机2分钟</option><option value="300">随机5分钟</option></select></label><button id="strategy-toggle" class="run-button" disabled>开启</button><button id="refresh">刷新 / 预览策略</button><button id="debug-toggle">调试日志</button><button id="log-toggle" aria-expanded="true" aria-controls="log-panel">隐藏总日志</button></div>
|
||||
<div class="run-controls"><label>刷新 <select id="refresh-interval" aria-label="随机刷新间隔" title="整体刷新完成后,从 0 到所选上限随机等待;空坑装填与到期同步独立执行"><option value="30">随机30秒</option><option value="60">随机60秒</option><option value="120">随机2分钟</option><option value="300">随机5分钟</option></select></label><button id="strategy-toggle" class="run-button" disabled>开启</button><button id="refresh">刷新 / 预览策略</button><button id="debug-toggle">调试日志</button><button id="log-toggle" aria-expanded="false" aria-controls="log-panel">显示日志</button></div>
|
||||
</div>
|
||||
<div class="summary-line"><span id="data-summary">等待连接服务</span><span id="save-status" role="status">配置未载入</span></div>
|
||||
<main id="workspace" class="workspace">
|
||||
<nav id="page-tabs" class="page-tabs" role="tablist" aria-label="功能页面"></nav>
|
||||
<div id="page-host" class="page-host"><div class="initial-state" role="status">正在载入工作台…</div></div>
|
||||
</main>
|
||||
<div id="log-resizer" class="log-resizer" role="separator" tabindex="0" aria-label="调整日志高度" aria-orientation="horizontal" aria-valuemin="64" aria-valuemax="480" aria-valuenow="150" title="上下拖动调整日志高度;也可使用方向键"></div>
|
||||
<section id="log-panel" class="log-panel" aria-label="总日志"><div class="log-toolbar"><strong id="log-heading">总日志</strong><label><input id="debug-log" type="checkbox">调试 / 脱敏</label><label><input id="log-follow" type="checkbox" checked>自动滚动</label><span id="log-count" class="muted" aria-live="off"></span><span class="spacer"></span><button id="download-log" class="small">下载日志</button><button id="clear-log" class="small" title="只清空本账号总日志显示,保留各任务日志及服务端历史">清空显示</button></div><div id="log-lines" class="log-lines" tabindex="0" role="log" aria-live="off" aria-label="总日志内容"></div></section>
|
||||
<div id="log-resizer" class="log-resizer" role="separator" tabindex="0" aria-label="调整日志高度" aria-orientation="horizontal" aria-valuemin="64" aria-valuemax="480" aria-valuenow="150" title="上下拖动调整日志高度;也可使用方向键" hidden></div>
|
||||
<section id="log-panel" class="log-panel" aria-label="登录日志" hidden><div class="log-toolbar"><strong id="log-heading">登录日志</strong><label><input id="debug-log" type="checkbox">调试 / 脱敏</label><label><input id="log-follow" type="checkbox" checked>自动滚动</label><label>搜索 <input id="log-search" type="search" aria-label="登录日志搜索" placeholder="筛选日志文字"></label><span id="log-count" class="muted" aria-live="off"></span><span class="spacer"></span><button id="download-log" class="small">下载日志</button><button id="clear-log" class="small" title="只清空本账号本页日志显示,保留其他页面及服务端历史">清空显示</button></div><div id="log-lines" class="log-lines" tabindex="0" role="log" aria-live="off" aria-label="登录日志内容"></div></section>
|
||||
<footer class="status-bar"><span id="status-text" role="status">连接中</span><span id="job-status" class="muted"></span><span class="spacer"></span><span>游戏 <span id="game-version">1.9.68</span></span><span id="clock"></span></footer>
|
||||
</div>
|
||||
<div id="notice" class="notice" role="status" hidden></div>
|
||||
|
||||
@@ -10,21 +10,7 @@
|
||||
@media(max-width:1000px){.window-title{display:none}.toolbar{gap:5px}.run-controls{width:100%}.player-line{gap:10px}.page-tab{padding-left:8px;padding-right:8px}.form-grid{grid-template-columns:repeat(2,minmax(240px,1fr))}.statistics-picker{width:220px}}
|
||||
@media(max-width:650px){:root{--log-height:120px}.workbench{min-width:340px}.window-header{gap:5px}.menu>summary{padding:5px 7px}.access-key{display:none}#access-mode{font-size:11px}.toolbar{padding:6px}.player-line{gap:7px 10px}.player-line>strong{max-width:135px}.experience progress{display:none}.run-controls{gap:4px}.run-controls>button{padding-left:7px;padding-right:7px;font-size:12px}.form-grid{grid-template-columns:1fr}.field>.field-label{min-width:120px}.field-wide{grid-column:auto}.login-layout{padding:3px}.login-layout .field{align-items:stretch;flex-direction:column;gap:4px}.login-layout .field>.field-label{flex-basis:auto;min-width:0}.login-layout input[type=text],.login-layout input[type=password]{width:100%}.login-options,.login-actions{margin-left:0}.server-row{flex-wrap:wrap}.statistics-layout{flex-direction:column}.statistics-picker{width:100%;max-height:130px}.log-toolbar{gap:7px}#download-log{display:none}.status-bar{gap:8px}.status-bar #game-version{display:none}dialog .field{flex-direction:column;align-items:stretch}dialog .field-label{flex-basis:auto}#save-status{max-width:160px;overflow:hidden;text-overflow:ellipsis}}
|
||||
@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important}}
|
||||
.page-content{display:flex;flex-direction:column;gap:7px;flex:1;min-height:0}.statistics-table-host{display:flex;flex-direction:column;flex:1;min-height:100px}.count-id{width:100px}.statistics-city>summary,.statistics-stage>summary{cursor:pointer;font-size:12px;padding:6px 7px;line-height:1.5;overflow-wrap:anywhere}.statistics-city>summary{background:#eef1f5;border-bottom:1px solid #d8dee6;font-weight:600}.statistics-stage{margin-left:10px}.statistics-stage>summary:hover{background:#edf3fa}.statistics-levels{padding-left:12px}.statistics-levels button{padding:5px 8px}.debug-json{margin:0;font:12px/1.6 Consolas,monospace;white-space:pre-wrap;overflow-wrap:anywhere}.log-entry.inspectable{cursor:pointer}.log-entry.inspectable:hover{background:#e8f0f9}.member-draft-note{font-size:11px;color:#805300}.counts-lines{display:flex;flex-direction:column;gap:3px;margin-bottom:4px}
|
||||
.page-content{display:flex;flex-direction:column;gap:7px;flex:1;min-height:160px;overflow:auto}.page-panel[data-page=login]>.page-content{flex:0 0 auto;min-height:0;overflow:visible}.statistics-table-host{display:flex;flex-direction:column;flex:1;min-height:100px}.count-id{width:100px}.statistics-city>summary,.statistics-stage>summary{cursor:pointer;font-size:12px;padding:6px 7px;line-height:1.5;overflow-wrap:anywhere}.statistics-city>summary{background:#eef1f5;border-bottom:1px solid #d8dee6;font-weight:600}.statistics-stage{margin-left:10px}.statistics-stage>summary:hover{background:#edf3fa}.statistics-levels{padding-left:12px}.statistics-levels button{padding:5px 8px}.debug-json{margin:0;font:12px/1.6 Consolas,monospace;white-space:pre-wrap;overflow-wrap:anywhere}.log-entry.inspectable{cursor:pointer}.log-entry.inspectable:hover{background:#e8f0f9}.member-draft-note{font-size:11px;color:#805300}.counts-lines{display:flex;flex-direction:column;gap:3px;margin-bottom:4px}
|
||||
.chart-axis{font-size:11px;fill:#55616e;font-variant-numeric:tabular-nums}
|
||||
.task-log-panel{flex:0 0 auto;min-width:0;border:1px solid var(--border);background:#fff;overflow-anchor:none}
|
||||
.has-task-log>.page-content{flex:1 0 160px;min-height:160px;overflow:auto}
|
||||
.has-task-log[data-page=login]>.page-content{flex:0 0 auto;overflow:visible}
|
||||
.task-log-heading{flex-wrap:wrap;gap:6px 12px}
|
||||
.task-log-heading h3{margin:0;font-size:13px;font-weight:600}
|
||||
.task-log-status{font-size:12px;overflow-wrap:anywhere}
|
||||
.task-log-body{position:relative;min-width:0}
|
||||
.task-log-controls{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;padding:6px 8px;border-bottom:1px solid var(--border);font-size:12px}
|
||||
.task-log-controls label{display:flex;align-items:center;gap:5px;min-width:0}
|
||||
.task-log-controls input[type=search]{width:185px;min-width:100px;max-width:100%}
|
||||
.task-log-lines{height:190px;min-height:120px;max-height:35vh;overflow-anchor:none;overscroll-behavior:contain}
|
||||
.task-log-viewport{position:relative}
|
||||
.task-log-empty{position:absolute;top:6px;left:10px;right:10px;margin:0;pointer-events:none;font-size:12px}
|
||||
.task-log-help{margin:0;padding:4px 8px;border-top:1px solid var(--border);font-size:12px;line-height:1.5}
|
||||
#log-lines{overflow-anchor:none;overscroll-behavior:contain}
|
||||
@media(max-width:700px){.task-log-controls button,.task-log-heading button{min-height:32px}.task-log-lines{height:165px}.task-log-status{flex:1 1 180px}}
|
||||
.log-toolbar{flex-wrap:wrap;gap:5px 13px}.log-toolbar input[type=search]{width:170px;min-width:100px;max-width:100%}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import {el, chinaTime, textValue, download} from './dom.js';
|
||||
import {el, chinaTime, textValue} from './dom.js';
|
||||
|
||||
const BUFFER_LIMIT = 1200;
|
||||
const RENDER_LIMIT = 600;
|
||||
const categories = new Set(['general', 'login', 'hatching', 'mainline', 'gifts', 'commissions', 'exploration', 'maps', 'ranch', 'daily']);
|
||||
const titles = {login:'登录日志', daily:'每日事务日志', ranch:'牧场日志', hatching:'孵蛋日志', mainline:'主线日志', gifts:'赠礼日志', commissions:'委托日志', exploration:'探险日志', maps:'扫荡日志'};
|
||||
let panelId = 0;
|
||||
const pageCategories = {login:'login', daily:'daily', ranch:'ranch', hatching:'hatching', mainline:'mainline', gifts:'gifts', commissions:'commissions', exploration:'exploration', maps:'maps', incubator:'hatching'};
|
||||
|
||||
export function createLogState() {
|
||||
return {entries:[], next:0, highWater:0, retainedAfter:0, revision:0, debug:false, loading:false,
|
||||
total:{clearedThrough:0, follow:true, scrollTop:0}};
|
||||
visible:false, views:new Map()};
|
||||
}
|
||||
|
||||
export function logView(log, page) {
|
||||
if (!log.views.has(page)) log.views.set(page, {clearedThrough:0, follow:true, scrollTop:0, search:''});
|
||||
return log.views.get(page);
|
||||
}
|
||||
|
||||
const levelOf = entry => String(entry.level || entry.kind || (entry.debug ? 'debug' : 'info')).toLowerCase();
|
||||
@@ -18,8 +22,8 @@ const debugEntry = entry => entry.debug || levelOf(entry) === 'debug';
|
||||
const lineSignature = (entry, inspect) => JSON.stringify([stampOf(entry), messageOf(entry), levelOf(entry),
|
||||
Boolean(inspect && (entry.details_available || entry.detail_url || entry.debug_url))]);
|
||||
|
||||
// All panels share this one bounded history. A cursor rewind for debug must not
|
||||
// reintroduce evicted records or move any panel's local clear watermark.
|
||||
// Each account keeps one bounded history. A cursor rewind for debug must not
|
||||
// reintroduce evicted records or move any tab's local clear watermark.
|
||||
export function mergeLogs(log, entries, next) {
|
||||
const bySequence = new Map(log.entries.map(entry => [entry.seq, entry]));
|
||||
let changed = false;
|
||||
@@ -47,8 +51,9 @@ export function mergeLogs(log, entries, next) {
|
||||
}
|
||||
|
||||
export function visibleLogs(log, view, page) {
|
||||
const category = Object.hasOwn(pageCategories, page) ? pageCategories[page] : null;
|
||||
return log.entries.filter(entry => entry.seq > view.clearedThrough && (log.debug || !debugEntry(entry))
|
||||
&& (!page || entry.category === page || page === 'login' && entry.category === 'general')
|
||||
&& entry.category === category
|
||||
&& (!view.level || levelOf(entry) === view.level)
|
||||
&& (!view.search || messageOf(entry).toLocaleLowerCase().includes(view.search.toLocaleLowerCase())));
|
||||
}
|
||||
@@ -106,86 +111,3 @@ export function syncLogLines(root, entries, {follow, reset=false, scrollTop, ins
|
||||
export function logText(entries) {
|
||||
return entries.map(entry => [stampOf(entry), messageOf(entry)].join(' ')).join('\n');
|
||||
}
|
||||
|
||||
export class TaskLogPanel {
|
||||
constructor(page) {
|
||||
this.page = page;
|
||||
this.log = page.account.logs;
|
||||
this.title = titles[page.key];
|
||||
this.view = {clearedThrough:0, follow:true, search:'', level:'', seenThrough:0};
|
||||
const id = `task-log-${++panelId}`;
|
||||
this.heading = el('h3', {id:`${id}-heading`, text:this.title});
|
||||
this.status = el('span', {class:'task-log-status muted', role:'status', 'aria-atomic':'true'});
|
||||
this.toggle = el('button', {type:'button', text:'隐藏', 'aria-label':`隐藏${this.title}`, 'aria-expanded':'true', 'aria-controls':`${id}-body`,
|
||||
onClick:() => this.setHidden(!this.body.hidden)});
|
||||
this.follow = el('button', {type:'button', text:'暂停跟随', 'aria-label':`${this.title}:暂停自动滚动`, 'aria-pressed':'true',
|
||||
onClick:() => this.setFollow(!this.view.follow)});
|
||||
this.search = el('input', {type:'search', 'aria-label':`${this.title}搜索`, placeholder:'筛选日志文字',
|
||||
onInput:() => {this.view.search = this.search.value;this.render();}});
|
||||
this.level = el('select', {'aria-label':`${this.title}级别`, onChange:() => {this.view.level = this.level.value;this.render();}},
|
||||
...[['','全部级别'],['info','信息'],['warning','警告'],['error','错误'],['debug','调试']].map(([value,text]) => el('option', {value,text})));
|
||||
const clear = el('button', {type:'button', text:'清空显示', 'aria-label':`清空当前账号${this.title}显示`,
|
||||
title:'只清空本账号本页显示,保留总日志及其他页面记录', onClick:() => {
|
||||
this.view.clearedThrough = this.log.highWater;
|
||||
this.view.seenThrough = this.log.highWater;
|
||||
this.render();
|
||||
}});
|
||||
const save = el('button', {type:'button', text:'下载日志', 'aria-label':`下载当前账号${this.title}`, title:'下载本页清空后保留、符合当前日志筛选的记录',
|
||||
onClick:() => download(new Blob([logText(this.entries())], {type:'text/plain;charset=utf-8'}), `${page.account.summary.label || page.account.id}-${this.title}.txt`)});
|
||||
this.lines = el('div', {class:'log-lines task-log-lines', role:'log', 'aria-live':'off', 'aria-label':`${this.title}内容`, tabindex:0,
|
||||
onScroll:() => {
|
||||
if (this.view.follow && this.lines.scrollHeight - this.lines.scrollTop - this.lines.clientHeight > 24) this.setFollow(false);
|
||||
}});
|
||||
this.empty = el('p', {class:'task-log-empty muted', text:'暂无日志;运行任务后将在此显示。'});
|
||||
this.body = el('div', {id:`${id}-body`, class:'task-log-body'},
|
||||
el('div', {class:'task-log-controls'}, el('label', {}, el('span', {text:'搜索'}), this.search),
|
||||
el('label', {}, el('span', {text:'级别'}), this.level), this.follow, save, clear), el('div', {class:'task-log-viewport'}, this.lines, this.empty),
|
||||
el('p', {class:'task-log-help muted', text:`${page.key === 'login' ? '含登录和常规记录(旧记录、未知分类);' : page.key === 'ranch' ? '含潜能突破和牧场记录;' : ''}仅清空本账号本页显示;下载遵循日志筛选。最多显示最近 600 条。`}));
|
||||
this.root = el('section', {class:'task-log-panel', 'data-task-log':page.key, 'aria-labelledby':`${id}-heading`},
|
||||
el('div', {class:'log-toolbar task-log-heading'}, this.heading, this.status, el('span', {class:'spacer'}), this.toggle), this.body);
|
||||
page.root.classList.add('has-task-log');
|
||||
page.root.append(this.root);
|
||||
}
|
||||
|
||||
entries() { return visibleLogs(this.log, this.view, this.page.key); }
|
||||
active() { return !this.page.root.hidden && !this.page.root.closest('[hidden]'); }
|
||||
|
||||
setHidden(hidden) {
|
||||
this.body.hidden = hidden;
|
||||
this.toggle.textContent = hidden ? '显示' : '隐藏';
|
||||
this.toggle.setAttribute('aria-label', `${hidden ? '显示' : '隐藏'}${this.title}`);
|
||||
this.toggle.setAttribute('aria-expanded', String(!hidden));
|
||||
this.render();
|
||||
}
|
||||
|
||||
setFollow(follow) {
|
||||
this.view.follow = follow;
|
||||
this.view.seenThrough = this.log.highWater;
|
||||
this.follow.textContent = follow ? '暂停跟随' : '跟随最新';
|
||||
this.follow.setAttribute('aria-label', `${this.title}:${follow ? '暂停自动滚动' : '跟随最新日志'}`);
|
||||
this.follow.setAttribute('aria-pressed', String(follow));
|
||||
this.render();
|
||||
if (follow && !this.body.hidden) this.lines.scrollTop = this.lines.scrollHeight;
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.active()) return;
|
||||
const entries = this.entries();
|
||||
const pending = !this.view.follow ? entries.filter(entry => entry.seq > this.view.seenThrough).length : 0;
|
||||
const status = `${this.title}:${entries.length} 条${entries.length > RENDER_LIMIT ? '(显示最近 600 条)' : ''};${this.view.follow ? '跟随最新' : '已暂停跟随'}${pending ? `,新增 ${pending} 条` : ''}`;
|
||||
if (this.status.textContent !== status) this.status.textContent = status;
|
||||
if (this.body.hidden) return;
|
||||
const token = JSON.stringify([this.log.revision, this.log.debug, this.view.clearedThrough, this.view.search, this.view.level]);
|
||||
if (token !== this.rendered) {
|
||||
syncLogLines(this.lines, entries, {follow:this.view.follow});
|
||||
this.rendered = token;
|
||||
this.empty.hidden = entries.length > 0;
|
||||
this.empty.textContent = this.view.search || this.view.level ? '没有符合当前筛选的日志。' : '暂无日志;运行任务后将在此显示。';
|
||||
}
|
||||
if (this.view.follow) this.view.seenThrough = this.log.highWater;
|
||||
}
|
||||
}
|
||||
|
||||
export function attachTaskLog(page) {
|
||||
if (Object.hasOwn(titles, page.key)) page.taskLog = new TaskLogPanel(page);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user