refactor(cost): 优化LME成员去重与措施清单标签还原,清理临时核查脚本

This commit is contained in:
lianjianwei2024
2026-11-04 18:03:16 +08:00
parent 4e5a157687
commit 449d6d18ba
157 changed files with 82259 additions and 300 deletions

View File

@@ -0,0 +1,211 @@
# -*- coding: utf-8 -*-
"""设置弹框 v3:①工料机表单元格=双击编辑(决策174:编辑框布满单元格偏差≤2px),起点+自定义列;
②自定义列单元格带圆形「代」按钮(haobtn 同款)→ 浮层=该列代号清单(序号|代号,可插行/删行/代入);
③列设置弹框名称列=双击编辑布满单元格。"""
import io
p = r"D:\PricingReview\CostReview\app\ui\admin.html"
s = io.open(p, encoding="utf-8").read()
# ---- ① lmeSetRender 单元格改:常显值+(自定义列)代按钮;双击编辑 ----
old = '''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>';
const sv = escLme(lmeStartGet('start', sfx));
html += '<td><input type="text" value="' + sv + '" style="width:100%;border:1px solid #c9d4e2;padding:2px 6px"'
+ ' onchange="lmeStartSet(\\'start\\',\\'' + escLme(sfx) + '\\',this.value)"></td>';
html += cols.map(c => {
const val = escLme(lmeStartGet(c.key, sfx));
return '<td><input type="text" value="' + val + '" style="width:100%;border:1px solid #c9d4e2;padding:2px 6px"'
+ ' onchange="lmeStartSet(\\'' + c.key + '\\',\\'' + escLme(sfx) + '\\',this.value)"></td>';
}).join('');
html += '</tr>';
});
$('lmeSetBody').innerHTML = html
|| '<tr><td colspan="9" class="c" style="color:#888">还没有骨架:先在「导出」卡添加,后缀会带到这里</td></tr>';
}'''
new = '''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);
}'''
assert old in s, "lmeSetRender NOT FOUND"
s = s.replace(old, new)
# ---- ② 列设置名称列改双击编辑(布满单元格) ----
old2 = '''function colRender(){
const cs = colSetLoad();
$('colBody').innerHTML = cs.map((c, i) =>
'<tr><td class="c">' + (i+1) + '</td>'
+ '<td><input type="text" value="' + escLme(c.name) + '" placeholder="列名"'
+ ' style="width:100%;border:1px solid #c9d4e2;padding:2px 6px"'
+ ' onchange="colRename(' + i + ',this.value)"></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('');
}'''
new2 = '''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);
}'''
assert old2 in s, "colRender NOT FOUND"
s = s.replace(old2, new2)
# ---- ③ .lmetd/.lmeval/.colnm 样式(一次性注入 style 块尾部) ----
old3 = '''/* 统一另存为(2026-11-03 主人定「导出一律另存为方式」):'''
new3 = '''/* 工料机卡单元格(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 主人定「导出一律另存为方式」):'''
assert old3 in s, "css anchor NOT FOUND"
s = s.replace(old3, new3)
io.open(p, "w", encoding="utf-8").write(s)
print("surgery v3 done")