feat(costreview): 新增清单库与项目目录管理并修复采纳定额单价回填及换行实体转义

This commit is contained in:
lianjianwei2024
2026-11-05 07:09:18 +08:00
parent 449d6d18ba
commit e113eb0264
69 changed files with 1487 additions and 39434 deletions

View File

@@ -298,6 +298,62 @@ tr.pedit{background:#fffbef}
td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb6d4;border-radius:4px}
/* 明细表操作列:同一格里第二个链接(删除/取消)与前面的拉开 12px(2026-10-13 主人定) */
#dtbd td a + a{margin-left:12px}
/* ===== 清单库三区域页(2026-11-04 主人定)=====
区域1=根目录→省→清单名称(严格三级)→ 区域2=选中清单名称的章节目录(层级不限)
→ 区域3=真正的清单条目(编码/名称/项目特征/单位/工程量,工程量默认 1.000)。
容器版式同 #dpage 口径(吃满剩余高度);区域1/2 背景同价格目录栏。 */
#klpage{display:none;flex-direction:column;background:#fff;border:1px solid var(--line);border-top:none;min-height:420px}
.klcols{display:flex;flex:1;min-height:0}
.kcol{display:flex;flex-direction:column;min-width:0;overflow:hidden}
#kc1{width:250px;flex:none;border-right:1px solid var(--line);background:#fcfdfe}
#kc2{width:320px;flex:none;border-right:1px solid var(--line);background:#fcfdfe}
#kc3{flex:1}
.kbody{flex:1;overflow:auto;padding:6px 10px}
.khint{color:#94a3b8;font-size:12px;padding:10px 4px;line-height:1.7}
/* 探索器式树:+/- 把手 + 连线(2026-11-04 主人定形式;只挂本页两棵树,原数据/组树样式不动)
连线:li::before=贯穿竖线(末位只到把手一半),li::after=把手到节点的横线 */
.ktree ul{list-style:none;margin:0;padding:0}
.ktree li{position:relative;padding-left:24px}
.ktree li::before{content:'';position:absolute;left:10px;top:0;bottom:0;border-left:1px solid #cdd6e2}
.ktree li:last-child::before{height:15px;bottom:auto}
.ktree li::after{content:'';position:absolute;left:10px;top:15px;width:10px;border-top:1px solid #cdd6e2}
.ktree > li.kt0{padding-left:0}
.ktree > li.kt0::before,.ktree > li.kt0::after{display:none}
.ktg{flex:none;width:14px;height:14px;line-height:12px;text-align:center;border:1px solid #9db3cf;
background:#fff;color:#34506f;font-size:10px;font-family:Consolas,monospace;border-radius:2px;
cursor:pointer;user-select:none}
.ktg:hover{background:var(--c2);color:#fff;border-color:var(--c2)}
.ktg.em{visibility:hidden}
.ktg.em:hover{background:#fff;color:#34506f;border-color:#9db3cf}
.kico{flex:none;font-size:11px;line-height:1}
.knode{display:flex;align-items:center;gap:4px;padding:2px 6px 2px 2px;cursor:pointer;border-radius:4px;
white-space:nowrap;color:#374151;font-size:12.5px}
.knode:hover{background:#eef3fa}
.knode.on{background:#2563eb;color:#fff}
.knode .knm{overflow:hidden;text-overflow:ellipsis}
.knode .kcnt{color:#9aa4b2;font-size:11px;flex:none}
.knode.on .kcnt{color:#dbe7ff}
.knode input.kren{width:150px;padding:1px 6px;font-size:12px;border-radius:4px;border:1px solid #9fb6d4}
.kcfm{display:inline-flex;gap:3px;flex:none}
.kcfm span{min-width:17px;height:17px;padding:0 2px;border-radius:4px;background:#fff;border:1px solid #c9d4e2;
color:#34506f;font-size:11px;line-height:15px;text-align:center;cursor:pointer}
.kcfm span.kpk:hover{background:#1a7f37;border-color:#1a7f37}
.kcfm span.kpd:hover{background:#c0392b;border-color:#c0392b}
/* 区域3 条目表(五列格式照工作台:编码/名称/项目特征 左,单位 居中,工程量 右 3 位小数) */
.ktable{border-collapse:collapse;width:100%;font-size:12.5px}
.ktable th{position:sticky;top:0;background:#f7f9fc;color:#374151;font-weight:600;padding:6px 8px;
text-align:left;border-bottom:1px solid var(--line);border-right:1px solid #eef1f5;white-space:nowrap}
.ktable td{padding:4px 8px;border-bottom:1px solid #f0f3f7;vertical-align:top}
.ktable td.kc{text-align:center}
.ktable td.kr{text-align:right}
.ktable td.kfeat{max-width:280px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#5b6472}
.ktable td input,.ktable td textarea{width:100%;box-sizing:border-box;padding:3px 7px;font-size:12.5px;
border:1px solid #9fb6d4;border-radius:4px;font-family:inherit}
.ktable td textarea{resize:vertical}
.ktable tr.pedit{background:#fffbef}
.kempty{color:#94a3b8;font-size:12px;text-align:center;padding:18px 0}
.kwhere{font-size:12px;color:#34506f;background:#eef3fa;border:1px solid #d8e0ec;border-radius:4px;
padding:2px 8px;max-width:340px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.newflag{display:inline-block;margin-left:6px;padding:0 5px;border-radius:3px;background:#fff7e6;
border:1px solid #f0d9a8;color:#8a6d1a;font-size:11px}
</style>
@@ -311,6 +367,8 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
<div class="tabs">
<div class="tab on" data-kind="project">入库项目</div>
<!-- 清单库固定标签(2026-11-04 主人定):固定四标签(原三标签 + 清单);不走批次列表,独立三区域页 -->
<div class="tab" data-kind="qlist">清单</div>
<div class="tab" data-kind="market">市场价</div>
<div class="tab" data-kind="info">信息价</div>
<!-- 动态明细标签挂点(2026-10-21 决策 150 主人定):点「明细」在此追加浏览器式标签,
@@ -488,6 +546,49 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
<input type="file" id="qfile" style="display:none">
</div>
<!-- 清单库三区域页(2026-11-04 主人定):固定四标签「清单」的内容页。
区域1(最左)=根目录→省→清单名称,严格三级(市不要);区域2(中间)=选中第3级「清单名称」后
的章节目录,层级不限;区域3(右)=真正的清单条目(编码/名称/项目特征/单位/工程量,工程量默认 1.000)。
两棵目录树都走探索器式 +/- 把手 + 连线(.ktree);工具排同价格目录 .rtbar(作用于选中项)。
库内容由主人在界面里建,后端只种根目录。 -->
<div id="klpage">
<div class="klcols">
<div class="kcol" id="kc1">
<div class="rtbar" id="krt1">
<span id="kadd1" title="在选中目录下新增(根下=省、省下=清单名称)" onclick="qlAdd1()">+子目录</span>
<span id="kren1" title="改名" onclick="qlRen1()">✎</span>
<span id="kup1" title="上移" onclick="qlSeq1(-1)">↑</span>
<span id="kdn1" title="下移" onclick="qlSeq1(1)">↓</span>
<span id="kdel1" title="删除" onclick="qlDel1()">✕</span>
</div>
<div class="kbody ktree" id="ktree1"></div>
</div>
<div class="kcol" id="kc2">
<div class="rtbar" id="krt2">
<span id="kadd2" title="新增章节目录(挂选中项下;没选中=挂清单名称下)" onclick="qlAdd2()">+子目录</span>
<span id="kren2" title="改名" onclick="qlRen2()">✎</span>
<span id="kup2" title="上移" onclick="qlSeq2(-1)">↑</span>
<span id="kdn2" title="下移" onclick="qlSeq2(1)">↓</span>
<span id="kdel2" title="删除" onclick="qlDel2()">✕</span>
</div>
<div class="kbody ktree" id="ktree2"></div>
</div>
<div class="kcol" id="kc3">
<div class="rtbar" id="krt3">
<span id="kaddi" title="新增清单条目(工程量默认 1.000)" onclick="qlItemAdd()">+条目</span>
<span class="kwhere" id="kwhere"></span>
</div>
<div class="kbody" id="kbody3">
<table class="ktable" id="kitems">
<thead><tr><th style="width:140px">编码</th><th>名称</th><th style="width:290px">项目特征</th>
<th style="width:90px">单位</th><th style="width:110px">工程量</th><th style="width:88px">操作</th></tr></thead>
<tbody id="kitemsb"></tbody>
</table>
</div>
</div>
</div>
</div>
<div class="mask" id="imask">
<!-- 决策 245(2026-11-01 主人定):后台弹框与工作台「打开项目」弹框统一,以工作台为准——
字段/顺序/提示/按钮一致,唯一区别=写入库(这里写 history.db 批次,工作台写 session.db 会话);
@@ -678,52 +779,18 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
<div class="mask" id="fmask">
<div class="dlg" style="width:min(760px,94vw)">
<div class="dh"><b>设置</b><span class="close" onclick="closeFrames()">×</span></div>
<div style="padding:10px 16px 0">
<div class="tabs">
<div class="dtab on" id="ftabExp" onclick="ftabSet('exp')">导出</div>
<div class="dtab" id="ftabLme" onclick="ftabSet('lme')">工料机</div>
<button class="btn pri" style="margin-left:auto;height:24px;padding:0 16px" onclick="fsetAdd()"
title="导出卡:选 .cos / .cos4 原件或骨架包入库;工料机卡:列设置(自定义列增删改/排序)">添加</button>
</div>
</div>
<div style="padding:14px 16px;display:flex;flex-direction:column;gap:10px">
<div id="fpaneExp">
<div style="display:flex;justify-content:flex-end">
<button class="btn pri" onclick="framesAdd()" title="选择 .cos / .cos4 原件或骨架包(zip 内含 cos 族件),入库后自动按后缀归类">添加</button>
<input type="file" id="ffile" style="display:none" onchange="framesSeed(this)">
</div>
<div class="tw" style="max-height:52vh">
<table><colgroup><col style="width:56px"><col style="width:110px"><col style="width:110px"><col></colgroup>
<thead><tr><th class="c">#</th><th>后缀</th><th>上传日期</th><th>导出文件数据结构</th></tr></thead>
<tbody id="frameBody"></tbody>
</table>
</div>
<div style="display:flex;justify-content:flex-end">
<button class="btn pri" onclick="framesAdd()" title="选择 .cos / .cos4 原件或骨架包(zip 内含 cos 族件),入库后自动按后缀归类">添加</button>
<input type="file" id="ffile" style="display:none" onchange="framesSeed(this)">
</div>
<div id="fpaneLme" style="display:none">
<div class="tw" style="max-height:52vh">
<table><colgroup><col style="width:56px"><col></colgroup>
<thead><tr id="lmeSetHead"></tr></thead>
<tbody id="lmeSetBody"></tbody>
</table>
</div>
<div class="tip" style="padding:0">行数=导出卡后缀列去重数(cos4 算一行);起点由软件商或租户填写</div>
</div>
<div class="tip" id="fmsg" style="padding:0;min-height:18px"></div>
</div>
</div>
</div>
<!-- ===== 列设置弹框(2026-11-04 主人定:序号|名称|值|操作;值=复选框;操作=上移/下移/插/删) ===== -->
<div class="mask" id="colmask">
<div class="dlg" style="width:min(520px,92vw)">
<div class="dh"><b>列设置(工料机)</b><span class="close" onclick="closeColSet()">×</span></div>
<div style="padding:14px 16px;display:flex;flex-direction:column;gap:10px">
<div class="tw" style="max-height:46vh">
<table><colgroup><col style="width:56px"><col><col style="width:64px"><col style="width:130px"></colgroup>
<thead><tr><th class="c">序号</th><th>名称</th><th class="c">值</th><th class="c">操作</th></tr></thead>
<tbody id="colBody"></tbody>
<div class="tw" style="max-height:52vh">
<table><colgroup><col style="width:56px"><col style="width:110px"><col style="width:110px"><col></colgroup>
<thead><tr><th class="c">#</th><th>后缀</th><th>上传日期</th><th>导出文件数据结构</th></tr></thead>
<tbody id="frameBody"></tbody>
</table>
</div>
<div class="tip" id="fmsg" style="padding:0;min-height:18px"></div>
</div>
</div>
</div>
@@ -1471,11 +1538,14 @@ function renderXTabs(){
}
function showPage(which){
// 决策 152:页面三态切换 —— 列表 / 明细(决策 150)/ 附件动态标签页
const lp=$('lpanel'), dp=$('dpage'), qp=$('qpage');
const lp=$('lpanel'), dp=$('dpage'), qp=$('qpage'), kp=$('klpage');
lp.style.display = which==='list' ? '' : 'none';
dp.style.display = which==='detail' ? 'flex' : 'none';
qp.style.display = which==='inq' ? 'flex' : 'none';
if(which!=='list'){
kp.style.display = which==='qlist' ? 'flex' : 'none';
if(which==='qlist'){
kp.style.height=Math.max(420, window.innerHeight-kp.getBoundingClientRect().top-24)+'px';
}else if(which!=='list'){
const el = which==='detail' ? dp : qp;
el.style.height=Math.max(420, window.innerHeight-el.getBoundingClientRect().top-24)+'px';
}
@@ -2015,6 +2085,11 @@ document.querySelectorAll('.tab[data-kind]').forEach(t=>t.onclick=()=>{
document.querySelectorAll('.tab[data-kind]').forEach(x=>x.classList.remove('on'));
t.classList.add('on'); KIND=t.dataset.kind; SORT={key:'',dir:'DESC'}; syncBtns();
XLAST=KIND;
// 清单库固定标签(2026-11-04 主人定):独立三区域页,不走批次列表/筛选
if(KIND==='qlist'){
if(XACT>=0){ XACT=-1; renderXTabs(); xsave(); }
showPage('qlist'); qlLoad(); return;
}
if(XACT>=0){ XACT=-1; renderXTabs(); showDetail(false); xsave(); } // 从明细标签切回列表区(动态标签保留)
ldWrap('','正在加载列表…',()=>{ load(1); loadFilters(); }); // 列表取数期间挂进度条(快则不闪);loadFilters=过滤文案随页签刷新(2026-11-02 询价单位/发布单位)
});
@@ -2549,231 +2624,8 @@ let FRAMES = [];
async function openFrames(){
$('fmask').classList.add('on');
$('fmsg').textContent='';
ftabSet('exp');
await framesLoad();
}
/* ---- 设置弹框标签卡 + 工料机卡 + 列设置(2026-11-04 主人定)---- */
function ftabSet(which){
const exp = which === 'exp';
$('ftabExp').classList.toggle('on', exp);
$('ftabLme').classList.toggle('on', !exp);
$('fpaneExp').style.display = exp ? '' : 'none';
$('fpaneLme').style.display = exp ? 'none' : '';
if(!exp) lmeSetRender();
}
function fsetAdd(){ // 共用「添加」:导出卡=选文件入库;工料机卡=列设置
const exp = $('fpaneExp').style.display !== 'none';
if(exp) framesAdd(); else openColSet();
}
function escLme(v){ return String(v==null?'':v).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
function colSetLoad(){ // 自定义列清单(localStorage 持久;损坏回空)
try{ const v = JSON.parse(localStorage.getItem('lme_colset')||'null');
if(Array.isArray(v) && v.every(c => c && c.key && 'name' in c))
return v; }catch(e){}
return [];
}
function colSetSave(cs){ try{ localStorage.setItem('lme_colset', JSON.stringify(cs)); }catch(e){} }
function lmeStartGet(key, sfx){ try{ return localStorage.getItem('lme_start_'+key+'_'+sfx)||''; }catch(e){ return ''; } }
function lmeStartSet(key, sfx, v){ try{ localStorage.setItem('lme_start_'+key+'_'+sfx, v); }catch(e){} }
function lmeSetRender(){ // 工料机卡:# /后缀 /起点 固定最前 + 自定义勾选列按序
const suffixes = [];
(FRAMES||[]).forEach(r => { if(!suffixes.includes(r.suffix)) suffixes.push(r.suffix); });
const cols = colSetLoad().filter(c => c.on);
$('lmeSetHead').innerHTML = '<th class="c" style="width:56px">#</th><th>后缀</th><th>起点</th>'
+ cols.map(c => '<th>' + escLme(c.name) + '</th>').join('');
let html = '';
suffixes.forEach((sfx, i) => {
html += '<tr><td class="c">' + (i+1) + '</td><td>' + escLme(sfx) + '</td>'
+ lmeCell('start', sfx)
+ cols.map(c => lmeCell(c.key, sfx, true)).join('')
+ '</tr>';
});
$('lmeSetBody').innerHTML = html
|| '<tr><td colspan="9" class="c" style="color:#888">还没有骨架:先在「导出」卡添加,后缀会带到这里</td></tr>';
}
/* 单元格(2026-11-04 主人定):常显值文本(自定义列带圆形「代」按钮=haobtn 同款);
双击进入行内编辑——编辑框布满单元格、与单元格边线偏差≤2px(决策 174 通用设计);
代按钮占位不算编辑区(点击它不开编辑)。 */
function lmeCell(key, sfx, dai){
const val = escLme(lmeStartGet(key, sfx));
return '<td class="lmetd" data-key="' + escLme(key) + '" data-sfx="' + escLme(sfx) + '"'
+ ' ondblclick="lmeCellEdit(this)" title="双击编辑">'
+ '<span class="lmeval">' + val + '</span>'
+ (dai ? '<span class="haobtn" title="代号清单:插行/删行,点行代入"'
+ ' onclick="event.stopPropagation();daiPop(this,\'' + escLme(key) + '\',\'' + escLme(sfx) + '\')">代</span>' : '')
+ '</td>';
}
function lmeCellEdit(td){
if(td.querySelector('input')) return;
const key = td.dataset.key, sfx = td.dataset.sfx;
const old = lmeStartGet(key, sfx);
td.style.position = 'relative';
const inp = document.createElement('input');
inp.type = 'text'; inp.value = old;
inp.style.cssText = 'position:absolute;left:1px;top:1px;right:1px;bottom:1px;width:calc(100% - 2px);'
+ 'height:calc(100% - 2px);border:1px solid var(--c2);padding:0 3px;box-sizing:border-box;font-size:12px;z-index:5';
td.appendChild(inp);
inp.focus(); inp.select();
let done = false;
const finish = save => {
if(done) return; done = true;
if(save && inp.value !== old) lmeStartSet(key, sfx, inp.value);
lmeSetRender();
};
inp.onkeydown = e => { if(e.key === 'Enter') finish(true); if(e.key === 'Escape') finish(false); };
inp.onblur = () => finish(true);
}
/* ---- 「代」按钮浮层:该列的代号清单(字段=序号|代号;可插行/删行;点行代入本格)---- */
function daiGet(key, sfx){
try{ const v = JSON.parse(localStorage.getItem('lme_dai_' + key + '_' + sfx) || 'null');
return Array.isArray(v) ? v : []; }catch(e){ return []; }
}
function daiSet(key, sfx, arr){ try{ localStorage.setItem('lme_dai_' + key + '_' + sfx, JSON.stringify(arr)); }catch(e){} }
let DAI_POP = null;
function daiClose(){ if(DAI_POP){ DAI_POP.remove(); DAI_POP = null; } }
function daiPop(btn, key, sfx){
daiClose();
const list = daiGet(key, sfx);
const p = document.createElement('div');
p.className = 'haopop';
p.style.cssText = 'width:230px;padding:8px';
p.innerHTML = '<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:6px">'
+ '<b style="color:#123a6b;font-size:12px">代号清单</b>'
+ '<a href="javascript:daiAdd(\'' + escLme(key) + '\',\'' + escLme(sfx) + '\')" style="color:#26405e">+插行</a></div>'
+ '<table style="width:100%"><thead><tr>'
+ '<th class="c" style="width:44px">序号</th><th>代号</th><th style="width:44px"></th></tr></thead><tbody>'
+ (list.length ? list.map((d, i) =>
'<tr><td class="c">' + (i+1) + '</td>'
+ '<td><input type="text" value="' + escLme(d) + '" style="width:100%;border:1px solid #c9d4e2;padding:1px 4px"'
+ ' onchange="daiRename(\'' + escLme(key) + '\',\'' + escLme(sfx) + '\',' + i + ',this.value)"></td>'
+ '<td class="c"><a href="javascript:daiPick(\'' + escLme(key) + '\',\'' + escLme(sfx) + '\',' + i + ')"'
+ ' style="color:#26405e" title="代入本格">代</a> '
+ '<a href="javascript:daiDel(\'' + escLme(key) + '\',\'' + escLme(sfx) + '\',' + i + ')" style="color:#c0392b">×</a></td></tr>').join('')
: '<tr><td colspan="3" class="c" style="color:#888">空——点右上「+插行」加代号</td></tr>')
+ '</tbody></table>';
document.body.appendChild(p);
const rc = btn.getBoundingClientRect();
p.style.left = Math.max(4, Math.min(rc.left, window.innerWidth - 244)) + 'px';
p.style.top = Math.min(rc.bottom + 4, window.innerHeight - 160) + 'px';
DAI_POP = p;
setTimeout(() => document.addEventListener('mousedown', daiOutside, true), 0);
}
function daiOutside(e){
if(DAI_POP && !DAI_POP.contains(e.target)) { daiClose();
document.removeEventListener('mousedown', daiOutside, true); }
}
function daiAdd(key, sfx){
const a = daiGet(key, sfx); a.push(''); daiSet(key, sfx, a);
const btn = document.querySelector('.haobtn[title*="代号清单"]');
daiClose();
if(btn) daiPop(btn, key, sfx);
}
function daiRename(key, sfx, i, v){
const a = daiGet(key, sfx); a[i] = v; daiSet(key, sfx, a);
}
function daiPick(key, sfx, i){
const a = daiGet(key, sfx);
if(a[i] === '' ) { $('fmsg').textContent = '代号是空的,先填内容'; return; }
lmeStartSet(key, sfx, a[i]);
daiClose();
lmeSetRender();
$('fmsg').textContent = '已代入:' + a[i];
}
function daiDel(key, sfx, i){
const a = daiGet(key, sfx); a.splice(i, 1); daiSet(key, sfx, a);
const btn = document.querySelector('.haobtn[title*="代号清单"]');
daiClose();
if(btn) daiPop(btn, key, sfx);
}
/* ---- 列设置弹框(2026-11-04 主人定 v2:无确定/取消=即时保存;插=往后面一行插入;
# /后缀/起点 固定最前、不进列设置——这里只管自定义列;新建时固定送一行空列;
自定义列有值不可删、无值才可删。---- */
function openColSet(){
const cs = colSetLoad();
if(cs.length === 0){ // 新建时固定有一行(空列占位)
cs.push({ key: 'c' + Date.now(), name: '', on: true });
colSetSave(cs);
}
colRender();
$('colmask').classList.add('on');
}
function closeColSet(){ $('colmask').classList.remove('on'); }
colmask.onclick = e => { if(e.target===colmask) closeColSet() };
function colSaveRender(){ // 每次改动即时落存+两处同步刷新
colRender();
lmeSetRender();
}
function colRender(){
const cs = colSetLoad();
$('colBody').innerHTML = cs.map((c, i) =>
'<tr><td class="c">' + (i+1) + '</td>'
+ '<td class="colnm" data-i="' + i + '" ondblclick="colNameEdit(this)" title="双击编辑列名">'
+ '<span class="lmeval">' + escLme(c.name) + '</span></td>'
+ '<td class="c"><input type="checkbox" ' + (c.on?'checked':'') + ' onchange="colToggle(' + i + ',this.checked)"></td>'
+ '<td class="c">'
+ '<a href="javascript:colMove(' + i + ',-1)" style="color:#26405e">↑</a> '
+ '<a href="javascript:colMove(' + i + ',1)" style="color:#26405e">↓</a> '
+ '<a href="javascript:colInsert(' + i + ')" style="color:#26405e" title="往后面一行插入新列">插</a> '
+ '<a href="javascript:colDel(' + i + ')" style="color:#c0392b">×</a>'
+ '</td></tr>').join('');
}
function colNameEdit(td){ // 列名:双击编辑(决策174 布满单元格)
if(td.querySelector('input')) return;
const i = +td.dataset.i;
const cs = colSetLoad();
const old = cs[i].name;
td.style.position = 'relative';
const inp = document.createElement('input');
inp.type = 'text'; inp.value = old;
inp.style.cssText = 'position:absolute;left:1px;top:1px;right:1px;bottom:1px;width:calc(100% - 2px);'
+ 'height:calc(100% - 2px);border:1px solid var(--c2);padding:0 3px;box-sizing:border-box;font-size:12px;z-index:5';
td.appendChild(inp);
inp.focus(); inp.select();
let done = false;
const finish = save => {
if(done) return; done = true;
if(save && inp.value !== old){ cs[i].name = inp.value; colSetSave(cs); }
colSaveRender();
};
inp.onkeydown = e => { if(e.key === 'Enter') finish(true); if(e.key === 'Escape') finish(false); };
inp.onblur = () => finish(true);
}
function colRename(i, v){
const cs = colSetLoad(); cs[i].name = v; colSetSave(cs);
colSaveRender();
}
function colToggle(i, on){
const cs = colSetLoad(); cs[i].on = on; colSetSave(cs);
colSaveRender();
}
function colMove(i, d){
const cs = colSetLoad();
const j = i + d;
if(j < 0 || j >= cs.length) return;
const t = cs[i]; cs[i] = cs[j]; cs[j] = t;
colSetSave(cs);
colSaveRender();
}
function colInsert(i){
const cs = colSetLoad();
cs.splice(i + 1, 0, { key: 'c' + Date.now(), name: '', on: true }); // 往后面一行插入
colSetSave(cs);
colSaveRender();
}
function colHasValue(i){ // 该列在所有后缀行上是否有值
const cs = colSetLoad();
const key = cs[i] ? cs[i].key : null;
const suffixes = [];
(FRAMES||[]).forEach(r => { if(!suffixes.includes(r.suffix)) suffixes.push(r.suffix); });
return suffixes.some(sfx => lmeStartGet(key, sfx) !== '');
}
function colDel(i){
if(colHasValue(i)) { $('fmsg').textContent = '该列已有值,不能删除'; return; }
const cs = colSetLoad();
cs.splice(i, 1);
colSetSave(cs);
colSaveRender();
}
function closeFrames(){ $('fmask').classList.remove('on'); }
fmask.onclick = e => { if(e.target===fmask) closeFrames() };
@@ -2828,11 +2680,6 @@ function framesExportAnnotated(sig){
framesSaveFile(sig, r.original_name || '骨架', '空骨架(标注)', r.suffix || 'cos4');
}
/* 工料机卡单元格(2026-11-04):值+圆形代按钮;双击编辑(决策174 布满) */
.lmetd{position:relative;cursor:default;min-width:90px}
.lmetd .lmeval{white-space:pre-wrap}
.lmetd .haobtn{float:right;margin-left:6px}
.colnm{position:relative;cursor:default;min-width:110px}
/* 统一另存为(2026-11-03 主人定「导出一律另存为方式」):
showSaveFilePicker 弹系统保存对话框,用户选路径后写入。
kind='空骨架(标注)' → /api/admin/frames/blankpkg/{sig}(原格式空骨架+自增/固定标注,后缀跟骨架);
@@ -3171,6 +3018,308 @@ dmask.onclick = e => { if(e.target===dmask) closeDict() };
/* 页面初始化(2026-10-06 修):这一行原本调用的是 loadUpMax() —— 本页根本没有这个函数
(真名是 upLoad(),就在上面十几行)。顶层一条语句炸掉,后面**全部不执行**:
load(1) 没了 → 列表空着、"共 N 个"也不出,页面却看着没坏,最难往这里想。 */
/* ===== 清单库三区域(2026-11-04 主人定)=====
区域1:根目录→省→清单名称(严格三级;根下加=省、省下加=清单名称,「清单名称」下加的进区域2);
区域2:选中第3级「清单名称」后画它的章节目录(层级不限,默认全展开),任一章节可再挂子章节;
区域3:真正的清单条目——编码/名称/项目特征/单位/工程量(工程量默认 1.000,空=1.000)。
两棵树探索器式 +/- 把手 + 连线;目录可编辑(+子目录/✎/↑/↓/✕,错误提示走 alert,同价格目录)。
后端:GET /api/admin/qlist/tree、/api/admin/qlist/items?dir_id=;
POST /api/admin/qlist/save(目录)、/api/admin/qlist/items(条目)。 */
const QL={tree:[],root:0,sel1:0,sel2:0,open1:{},open2:{},rows:[],ren:0,newp:0,edit:0};
function qlNode(id,list){ // 按 id 找节点(QL.tree 顶层=省列表;根是虚拟节点)
list=list||QL.tree;
for(const n of list){ if(n.id===id) return n; const h=qlNode(id,n.children); if(h) return h; }
return null;
}
function qlParent(id,list,pid){ // 父 id(找不到=-1;根的父=0)
list=list||QL.tree; pid=pid===undefined?0:pid;
for(const n of list){ if(n.id===id) return pid; const r=qlParent(id,n.children,n.id); if(r!==-1) return r; }
return -1;
}
function qlSibsArr(id){ // 同级数组(算 ↑↓ 可用性)
if(id===QL.root) return null;
const p=qlParent(id);
if(p<=0) return QL.tree; // 省(父=根)
const pn=qlNode(p); return pn?pn.children:null;
}
function qlSel1(id){ // 区域1 选中(切选中必清区域2/3,防旧章节残留)
QL.sel1=id; QL.ren=0; QL.newp=0; QL.sel2=0; QL.open2={};
qlRender1(); qlRender2(); qlLoadItems();
}
function qlSel2(id){ QL.sel2=id; QL.ren=0; QL.newp=0; QL.edit=0; qlRender2(); qlLoadItems(); }
function qlTgl(id,region,ev){ // +/- 把手:未标记=展开(默认全开),false=收
ev.stopPropagation();
const bag=(region===1)?QL.open1:QL.open2;
bag[id]=(bag[id]===false);
qlRender1(); qlRender2();
}
/* ---- 渲染:区域1(根→省→清单名称,深度>2 的章节不进这棵树)---- */
function qlRender1(){
$('ktree1').innerHTML='<ul class="ktree">'+qlHtml1()+'</ul>';
qlSyncRt();
const ip=$('knew_ip')||$('kren_ip'); if(ip){ ip.focus(); ip.select(); qlArm(); }
}
function qlHtml1(){
const open=QL.open1[QL.root]!==false;
let root;
if(QL.ren===QL.root) root=qlRenInner({name:'根目录'});
else root='<div class="knode'+(QL.sel1===QL.root?' on':'')+'" onclick="qlSel1('+QL.root+')">'
+'<span class="ktg" onclick="qlTgl('+QL.root+',1,event)">'+(open?'-':'+')+'</span>'
+'<span class="kico">'+(open?'📂':'📁')+'</span><span class="knm">根目录</span></div>';
let h='<li class="kt0">'+root;
if(QL.newp && QL.newp.region===1 && QL.newp.parent===QL.root) h+=qlNewRow(QL.root,1);
if(open) h+='<ul>'+QL.tree.map(n=>qlLi1(n)).join('')+'</ul>';
return h+'</li>';
}
function qlLi1(n){ // 省(深度1,可展开)/清单名称(深度2,区域1叶子)
const kids=n.children||[], open=QL.open1[n.id]!==false, isTop=(n.depth<2);
let inner;
if(QL.ren===n.id) inner=qlRenInner(n);
else inner='<div class="knode'+(QL.sel1===n.id?' on':'')+'" onclick="qlSel1('+n.id+')">'
+'<span class="ktg'+((!isTop||!kids.length)?' em':'')+'"'
+((isTop&&kids.length)?' onclick="qlTgl('+n.id+',1,event)"':'')+'>'+(open?'-':'+')+'</span>'
+'<span class="kico">'+((open&&isTop&&kids.length)?'📂':'📁')+'</span>'
+'<span class="knm" title="'+esc(n.name)+'">'+esc(n.name)+'</span>'
+(n.depth===2&&n.n_items?'<span class="kcnt">'+n.n_items+'</span>':'')
+'</div>';
let kid='';
if(isTop&&open&&kids.length) kid='<ul>'+kids.map(c=>qlLi1(c)).join('')+'</ul>';
if(QL.newp && QL.newp.region===1 && QL.newp.parent===n.id) kid+='<ul>'+qlNewRow(n.id,1)+'</ul>';
return '<li>'+inner+kid+'</li>';
}
/* ---- 渲染:区域2(选中清单名称的章节树,层级不限,默认全展开)---- */
function qlRender2(){
$('ktree2').innerHTML=qlHtml2();
qlSyncRt();
const ip=$('knew_ip')||$('kren_ip'); if(ip){ ip.focus(); ip.select(); qlArm(); }
}
function qlHtml2(){
const n=qlNode(QL.sel1);
if(!n || n.depth!==2)
return '<div class="khint">← 在左边点选第 3 级「清单名称」,<br>这里显示它的章节目录</div>';
if(!n.children.length){
// 空目录也要能建第一个章节:新增行挂在选中的清单名下(2026-11-04 实测补)
if(QL.newp && QL.newp.region===2 && QL.newp.parent===n.id)
return '<ul class="ktree">'+qlNewRow(n.id,2)+'</ul>';
return '<div class="khint">「'+esc(n.name)+'」还没有章节目录 ——<br>点上面「+子目录」建第一个</div>';
}
return '<ul class="ktree">'+n.children.map(c=>qlLi2(c)).join('')+'</ul>';
}
function qlLi2(n){
const kids=n.children||[], open=QL.open2[n.id]!==false;
let inner;
if(QL.ren===n.id) inner=qlRenInner(n);
else inner='<div class="knode'+(QL.sel2===n.id?' on':'')+'" onclick="qlSel2('+n.id+')">'
+'<span class="ktg'+(kids.length?'':' em')+'"'+(kids.length?' onclick="qlTgl('+n.id+',2,event)"':'')+'>'+(open?'-':'+')+'</span>'
+'<span class="kico">'+((open&&kids.length)?'📂':'📁')+'</span>'
+'<span class="knm" title="'+esc(n.name)+'">'+esc(n.name)+'</span>'
+(n.n_items?'<span class="kcnt">'+n.n_items+'</span>':'')
+'</div>';
let kid=(open&&kids.length)?'<ul>'+kids.map(c=>qlLi2(c)).join('')+'</ul>':'';
if(QL.newp && QL.newp.region===2 && QL.newp.parent===n.id) kid+='<ul>'+qlNewRow(n.id,2)+'</ul>';
return '<li>'+inner+kid+'</li>';
}
/* ---- 行内编辑(改名 / 新增目录)----
输入口径全按决策 271补(项目目录同款缺陷已定案):①中文输入法组词回车不作数
(isComposing/229);②点别处=有值就提交、空值放弃(blur + document mousedown 双通道,
mousedown 先于 blur 必发、不依赖焦点移动);③提交路径开头先摘保底监听+清状态,防二次提交。 */
function qlRenInner(n){
return '<div class="knode"><span class="ktg em"></span><span class="kico">📁</span>'
+'<input class="kren" id="kren_ip" value="'+esc(n.name)+'" onkeydown="qlRenKey(event)" onblur="qlRenBlur()">'
+'<span class="kcfm"><span class="kpk" title="确认" onclick="qlRenGo()">✓</span>'
+'<span class="kpd" title="取消" onclick="qlRenCancel()">✕</span></span></div>';
}
function qlNewRow(parentId,region){
return '<li><div class="knode"><span class="ktg em"></span><span class="kico">📁</span>'
+'<input class="kren" id="knew_ip" placeholder="目录名称,回车保存" onkeydown="qlNewKey(event)" onblur="qlNewBlur()">'
+'<span class="kcfm"><span class="kpk" title="保存" onclick="qlNewGo()">✓</span>'
+'<span class="kpd" title="取消" onclick="qlNewCancel()">✕</span></span></div></li>';
}
let QLOUT=null;
function qlDisarm(){ if(QLOUT){ document.removeEventListener('mousedown',QLOUT); QLOUT=null; } }
function qlArm(){ // 点别处提交的保底(新增/改名共用)
qlDisarm();
QLOUT=function(e){
if(e.target && (e.target.id==='knew_ip' || e.target.id==='kren_ip')) return;
qlDisarm();
if(QL.newp) qlNewGo();
if(QL.ren) qlRenGo();
};
document.addEventListener('mousedown',QLOUT);
}
function qlOpenPath(id,region){ // 新增/选中时把父链全展开
const bag=(region===1)?QL.open1:QL.open2;
let cur=id;
while(cur && cur!==QL.root && cur!==QL.sel1){ bag[cur]=true; const p=qlParent(cur); if(p<=0) break; cur=p; }
}
/* ---- 工具排可用性(.rtbar span.dis 灰禁)---- */
function qlSyncRt(){
const set=(id,on)=>{ const el=$(id); if(el) el.classList.toggle('dis',!on); };
const n1=qlNode(QL.sel1), n2=qlNode(QL.sel2);
const hasSib=(n,d)=>{ if(!n) return false; const a=qlSibsArr(n.id); if(!a) return false;
const i=a.findIndex(x=>x.id===n.id), j=i+d; return i>=0&&j>=0&&j<a.length; };
set('kadd1',true);
set('kren1',!!QL.sel1);
set('kup1',hasSib(n1,-1)); set('kdn1',hasSib(n1,1));
set('kdel1',!!QL.sel1&&QL.sel1!==QL.root);
set('kadd2',!!n1&&n1.depth===2);
set('kren2',!!n2); set('kup2',hasSib(n2,-1)); set('kdn2',hasSib(n2,1)); set('kdel2',!!n2);
set('kaddi',!!n2);
}
/* ---- 目录增删改名上下移(POST /api/admin/qlist/save)---- */
async function qlDirPost(payload){
const r=await J('/api/admin/qlist/save',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify(payload)});
if(!r.ok){ alert(r.msg); return null; }
return r;
}
function qlAdd1(){ qlNewStart(QL.sel1||QL.root,1); } // 根下=省、省下=清单名称、清单名称下=章节(层级自动)
function qlAdd2(){ const n=qlNode(QL.sel1); if(!n||n.depth!==2) return; qlNewStart(QL.sel2||QL.sel1,2); }
function qlNewStart(parent,region){ QL.newp={parent,region}; QL.ren=0; qlOpenPath(parent,region); qlRender1(); qlRender2(); }
function qlNewCancel(){ QL.newp=0; qlDisarm(); qlRender1(); qlRender2(); }
function qlNewKey(e){
e.stopPropagation();
if(e.isComposing || e.keyCode===229) return; // 输入法组词回车不作数(决策 271补 同款)
if(e.key==='Enter') qlNewGo();
else if(e.key==='Escape') qlNewCancel();
}
function qlNewBlur(){ if(QL.newp) qlNewGo(); } // 点开别处=有值就提交、空值放弃
async function qlNewGo(){
if(!QL.newp) return;
qlDisarm();
const ip=$('knew_ip');
const parent=QL.newp.parent, region=QL.newp.region;
const name=(ip&&ip.value||'').trim();
QL.newp=0; // 先摘状态:blur/保底监听不再二次提交
if(!name){ qlRender1(); qlRender2(); return; }
const r=await qlDirPost({op:'add',parent_id:parent,name});
if(!r){ qlRender1(); qlRender2(); return; }
await qlLoad();
if(r.id){ // 新清单名称=自动选中(区域2立即可用);新章节=自动选中出条目表
if(r.depth===2) qlSel1(r.id);
else if(r.depth>=3 && qlNode(QL.sel1) && qlParent(r.id)===QL.sel1) qlSel2(r.id);
}
}
function qlRen1(){ if(!QL.sel1) return; QL.newp=0; QL.ren=QL.sel1; qlRender1(); qlRender2(); }
function qlRen2(){ if(!QL.sel2) return; QL.newp=0; QL.ren=QL.sel2; qlRender1(); qlRender2(); }
function qlRenCancel(){ QL.ren=0; qlDisarm(); qlRender1(); qlRender2(); }
function qlRenKey(e){
e.stopPropagation();
if(e.isComposing || e.keyCode===229) return; // 同 qlNewKey:组词回车不作数
if(e.key==='Enter') qlRenGo();
else if(e.key==='Escape') qlRenCancel();
}
function qlRenBlur(){ if(QL.ren) qlRenGo(); } // 点开别处=有值就提交
async function qlRenGo(){
if(!QL.ren) return;
qlDisarm();
const ip=$('kren_ip'); const did=QL.ren;
const name=(ip&&ip.value||'').trim();
QL.ren=0; // 先摘状态防二次提交
if(!name){ qlRender1(); qlRender2(); return; }
const r=await qlDirPost({op:'rename',id:did,name});
if(!r){ qlRender1(); qlRender2(); return; }
await qlLoad();
}
async function qlSeq(d,region){
const id=(region===1)?QL.sel1:QL.sel2; if(!id) return;
const r=await qlDirPost({op:'seq',id:id,dir:d>0?'down':'up'});
if(!r) return; await qlLoad();
}
function qlSeq1(d){ qlSeq(d,1); } function qlSeq2(d){ qlSeq(d,2); }
async function qlDel1(){
const id=QL.sel1; if(!id||id===QL.root) return;
const n=qlNode(id); if(!n) return;
if(!(await uiConfirm('删除目录「'+n.name+'」?',
(n.children&&n.children.length)?'它下面还有子目录,要先删光子目录才能删它。':'删除后不可恢复。'))) return;
const r=await qlDirPost({op:'del',id:id}); if(!r) return;
if(QL.sel1===id){ QL.sel1=0; QL.sel2=0; QL.rows=[]; }
await qlLoad();
}
async function qlDel2(){
const id=QL.sel2; if(!id) return;
const n=qlNode(id); if(!n) return;
const warn=[];
if(n.children&&n.children.length) warn.push('子目录 '+n.children.length+' 个(要先删光子目录)');
if(n.n_items) warn.push('清单条目 '+n.n_items+' 条(将一并删除)');
if(!(await uiConfirm('删除章节目录「'+n.name+'」?', warn.length?warn.join(';'):'删除后不可恢复。'))) return;
const r=await qlDirPost({op:'del',id:id}); if(!r) return;
if(QL.sel2===id){ QL.sel2=0; QL.rows=[]; }
await qlLoad();
}
/* ---- 加载 ---- */
async function qlLoad(){
const d=await J('/api/admin/qlist/tree');
if(d.ok===false){ alert(d.msg||'清单库加载失败'); return; }
QL.tree=d.tree||[]; QL.root=d.root||0;
if(QL.sel1 && QL.sel1!==QL.root && !qlNode(QL.sel1)){ QL.sel1=0; QL.sel2=0; QL.rows=[]; }
if(QL.sel2 && !qlNode(QL.sel2)){ QL.sel2=0; QL.rows=[]; }
qlRender1(); qlRender2(); qlLoadItems();
}
/* ---- 区域3:真正的清单条目(编码/名称/项目特征/单位/工程量)---- */
async function qlLoadItems(){
const tb=$('kitemsb'), where=$('kwhere');
if(!QL.sel2){
tb.innerHTML='<tr><td colspan="6" class="kempty">← 在中间区域选中章节目录,这里出真正的清单条目</td></tr>';
where.textContent=''; where.title=''; return;
}
const n=qlNode(QL.sel2);
where.textContent='目录:'+(n?n.name:'');
where.title=where.textContent;
const d=await J('/api/admin/qlist/items?dir_id='+QL.sel2);
if(d.ok===false){ tb.innerHTML='<tr><td colspan="6" class="kempty">'+esc(d.msg||'加载失败')+'</td></tr>'; return; }
QL.rows=d.rows||[];
tb.innerHTML=QL.rows.length?QL.rows.map(qlItemRow).join('')
:'<tr><td colspan="6" class="kempty">这个章节还没有条目 —— 点「+条目」录第一条(工程量默认 1.000)</td></tr>';
}
function qlItemRow(r){
if(QL.edit===r.id){
return '<tr class="pedit">'
+'<td><input id="ke_code" value="'+esc(r.code)+'"></td>'
+'<td><input id="ke_name" value="'+esc(r.name)+'" onkeydown="if(event.key===\'Enter\')qlItemSave('+(r.id||0)+')"></td>'
+'<td><textarea id="ke_feat" rows="3">'+esc(r.feature)+'</textarea></td>'
+'<td><input id="ke_unit" value="'+esc(r.unit)+'" onkeydown="if(event.key===\'Enter\')qlItemSave('+(r.id||0)+')"></td>'
+'<td><input id="ke_qty" value="'+Number(r.qty||0).toFixed(3)+'" onkeydown="if(event.key===\'Enter\')qlItemSave('+(r.id||0)+')"></td>'
+'<td><a href="javascript:void(0)" onclick="qlItemSave('+(r.id||0)+')">保存</a>'
+'<a href="javascript:void(0)" onclick="qlItemCancel()">取消</a></td></tr>';
}
return '<tr>'
+'<td>'+esc(r.code)+'</td>'
+'<td>'+esc(r.name)+'</td>'
+'<td class="kfeat" title="'+esc(r.feature)+'">'+esc(r.feature)+'</td>'
+'<td class="kc">'+esc(r.unit)+'</td>'
+'<td class="kr">'+num(r.qty,3)+'</td>'
+'<td><a href="javascript:void(0)" onclick="qlItemEdit('+r.id+')">编辑</a>'
+'<a href="javascript:void(0)" onclick="qlItemDel('+r.id+')">删除</a></td></tr>';
}
function qlItemAdd(){
if(!QL.sel2){ alert('先在中间区域选中章节目录'); return; }
QL.edit=-1;
const blank={id:-1,code:'',name:'',feature:'',unit:'',qty:1};
$('kitemsb').innerHTML=(QL.rows.length?QL.rows.map(qlItemRow).join(''):'')+qlItemRow(blank);
const f=$('ke_name'); if(f) f.focus();
}
function qlItemEdit(id){ QL.edit=id; $('kitemsb').innerHTML=QL.rows.map(qlItemRow).join('');
const f=$('ke_name'); if(f){ f.focus(); f.select(); } }
function qlItemCancel(){ QL.edit=0; qlLoadItems(); }
async function qlItemSave(id){
const body={op:id>0?'edit':'add',dir_id:QL.sel2,
code:$('ke_code').value.trim(), name:$('ke_name').value.trim(),
feature:$('ke_feat').value, unit:$('ke_unit').value.trim(), qty:$('ke_qty').value};
if(id>0) body.id=id;
const r=await J('/api/admin/qlist/items',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify(body)});
if(!r.ok){ alert(r.msg); return; }
QL.edit=0; await qlLoad(); // 整树重拉:区域1/2 的条数徽章同步刷新
}
async function qlItemDel(id){
const r0=QL.rows.find(x=>x.id===id);
if(!(await uiConfirm('删除清单条目「'+(r0?r0.name:'')+'」?','删除后不可恢复。'))) return;
const r=await J('/api/admin/qlist/items',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify({op:'del',id:id})});
if(!r.ok){ alert(r.msg); return; }
await qlLoad();
}
// 页面初载(2026-10-13 主人定:进页面要等待时挂进度条——从工作台切过来时首屏不再是空白静默)
(async function(){
await ldWrap('','正在加载后台数据(项目/筛选/汇总)…', async ()=>{