perf: cache static assets and validate only requested refresh regions
This commit is contained in:
1 parent
f317314a3c
commit
73773f9526
31 files changed
+554
-41
No files matched your search
@@ -16,10 +16,10 @@ window.OrderViews=(()=>{
|
||||
function open(row,trigger){const f=(label,value)=>window.RecordUi.field(esc,label,value);detail.show('<dl class="record-detail-grid">'+f('流水号',row.serialNum)+f('流程',row.processName)+f('流程版本',row.processVersion)+f('节点',row.activityName)+f('到达类型',row.kind==='todo'?'待办到达记录':'待阅到达记录')+f('到达时间',formatDate(row.arrivedAt))+f('来源连接',row.origin.name)+f('来源账号',row.origin.identity||'账号未记录')+f('负责人',row.origin.owner)+f('来源状态',row.origin.status==='archived'?'历史归档':row.origin.enabled?'现有连接':'现有连接 · 已停用')+f('来源归档时间',row.origin.archivedAt?formatDate(row.origin.archivedAt):row.origin.status==='archived'?'未记录':'—')+(row.origin.missing?f('来源说明','来源信息缺失,保留原连接标识:'+row.connectionId):'')+f('首次采集',formatDate(row.firstSeenAt))+f('最近观察',formatDate(row.lastSeenAt))+f('任务标识',row.taskId)+f('完整标题',row.subject)+'</dl>',trigger);}
|
||||
function draw(data){const host=container.querySelector('[data-arrival-list]');host.innerHTML=data.items.length?'<div class="table-responsive"><table class="table table-vcenter table-hover card-table record-ledger"><thead><tr><th scope="col">流水号/流程</th><th scope="col" class="record-node">节点/类型</th><th scope="col">标题摘要</th><th scope="col" class="record-source">来源</th><th scope="col" class="record-time">到达时间</th><th scope="col">详情</th></tr></thead><tbody>'+data.items.map((row,index)=>'<tr data-arrival-row><td class="record-identity"><strong>'+esc(row.serialNum||'—')+'</strong><div class="small text-secondary">'+esc(row.processName)+'</div><div class="record-inline-source small text-secondary">'+esc(row.origin.name)+(row.origin.status==='archived'?' · 历史归档':row.origin.enabled?'':' · 已停用')+'</div><div class="record-inline-time small text-secondary">'+esc(formatDate(row.arrivedAt))+'</div><div class="record-inline-summary record-summary small">'+esc(row.subject||'—')+'</div></td><td class="record-node">'+esc(row.activityName==='sysInform'?'知会':row.activityName||'—')+'<div class="small text-secondary">'+(row.kind==='todo'?'待办到达':'待阅到达')+'</div></td><td class="record-summary-cell"><div class="record-summary">'+esc(row.subject||'—')+'</div></td><td class="record-source"><div>'+esc(row.origin.name)+'</div><span class="badge bg-'+(row.origin.status==='archived'?'secondary':row.origin.enabled?'green':'yellow')+'-lt">'+(row.origin.status==='archived'?'历史归档':row.origin.enabled?'现有连接':'已停用')+'</span></td><td class="record-time small text-secondary text-nowrap">'+esc(formatDate(row.arrivedAt))+'</td><td class="record-action"><button type="button" class="btn btn-sm" data-arrival-detail="'+index+'">查看详情</button></td></tr>').join('')+'</tbody></table></div>':'<div class="empty py-5"><p class="empty-title">暂无匹配的到达记录</p><p class="empty-subtitle text-secondary">可调整日期、业务范围或查看历史归档。</p></div>';host.querySelectorAll('[data-arrival-detail]').forEach(button=>button.onclick=()=>open(data.items[Number(button.dataset.arrivalDetail)],button));sourceOptions(data.sources);monitor();}
|
||||
const table=window.RecordTable.mount({view:'records',container,isActive:live,api,onCommit:next=>{filters=next;},render:draw,readDraft(){const scope=get('arrival-scope').value;return {q:get('arrival-query').value.trim(),scope,business:get('arrival-business').value,kind:get('arrival-kind').value,connectionId:filters.scope!==scope?'':get('arrival-connection').value,from:get('arrival-from').value,to:get('arrival-to').value};},writeDraft(next){for(const [field,id]of Object.entries({q:'arrival-query',scope:'arrival-scope',business:'arrival-business',kind:'arrival-kind',connectionId:'arrival-connection',from:'arrival-from',to:'arrival-to'}))get(id).value=next[field];}});
|
||||
async function refresh(signal){try{statusController?.abort();statusController=new AbortController();const next=await api('/bpm-scan',undefined,{signal:AbortSignal.any([signal,statusController.signal]),ownerCheck:live});if(!live())return;status=next;monitor();const runs=status.runs.filter(r=>(filters.kind==='all'||(r.kind||'inform')===filters.kind)&&(!filters.connectionId||r.connectionId===filters.connectionId));if(runs[0]?.status==='error')container.querySelector('[data-monitor]').textContent+=' · 最近同步失败:'+runs[0].message;else if(runs[0]?.status==='success')container.querySelector('[data-monitor]').textContent+=' · 同步完成 '+formatDate(runs[0].finishedAt);}catch(e){if(!signal.aborted&&live())error('监听状态读取失败:'+e.message);}}
|
||||
const polling=window.PageLifecycle.poll(refresh,10000,{isActive:live});
|
||||
async function refresh(signal){try{statusController?.abort();statusController=new AbortController();const next=await api('/bpm-scan',undefined,{signal:AbortSignal.any([signal,statusController.signal]),ownerCheck:live});if(!live())return;status=next;monitor();const runs=status.runs.filter(r=>(filters.kind==='all'||(r.kind||'inform')===filters.kind)&&(!filters.connectionId||r.connectionId===filters.connectionId));if(runs[0]?.status==='error')container.querySelector('[data-monitor]').textContent+=' · 最近同步失败:'+runs[0].message;else if(runs[0]?.status==='success')container.querySelector('[data-monitor]').textContent+=' · 同步完成 '+formatDate(runs[0].finishedAt);}catch(e){throw e;}}
|
||||
const polling=window.PageLifecycle.regionPoll('bpm',{refresh,onError:e=>{if(live())error('监听状态读取失败:'+e.message);}},10000,{isActive:live});
|
||||
if(get('scan-now'))get('scan-now').onclick=async()=>{const button=get('scan-now');button.disabled=true;try{for(const c of candidates())for(const kind of filters.kind==='all'?['todo','inform']:[filters.kind])await api('/bpm-scan/run',{connectionId:c.id,kind});if(live()){notify('只读同步已启动。');await polling.refresh();}}catch(e){if(live())error(e.message+';已接受的同步请查看最新结果。');}finally{if(live())monitor();}};
|
||||
await Promise.all([table.ready,polling.run()]);
|
||||
await Promise.all([table.ready,polling.run().catch(async()=>{await refresh(new AbortController().signal).catch(e=>{if(live())error('监听状态读取失败:'+e.message);});})]);
|
||||
}
|
||||
return {configure,records};
|
||||
})();
|
||||
@@ -97,11 +97,11 @@ window.BpmLogin=(()=>{
|
||||
async function refreshStatus(signal){
|
||||
if(!live())return;
|
||||
try{
|
||||
if(accountBusy||mutationBusy)return;const request=statusRevision,next=await api('/workspace',undefined,{signal,ownerCheck:live});if(!live()||request!==statusRevision)return;
|
||||
if(accountBusy||mutationBusy)return false;const request=statusRevision,next=await api('/workspace',undefined,{signal,ownerCheck:live});if(!live()||request!==statusRevision)return false;
|
||||
const rows=next.connections||[],changed=JSON.stringify(connections.map(c=>[c.id,c.status,c.version,c.owner]))!==JSON.stringify(rows.map(c=>[c.id,c.status,c.version,c.owner]));connections=rows;
|
||||
if(changed&&!remote&&!container.querySelector('[data-account-form]')&&!window.PageLifecycle?.dirty())drawCards();
|
||||
else for(const c of connections){const badge=container.querySelector('[data-connection-status="'+c.id+'"]'),health=container.querySelector('[data-connection-health="'+c.id+'"]');if(badge)badge.innerHTML=status(c);if(health){const expanded=health.querySelector('details')?.open;health.innerHTML=observations(c);if(expanded)health.querySelector('details').open=true;}}
|
||||
}catch{}
|
||||
}catch(error){throw error;}
|
||||
}
|
||||
function ownerForm(c){
|
||||
if(user.role!=='admin')return '';
|
||||
@@ -194,12 +194,12 @@ window.BpmLogin=(()=>{
|
||||
input.onkeydown=keydown;surface.onkeydown=event=>{if(event.target!==input)keydown(event);};surface.onpaste=event=>{if(event.target!==input)input.onpaste(event);};
|
||||
}
|
||||
try{
|
||||
data=await api('/workspace');if(!live())return;connections=data.connections||[];
|
||||
let initial,initialError;try{initial=await window.PageLifecycle.validateRegion('bpm');}catch(error){initialError=error;}data=await api('/workspace');if(!live())return;connections=data.connections||[];
|
||||
container.innerHTML=`<div data-bpm-feedback hidden role="alert"></div><div class="connection-layout bpm-layout"><div><div id="bpm-list"></div></div>${user.role==='admin'?`<form class="card" id="connection-create"><div class="card-header"><h2 class="card-title">添加 BPM 连接</h2></div><div class="card-body"><div class="mb-3"><label class="form-label required" for="connection-name">连接名称</label><input class="form-control" id="connection-name" required maxlength="100" placeholder="例如:业务团队 BPM"></div><div><label class="form-label required" for="connection-owner">负责人</label><select class="form-select" id="connection-owner" required><option value="">请选择负责人</option>${(data.members||[]).filter(m=>m.role!=='viewer').map(m=>`<option value="${esc(m.username)}">${esc(m.username)}</option>`).join('')}</select></div></div><div class="card-footer text-end"><button class="btn btn-primary" type="submit">创建连接</button></div></form>`:''}</div><div id="bpm-remote" aria-live="polite"></div><div id="bpm-sync-settings"></div>`;
|
||||
if(user.role==='admin')$('#connection-create').onsubmit=async event=>{event.preventDefault();const button=event.target.querySelector('button[type=submit]');button.disabled=true;try{const result=await api('/connections',{name:$('#connection-name').value.trim(),owner:$('#connection-owner').value});if(!live())return;++statusRevision;connections.unshift(result.connection||result);event.target.reset();drawCards();feedback('连接已创建。','success');}catch(error){feedback(error.message);}finally{if(live())button.disabled=false;}};
|
||||
drawCards();
|
||||
connections.filter(c=>c.status!=='disabled'&&authorized(c)).forEach(c=>loadAccount(c.id).then(refreshAccountSummary).catch(error=>feedback(error.message)));
|
||||
statusTimer=window.PageLifecycle.poll(refreshStatus,5000,{isActive:live});
|
||||
statusTimer=window.PageLifecycle.regionPoll('bpm',{refresh:refreshStatus,onError:error=>feedback('状态读取失败:'+error.message+';保留上次状态,请刷新重试。')},5000,{isActive:live,initial});if(initialError)feedback('状态读取失败:'+initialError.message+';正在显示已读取的连接,请刷新重试。');
|
||||
await window.BpmSyncSettings?.mount($('#bpm-sync-settings'),{api,user,notify,isActive:live});
|
||||
}catch(error){if(live())throw error;}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user