feat(records): add source history and Tabler record ledgers
This commit is contained in:
1 parent
1421edd6d4
commit
20bb68615f
27 files changed
+291
-91
No files matched your search
@@ -47,3 +47,8 @@
|
||||
.rule-workbench-grid{grid-template-columns:280px minmax(0,1fr);gap:24px}.rule-category-directory{overflow:hidden}.rule-category-directory .card-header{padding:18px}.rule-category-list{max-height:calc(100vh - 355px);min-height:220px;overflow:auto;overscroll-behavior:contain;padding:6px}.rule-category-item{border:1px solid transparent;border-radius:10px;margin:4px 0;overflow:hidden}.rule-category-item.is-selected{background:#f0f7f3;border-color:#b8d5c5}.rule-category-select{display:block;width:100%;border:0;background:none;text-align:left;padding:13px 12px 6px;color:inherit;overflow-wrap:anywhere}.rule-category-select:hover{background:#28745b08}.rule-category-select:focus-visible{outline:2px solid #28745b;outline-offset:-2px;border-radius:8px}.rule-category-select strong{display:block;font-size:.86rem;font-weight:600;line-height:1.6}.rule-category-kind{display:block;font-size:.65rem;color:#83928a;margin-bottom:4px;letter-spacing:.03em}.rule-category-meta{display:block;font-size:.69rem;color:#79857e;margin-top:6px}.rule-category-readiness,.rule-category-ready{display:block;font-size:.69rem;margin-top:5px;color:#a47430}.rule-category-ready{color:#368266}.rule-category-control{display:flex;justify-content:space-between;align-items:center;padding:7px 12px 12px;gap:12px}.rule-category-control .small{font-size:.7rem}.rule-category-control .form-switch .form-check-input{width:2.25rem;height:1.25rem;cursor:pointer;margin:0;float:none}.rule-category-control .form-switch{min-height:0;padding:0;display:flex}.rule-category-control .form-check-input:checked{background-color:#28745b;border-color:#28745b}.rule-category-control .form-check-input:disabled{cursor:default}.rule-recognition-flow{display:flex;align-items:center;gap:12px;flex-wrap:wrap;font-size:.8rem}.rule-recognition-flow span:nth-child(odd){padding:8px 12px;border:1px solid #dfe9e2;background:#f8fbf9;border-radius:8px}.rule-recognition-coverage,.rule-empty-recognition{font-size:.8rem;padding:14px;border-radius:8px;background:#f5f7fa;border:1px solid #e9edf1;line-height:1.8}.rule-archive-destination,.rule-folder-browser{background:#f8faf9;border:1px solid #e3eae5;border-radius:8px;padding:12px;font-size:.8rem}.rule-folder-browser .list-group{max-height:260px;overflow:auto}.rule-recognition-check select{flex-basis:65%;width:auto;min-width:0}.rule-recognition-check .btn{align-self:start}.rule-result-heading{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.rule-business-summary{white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word;font-size:.8rem;background:#f7f9fb;border-radius:8px;padding:12px}.rule-editor-column{max-width:1080px}.rule-effect-preview dl{margin-top:16px}.rule-config-section summary{font-size:.8rem;color:#53645b;cursor:pointer}.rule-save-bar>span{flex:1 1 300px}.rule-category-directory .card-footer{line-height:1.8;font-size:.7rem}@media(max-width:1350px){.rule-workbench-grid{grid-template-columns:250px minmax(0,1fr)}}@media(max-width:991px){.rule-workbench-grid{grid-template-columns:minmax(0,1fr)}.rule-category-list{max-height:280px;min-height:0;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px}.rule-category-item{margin:0}.rule-category-directory{position:static}.rule-category-directory .card-footer{display:none}.rule-editor-column{max-width:100%}.rule-save-bar>span{flex-basis:100%}}@media(max-width:440px){.rule-category-select{padding:10px 9px 5px}.rule-category-select strong{font-size:.78rem}.rule-category-meta{font-size:.65rem}.rule-category-control{padding:6px 9px 10px}.rule-recognition-flow{gap:7px;font-size:.7rem}.rule-recognition-flow span:nth-child(odd){padding:6px 8px}.rule-recognition-check select{flex-basis:100%;width:100%}}
|
||||
|
||||
.rule-scope-row{grid-template-columns:repeat(2,minmax(0,1fr))}.rule-scope-node-control{flex-wrap:nowrap;align-items:stretch}.rule-scope-node-control>.form-select{min-width:0}.rule-scope-node-control>.rule-scope-remove{flex:0 0 38px;width:38px;height:auto;min-width:0;min-height:0;padding:0;font-size:22px;line-height:1;border-color:#dfe6eb;color:var(--tblr-secondary);background:#fff;display:inline-flex;align-items:center;justify-content:center;border-radius:0 7px 7px 0}.rule-scope-node-control>.rule-scope-remove:hover{color:#b42318;background:#fff5f4}.rule-scope-node-control>.rule-scope-remove:focus-visible{outline:2px solid #73a591;outline-offset:2px;z-index:3}@media(max-width:991px){.rule-scope-row{grid-template-columns:minmax(0,1fr)}}
|
||||
|
||||
/* Record ledgers reuse Tabler tables, segmented navigation and offcanvas. */
|
||||
.record-monitor{margin-bottom:16px;padding:10px 14px;background:var(--tblr-bg-surface);border:1px solid var(--tblr-border-color);border-radius:8px}.record-filters{border-bottom:1px solid var(--tblr-border-color)}.record-ledger td{padding-top:13px;padding-bottom:13px}.record-summary-cell{min-width:200px;max-width:400px}.record-summary{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;line-height:1.5;overflow-wrap:anywhere}.record-detail{--tblr-offcanvas-width:560px;width:min(560px,100vw)!important}.record-detail-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px 24px}.record-detail-field{min-width:0}.record-detail-field:last-child{grid-column:1/-1}.record-detail-field dt{font-size:.8rem;font-weight:400;color:var(--tblr-secondary);margin-bottom:5px}.record-detail-field dd{margin:0;white-space:pre-wrap;overflow-wrap:anywhere}.record-receipt{padding:12px 0;border-top:1px solid var(--tblr-border-color);overflow-wrap:anywhere}@media(max-width:575px){.record-detail-grid{grid-template-columns:1fr}.record-ledger{font-size:.85rem}.record-monitor{line-height:1.7}}
|
||||
|
||||
.record-identity{min-width:140px}.record-identity strong{display:block;max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.record-node{min-width:115px}.record-source{min-width:120px}.record-action{white-space:nowrap}.record-inline-source,.record-inline-time,.record-inline-summary,.record-inline-export{display:none}@media(max-width:991px){.record-ledger .record-node,.record-ledger .record-source{display:none}.record-inline-source{display:block;margin-top:4px;max-width:200px;overflow-wrap:anywhere}}@media(max-width:767px){.record-ledger .record-time{display:none}.record-inline-time{display:block;margin-top:3px;font-size:.72rem}.record-identity{min-width:140px}}@media(max-width:575px){.record-ledger .record-summary-cell,.record-ledger .record-export-state,.record-ledger .record-file{display:none}.record-inline-summary{display:-webkit-box;margin-top:7px}.record-inline-export{display:block;margin-top:5px}.record-ledger .record-identity{min-width:0}.record-identity strong{max-width:200px}.record-pdf-actions{flex-direction:column;align-items:stretch}.record-action{width:90px}.record-ledger td{padding-left:14px;padding-right:14px}}
|
||||
+7
-14
@@ -5,7 +5,7 @@ const formatDate=value=>{const date=new Date(value);return value&&!Number.isNaN(
|
||||
const roles={admin:'管理员',operator:'操作员',viewer:'只读成员'};
|
||||
const statusMap={running:['处理中','blue'],success:['已完成','green'],error:['失败','red'],interrupted:['已中断','orange']};
|
||||
let currentUser=null,settings=null,currentView='overview',overview=null,refreshTimer=null,viewGeneration=0,historyIndex=0,historyTransition=null,automationRevision=0,overviewRevision=0;
|
||||
const views={'order-notifications':['通知总览','查看当前发送时段、待发订单及接入阻塞'],'notification-execution':['订单执行','扫描真实待办,查看归档进度与受控恢复'],'notification-orders':['通知订单','查看订单分类、归档证据及所属邮件批次'],'notification-batches':['待发批次','按发送时段检查分类汇总和冻结内容'],'notification-history':['发送记录','核对发送结果、冻结内容和人工恢复记录'],'notification-settings':['发送设置','维护发件邮箱、邮件限制与自动通知开关'],'rule-fields':['字段映射','从真实 BPM 样本选择字段,按表单版本保存对应关系'],'assistant-settings':['助手设置','配置 ZCode 运行包、模型与受控操作权限'],'business-settings':['业务设置','维护 Excel 分类规则、收件人和真实字段对应'],'system-settings':['系统设置','集中管理服务连接、运行维护和团队权限'],account:['个人账号','维护自己的登录密码与访问安全'],'order-rules':['分类通知规则','按 Excel 类别维护匹配、归档、收件人与通知正文'],health:['系统健康','查看服务守护、登录自启和各模块最近检查结果'],assistant:['ZCode 助手','对话查询运行状态、分析异常与执行受控恢复'],storage:['存储服务器','配置 SMB 共享目录、检查连接与管理 PDF 归档'],notifications:['兼容业务通知','原来源映射、产业接口人与通知队列'],overview:['工作总览','团队工作一目了然,每一次协作都有记录'],calendar:['业务日历','按公司实际安排设置工作日、休息日与暂停日期'],exceptions:['异常待办','认领、转交和跟进异常'],bpm:['BPM 连接','管理连接及负责人'],supervisor:['运行监管','配置负责人、通知方式与重试上限'],records:['订单与导出记录','查询已经采集的订单,下载已完成的 PDF'],rules:['分类通知规则','按 Excel 类别维护匹配、归档、收件人与通知正文'],schedule:['发送计划','设置每日两个发送时间及周末安排'],templates:['邮件模板','管理模板及 Excel 类别关联;收件名单在分类规则维护'],mail:['邮箱管理','维护托管邮箱、模板收信与连接状态'],connections:['服务接入','查看各个环节的接入情况'],users:['团队账号','为局域网内的同事分配访问权限'],audit:['操作记录','查看配置变更和导出任务的处理记录']};
|
||||
const views={'records-pdf':['订单与导出记录','查询PDF导出结果、文件可用性与存储归档记录'],'order-notifications':['通知总览','查看当前发送时段、待发订单及接入阻塞'],'notification-execution':['订单执行','扫描真实待办,查看归档进度与受控恢复'],'notification-orders':['通知订单','查看订单分类、归档证据及所属邮件批次'],'notification-batches':['待发批次','按发送时段检查分类汇总和冻结内容'],'notification-history':['发送记录','核对发送结果、冻结内容和人工恢复记录'],'notification-settings':['发送设置','维护发件邮箱、邮件限制与自动通知开关'],'rule-fields':['字段映射','从真实 BPM 样本选择字段,按表单版本保存对应关系'],'assistant-settings':['助手设置','配置 ZCode 运行包、模型与受控操作权限'],'business-settings':['业务设置','维护 Excel 分类规则、收件人和真实字段对应'],'system-settings':['系统设置','集中管理服务连接、运行维护和团队权限'],account:['个人账号','维护自己的登录密码与访问安全'],'order-rules':['分类通知规则','按 Excel 类别维护匹配、归档、收件人与通知正文'],health:['系统健康','查看服务守护、登录自启和各模块最近检查结果'],assistant:['ZCode 助手','对话查询运行状态、分析异常与执行受控恢复'],storage:['存储服务器','配置 SMB 共享目录、检查连接与管理 PDF 归档'],notifications:['兼容业务通知','原来源映射、产业接口人与通知队列'],overview:['工作总览','团队工作一目了然,每一次协作都有记录'],calendar:['业务日历','按公司实际安排设置工作日、休息日与暂停日期'],exceptions:['异常待办','认领、转交和跟进异常'],bpm:['BPM 连接','管理连接及负责人'],supervisor:['运行监管','配置负责人、通知方式与重试上限'],records:['订单与导出记录','查询已经采集的订单,下载已完成的 PDF'],rules:['分类通知规则','按 Excel 类别维护匹配、归档、收件人与通知正文'],schedule:['发送计划','设置每日两个发送时间及周末安排'],templates:['邮件模板','管理模板及 Excel 类别关联;收件名单在分类规则维护'],mail:['邮箱管理','维护托管邮箱、模板收信与连接状态'],connections:['服务接入','查看各个环节的接入情况'],users:['团队账号','为局域网内的同事分配访问权限'],audit:['操作记录','查看配置变更和导出任务的处理记录']};
|
||||
const pendingWrites=new Map();
|
||||
async function api(route,body,{signal,ownerCheck,managedOutcome=false}={}) {
|
||||
const originGeneration=viewGeneration,originUser=currentUser,originRevision=window.PageLifecycle?.revision;const originActive=()=>viewGeneration===originGeneration&¤tUser===originUser&&window.PageLifecycle?.revision===originRevision;const submission=window.PageLifecycle?.submission,hasBody=body!==undefined,write=hasBody&&route!=='/order-rules/field-mappings/propose',key=originGeneration+':'+originRevision+':'+route+':'+JSON.stringify(body);const pending=pendingWrites.get(key);if(write&&pending?.user===originUser)return pending.work;
|
||||
@@ -50,16 +50,9 @@ async function viewOverview(container,isActive=()=>true) {
|
||||
container.innerHTML=empty('工作台模块未加载','请刷新页面后重试。');
|
||||
}catch(error){if(ownsResponse())throw error;}
|
||||
}
|
||||
async function viewRecords(container,isActive=()=>true) {
|
||||
await window.OrderViews.records(container,isActive,viewPdfRecords);if(!isActive())return;const notice=document.createElement('div');notice.className='alert alert-info';notice.innerHTML='此处查询采集与 PDF 导出记录;分类和邮件批次请到 <a href="#notification-orders">通知订单</a> 查看。';container.prepend(notice);const history=document.createElement('section');history.className='mt-3';history.innerHTML='<button class="btn mb-3" id="legacy-notifications-open">查看旧通知历史(只读)</button><div id="legacy-notification-history"></div>';container.append(history);history.querySelector('button').onclick=async event=>{const button=event.currentTarget;button.disabled=true;try{await window.NotificationViews.history(history.querySelector('#legacy-notification-history'),isActive);}catch(error){if(isActive())notify(error.message,'danger');}finally{if(button.isConnected)button.disabled=false;}};
|
||||
}
|
||||
async function viewPdfRecords(container,isActive=()=>true) {
|
||||
const {jobs}=await api('/jobs');if(!isActive())return;
|
||||
container.innerHTML=`<div class="card"><div class="card-header gap-3 flex-wrap"><h2 class="card-title">导出记录 <span class="text-secondary">${jobs.length}</span></h2><div class="ms-auto d-flex gap-2"><input class="form-control" id="record-search" placeholder="搜索订单号、项目或型号" aria-label="搜索订单"><select class="form-select" id="record-status" aria-label="任务状态"><option value="">全部状态</option><option value="success">已完成</option><option value="running">处理中</option><option value="error">失败</option><option value="interrupted">已中断</option></select></div></div><div id="records-body"></div><div class="card-footer d-flex align-items-center"><span class="text-secondary" id="records-count"></span><div class="btn-list ms-auto"><button class="btn btn-sm" id="prev-page">上一页</button><button class="btn btn-sm" id="next-page">下一页</button></div></div></div>`;
|
||||
let page=0;
|
||||
function render(){const search=document.querySelector('#record-search').value.toLowerCase().trim();const status=document.querySelector('#record-status').value;const filtered=jobs.filter(job=>(!status || job.status===status) && (!search || [job.metadata?.order,job.metadata?.project,job.metadata?.model,job.metadata?.serial,job.filename].join(' ').toLowerCase().includes(search)));page=Math.max(0,Math.min(page,Math.ceil(filtered.length/25)-1));const selected=filtered.slice(page*25,page*25+25);document.querySelector('#records-body').innerHTML=selected.length?jobTable(selected):empty('暂无匹配记录','调整搜索条件,或先从订单页面导出一份通知书。');document.querySelector('#records-count').textContent=`共 ${filtered.length} 条 · 第 ${page+1} 页`;document.querySelector('#prev-page').disabled=page===0;document.querySelector('#next-page').disabled=(page+1)*25>=filtered.length;}
|
||||
document.querySelector('#record-search').oninput=()=>{page=0;render();};document.querySelector('#record-status').onchange=()=>{page=0;render();};document.querySelector('#prev-page').onclick=()=>{page--;render();};document.querySelector('#next-page').onclick=()=>{page++;render();};render();
|
||||
}
|
||||
function recordHistory(container,isActive){const history=document.createElement('section');history.className='mt-3';history.innerHTML='<button class="btn btn-sm mb-3" id="legacy-notifications-open">查看旧通知历史(只读)</button><div id="legacy-notification-history"></div>';container.append(history);history.querySelector('button').onclick=async event=>{const button=event.currentTarget;button.disabled=true;try{await window.NotificationViews.history(history.querySelector('#legacy-notification-history'),isActive);}catch(error){if(isActive())notify(error.message,'danger');}finally{if(button.isConnected)button.disabled=false;}};}
|
||||
async function viewRecords(container,isActive=()=>true){await window.OrderViews.records(container,isActive);if(isActive())recordHistory(container,isActive);}
|
||||
async function viewPdfRecords(container,isActive=()=>true){await window.PdfRecordViews.records(container,isActive);if(isActive())recordHistory(container,isActive);}
|
||||
async function viewSchedule(container,isActive=()=>true) {
|
||||
const loaded=await api('/settings');if(!isActive())return;let draft=loaded;const s=draft.schedule;const disabled=currentUser.role!=='admin'?'disabled':'';
|
||||
container.innerHTML=`<div class="settings-width">${readOnlyNote()}<div class="alert alert-info">收件人及类别要求在 <a href="#order-rules">分类通知规则</a> 维护。按北京时间和业务日历生成发送时段,更早历史不自动补发。</div><form id="schedule-form"><div class="card"><div class="card-header"><h2 class="card-title">每日两次通知</h2><span class="badge bg-blue-lt">北京时间</span></div><div class="card-body"><div class="row g-4"><div class="col-sm-6"><label class="form-label required" for="time-first">第一个发送时间</label><input class="form-control schedule-time" id="time-first" type="time" value="${s.times[0]}" required ${disabled}></div><div class="col-sm-6"><label class="form-label required" for="time-second">第二个发送时间</label><input class="form-control schedule-time" id="time-second" type="time" value="${s.times[1]}" required ${disabled}></div><div class="col-12"><label class="form-check form-switch"><input class="form-check-input" type="checkbox" id="weekends" ${s.weekends?'checked':''} ${disabled}><span class="form-check-label">周六、周日照常发送</span></label><div class="form-hint">关闭后仅在周一至周五发送;公司调休与暂停安排可在 <a href="#calendar">业务日历</a> 中按日期覆盖。</div></div></div></div><div class="card-footer d-flex align-items-center"><span class="text-secondary small">配置供整个团队共用</span>${currentUser.role==='admin'?'<button class="btn btn-primary ms-auto" type="submit">保存发送计划</button>':''}</div></div></form></div>`;
|
||||
@@ -103,12 +96,12 @@ async function renderView() {
|
||||
window.AppNavigation.renderTabs(document.querySelector('#settings-tabs'),{id:currentView,user:currentUser,views,esc});
|
||||
document.querySelectorAll('[data-view]').forEach(link=>{const active=link.dataset.view===(section||currentView);link.classList.toggle('active',active);if(active)link.setAttribute('aria-current','page');else link.removeAttribute('aria-current');});
|
||||
const sectionTitle=section==='order-notifications'?'订单通知管理':views[section]?.[0];
|
||||
const breadcrumb=document.querySelector('#view-breadcrumb');breadcrumb.hidden=!section||section===currentView;breadcrumb.innerHTML=breadcrumb.hidden?'':`<a href="#${section}" aria-label="返回${sectionTitle}">← ${sectionTitle}</a> <span class="text-secondary"> / ${esc(views[currentView][0])}</span>`;
|
||||
const breadcrumb=document.querySelector('#view-breadcrumb');breadcrumb.hidden=!section||section===currentView||section==='records';breadcrumb.innerHTML=breadcrumb.hidden?'':`<a href="#${section}" aria-label="返回${sectionTitle}">← ${sectionTitle}</a> <span class="text-secondary"> / ${esc(views[currentView][0])}</span>`;
|
||||
document.querySelector('#view-title').textContent=views[currentView][0];document.querySelector('#view-description').textContent=views[currentView][1];
|
||||
const container=document.querySelector('#content');container.innerHTML='<div class="card"><div class="card-body text-secondary">正在加载…</div></div>';
|
||||
|
||||
const notificationSections={'order-notifications':'workbench','notification-execution':'execution','notification-orders':'orders','notification-batches':'pending','notification-history':'history','notification-settings':'settings'};
|
||||
const fn={'rule-fields':(host,active)=>window.OrderRuleViews.render(host,active,'fields'),...Object.fromEntries(Object.entries(notificationSections).map(([route,section])=>[route,(host,active)=>window.OrderNotificationViews.render(host,active,section)])),'assistant-settings':window.AssistantViews?.settings,account:window.AccountViews?.account,'order-rules':window.OrderRuleViews?.render,health:window.HealthViews?.render,assistant:window.AssistantViews?.render,storage:window.StorageViews?.render,overview:viewOverview,calendar:window.WorkspaceViews?.calendar,exceptions:window.WorkspaceViews?.exceptions,bpm:window.WorkspaceViews?.bpm,records:viewRecords,schedule:viewSchedule,templates:viewTemplates,mail:window.MailViews?.accounts,users:window.AccountViews?.users,audit:viewAudit,rules:viewRules}[currentView];
|
||||
const fn={'rule-fields':(host,active)=>window.OrderRuleViews.render(host,active,'fields'),...Object.fromEntries(Object.entries(notificationSections).map(([route,section])=>[route,(host,active)=>window.OrderNotificationViews.render(host,active,section)])),'assistant-settings':window.AssistantViews?.settings,account:window.AccountViews?.account,'order-rules':window.OrderRuleViews?.render,health:window.HealthViews?.render,assistant:window.AssistantViews?.render,storage:window.StorageViews?.render,overview:viewOverview,calendar:window.WorkspaceViews?.calendar,exceptions:window.WorkspaceViews?.exceptions,bpm:window.WorkspaceViews?.bpm,records:viewRecords,'records-pdf':viewPdfRecords,schedule:viewSchedule,templates:viewTemplates,mail:window.MailViews?.accounts,users:window.AccountViews?.users,audit:viewAudit,rules:viewRules}[currentView];
|
||||
void updateAutomationStatus(isActive);
|
||||
try{window.PageLifecycle?.attach(container);const host=window.AppNavigation.isConfiguration(currentView)?configurationHost(container):container;await fn(host,isActive);if(isActive())window.PageLifecycle?.bind();}catch(error){if(isActive())container.innerHTML=`<div class="alert alert-danger">${esc(error.message)}</div>`;}
|
||||
}
|
||||
@@ -119,7 +112,7 @@ async function authScreen() {
|
||||
|
||||
}
|
||||
async function passwordChanged(actorId){if(currentUser&¤tUser.id!==actorId)return false;currentUser=null;++viewGeneration;clearInterval(refreshTimer);await window.PageLifecycle?.dispose();await window.BpmLogin?.dispose().catch(()=>{});await boot();return true;}
|
||||
function enter(){window.AccountViews?.configure({api,esc,formatDate,notify,user:currentUser,onPasswordChanged:passwordChanged});window.OrderRuleViews?.configure({api,esc,formatDate,notify,user:currentUser});window.OrderNotificationViews?.configure({api,esc,formatDate,notify,user:currentUser});window.HealthViews?.configure({api,esc,formatDate});window.AssistantViews?.configure({api,esc,formatDate,notify,user:currentUser});window.StorageViews?.configure({api,esc,formatDate,notify,user:currentUser});window.NotificationViews?.configure({api,esc,formatDate,notify,user:currentUser});window.OrderViews?.configure({api,esc,formatDate,notify,user:currentUser});window.MailViews?.configure({api,esc,formatDate,notify,user:currentUser});window.WorkspaceViews?.configure({api,esc,formatDate,notify,user:currentUser});shell();renderView();clearInterval(refreshTimer);refreshTimer=setInterval(()=>{if(currentUser&&!document.hidden){const statusGeneration=viewGeneration,statusUser=currentUser;void updateAutomationStatus(()=>statusGeneration===viewGeneration&&statusUser===currentUser);}if(currentUser && currentView==='overview' && !document.hidden){const generation=viewGeneration;viewOverview(document.querySelector('#content'),()=>generation===viewGeneration && !!currentUser && currentView==='overview').catch(()=>{});}},15000);}
|
||||
function enter(){window.PdfRecordViews?.configure({api,esc,formatDate,notify,user:currentUser});window.AccountViews?.configure({api,esc,formatDate,notify,user:currentUser,onPasswordChanged:passwordChanged});window.OrderRuleViews?.configure({api,esc,formatDate,notify,user:currentUser});window.OrderNotificationViews?.configure({api,esc,formatDate,notify,user:currentUser});window.HealthViews?.configure({api,esc,formatDate});window.AssistantViews?.configure({api,esc,formatDate,notify,user:currentUser});window.StorageViews?.configure({api,esc,formatDate,notify,user:currentUser});window.NotificationViews?.configure({api,esc,formatDate,notify,user:currentUser});window.OrderViews?.configure({api,esc,formatDate,notify,user:currentUser});window.MailViews?.configure({api,esc,formatDate,notify,user:currentUser});window.WorkspaceViews?.configure({api,esc,formatDate,notify,user:currentUser});shell();renderView();clearInterval(refreshTimer);refreshTimer=setInterval(()=>{if(currentUser&&!document.hidden){const statusGeneration=viewGeneration,statusUser=currentUser;void updateAutomationStatus(()=>statusGeneration===viewGeneration&&statusUser===currentUser);}if(currentUser && currentView==='overview' && !document.hidden){const generation=viewGeneration;viewOverview(document.querySelector('#content'),()=>generation===viewGeneration && !!currentUser && currentView==='overview').catch(()=>{});}},15000);}
|
||||
async function boot(){try{const setup=await api('/bootstrap/status');currentUser=(await api('/me')).user;enter();}catch{await authScreen();}}
|
||||
window.addEventListener('page-operation-error',event=>notify(event.detail.message,'danger'));
|
||||
window.addEventListener('pagehide',()=>{window.BpmLogin?.dispose({unload:true});});
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>订单通知中心</title><link href="/vendor/tabler.css" rel="stylesheet"><link href="/app.css" rel="stylesheet"><link href="/field-mappings.css" rel="stylesheet"></head>
|
||||
<body><div id="app"><div class="page page-center"><div class="container-tight py-4"><div class="card"><div class="card-body text-center">正在连接订单通知中心…</div></div></div></div></div><script src="/vendor/tabler.js" defer></script><script src="/bpm.js" defer></script><script src="/workspace.js" defer></script><script src="/mail-history.js" defer></script><script src="/mail.js" defer></script><script src="/orders.js" defer></script><script src="/storage-preview-host.js" defer></script><script src="/storage.js" defer></script><script src="/notifications.js" defer></script><script src="/field-sample-picker.js" defer></script><script src="/field-recognition-panel.js" defer></script><script src="/order-rules-scopes.js" defer></script><script src="/order-rules-resources.js" defer></script><script src="/order-rules-import.js" defer></script><script src="/order-rules-editor.js" defer></script><script src="/order-rules-preview.js" defer></script><script src="/field-mappings.js" defer></script><script src="/order-execution.js" defer></script><script src="/order-notifications-shared.js" defer></script><script src="/order-notifications.js" defer></script><script src="/order-rules.js" defer></script><script src="/health.js" defer></script><script src="/assistant.js" defer></script><script src="/account.js" defer></script><script src="/navigation.js" defer></script><script src="/page-lifecycle.js" defer></script><script src="/app.js" defer></script></body></html>
|
||||
<body><div id="app"><div class="page page-center"><div class="container-tight py-4"><div class="card"><div class="card-body text-center">正在连接订单通知中心…</div></div></div></div></div><script src="/vendor/tabler.js" defer></script><script src="/bpm.js" defer></script><script src="/workspace.js" defer></script><script src="/mail-history.js" defer></script><script src="/mail.js" defer></script><script src="/record-ui.js" defer></script><script src="/orders.js" defer></script><script src="/pdf-records.js" defer></script><script src="/storage-preview-host.js" defer></script><script src="/storage.js" defer></script><script src="/notifications.js" defer></script><script src="/field-sample-picker.js" defer></script><script src="/field-recognition-panel.js" defer></script><script src="/order-rules-scopes.js" defer></script><script src="/order-rules-resources.js" defer></script><script src="/order-rules-import.js" defer></script><script src="/order-rules-editor.js" defer></script><script src="/order-rules-preview.js" defer></script><script src="/field-mappings.js" defer></script><script src="/order-execution.js" defer></script><script src="/order-notifications-shared.js" defer></script><script src="/order-notifications.js" defer></script><script src="/order-rules.js" defer></script><script src="/health.js" defer></script><script src="/assistant.js" defer></script><script src="/account.js" defer></script><script src="/navigation.js" defer></script><script src="/page-lifecycle.js" defer></script><script src="/app.js" defer></script></body></html>
|
||||
+21
-47
@@ -1,52 +1,26 @@
|
||||
'use strict';
|
||||
window.OrderViews=(()=>{
|
||||
let api,esc,formatDate,notify,user,filters={q:'',connectionId:'',kind:'inform'};
|
||||
const configure=options=>{if(user?.username!==options.user.username)filters={q:'',connectionId:''};({api,esc,formatDate,notify,user}=options);};
|
||||
async function records(container,isActive,renderPdf){
|
||||
let initial;
|
||||
try{initial=await api('/bpm-scan');}catch(cause){
|
||||
if(!isActive())return;
|
||||
container.innerHTML=`<div class="alert alert-warning">${esc(cause.message)}</div><button class="btn mb-3" id="pdf-fallback">PDF 导出记录</button><div id="pdf-fallback-panel"></div>`;
|
||||
container.querySelector('#pdf-fallback').onclick=()=>renderPdf(container.querySelector('#pdf-fallback-panel'),isActive).catch(e=>notify(e.message,'danger'));return;
|
||||
}
|
||||
if(!isActive())return;
|
||||
let mode='arrivals',before='',loading=false,revision=0,watching=false,lastSignature='',status=initial;
|
||||
const names=new Map(initial.connections.map(c=>[c.id,c.name]));
|
||||
const nodeLabel=value=>value==='sysInform'?'知会':value||'—';
|
||||
container.innerHTML=`<div class="btn-list mb-3"><button class="btn btn-primary" id="arrivals-tab">流程到达记录</button><button class="btn" id="pdf-tab">PDF 导出记录</button></div><div id="order-panel"></div>`;
|
||||
const panel=container.querySelector('#order-panel');
|
||||
const active=()=>isActive()&&mode==='arrivals';
|
||||
function toolbar(){panel.innerHTML=`<section class="card mb-4"><div class="card-header flex-wrap gap-3"><div><h2 class="card-title mb-1">BPM 自动扫描</h2><div class="text-secondary small" id="scan-summary"></div></div><div class="ms-auto btn-list"><a class="btn" href="#bpm">管理连接</a>${user.role!=='viewer'?'<button class="btn btn-primary" id="scan-now">立即扫描</button>':''}</div></div><div class="card-body"><form id="arrival-filter" class="row g-3 align-items-end"><div class="col-md-4"><label class="form-label" for="arrival-query">搜索流程记录</label><input class="form-control" id="arrival-query" value="${esc(filters.q)}" placeholder="流水号、流程名、标题或发起人" maxlength="200"></div><div class="col-md-3"><label class="form-label" for="arrival-connection">BPM 连接</label><select class="form-select" id="arrival-connection"><option value="">全部连接</option>${initial.connections.map(c=>`<option value="${esc(c.id)}" ${c.id===filters.connectionId?'selected':''}>${esc(c.name)}${c.status==='disabled'?'(已停用)':''}</option>`).join('')}</select></div><div class="col-md-3"><label class="form-label" for="arrival-kind">到达类型</label><select class="form-select" id="arrival-kind"><option value="inform" ${filters.kind!=='todo'?'selected':''}>待阅记录</option><option value="todo" ${filters.kind==='todo'?'selected':''}>真实待办</option></select></div><div class="col-md-2"><button class="btn w-100" type="submit">查询</button></div></form><div id="scan-result" class="small mt-3" role="status"></div>${user.role==='admin'?`<details class="mt-3"><summary class="text-secondary">扫描设置</summary><form id="scan-config" class="d-flex flex-wrap align-items-center gap-3 mt-3"><label class="form-check form-switch mb-0"><input id="scan-enabled" class="form-check-input" type="checkbox" ${status.config.enabled?'checked':''}><span class="form-check-label">自动扫描</span></label><label class="d-flex align-items-center gap-2">间隔(分钟)<input id="scan-interval" class="form-control scan-interval" type="number" min="1" max="1440" required value="${status.config.intervalMinutes}"></label><button class="btn" type="submit">保存设置</button><a href="#calendar" class="small">业务日历</a></form></details>`:''}</div></section><div class="d-flex align-items-center mb-3"><h2 class="h3 m-0">按到达日期</h2><span class="text-secondary small ms-auto" id="arrival-count"></span></div><div id="arrival-groups"></div><div class="text-center mt-3"><button id="arrival-more" class="btn" hidden>加载更早日期</button></div>`;
|
||||
panel.querySelector('#arrival-filter').onsubmit=event=>{event.preventDefault();filters={q:panel.querySelector('#arrival-query').value.trim(),connectionId:panel.querySelector('#arrival-connection').value,kind:panel.querySelector('#arrival-kind').value};load(false).catch(showError);};
|
||||
panel.querySelector('#arrival-more').onclick=()=>load(true).catch(showError);
|
||||
panel.querySelector('#scan-config')?.addEventListener('submit',async event=>{event.preventDefault();const button=event.target.querySelector('button');button.disabled=true;try{status.config=await api('/bpm-scan/config',{enabled:panel.querySelector('#scan-enabled').checked,intervalMinutes:Number(panel.querySelector('#scan-interval').value)});if(active()){summary();notify('扫描设置已保存。');}}catch(e){showError(e);}finally{button.disabled=false;}});
|
||||
panel.querySelector('#scan-now')?.addEventListener('click',async()=>{
|
||||
const button=panel.querySelector('#scan-now');button.disabled=true;
|
||||
try{const selected=panel.querySelector('#arrival-connection').value,connections=status.connections.filter(c=>c.status!=='disabled'&&(!selected||c.id===selected)&&(user.role==='admin'||c.owner===user.username));if(!connections.length)throw Error('没有可扫描的连接,请先在 BPM 连接中完成登录。');
|
||||
for(const c of connections)await api('/bpm-scan/run',{connectionId:c.id,...(filters.kind==='todo'?{kind:'todo'}:{})});if(active()){panel.querySelector('#scan-result').textContent='正在扫描…';await refresh();watch();}
|
||||
}catch(e){showError(e);}finally{if(active())button.disabled=false;}
|
||||
});summary();
|
||||
}
|
||||
function showError(e){if(active())notify(e.message,'danger');}
|
||||
function summary(){
|
||||
if(!active())return;panel.querySelector('#scan-summary').textContent=`${status.config.enabled?'已开启':'已暂停'} · 推送连接 ${status.connections.filter(c=>c.monitoring?.status==='listening').length} 个 · 每 ${status.config.intervalMinutes} 分钟完整对账 · 按业务日历运行`;
|
||||
const runs=status.runs.filter(r=>(r.kind||'inform')===(filters.kind||'inform')),latest=runs[0],ok=runs.find(r=>r.status==='success');
|
||||
const el=panel.querySelector('#scan-result');el.className='small mt-3 '+(latest?.status==='error'?'text-danger':'text-secondary');
|
||||
el.textContent=latest?.status==='running'?'正在扫描…':latest?.status==='error'?`${names.get(latest.connectionId)||'BPM'}:${latest.message}`:ok?`扫描完成 · ${formatDate(ok.finishedAt)} · 本次 ${ok.seen} 条,新增 ${ok.added} 条`:'尚无扫描记录';
|
||||
}
|
||||
function groupHtml(group){return `<details open class="card arrival-day mb-4" data-arrival-day="${esc(group.day)}"><summary class="card-header"><span class="arrival-date">${esc(group.day)}</span><span class="badge bg-blue-lt ms-3">${group.items.length} 条</span><span class="small text-secondary ms-auto">到达时间 · 北京时间</span></summary><div class="table-responsive"><table class="table table-vcenter card-table arrival-table"><thead><tr><th>到达时间 / 连接</th><th>流水号 / 流程</th><th>标题</th><th>发起人 / 节点</th></tr></thead><tbody>${group.items.map(row=>`<tr><td class="text-secondary small">${formatDate(row.arrivedAt)}<div class="mt-1">${esc(names.get(row.connectionId)||'已删除连接')}</div></td><td><strong>${esc(row.serialNum||'—')}</strong><div class="text-secondary small mt-1">${esc(row.processName||'—')}</div></td><td class="arrival-subject">${esc(row.subject||'—')}</td><td>${esc(row.initiator||'—')}<div class="text-secondary small mt-1">${esc(nodeLabel(row.activityName))}</div></td></tr>`).join('')}</tbody></table></div></details>`;}
|
||||
async function load(append=false){
|
||||
if(loading&&append)return;loading=true;const request=++revision;
|
||||
try{const params=new URLSearchParams({...filters,...(append&&before?{before}:{} )});const result=await api('/arrivals?'+params);if(!active()||request!==revision)return;
|
||||
const groups=panel.querySelector('#arrival-groups'),html=result.groups.map(groupHtml).join('');if(append)groups.insertAdjacentHTML('beforeend',html);else groups.innerHTML=html||'<div class="card"><div class="card-body text-center text-secondary py-5">暂无匹配的流程记录</div></div>';
|
||||
before=result.nextBefore;panel.querySelector('#arrival-more').hidden=!before;panel.querySelector('#arrival-count').textContent=`共 ${result.total} 条流程`;
|
||||
}finally{if(request===revision)loading=false;}
|
||||
}
|
||||
async function refresh(){const next=await api('/bpm-scan');if(!active())return;status=next;summary();const signature=JSON.stringify(status.runs.map(r=>[r.id,r.status]));if(lastSignature&&signature!==lastSignature)await load(false);lastSignature=signature;}
|
||||
function watch(){if(watching||!active())return;watching=true;setTimeout(async()=>{watching=false;if(!active())return;try{await refresh();}catch(e){showError(e);}if(active())watch();},status.runs.some(r=>r.status==='running')?1500:10000);}
|
||||
container.querySelector('#pdf-tab').onclick=async()=>{mode='pdf';++revision;container.querySelector('#pdf-tab').classList.add('btn-primary');container.querySelector('#arrivals-tab').classList.remove('btn-primary');try{await renderPdf(panel,()=>isActive()&&mode==='pdf');}catch(e){if(isActive())notify(e.message,'danger');}};
|
||||
container.querySelector('#arrivals-tab').onclick=async()=>{mode='arrivals';container.querySelector('#arrivals-tab').classList.add('btn-primary');container.querySelector('#pdf-tab').classList.remove('btn-primary');toolbar();try{await load();await refresh();watch();}catch(e){showError(e);}};
|
||||
toolbar();await load();await refresh();watch();
|
||||
let api,esc,formatDate,notify,user,filters;
|
||||
const defaults=()=>({scope:'current',business:'orders',kind:'all',q:'',connectionId:'',from:'',to:'',page:1});
|
||||
function configure(options){if(user?.username!==options.user.username)filters=defaults();({api,esc,formatDate,notify,user}=options);}
|
||||
async function records(container,isActive){
|
||||
let disposed=false,revision=0,status=null,timer,lastSignature='',controller;const live=()=>!disposed&&isActive(),get=id=>container.querySelector('#'+id);
|
||||
window.PageLifecycle?.onDispose(()=>{disposed=true;clearTimeout(timer);controller?.abort();});
|
||||
const option=(value,label,current)=>'<option value="'+esc(value)+'" '+(value===current?'selected':'')+'>'+esc(label)+'</option>';
|
||||
container.innerHTML='<div class="record-monitor small text-secondary" data-monitor aria-live="polite">正在读取监听状态…</div><div class="alert alert-warning" data-record-error hidden role="alert"></div><section class="card"><div class="card-header flex-wrap gap-2"><h2 class="card-title">流程到达台账</h2><div class="btn-list ms-auto"><a href="#bpm" class="btn btn-sm">管理连接</a>'+(user.role!=='viewer'?'<button type="button" class="btn btn-primary btn-sm" id="scan-now">立即同步</button>':'')+'</div></div><div class="card-body record-filters"><div class="row g-3"><div class="col-12 col-sm-6 col-lg-4"><label class="form-label" for="arrival-query">搜索流程记录</label><input class="form-control" id="arrival-query" maxlength="200" placeholder="流水号、流程、订单标题" value="'+esc(filters.q)+'"></div><div class="col-6 col-sm-3 col-lg-2"><label class="form-label" for="arrival-scope">记录范围</label><select class="form-select" id="arrival-scope">'+option('current','现有连接',filters.scope)+option('archived','历史归档',filters.scope)+option('all','全部来源',filters.scope)+'</select></div><div class="col-6 col-sm-3 col-lg-2"><label class="form-label" for="arrival-business">业务范围</label><select class="form-select" id="arrival-business">'+option('orders','订单相关流程',filters.business)+option('all','全部 BPM 流程',filters.business)+'</select></div><div class="col-6 col-sm-8 col-lg-2"><label class="form-label" for="arrival-kind">到达类型</label><select class="form-select" id="arrival-kind">'+option('all','全部到达类型',filters.kind)+option('todo','待办到达记录',filters.kind)+option('inform','待阅到达记录',filters.kind)+'</select></div><div class="col-6 col-sm-4 col-lg-2 d-flex align-items-end"><button type="button" class="btn w-100" id="arrival-submit">查询</button></div></div><details class="mt-3"><summary class="small text-secondary">更多筛选:来源与日期</summary><div class="row g-3 mt-0"><div class="col-12 col-md-4"><label class="form-label" for="arrival-connection">来源连接</label><select class="form-select" id="arrival-connection"><option value="">全部来源连接</option></select></div><div class="col-6 col-md-4"><label class="form-label" for="arrival-from">起始日期</label><input class="form-control" id="arrival-from" type="date" value="'+esc(filters.from)+'"></div><div class="col-6 col-md-4"><label class="form-label" for="arrival-to">结束日期</label><input class="form-control" id="arrival-to" type="date" value="'+esc(filters.to)+'"></div></div></details></div><div data-arrival-list></div>'+window.RecordUi.footer+'</section><div class="small text-secondary mt-2">按北京时间记录到达历史 · 分类与邮件批次见 <a href="#notification-orders">通知订单</a></div><div id="record-scan-settings"></div>';
|
||||
const detail=window.RecordUi.details(container,'流程到达详情');
|
||||
function error(message){if(!live())return;const node=container.querySelector('[data-record-error]');node.hidden=!message;node.textContent=message||'';}
|
||||
function candidates(){return status?.connections?.filter(c=>c.status!=='disabled'&&(!filters.connectionId||c.id===filters.connectionId)&&(user.role==='admin'||c.owner===user.username))||[];}
|
||||
function monitor(){if(!live()||!status)return;const active=status.connections.filter(c=>c.status!=='disabled'),listening=active.filter(c=>c.monitoring?.status==='listening').length,times=active.map(c=>c.monitoring?.lastSyncAt).filter(Boolean).sort();container.querySelector('[data-monitor]').textContent=(status.config.enabled?'监听已开启':'自动同步已暂停')+' · 推送连接 '+listening+' 个 · 每 '+status.config.intervalMinutes+' 分钟完整对账'+(times.length?' · 最近同步 '+formatDate(times.at(-1)):'');const button=get('scan-now');if(button){button.hidden=filters.scope==='archived';button.disabled=filters.scope==='archived'||!candidates().length;}}
|
||||
function sourceOptions(sources){get('arrival-connection').innerHTML='<option value="">全部来源连接</option>'+sources.filter(s=>filters.scope==='all'||s.status===filters.scope).map(s=>option(s.id,s.name+(s.status==='archived'?'(历史)':s.enabled?'':'(已停用)'),filters.connectionId)).join('');if(filters.connectionId&&!sources.some(s=>s.id===filters.connectionId&&(filters.scope==='all'||s.status===filters.scope)))get('arrival-connection').innerHTML+=option(filters.connectionId,'所选历史来源',filters.connectionId);}
|
||||
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));window.RecordUi.pager(container,{...data,change:page=>{filters.page=page;void load();}});}
|
||||
async function load(){const request=++revision;controller?.abort();controller=new AbortController();try{const data=await api('/arrivals?'+new URLSearchParams({view:'ledger',...filters,pageSize:25}),undefined,{signal:controller.signal});if(!live()||request!==revision)return;error('');sourceOptions(data.sources);draw(data);monitor();}catch(e){if(live()&&request===revision)error(e.message+';可重试查询,已有记录仍保留。');}}
|
||||
function apply(){const scope=get('arrival-scope').value;filters={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,page:1};monitor();void load();}
|
||||
get('arrival-submit').onclick=apply;get('arrival-query').onkeydown=event=>{if(event.key==='Enter')apply();};for(const id of ['arrival-scope','arrival-business','arrival-kind','arrival-connection'])get(id).onchange=apply;
|
||||
async function refresh(){try{const next=await api('/bpm-scan');if(!live())return;status=next;monitor();const signature=JSON.stringify([status.runs.map(r=>[r.id,r.status]),status.connections.map(c=>[c.id,c.status])]);if(lastSignature&&signature!==lastSignature)await load();lastSignature=signature;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(live())error('监听状态读取失败:'+e.message);}finally{if(live())timer=setTimeout(refresh,status?.runs.some(r=>r.status==='running')?1500:10000);}}
|
||||
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('只读同步已启动。');clearTimeout(timer);await refresh();}}catch(e){if(live())error(e.message+';已接受的同步请查看最新结果。');}finally{if(live())monitor();}};
|
||||
await load();if(!live())return;await refresh();if(live()&&user.role==='admin'&&status){get('record-scan-settings').innerHTML='<details class="record-settings mt-3"><summary class="small text-secondary">同步设置</summary><form id="scan-config" class="d-flex flex-wrap gap-3 align-items-center mt-3"><label class="form-check form-switch mb-0"><input type="checkbox" class="form-check-input" id="scan-enabled" '+(status.config.enabled?'checked':'')+'><span class="form-check-label">自动同步</span></label><label class="d-flex gap-2 align-items-center">完整对账间隔(分钟)<input type="number" min="1" max="1440" required class="form-control scan-interval" id="scan-interval" value="'+status.config.intervalMinutes+'"></label><button type="submit" class="btn btn-sm">保存设置</button><a href="#calendar" class="small">业务日历</a></form></details>';get('scan-config').onsubmit=async event=>{event.preventDefault();const config=await api('/bpm-scan/config',{enabled:get('scan-enabled').checked,intervalMinutes:Number(get('scan-interval').value)});if(live()){status.config=config;monitor();notify('同步设置已保存。');}};}
|
||||
}
|
||||
return {configure,records};
|
||||
})();
|
||||
@@ -2,6 +2,7 @@
|
||||
window.AppNavigation=(()=>{
|
||||
const primary=[['overview','overview'],['order-notifications','mail'],['records','file'],['exceptions','alert'],['assistant','spark'],['business-settings','rules'],['system-settings','settings']];
|
||||
const groups={
|
||||
records:['records','records-pdf'],
|
||||
'order-notifications':['order-notifications','notification-execution','notification-orders','notification-batches','notification-history','schedule'],
|
||||
'business-settings':['order-rules','rule-fields'],
|
||||
'system-settings':['bpm','mail','storage','assistant-settings','health','users','audit']
|
||||
@@ -24,7 +25,7 @@ window.AppNavigation=(()=>{
|
||||
link:'M10 13a5 5 0 0 0 7 0l3-3a5 5 0 0 0-7-7l-2 2 M14 11a5 5 0 0 0-7 0l-3 3a5 5 0 0 0 7 7l2-2',
|
||||
users:'M8 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8z M2 21v-3a6 6 0 0 1 12 0v3 M17 3a4 4 0 0 1 0 8 M18 15a5 5 0 0 1 4 5'
|
||||
};
|
||||
const routeIcons={'order-notifications':'overview','notification-execution':'play','notification-orders':'file','notification-batches':'batches','notification-history':'history',schedule:'calendar',calendar:'calendar',templates:'mail','notification-settings':'settings','order-rules':'rules','rule-fields':'fields',bpm:'link',mail:'mail',storage:'batches','assistant-settings':'spark',health:'alert',users:'users',audit:'history'};
|
||||
const routeIcons={records:'history','records-pdf':'file','order-notifications':'overview','notification-execution':'play','notification-orders':'file','notification-batches':'batches','notification-history':'history',schedule:'calendar',calendar:'calendar',templates:'mail','notification-settings':'settings','order-rules':'rules','rule-fields':'fields',bpm:'link',mail:'mail',storage:'batches','assistant-settings':'spark',health:'alert',users:'users',audit:'history'};
|
||||
const resolve=id=>aliases[id]||id;
|
||||
const isConfiguration=id=>configuration.includes(resolve(id));
|
||||
function sectionFor(id){id=resolve(id);if(isConfiguration(id))return 'order-notifications';return Object.keys(groups).find(section=>groups[section].includes(id))||null;}
|
||||
@@ -38,8 +39,8 @@ window.AppNavigation=(()=>{
|
||||
function links(ids,active,{views,esc},labels={}){return ids.map(id=>`<a class="nav-link settings-tab ${active===id?'active':''}" href="#${id}" ${active===id?'aria-current="page"':''}>${icon(routeIcons[id])}<span>${esc(labels[id]||views[id][0])}</span></a>`).join('');}
|
||||
function renderTabs(container,{id,user,views,esc}){
|
||||
const section=sectionFor(id);container.hidden=!section;
|
||||
container.className='nav nav-segmented settings-tabs';container.setAttribute('aria-label',section==='order-notifications'?'订单通知管理导航':section==='business-settings'?'业务设置导航':'系统设置导航');
|
||||
container.innerHTML=section?links(groups[section].filter(item=>item!=='users'||user.role==='admin'),isConfiguration(id)?'schedule':id,{views,esc},{schedule:'通知配置'}):'';
|
||||
container.className='nav nav-segmented settings-tabs';container.setAttribute('aria-label',section==='records'?'记录导航':section==='order-notifications'?'订单通知管理导航':section==='business-settings'?'业务设置导航':'系统设置导航');
|
||||
container.innerHTML=section?links(groups[section].filter(item=>item!=='users'||user.role==='admin'),isConfiguration(id)?'schedule':id,{views,esc},{schedule:'通知配置',records:'流程到达记录','records-pdf':'PDF 导出记录'}):'';
|
||||
reveal(container);
|
||||
}
|
||||
function renderConfiguration(container,{id,views,esc}){
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
window.PdfRecordViews=(()=>{
|
||||
let api,esc,formatDate,notify,user,filters;
|
||||
function configure(options){if(user?.username!==options.user.username)filters={q:'',status:'',page:1};({api,esc,formatDate,notify,user}=options);}
|
||||
async function records(container,isActive){
|
||||
let disposed=false,revision=0,controller,pollTimer,searchTimer;const live=()=>!disposed&&isActive(),get=id=>container.querySelector('#'+id),states={success:'已完成',running:'处理中',error:'失败',interrupted:'已中断'},files={available:'可下载',missing:'文件缺失',unavailable:'不可下载',pending:'等待导出'};
|
||||
window.PageLifecycle?.onDispose(()=>{disposed=true;controller?.abort();clearTimeout(pollTimer);clearTimeout(searchTimer);});
|
||||
container.innerHTML='<div class="alert alert-warning" data-record-error hidden role="alert"></div><section class="card"><div class="card-header flex-wrap gap-3"><h2 class="card-title">PDF 导出台账</h2><div class="ms-auto d-flex gap-2"><input class="form-control" id="record-search" maxlength="200" aria-label="搜索订单" placeholder="搜索订单号、项目或型号" value="'+esc(filters.q)+'"><select class="form-select" id="record-status" aria-label="任务状态"><option value="">全部状态</option>'+Object.entries(states).map(([value,label])=>'<option value="'+value+'" '+(filters.status===value?'selected':'')+'>'+label+'</option>').join('')+'</select></div></div><div data-pdf-list></div>'+window.RecordUi.footer+'</section><div class="small text-secondary mt-2">文件下载与存储归档分别记录 · 分类订单见 <a href="#notification-orders">通知订单</a></div>';
|
||||
const detail=window.RecordUi.details(container,'PDF 导出详情'),archiveLabel=job=>job.archiveReceipts.some(r=>r.status==='success')?'已存储归档':job.archiveReceipts.some(r=>r.status==='running')?'归档中':job.archiveReceipts.some(r=>r.status==='error')?'归档失败':job.archiveKnown?'无归档记录':'归档状态未提供';
|
||||
function open(job,button){const f=(label,value)=>window.RecordUi.field(esc,label,value);detail.show('<dl class="record-detail-grid">'+f('订单号',job.metadata?.order)+f('通知书编号',job.metadata?.serial)+f('项目',job.metadata?.project)+f('型号',job.metadata?.model)+f('导出状态',states[job.status]||job.status)+f('文件名',job.filename)+f('本地文件',files[job.fileStatus])+f('文件大小',job.fileBytes?job.fileBytes+' 字节':'—')+f('文件检查',formatDate(job.fileCheckedAt))+f('创建时间',formatDate(job.createdAt))+f('更新时间',formatDate(job.updatedAt))+f('导出来源','浏览器导出,未记录BPM连接关联')+f('错误信息',job.error)+f('存储归档',archiveLabel(job))+'</dl>'+job.archiveReceipts.map(r=>'<div class="record-receipt"><strong>'+esc(r.serverName||'存储服务器')+'</strong><div>'+esc(r.relativePath||'目录未记录')+'</div><div class="small text-secondary">'+esc(({success:'归档完成',running:'归档中',error:'归档失败'})[r.status]||r.status)+' · '+esc(formatDate(r.finishedAt))+'</div></div>').join('')+(job.downloadable?'<a class="btn btn-primary mt-3" href="/api/jobs/'+encodeURIComponent(job.jobId)+'/file">下载 PDF</a>':''),button);}
|
||||
async function load(){const request=++revision;controller?.abort();controller=new AbortController();try{const data=await api('/jobs?'+new URLSearchParams({view:'ledger',...filters,pageSize:25}),undefined,{signal:controller.signal});if(!live()||request!==revision)return;container.querySelector('[data-record-error]').hidden=true;const host=container.querySelector('[data-pdf-list]');host.innerHTML=data.jobs.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" class="record-export-state">导出状态</th><th scope="col" class="record-file">本地文件</th><th scope="col" class="record-source">存储归档</th><th scope="col" class="record-time">更新时间</th><th scope="col">操作</th></tr></thead><tbody>'+data.jobs.map((job,index)=>'<tr data-pdf-row><td class="record-identity"><strong>'+esc(job.metadata?.order||'订单号未记录')+'</strong><div class="small text-secondary">'+esc(job.metadata?.serial||'—')+'</div><div class="record-inline-export small">'+esc(states[job.status]||job.status)+' · '+esc(files[job.fileStatus])+'</div></td><td class="record-node">'+esc(job.metadata?.project||'—')+'<div class="small text-secondary">'+esc(job.metadata?.model||'—')+'</div></td><td class="record-export-state"><span class="badge bg-'+(job.status==='success'?'green':job.status==='running'?'blue':'red')+'-lt">'+esc(states[job.status]||job.status)+'</span></td><td class="record-file">'+esc(files[job.fileStatus]||'待检查')+'</td><td class="record-source">'+esc(archiveLabel(job))+'</td><td class="record-time small text-secondary text-nowrap">'+esc(formatDate(job.updatedAt))+'</td><td class="record-action"><div class="btn-list record-pdf-actions"><button class="btn btn-sm" type="button" data-pdf-detail="'+index+'">查看详情</button>'+(job.downloadable?'<a class="btn btn-sm" href="/api/jobs/'+encodeURIComponent(job.jobId)+'/file">下载 PDF</a>':'')+'</div></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-pdf-detail]').forEach(button=>button.onclick=()=>open(data.jobs[Number(button.dataset.pdfDetail)],button));window.RecordUi.pager(container,{...data,change:page=>{filters.page=page;void load();}});clearTimeout(pollTimer);if(data.jobs.some(j=>j.status==='running'))pollTimer=setTimeout(load,3000);
|
||||
}catch(e){if(live()&&request===revision){const error=container.querySelector('[data-record-error]');error.hidden=false;error.textContent=e.message+';请刷新重试。';}}}
|
||||
get('record-search').oninput=()=>{clearTimeout(searchTimer);searchTimer=setTimeout(()=>{filters.q=get('record-search').value.trim();filters.page=1;void load();},300);};get('record-status').onchange=()=>{filters.status=get('record-status').value;filters.q=get('record-search').value.trim();filters.page=1;void load();};await load();
|
||||
}
|
||||
return {configure,records};
|
||||
})();
|
||||
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
window.RecordUi=(()=>{
|
||||
function details(container,title){
|
||||
const panel=document.createElement('section');panel.className='offcanvas offcanvas-end record-detail';panel.tabIndex=-1;panel.setAttribute('aria-label',title);
|
||||
panel.innerHTML='<div class="offcanvas-header"><h2 class="offcanvas-title h3 mb-0"></h2><button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="关闭详情"></button></div><div class="offcanvas-body"></div>';panel.querySelector('h2').textContent=title;container.append(panel);
|
||||
const instance=new window.tabler.Offcanvas(panel);let disposed=false;
|
||||
const destroy=()=>new Promise(resolve=>{if(disposed)return resolve();disposed=true;let timer,finished=false;const finish=()=>{if(finished)return;finished=true;clearTimeout(timer);instance.dispose();panel.remove();resolve();};if(panel.classList.contains('show')||panel.classList.contains('showing')){panel.addEventListener('hidden.bs.offcanvas',finish,{once:true});instance.hide();timer=setTimeout(finish,600);}else finish();});
|
||||
window.PageLifecycle?.onDispose(destroy);
|
||||
return {show(html,trigger){if(disposed)return;panel.querySelector('.offcanvas-body').innerHTML=html;instance.show(trigger);},destroy};
|
||||
}
|
||||
function field(esc,label,value){return '<div class="record-detail-field"><dt>'+esc(label)+'</dt><dd>'+esc(value||'—')+'</dd></div>';}
|
||||
function pager(container,{page,pageSize,total,change}){const count=container.querySelector('[data-record-count]'),previous=container.querySelector('[data-record-prev]'),next=container.querySelector('[data-record-next]');count.textContent=total?'共 '+total+' 条 · 第 '+page+' / '+Math.ceil(total/pageSize)+' 页':'共 0 条';previous.disabled=page<=1;next.disabled=page*pageSize>=total;previous.onclick=()=>change(page-1);next.onclick=()=>change(page+1);}
|
||||
const footer='<div class="card-footer d-flex align-items-center gap-2"><span class="text-secondary small" data-record-count></span><div class="btn-list ms-auto"><button type="button" class="btn btn-sm" data-record-prev>上一页</button><button type="button" class="btn btn-sm" data-record-next>下一页</button></div></div>';
|
||||
return {details,field,pager,footer};
|
||||
})();
|
||||
Reference in new issue
Block a user