Files
pricing_review/CostReview/app/ui/sessions.html

324 lines
19 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>最近审核</title>
<style>
:root{--c1:#123a6b;--c2:#1f5fae;--line:#c9d4e2;--head:#eef3fa;--bg:#f5f7fa;--txt:#1c2733;--muted:#5a6b7f}
*{box-sizing:border-box}
html,body{height:100%}
body{font-family:"Microsoft YaHei",system-ui,sans-serif;margin:0;background:var(--bg);color:var(--txt);font-size:13px}
/* 2026-10-22 主人定:显示区按最大行撑满(去掉原 max-height:100vh-230px 的底部留白);
行数超过可视范围走前端分页(只改显示,接口/数据逻辑不动)。 */
.wrap{margin:0 auto;padding:10px 16px 14px;height:100%;display:flex;flex-direction:column}
h1{font-size:19px;margin:0 0 3px;color:var(--c1)}
.panel{background:#fff;border:1px solid var(--line);flex:1;display:flex;flex-direction:column;min-height:0}
.bar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;padding:6px 0 8px}
/* 2026-10-22 主人定:搜索框与「工作台」按钮同款(28px 高/12.5px 字号/同边框圆角) */
.bar input{width:250px;height:28px;padding:0 10px;border:1px solid #b8c4d4;border-radius:6px;font:inherit;font-size:12.5px;background:#fff;box-sizing:border-box}
.btn{padding:4px 10px;border-radius:6px;border:1px solid #b8c4d4;background:#fff;cursor:pointer;font-size:12px;line-height:1.3;text-decoration:none;display:inline-block}
.btn:hover{background:#eef3fa}
.btn.pri{background:var(--c2);color:#fff;border-color:var(--c2)}
.btn.danger{color:#c0392b;border-color:#e0b4b4}
/* 「工作台 / 删除所选」尺寸样式对齐工作台顶栏按钮=「打开项目」(2026-10-19 主人定:
大小风格与工作台一致=28px 高 / 左右 12px / 12.5px 字号白底;删除所选保留红色) */
.btn.wb{display:inline-flex;align-items:center;justify-content:center;height:28px;padding:0 12px;border:1px solid #b8c4d4;border-radius:6px;background:#fff;cursor:pointer;font:inherit;font-size:12.5px;color:#26405e;text-decoration:none;line-height:1;white-space:nowrap;vertical-align:middle;user-select:none;flex:none}
.btn.wb:hover{background:#eef3fa}
.btn.wb:active{background:#e0effc}
.btn.wb.danger{color:#c0392b;border-color:#e0b4b4}
.btn:disabled{opacity:.45;cursor:not-allowed}
.ck{display:flex;align-items:center;gap:5px;font-size:12.5px;color:var(--muted);cursor:pointer}
/* 2026-10-22 主人定:全选复选框做小做精致(13px、圆角、主题色勾) */
.ck input{width:13px;height:13px;margin:0;accent-color:var(--c2);cursor:pointer}
.tip{color:var(--muted);font-size:12px}
.tw{overflow:auto;flex:1;min-height:0}
table{width:100%;border-collapse:collapse;table-layout:fixed}
th,td{border:1px solid var(--line);padding:5px 8px;vertical-align:top}
th{background:var(--head);position:sticky;top:0;z-index:3;box-shadow:inset 0 -1px 0 var(--line);
text-align:center;font-weight:600;white-space:nowrap;font-size:12.5px}
td.r{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
td.c{text-align:center;white-space:nowrap}
td.l{text-align:left}
td.name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
tr.duprow td{background:#fbfcfe;color:#456;font-size:11.5px}
tr:hover td{background:#f6f9fd}
.empty{padding:26px;text-align:center;color:var(--muted)}
.pager{flex:none;display:none;align-items:center;justify-content:flex-end;gap:8px;margin-left:auto}
.manualtag{color:#1f5fae;font-weight:600;white-space:nowrap}
a{color:var(--c2);text-decoration:none;cursor:pointer}
a:hover{text-decoration:underline}
/* 统一弹框体系(2026-10-19 主人定:删除确认按「风格预览」里打开项目的弹框样式) */
.mask{position:fixed;inset:0;background:rgba(20,30,45,.45);display:none;align-items:center;justify-content:center;z-index:99}
.mask.on{display:flex}
.dlg{background:#fff;border-radius:10px;box-shadow:0 18px 48px rgba(15,30,50,.25);width:420px;max-width:94vw;max-height:92vh;display:flex;flex-direction:column;overflow:hidden}
.dlg .dh{flex:none;display:flex;justify-content:space-between;align-items:center;padding:11px 16px;border-bottom:1px solid var(--line);background:var(--head);border-radius:10px 10px 0 0}
.dlg .dh b{color:var(--c1);font-size:14px}
.close{cursor:pointer;color:#8899aa;font-size:20px;line-height:1;user-select:none;padding:0 2px}
.close:hover{color:#e5484d}
.dbody{padding:18px 16px;overflow:auto;display:flex;flex-direction:column;gap:10px}
.dfoot{flex:none;display:flex;justify-content:flex-end;gap:8px;padding:11px 16px;border-top:1px solid var(--line);background:#fafcff}
</style>
<!-- 2026-10-19 补引共用层样式:本页此前漏引 common.css,.rs 列宽把手因此 0 宽度、
列宽拖不动(核对时发现);表头底线 1px→2px 与工作台/后台一致。 -->
<link rel="stylesheet" href="common.css?v=20261017c">
</head>
<body>
<div class="wrap">
<!-- 决策 226(2026-10-27 主人定):标题行加工作台顶栏同款 2px 蓝色底线(--c1 同一变量),与下一行筛选区分割 -->
<div style="display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:8px;padding-bottom:6px;border-bottom:2px solid var(--c1)">
<h1 style="margin:0;font-size:12.5px">最近审核</h1>
<!-- 时间戳参数:老 WebView2 对 no-store 不完全遵守,跨页跳转带新 URL 强制绕缓存(2026-10-12) -->
<!-- 2026-10-19 主人定:去掉 ▶ 图标,尺寸样式对齐工作台顶栏「打开项目」按钮 -->
<button class="btn wb" onclick="location.href='/workbench.html?v='+Date.now()"
title="打开工作台:导入工程、做历史比对与审核">工作台</button>
</div>
<!-- 2026-10-22 主人定:筛选行移到「工作台」按钮下一行;分页条放同一行右端(右上角)。
搜索框/删除所选与「工作台」按钮同款(28px 高、同边框圆角字号)。 -->
<div class="bar">
<input id="fq" placeholder="项目名称 / 文件名关键字" oninput="render()">
<label class="ck"><input type="checkbox" id="ckall" onchange="selAll(this)"> 全选</label>
<button class="btn wb danger" id="bdel" disabled onclick="delSel()">删除所选 (0)</button>
<div class="pager" id="pager"></div>
</div>
<div class="panel">
<div class="tw" id="tw">
<table id="tb">
<colgroup id="cg"></colgroup>
<thead id="th"></thead>
<tbody id="tbody"></tbody>
</table>
</div>
</div>
</div>
<!-- 统一确认/提示弹框(2026-10-19 主人定:删除确认只用一句「删除后不可恢复,是否删除?」) -->
<div class="mask" id="dlgmask">
<div class="dlg">
<div class="dh"><b id="dlgtitle">确认</b><span class="close" title="关闭" onclick="dlgCancel()">×</span></div>
<div class="dbody"><div id="dlgtext" style="color:var(--txt);font-size:13px;line-height:1.7">删除后不可恢复,是否删除?</div></div>
<div class="dfoot">
<button class="btn wb" id="dlgcancel" onclick="dlgCancel()">取消</button>
<button class="btn wb danger" id="dlgok" onclick="dlgOk()">删除</button>
</div>
</div>
</div>
<script src="common.js?v=20261021e"></script>
<script>
/* 会话管理页:照后台「项目界面」的版式,管的是**还没入库**的工作台会话。
会话库不自动清(SESSION_KEEP_DAYS=0),要删只能在这里手动删。
2026-10-11 主人五点:①列宽左右拖拉(公共层 .rs 手柄+localStorage 记忆)
②当页排序(sortHeadHTML/sortRows 共用层)③操作列收窄、余量给「项目名称」(原「项目名」改名)
④表格撑满屏幕(项目名称列=伸缩列 attrFillBind,.wrap 去掉 max-width 上限)。
排序状态 ST={k,dir}:k=SCOLS 下标,刷新/过滤后保持,换数据不重置。 */
/* 决策 213 补记七(2026-10-26 主人定):单位工程/清单/定额/工料机/备注 五个统计列取消
(后端不再逐会话 COUNT,确实取消提速)——列表只留 身份/总造价/源文件/打开时间/操作。 */
const SCOLS=[['',36,'c','','ns'],['序号',50,'c','','ns'],['项目名称',260,'l'],['项目总造价',140,'r'],['源文件',220,'l'],['打开时间',150,'c'],['操作',96,'c','','ns']];
let ITEMS=[], ST={k:-1,dir:1};
const SES_NUM=new Set([3]); // 项目总造价 按数值比
const NAME_IDX=2; // 伸缩列:项目名称(余宽都给它)
const n2 =n=>(n==null?'—':(+n).toLocaleString('zh-CN'));
// 金额:带两位小数。⚠️ 项目总造价取自原文件(含税金/其他项目),**不是**清单合价求和
const money=n=>(n==null?'—':(+n).toLocaleString('zh-CN',{minimumFractionDigits:2,maximumFractionDigits:2}));
const $=id=>document.getElementById(id);
async function J(u,o){ const r=await fetch(u,o); const d=await r.json(); if(!r.ok) throw new Error((d&&d.error)||('HTTP '+r.status)); return d; }
function head(){
$('cg').innerHTML=colgHTML(SCOLS);
$('th').innerHTML=sortHeadHTML(SCOLS,ST,'sesSort');
}
function sesSort(i){
if(ST.k===i) ST.dir=-ST.dir; else { ST.k=i; ST.dir=(i===5?-1:1); } /* 打开时间首点=最新在前(2026-10-13 主人问询后定);213 补记七:列缩后 10→5 */
$('th').innerHTML=sortHeadHTML(SCOLS,ST,'sesSort');
render();
}
function srcShort(s){ s=s||''; return s.split('_').length>1 ? s.split('_').slice(1).join('_') : s; }
/* 上次列表缓存:进页面先画上次的名单,再后台刷新。
2026-10-20 主人反馈「进最近审核还要正在加载、太久」——启动自愈/冷盘时 /api/sessions
可能被挡十几秒;有缓存就不让页面等接口,接口回来再静默替换。 */
const SESS_CACHE_KEY='sess_list_cache_v1';
const SESSION_FETCH_TIMEOUT_MS=8000;
const SESSION_FETCH_ATTEMPTS=2;
let LOAD_SEQ=0;
function cacheLoad(){
try{
const s=localStorage.getItem(SESS_CACHE_KEY);
if(!s) return null;
const c=JSON.parse(s);
return (c && Array.isArray(c.items) && c.items.every(x=>x && typeof x==='object')) ? c.items : null;
}catch(e){ return null; }
}
function cacheSave(){
try{ localStorage.setItem(SESS_CACHE_KEY, JSON.stringify({t:Date.now(),items:ITEMS})); }catch(e){}
}
async function load(silent){
const seq=++LOAD_SEQ;
if(!silent && !ITEMS.length) $('tbody').innerHTML='<tr><td colspan="'+SCOLS.length+'" class="empty">正在读取…</td></tr>';
let d, lastErr;
for(let attempt=0; attempt<SESSION_FETCH_ATTEMPTS; attempt++){
const ctl=typeof AbortController==='function' ? new AbortController() : null;
const timer=ctl ? setTimeout(()=>ctl.abort(),SESSION_FETCH_TIMEOUT_MS) : null;
try{
d=await J('/api/sessions',ctl?{signal:ctl.signal}:undefined);
if(!d || d.ok!==true || !Array.isArray(d.items)) throw new Error('会话列表响应格式错误');
break;
}catch(e){
lastErr=e;
if(attempt+1<SESSION_FETCH_ATTEMPTS) await new Promise(r=>setTimeout(r,250));
}finally{ if(timer) clearTimeout(timer); }
}
if(!d){
if(seq!==LOAD_SEQ) return;
if(ITEMS.length){ if(typeof toast==='function') toast('刷新失败:显示上次列表'); return; }
$('tbody').innerHTML='<tr><td colspan="'+SCOLS.length+'" class="empty">读取失败:服务没连上(软件可能没启动)</td></tr>';
return;
}
if(seq!==LOAD_SEQ) return;
ITEMS=d.items;
render();
cacheSave();
}
function render(){
const q=($('fq').value||'').trim().toLowerCase();
const rows=ITEMS.filter(x=>!q || (x.name||'').toLowerCase().includes(q) || (x.src_name||'').toLowerCase().includes(q))
.map(x=>[x.id, 0, x.name||'', x.total, srcShort(x.src_name), x.at||'', (x.all||[]).map(a=>a.id), x.src_name,
x.can_reparse === false, x.manual === true]); /* [8] 源文件缺失(决策 94) [9] 手工工程;[5]打开时间 [6]删除ids [7]源文件名;[1]=序号占位 */
const view=sortRows(rows, ST.k, ST.dir, SES_NUM);
view.forEach((r,i)=>{ r[1]=view.length-i; }); /* 序号倒序编号(与后台入库项目一致:第一行=总数,往下递减);默认序=打开时间越新越靠前(服务端 id 倒序=打开时间倒序,同名工程后端只留最近一次,2026-10-07 主人定) */
/* 2026-10-22 主人定:显示区按最大行撑满(.tw flex 撑满窗口余量),行数超可视范围=前端分页
(只改显示,接口/数据不动)。每页行数按表格区实际高度÷行高动态算,窗口缩放自动跟随。 */
const tw=$('tw');
const thH=$('th').getBoundingClientRect().height||30;
const rowH=PAG.rowH||29;
const size=Math.max(1,Math.floor(((tw?tw.clientHeight:0)-thH-4)/rowH)||1); /* 容器未就绪时兜底 1 行,绝不让 render 抛错 */
PAG.size=size;
let rowsToShow=view;
if(view.length>size){
const tp=Math.max(1,Math.ceil(view.length/size));
if(PAG.p>tp) PAG.p=tp; if(PAG.p<1) PAG.p=1;
const st=(PAG.p-1)*size;
rowsToShow=view.slice(st,st+size);
}else PAG.p=1;
let h='';
rowsToShow.forEach(r=>{
const srcCell = r[9]
? `<span class="manualtag" title="手工工程:没有源文件,不能按原格式导出/重新解析;用「打开项目」选择同名源文件可补传">手工创建</span>`
: (r[8]
? esc(r[4]) + ' <span class="srcmiss" style="color:#c0392b;font-weight:600;white-space:nowrap" title="原文件已不在软件里:该工程无法导出、无法重新解析(已解析的数据仍可查看)。删除会话不受影响">源文件缺失</span>'
: esc(r[4]));
h+=`<tr>
<td class="c"><input type="checkbox" class="f-sel" value="${r[0]}" onchange="updDel()"></td>
<td class="c" title="${r[1]}">${r[1]}</td>
<td class="l name" title="${esc(r[2])}">${esc(r[2]||'(无名)')}</td>
<td class="r" title="${r[3]==null?'原文件里没取到总造价':'工程总造价(原文件口径,含税金与其他项目)'}">${money(r[3])}</td>
<td class="l name" title="${esc(r[7])}">${srcCell}</td>
<td class="c" title="${esc(r[5]||'')}">${esc(r[5]||'—')}</td>
<td class="c">
<a onclick="go(${r[0]})" title="打开最近一次审核,接着上次的活干">打开</a>
<a onclick="del([${(r[6]||[]).join(',')}])" style="margin-left:8px;color:#c0392b">删除</a>
</td></tr>`;
});
$('tbody').innerHTML=h||`<tr><td colspan="${SCOLS.length}" class="empty">没有匹配的会话</td></tr>`;
/* 行高实测回填(行高变了且正在分页 → 重算一次;rowH 稳定后不再二次渲染) */
const fr=$('tbody').firstElementChild;
if(fr && !fr.classList.contains('empty')){
const rh=fr.getBoundingClientRect().height;
if(rh && Math.abs(rh-(PAG.rowH||0))>0.5){ PAG.rowH=rh; if(view.length>PAG.size){ render(); return; } }
}
/* 分页条:只有超页时显示 */
const pg=$('pager');
if(view.length>PAG.size){
const tp=Math.ceil(view.length/PAG.size);
pg.style.display='flex';
pg.innerHTML='<span class="tip">共 '+view.length+' 行 · 第 '+PAG.p+' / '+tp+' 页 · 每页 '+PAG.size+' 行</span>'
+'<button class="btn wb" onclick="pgGo(-1)"'+(PAG.p<=1?' disabled':'')+'>上一页</button>'
+'<button class="btn wb" onclick="pgGo(1)"'+(PAG.p>=tp?' disabled':'')+'>下一页</button>';
}else pg.style.display='none';
updDel();
}
/* 分页翻页(前端切片,不动数据) */
const PAG={p:1,size:0,rowH:0};
function pgGo(d){ PAG.p+=d; render(); }
function selAll(el){ document.querySelectorAll('.f-sel').forEach(x=>x.checked=el.checked); updDel(); }
function updDel(){
const n=document.querySelectorAll('.f-sel:checked').length;
$('bdel').textContent='删除所选 ('+n+')'; $('bdel').disabled=n===0;
}
/* 删除所选 = 把每个勾中名称下的**全部**审核记录一起删(代表 id → 该组所有会话 id) */
function delSel(){
const rep=Array.from(document.querySelectorAll('.f-sel:checked')).map(x=>+x.value);
del(ITEMS.filter(x=>rep.includes(x.id)).flatMap(x=>(x.all||[]).map(a=>a.id)));
}
function go(id){ location.href='/workbench.html?sid='+id+'&t='+Date.now(); }
/* 2026-09-30 主人定:落地页每行**只留「打开」+「删除」**,去掉「重新解析」按钮。
它只在解析器更新后才需要,不该占日常位置。
2026-10-07:同名工程按名称合并成一行,删除传入该名称下全部会话 id(不分时间版本)。
2026-10-19 主人定:删除=连带清干净(备注/源文件/采纳事件一起走;后台同源还引用时保留),
确认弹框统一为一句「删除后不可恢复,是否删除?」。 */
/* ---- 统一确认/提示弹框(2026-10-19 主人定)----
删除确认只用一句「删除后不可恢复,是否删除?」,取消/关闭=不删;
原先那句「要刷新数据=删了重开」的旧提示随 2026-09-30 决定一并废除(主人 2026-10-19 拍板)。*/
let DLG_CB=null;
function dlgShow(text, okText, cb, title, danger){
$('dlgtitle').textContent=title||'确认';
$('dlgtext').textContent=text;
$('dlgok').textContent=okText||'确定';
$('dlgok').className='btn wb'+(danger?' danger':'');
$('dlgcancel').style.display=cb?'':'none';
DLG_CB=cb||null;
$('dlgmask').classList.add('on');
}
function dlgCancel(){ $('dlgmask').classList.remove('on'); DLG_CB=null; }
function dlgOk(){ const cb=DLG_CB; dlgCancel(); if(cb) cb(); }
function dlgNotice(text){ dlgShow(text,'确定',null,'提示',false); }
$('dlgmask').addEventListener('click',function(e){ if(e.target===this) dlgCancel(); });
document.addEventListener('keydown',function(e){
if(e.key==='Escape' && $('dlgmask').classList.contains('on')) dlgCancel();
});
async function del(ids){
if(!ids.length) return;
dlgShow('删除后不可恢复,是否删除?','删除',async ()=>{
/* 2026-10-19 主人定:乐观删除——确认后行立即消失,子表/备注/文件由服务端后台清;
接口失败则整表还原并提示。 */
const before=ITEMS.slice();
++LOAD_SEQ; // 删除期间的旧读响应不得把已消失的行补回来
ITEMS=ITEMS.filter(x=>!(x.all||[]).some(a=>ids.includes(a.id)));
$('ckall').checked=false;
render();
cacheSave();
let r;
try{
r=await J('/api/session/delete',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify({ids})});
}catch(e){ ITEMS=before; render(); cacheSave(); dlgNotice('删除失败:服务没连上'); return; }
if(r&&r.ok){
toast('已删除'); // 2026-10-19 主人定:删除成功只弹右下角消息,不再弹确认框
load(true); // 静默对账(行已消失,不闪"正在读取…")
}else{
ITEMS=before; render(); cacheSave();
dlgNotice((r&&r.msg)||'删除失败');
}
},'确认',true);
}
head();
sumw($('tb')); // 表宽=列宽和(先按基础宽出表)
colwApply($('tb')); // 套用上次拖动记忆(伸缩列只记基础宽)
attrFillBind($('tb'), NAME_IDX, 260); // 项目名称列吃掉全部余宽 → 表格撑满屏幕(RO 盯缩放)
const _sessCached=cacheLoad();
if(_sessCached!==null){
ITEMS=_sessCached; render(); load(true); // 先出上次名单,后台静默刷新(不等接口)
}else{
ldWrap('','正在加载会话…',()=>load()); // 首次无缓存:保留进度条
}
</script>
</body>
</html>