22 lines
2.5 KiB
JavaScript
22 lines
2.5 KiB
JavaScript
(() => {
|
|
'use strict';
|
|
window.OrderNotificationShared={create({esc}){
|
|
const statuses={draft:'草稿',enabled:'已发布',paused:'已暂停',identified:'已识别',preparing:'准备中',archived:'已归档',pending:'待发',batched:'已编入批次',blocked:'受阻',prepared:'已准备',sending:'发送中',sent:'已提交邮件服务器',failed:'失败',unknown:'结果待核实',cancelled:'已取消',ignored:'更早历史,不补发'};
|
|
const status=s=>`<span class="badge bg-${['unknown','blocked','failed'].includes(s)?'yellow':s==='sent'?'green':'secondary'}-lt">${esc(statuses[s]||s||'未记录')}</span>`;
|
|
const empty=text=>`<div class="order-rules-empty text-secondary">${esc(text)}</div>`;
|
|
const table=(heads,rows,none)=>`<div class="table-responsive"><table class="table card-table order-rules-table"><thead><tr>${heads.map(h=>`<th>${h}</th>`).join('')}</tr></thead><tbody>${rows.join('')||`<tr><td colspan="${heads.length}">${empty(none)}</td></tr>`}</tbody></table></div>`;
|
|
const list=v=>(v||[]).join('、')||'未配置';
|
|
const operationKey=(form,body)=>{const signature=JSON.stringify(body);if(form.dataset.requestSignature!==signature){form.dataset.requestSignature=signature;form.dataset.requestKey=window.PageLifecycle.requestKey();}return form.dataset.requestKey;};
|
|
const capabilityNames={liveTodo:'实时待办接入',pdfExport:'通知书 PDF 导出',automaticArchive:'自动归档'};
|
|
const ready=c=>Object.keys(capabilityNames).every(k=>c[k]===true);
|
|
function capabilities(c){return `<div class="order-rule-capabilities">${Object.entries(capabilityNames).map(([key,label])=>`<div><span class="badge bg-${c[key]===true?'green':'yellow'}-lt">${c[key]===true?'已就绪':'待联调'}</span><span>${label}</span></div>`).join('')}</div>`;}
|
|
|
|
function capabilityBlockers(c){
|
|
const checks=[['liveTodo','实时待办接入尚未验证,不能自动采集订单。','#bpm','检查 BPM 连接'],['pdfExport','通知书 PDF 导出尚未验证,不能提供附件证据。','#rule-fields','核实真实字段'],['automaticArchive','自动归档尚未验证,不能确认文件已安全归档。','#storage','检查存储服务器']];
|
|
const missing=checks.filter(([key])=>c[key]!==true);
|
|
return missing.length?`<div class="alert alert-warning mt-3"><strong>自动执行受阻</strong>${missing.map(([,reason,href,label])=>`<div>${esc(reason)} <a href="${href}">${label}</a></div>`).join('')}</div>`:'';
|
|
}
|
|
return {capabilityBlockers,status,empty,table,list,operationKey,capabilities,ready};
|
|
}};
|
|
})();
|