保存前端调整前的当前状态
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
10 files changed
+204
-3
No files matched your search
+41
-1
@@ -1,6 +1,24 @@
|
||||
'use strict';
|
||||
const $=id=>document.getElementById(id);
|
||||
let token='',state=null,loadedKey='',refreshing=false;
|
||||
const selectedJobs=new Set();
|
||||
let removing=false;
|
||||
function removalBlocked(job,run){
|
||||
if(job.id===run.active)return '当前任务请先通过“人工核对 / 处理”核对并移出';
|
||||
if(['user_submitting','submit_unknown'].includes(job.state)||(job.submitted_at&&!['published','accepted_pending_moderation'].includes(job.state)))return '请先核对提交结果并处理';
|
||||
return '';
|
||||
}
|
||||
function updateSelection(){
|
||||
if(!state)return;
|
||||
const eligible=state.jobs.filter(job=>!removalBlocked(job,state.run));
|
||||
const eligibleIds=new Set(eligible.map(job=>job.id));
|
||||
$('selected-count').textContent=`已选 ${selectedJobs.size} 篇`;
|
||||
$('remove-selected').disabled=removing||state.run.running||!selectedJobs.size;
|
||||
$('select-all').disabled=removing||!eligible.length;
|
||||
$('select-all').checked=eligible.length>0&&eligible.every(job=>selectedJobs.has(job.id));
|
||||
$('select-all').indeterminate=selectedJobs.size>0&&!$('select-all').checked;
|
||||
document.querySelectorAll('.job-select').forEach(input=>{input.checked=selectedJobs.has(input.value);input.disabled=removing||!eligibleIds.has(input.value);});
|
||||
}
|
||||
const labels={queued:'待处理',preparing:'准备中',importing:'上传与导入',formatting:'排版中',awaiting_user_review:'等待人工审核',user_submitting:'已观察到人工提交',submit_unknown:'发布结果待核对',accepted_pending_moderation:'已受理 · 审核中',published:'已确认公开',needs_attention:'需要处理',cancelled:'已移出',skipped:'已跳过',rejected:'网站明确拒绝'};
|
||||
function notice(message){$('notice').hidden=!message;$('notice').textContent=message;}
|
||||
async function api(route,body={}) {
|
||||
@@ -11,12 +29,18 @@ function action(id,fn){$(id).addEventListener('click',async()=>{const button=$(i
|
||||
function text(tag,value,className){const e=document.createElement(tag);e.textContent=value;if(className)e.className=className;return e;}
|
||||
function render(data){
|
||||
state=data;const {jobs,run,download}=data;
|
||||
const eligibleIds=new Set(jobs.filter(job=>!removalBlocked(job,run)).map(job=>job.id));
|
||||
for(const id of selectedJobs)if(!eligibleIds.has(id))selectedJobs.delete(id);
|
||||
$('total').textContent=jobs.length;$('review').textContent=jobs.filter(j=>j.state==='awaiting_user_review').length;
|
||||
$('accepted').textContent=jobs.filter(j=>['published','accepted_pending_moderation'].includes(j.state)).length;
|
||||
$('batch').textContent=run.batch?`${run.batch.count} / ${run.batch.target}`:'—';$('account').textContent=run.batch?run.batch.account.name:'尚未绑定账号';
|
||||
$('run-state').textContent=run.running?'流程运行中':'流程已暂停';$('run-reason').textContent=run.reason;
|
||||
$('run-light').classList.toggle('gray',!run.running);$('empty').hidden=jobs.length>0;
|
||||
$('jobs').replaceChildren(...jobs.map(job=>{
|
||||
const selection=document.createElement('td'),checkbox=document.createElement('input');
|
||||
checkbox.type='checkbox';checkbox.className='job-select';checkbox.value=job.id;
|
||||
checkbox.setAttribute('aria-label','选择文章:'+job.title);checkbox.title=removalBlocked(job,run)||'选择此文章';
|
||||
checkbox.onchange=()=>{checkbox.checked?selectedJobs.add(job.id):selectedJobs.delete(job.id);updateSelection();};selection.append(checkbox);
|
||||
const tr=document.createElement('tr'),title=document.createElement('td');title.append(text('div',job.title),text('small',`${job.image_count} 张配图 · ${job.source}`));if(job.original_title!==job.title)title.append(text('small','已缩短标题,原题:'+job.original_title));
|
||||
const status=document.createElement('td');status.append(text('span',labels[job.state]||job.state,'badge'));if(job.error)status.append(text('small',job.error));
|
||||
for(const issue of job.integrity_issues||[])status.append(text('small',issue));
|
||||
@@ -45,8 +69,9 @@ function render(data){
|
||||
try{await api('resolve',{id:job.id,confirmed_not_accepted:true,retry:again});await refresh();}catch(error){notice(error.message);}
|
||||
};result.append(retry);
|
||||
}
|
||||
tr.append(title,status,account,result);return tr;
|
||||
tr.append(selection,title,status,account,result);return tr;
|
||||
}));
|
||||
updateSelection();
|
||||
const dlLabels={idle:'等待开始',running:'下载中',completed:'下载完成',partial:'未达到目标',cancelled:'已停止',error:'下载出错'};
|
||||
$('download-state').textContent=dlLabels[download.status]||download.status;$('download-progress').textContent=`已保存 ${download.saved}/${download.target} 篇 · 跳过 ${download.skipped} · 失败 ${download.failed}`;
|
||||
$('progress').value=download.target?Math.floor(download.saved/download.target*100):0;
|
||||
@@ -55,6 +80,21 @@ function render(data){
|
||||
$('clients').textContent=data.clients.map(c=>`${c.account?.name||'未识别账号'} · 换号插件${c.extension?.ready?'已就绪':'未连接或需更新'}`).join('\n')||'没有在线执行标签';
|
||||
}
|
||||
async function refresh(){if(refreshing||!token)return;refreshing=true;try{render(await api('state'));}catch(error){notice(error.message);$('run-state').textContent='本地服务连接中断';}finally{refreshing=false;}}
|
||||
$('select-all').onchange=()=>{
|
||||
const checked=$('select-all').checked;
|
||||
for(const job of state?.jobs||[])if(!removalBlocked(job,state.run)){checked?selectedJobs.add(job.id):selectedJobs.delete(job.id);}
|
||||
updateSelection();
|
||||
};
|
||||
$('remove-selected').onclick=async()=>{
|
||||
if(removing||!selectedJobs.size)return;
|
||||
if(state.run.running){notice('请先暂停流程,再移除文章');return;}
|
||||
const ids=[...selectedJobs];
|
||||
if(!confirm(`确定从文章队列移除所选的 ${ids.length} 篇文章?\n原始文章和图片文件、已受理去重记录会保留。未受理文章以后可通过扫描目录重新加入。`))return;
|
||||
removing=true;updateSelection();
|
||||
try{const result=await api('remove',{ids});for(const id of ids)selectedJobs.delete(id);notice(`已从队列移除 ${result.removed} 篇文章`);await refresh();}
|
||||
catch(error){notice(error.message);}
|
||||
finally{removing=false;updateSelection();}
|
||||
};
|
||||
action('pair',async()=>{const value=await api('pair');$('pair-code').hidden=false;$('pair-code').type='text';$('pair-code').value=value.token;$('pair-code').select();});
|
||||
action('channels',async()=>{const value=await api('channels',{key:$('key').value.trim()});loadedKey=$('key').value.trim();$('channel').replaceChildren(...value.channels.map(c=>new Option(c,c)));});
|
||||
$('key').oninput=()=>{loadedKey='';$('channel').replaceChildren(new Option('请重新获取频道',''));};
|
||||
|
||||
Reference in new issue
Block a user