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 ()=>{

View File

@@ -13,7 +13,8 @@ body{font-family:"Microsoft YaHei",system-ui,sans-serif;margin:0;background:var(
.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-11-04 主人定:搜索框及右侧全部按钮整行右移(右对齐) */
.bar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;padding:6px 0 8px;justify-content:flex-end}
/* 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}
@@ -57,6 +58,26 @@ a:hover{text-decoration:underline}
.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}
/* 项目目录弹框(2026-11-04 主人定):大号弹框 + 目录树(多根/±把手/项目挂下一级) */
.dlg.big{width:780px}
.rtbar{flex:none;display:flex;gap:6px;padding:8px 12px;border-bottom:1px solid var(--line);background:#fafcff;flex-wrap:wrap;align-items:center}
.rtbar .btn{height:26px;padding:0 10px;font-size:12px}
.rtbar .who{color:var(--muted);font-size:11.5px;margin-left:auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:300px}
.pdtree{flex:1;overflow:auto;padding:6px 10px 10px;min-height:300px;max-height:56vh;font-size:12.5px}
.pdrow{display:flex;align-items:center;gap:6px;padding:3px 6px;border-radius:5px;white-space:nowrap;line-height:20px}
.pdrow:hover{background:#f0f5fb}
.pdrow.sel{background:#e0effc}
.pdrow .tw{width:16px;flex:none;text-align:center;cursor:pointer;color:#52708f;font-family:Consolas,monospace;font-weight:700;user-select:none;font-size:14px}
.pdrow .tw:hover{color:var(--c2)}
.pdrow .tw.off{visibility:hidden;cursor:default}
.pdrow .dn{font-weight:600;color:var(--c1);overflow:hidden;text-overflow:ellipsis}
.pdrow .cnt{color:var(--muted);font-size:11px}
.pdrow .pn{color:#26405e;overflow:hidden;text-overflow:ellipsis}
.pdrow .ic{color:#b8860b;font-size:12px;flex:none}
.pdrow select{max-width:280px;height:24px;font:inherit;font-size:12px;border:1px solid #b8c4d4;border-radius:5px;background:#fff;color:#26405e;padding:0 4px}
.pdrow select:focus{outline:2px solid #9cc3ec}
.pdrow input.ren{flex:1;min-width:120px;max-width:320px;height:24px;font:inherit;font-size:12.5px;border:1px solid var(--c2);border-radius:5px;padding:0 6px}
.pdnote{flex:none;padding:8px 12px;border-top:1px solid var(--line);color:var(--muted);font-size:11.5px;background:#fafcff}
</style>
<!-- 2026-10-19 补引共用层样式:本页此前漏引 common.css,.rs 列宽把手因此 0 宽度、
列宽拖不动(核对时发现);表头底线 1px→2px 与工作台/后台一致。 -->
@@ -78,6 +99,8 @@ a:hover{text-decoration:underline}
<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>
<!-- 项目目录(2026-11-04 主人定):全部项目按目录归类管理(弹框树:多根/可多级/±把手/未归类固定节点) -->
<button class="btn wb" onclick="pdOpen()" title="按目录归类管理全部项目:目录可增删改名/上下移,项目行下拉改归属">项目目录</button>
<div class="pager" id="pager"></div>
</div>
<div class="panel">
@@ -103,6 +126,22 @@ a:hover{text-decoration:underline}
</div>
</div>
<!-- 项目目录弹框(2026-11-04 主人定):全部项目按目录归类管理(类似后台信息价的目录树)。
根节点可多个、目录可多级、项目只挂目录的下一级;每个节点最左侧 +/− 展开把手;
「未归类」固定节点在最上;目录增删改名/上下移照决策 48 收编根工具排。 -->
<div class="mask" id="pdmask">
<div class="dlg big">
<div class="dh"><b>项目目录</b><span class="close" title="关闭" onclick="pdClose()">×</span></div>
<div class="dbody" style="padding:0">
<div style="display:flex;flex-direction:column;min-height:0;flex:1">
<div class="rtbar" id="pdrt"></div>
<div class="pdtree" id="pdtree"></div>
<div class="pdnote">提示:点项目行的「所属目录」下拉直接改归属;目录按钮作用于选中的目录(未选中时只有「+子目录」=新增一级根目录);删除目录=其子目录一并删除,目录内项目回「未归类」。</div>
</div>
</div>
</div>
</div>
<script src="common.js?v=20261102a"></script>
<script>
/* 会话管理页:照后台「项目界面」的版式,管的是**还没入库**的工作台会话。
@@ -113,10 +152,10 @@ a:hover{text-decoration:underline}
排序状态 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']];
const SCOLS=[['',36,'c','','ns'],['序号',50,'c','','ns'],['目录',120,'l'],['项目名称',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 SES_NUM=new Set([4]); // 项目总造价 按数值比(2026-11-04 加「目录」列后 3→4)
const NAME_IDX=3; // 伸缩列:项目名称(余宽都给它)(2026-11-04 加「目录」列后 2→3)
const n2 =n=>(n==null?'—':(+n).toLocaleString('zh-CN'));
// 金额:带两位小数。⚠️ 项目总造价取自原文件(含税金/其他项目),**不是**清单合价求和
@@ -129,7 +168,7 @@ function head(){
$('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 */
if(ST.k===i) ST.dir=-ST.dir; else { ST.k=i; ST.dir=(i===6?-1:1); } /* 打开时间首点=最新在前(2026-10-13 主人问询后定);213 补记七:列缩后 10→5;2026-11-04 加「目录」列后 5→6 */
$('th').innerHTML=sortHeadHTML(SCOLS,ST,'sesSort');
render();
}
@@ -185,8 +224,8 @@ async function load(silent){
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]=序号占位 */
.map(x=>[x.id, 0, x.dir||'', 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]); /* [2]目录(2026-11-04 加) [10]手工工程 [9]源文件缺失(决策 94);[6]打开时间 [7]删除ids [8]源文件名;[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 撑满窗口余量),行数超可视范围=前端分页
@@ -205,21 +244,22 @@ function render(){
}else PAG.p=1;
let h='';
rowsToShow.forEach(r=>{
const srcCell = r[9]
const srcCell = r[10]
? `<span class="manualtag" title="手工工程:没有源文件,不能按原格式导出/重新解析;要上源文件数据请先删除本工程,再按源文件重新导入(同名导入会被拒,决策 242)">手工创建</span>`
: (r[8]
? esc(r[4]) + ' <span class="srcmiss" style="color:#c0392b;font-weight:600;white-space:nowrap" title="原文件已不在软件里:该工程无法导出、无法重新解析(已解析的数据仍可查看)。删除会话不受影响">源文件缺失</span>'
: esc(r[4]));
: (r[9]
? esc(r[5]) + ' <span class="srcmiss" style="color:#c0392b;font-weight:600;white-space:nowrap" title="原文件已不在软件里:该工程无法导出、无法重新解析(已解析的数据仍可查看)。删除会话不受影响">源文件缺失</span>'
: esc(r[5]));
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="l name" title="${esc(r[2]||'未归类')}">${esc(r[2]||'—')}</td>
<td class="l name" title="${esc(r[3])}">${esc(r[3]||'(无名)')}</td>
<td class="r" title="${r[4]==null?'原文件里没取到总造价':'工程总造价(原文件口径,含税金与其他项目)'}">${money(r[4])}</td>
<td class="l name" title="${esc(r[8])}">${srcCell}</td>
<td class="c" title="${esc(r[6]||'')}">${esc(r[6]||'—')}</td>
<td class="c">
<a onclick="go(${r[0]})" title="打开最近一次审核,接着上次的活干">打开</a>
<a onclick="del([${(r[6]||[]).join(',')}])" style="margin-left:8px;color:#c0392b">删除</a>
<a onclick="del([${(r[7]||[]).join(',')}])" style="margin-left:8px;color:#c0392b">删除</a>
</td></tr>`;
});
$('tbody').innerHTML=h||`<tr><td colspan="${SCOLS.length}" class="empty">没有匹配的会话</td></tr>`;
@@ -229,15 +269,13 @@ function render(){
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; } }
}
/* 分页条:只有超页时显示 */
/* 分页条常驻(2026-11-04 主人定:上一页/下一页要一直看得见;只有 1 页时两钮置灰) */
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';
const tp=Math.max(1,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>';
updDel();
}
/* 分页翻页(前端切片,不动数据) */
@@ -281,6 +319,246 @@ document.addEventListener('keydown',function(e){
if(e.key==='Escape' && $('dlgmask').classList.contains('on')) dlgCancel();
});
/* ================= 项目目录(2026-11-04 主人定)====================
全部项目按目录归类管理(类似后台信息价的目录树):
· 根节点可多个;目录可多级;项目只挂目录的下一级;
· 每个节点最左侧 +/− 展开把手(有子内容才显示,叶子留空占位);
· 「未归类」固定节点在最上,无目录的项目都列它下面;
· 项目行「所属目录」下拉直接改归属(归属键=项目名称,删工程/重导入不丢);
· 目录 增/改名/删/上下移 收编根工具排,作用于选中目录(决策 48 同款:
未选中时只有「+子目录」=新增一级根目录;↑↓✕ 两段式确认)。 */
let PDIRS=[], PASG={}, PDSEL=0, PDCOL={_n:1}, PDNEW=null, PDREN=0, PDBUSY=false;
async function pdOpen(){
PDSEL=0; PDNEW=null; PDREN=0; PDCOL={};
$('pdmask').classList.add('on');
try{ await pdReload(); }
catch(e){ PDIRS=[]; PASG={}; pdDraw(); toast('目录读取失败:'+e.message); }
}
function pdClose(){ $('pdmask').classList.remove('on'); }
async function pdReload(){
const d=await J('/api/projdirs');
PDIRS=d.dirs||[]; PASG=d.map||{};
syncListDirs(); pdDraw();
}
async function pdSave(body){
if(PDBUSY) return null;
PDBUSY=true;
try{ return await J('/api/projdirs/save',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify(body)}); }
catch(e){ toast('保存失败:'+e.message); return null; }
finally{ PDBUSY=false; }
}
/* 目录变动(改名/移动/删除)后,列表「目录」列的全路径同步重算 */
function syncListDirs(){
ITEMS.forEach(x=>{
const n=(x.name||'').trim();
const did=n?(+PASG[n]||0):0;
x.dir=did?(pdPath(did)||''):'';
});
render(); cacheSave();
}
/* ---- 数据助手 ---- */
function pdKids(pid){ return PDIRS.filter(d=>(+d.parent|0)===(pid|0))
.sort((a,b)=>((+a.sort||0)-(+b.sort||0))||(a.id-b.id)); }
function pdName(id){ const d=PDIRS.find(x=>x.id===id); return d?d.name:''; }
function pdPath(id){ const p=[]; let d=PDIRS.find(x=>x.id===id); const seen=new Set();
while(d && !seen.has(d.id)){ seen.add(d.id); p.unshift(d.name); d=PDIRS.find(x=>x.id===(+d.parent|0)); }
return p.join('/'); }
function pdItemsIn(pid){ return ITEMS.filter(x=>{ const n=(x.name||'').trim();
return n && (+PASG[n]||0)===(pid|0); }); }
function pdItemsNone(){ return ITEMS.filter(x=>{ const n=(x.name||'').trim();
return !n || !(+PASG[n]||0); }); }
function pdDepth(id){ // 目录层号:根=1,子=2,孙=3(2026-11-04 主人定:目录最多 3 层)
let lvl=0, cur=id; const seen=new Set();
while(cur && !seen.has(cur)){ seen.add(cur); lvl++;
const p=PDIRS.find(x=>x.id===cur); if(!p) break; cur=(+p.parent|0); }
return lvl; }
/* ---- 绘制 ---- */
function pdDirOpts(cur){
let h='<option value="0"'+(!cur?' selected':'')+'>未归类</option>';
const walk=pid=>{ pdKids(pid).forEach(d=>{
h+='<option value="'+d.id+'"'+(cur===d.id?' selected':'')+'>'+esc(pdPath(d.id))+'</option>'; walk(d.id); }); };
walk(0);
return h;
}
function pdProjRow(x, depth){
const nm=(x.name||'').trim();
const cur=nm?(+PASG[nm]||0):0;
return `<div class="pdrow pj" style="padding-left:${depth*18+4}px">
<span class="tw off"></span><span class="ic">📄</span>
<span class="pn" style="max-width:360px" title="${esc(nm||'(无名)')}">${esc(nm||'(无名)')}</span>
<select ${nm?'':'disabled title="无名项目不能归类"'} title="改所属目录" onclick="event.stopPropagation()"
onchange="pdAssign(${x.id},this)">${pdDirOpts(cur)}</select></div>`;
}
function pdDirRow(d, depth){
const kd=pdKids(d.id).length, pj=pdItemsIn(d.id).length;
let h=`<div class="pdrow${PDSEL===d.id?' sel':''}" onclick="pdSel(${d.id},event)" style="padding-left:${depth*18+4}px">`;
h+= (kd+pj)>0
? `<span class="tw" title="${PDCOL[d.id]?'展开':'收起'}" onclick="pdToggle(event,${d.id})">${PDCOL[d.id]?'+':'−'}</span>`
: '<span class="tw off"></span>';
h+='<span class="ic">📁</span>';
if(PDREN===d.id){
h+=`<input class="ren" id="pdrenin" value="${esc(d.name)}" onclick="event.stopPropagation()"
onkeydown="pdRenKey(event)" onblur="pdRenBlur()">`;
}else{
h+=`<span class="dn" style="max-width:340px" title="${esc(pdPath(d.id))}">${esc(d.name)}</span>`;
}
h+=`<span class="cnt">(${kd+pj})</span></div>`;
return h;
}
function pdNewRow(depth){
const ph=(PDNEW && (+PDNEW.parent|0)===0)?'根目录名称:回车确认 / ESC 取消':'子目录名称:回车确认 / ESC 取消';
return `<div class="pdrow" style="padding-left:${depth*18+4}px"><span class="tw off"></span><span class="ic">📁</span>
<input class="ren" id="pdnewin" placeholder="${ph}"
onkeydown="pdNewKey(event)" onblur="pdNewBlur()"></div>`;
}
function pdDirRows(pid, depth){
let h='';
pdKids(pid).forEach(d=>{
h+=pdDirRow(d, depth);
if(PDNEW && PDNEW.mode==='sib' && PDNEW.sib===d.id) h+=pdNewRow(depth); // +平级:插在它后面
if(PDNEW && PDNEW.mode==='child' && (+PDNEW.parent|0)===d.id) h+=pdNewRow(depth+1); // +子目录:输入框紧跟父行
if(!PDCOL[d.id]){
h+=pdDirRows(d.id, depth+1);
pdItemsIn(d.id).forEach(x=>{ h+=pdProjRow(x, depth+1); }); // 项目挂目录下一级
}
});
if(PDNEW && PDNEW.mode==='child' && (+PDNEW.parent|0)===0 && pid===0) h+=pdNewRow(depth); // 新增一级根目录:排在根级末尾
return h;
}
function pdNoneRow(){
const none=pdItemsNone(), open=!PDCOL._n;
let h=`<div class="pdrow" style="padding-left:4px">`
+(none.length?`<span class="tw" title="${open?'收起':'展开'}" onclick="pdToggle(event,'_n')">${open?'−':'+'}</span>`
:'<span class="tw off"></span>')
+'<span class="ic">📂</span><span class="dn">未归类</span>'
+`<span class="cnt">(${none.length})</span></div>`;
if(open) none.forEach(x=>{ h+=pdProjRow(x, 1); });
return h;
}
function pdDrawBar(){
const d=PDIRS.find(x=>x.id===PDSEL);
const B=(t,tt,fn,dis,disT)=>dis
? `<button class="btn" disabled title="${disT||'请先点选一个目录'}">${t}</button>`
: `<button class="btn" title="${tt}" onclick="${fn}">${t}</button>`;
const full=d && pdDepth(d.id)>=3; // 目录最多 3 层(2026-11-04 主人定)
$('pdrt').innerHTML =
B(d?'+子目录':'+根目录',
full?'目录最多 3 层:「'+d.name+'」已是第 3 层,不能再建子级'
:(d?('在「'+d.name+'」下新增子目录'):'新增一级根目录(未归类不算目录,不能在它下面建子级)'),
'pdAdd()', !!full, '目录最多 3 层:不能再建子级')
+ B('+平级','在选中目录后面插入平级目录','pdAddSib()',!d)
+ B('✎','重命名选中目录','pdRen()',!d)
+ B('↑','上移选中目录(需确认)','pdMove(-1)',!d)
+ B('↓','下移选中目录(需确认)','pdMove(1)',!d)
+ B('✕','删除选中目录(需确认)','pdDel()',!d)
+ `<span class="who">${d?('当前选中:'+esc(pdPath(d.id))):'未选中目录'}</span>`;
}
function pdDraw(){
pdDrawBar();
$('pdtree').innerHTML=pdNoneRow()+pdDirRows(0,0);
const ni=$('pdnewin'); if(ni) ni.focus();
const ri=$('pdrenin'); if(ri){ ri.focus(); ri.select(); }
if(ni || ri) pdArmOutsideCommit(); // 输入态挂「点别处提交」保底
}
/* ---- 交互 ---- */
function pdSel(id, e){ if(e) e.stopPropagation(); PDSEL=id; PDREN=0; pdDraw(); }
function pdToggle(e, key){ if(e) e.stopPropagation(); if(PDCOL[key]) delete PDCOL[key]; else PDCOL[key]=1; pdDraw(); }
function pdAdd(){ const d=PDIRS.find(x=>x.id===PDSEL);
if(d && pdDepth(d.id)>=3) return; // 目录最多 3 层(双保险,按钮已禁用)
const p=(d?d.id:0); delete PDCOL[p]; // 给折叠目录加子目录时自动展开,否则提交后看不见
PDNEW={parent:p, mode:'child'}; PDREN=0; pdDraw(); }
function pdAddSib(){ const d=PDIRS.find(x=>x.id===PDSEL); if(!d) return;
PDNEW={parent:(+d.parent|0), mode:'sib', sib:d.id}; PDREN=0; pdDraw(); }
function pdRen(){ PDREN=PDSEL; PDNEW=null; pdDraw(); }
function pdNewKey(e){ e.stopPropagation();
if(e.isComposing || e.keyCode===229) return; // 中文输入法组词中的回车/按键不作数(决策 271 补记:组词回车曾把空值当提交→目录"建不出来")
if(e.key==='Escape'){ PDNEW=null; pdDraw(); }
else if(e.key==='Enter'){ pdNewGo(); } }
function pdNewBlur(){ if(PDNEW) pdNewGo(); } // 点开别处=有值就提交、空值放弃(2026-11-04 主人报"建目录失效"后改)
async function pdNewGo(){
if(!PDNEW) return;
pdDisarmOutsideCommit();
const el=$('pdnewin'); const nm=el?el.value.trim():'';
const parent=PDNEW.parent;
PDNEW=null;
if(!nm){ pdDraw(); return; }
const r=await pdSave({op:'add', name:nm, parent:(+parent|0)});
if(r && r.ok){ if(r.id) PDSEL=r.id; await pdReload(); toast('已新增目录「'+nm+'」'); }
else if(r){ dlgNotice(r.msg||'新增失败'); }
}
function pdRenKey(e){ e.stopPropagation();
if(e.isComposing || e.keyCode===229) return; // 同 pdNewKey:输入法组词回车不作数
if(e.key==='Escape'){ PDREN=0; pdDraw(); }
else if(e.key==='Enter'){ pdRenGo(); } }
function pdRenBlur(){ if(PDREN) pdRenGo(); } // 点开别处=有值就提交(pdRenGo 自带空值/同名放弃)
/* 点别处提交的保底(新增/改名共用):mousedown 在 blur 之前必发、不依赖默认行为。
提交路径(Enter/blur)开头主动摘除,防止旧监听在下次点击时把新输入提前提交。 */
let PDOUT=null;
function pdDisarmOutsideCommit(){ if(PDOUT){ document.removeEventListener('mousedown', PDOUT); PDOUT=null; } }
function pdArmOutsideCommit(){
pdDisarmOutsideCommit();
PDOUT=function(e){
if(e.target && (e.target.id==='pdnewin' || e.target.id==='pdrenin')) return;
pdDisarmOutsideCommit();
if(PDNEW) pdNewGo();
if(PDREN) pdRenGo();
};
document.addEventListener('mousedown', PDOUT);
}
async function pdRenGo(){
const el=$('pdrenin'); const did=PDREN;
if(!el || !did) return;
pdDisarmOutsideCommit();
const nm=el.value.trim();
if(!nm || nm===pdName(did)){ PDREN=0; pdDraw(); return; }
PDREN=0;
const r=await pdSave({op:'ren', id:did, name:nm});
if(r && r.ok){ await pdReload(); toast('已改名'); }
else if(r){ dlgNotice(r.msg||'改名失败'); PDREN=did; pdDraw(); }
}
function pdMove(d){
const dsel=PDIRS.find(x=>x.id===PDSEL); if(!dsel) return;
dlgShow('确定把「'+dsel.name+'」'+(d<0?'上移':'下移')+'一位?','确定',async ()=>{
const r=await pdSave({op:'move', id:PDSEL, d});
if(r && r.ok){ await pdReload(); } else if(r){ dlgNotice(r.msg||'移动失败'); }
},'确认',false);
}
function pdDel(){
const dsel=PDIRS.find(x=>x.id===PDSEL); if(!dsel) return;
dlgShow('删除目录「'+dsel.name+'」:其下子目录一并删除,目录内项目回「未归类」。是否删除?','删除',async ()=>{
const did=PDSEL;
const r=await pdSave({op:'del', id:did});
if(r && r.ok){ if(PDSEL===did) PDSEL=0; await pdReload(); toast('已删除'); }
else if(r){ dlgNotice(r.msg||'删除失败'); }
},'确认',true);
}
async function pdAssign(id, sel){
const x=ITEMS.find(v=>v.id===id); if(!x) return;
const nm=(x.name||'').trim();
if(!nm){ toast('无名项目不能归类'); pdDraw(); return; }
const did=+sel.value||0;
const r=await pdSave({op:'assign', name:nm, dir_id:did});
if(r && r.ok){
if(did) PASG[nm]=did; else delete PASG[nm];
syncListDirs(); pdDraw();
toast(did?('已归入「'+pdPath(did)+'」'):'已移出目录(未归类)');
}else if(r){ dlgNotice(r.msg||'归类失败'); }
}
/* 点弹框空白处关闭;ESC 先退输入态、再退选择、最后关弹框(确认弹框开着时只关确认框) */
$('pdmask').addEventListener('click',function(e){ if(e.target===this) pdClose(); });
document.addEventListener('keydown',function(e){
if(e.key!=='Escape' || !$('pdmask').classList.contains('on')) return;
if($('dlgmask').classList.contains('on')) return; // 确认弹框优先,交给它自己的 ESC 处理
if(PDNEW || PDREN){ PDNEW=null; PDREN=0; pdDraw(); return; }
pdClose();
});
async function del(ids){
if(!ids.length) return;
dlgShow('删除后不可恢复,是否删除?','删除',async ()=>{