# -*- 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 = '
# | 后缀 | 起点 | '
+ cols.map(c => '' + escLme(c.name) + ' | ').join('');
let html = '';
suffixes.forEach((sfx, i) => {
html += '| ' + (i+1) + ' | ' + escLme(sfx) + ' | ';
const sv = escLme(lmeStartGet('start', sfx));
html += ' | ';
html += cols.map(c => {
const val = escLme(lmeStartGet(c.key, sfx));
return ' | ';
}).join('');
html += '
';
});
$('lmeSetBody').innerHTML = html
|| '| 还没有骨架:先在「导出」卡添加,后缀会带到这里 |
';
}'''
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 = '# | 后缀 | 起点 | '
+ cols.map(c => '' + escLme(c.name) + ' | ').join('');
let html = '';
suffixes.forEach((sfx, i) => {
html += '| ' + (i+1) + ' | ' + escLme(sfx) + ' | '
+ lmeCell('start', sfx)
+ cols.map(c => lmeCell(c.key, sfx, true)).join('')
+ '
';
});
$('lmeSetBody').innerHTML = html
|| '| 还没有骨架:先在「导出」卡添加,后缀会带到这里 |
';
}
/* 单元格(2026-11-04 主人定):常显值文本(自定义列带圆形「代」按钮=haobtn 同款);
双击进入行内编辑——编辑框布满单元格、与单元格边线偏差≤2px(决策 174 通用设计);
代按钮占位不算编辑区(点击它不开编辑)。 */
function lmeCell(key, sfx, dai){
const val = escLme(lmeStartGet(key, sfx));
return ''
+ '' + val + ''
+ (dai ? '代' : '')
+ ' | ';
}
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 = ''
+ '';
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) =>
'| ' + (i+1) + ' | '
+ ' | '
+ ' | '
+ ''
+ '↑ '
+ '↓ '
+ '插 '
+ '×'
+ ' |
').join('');
}'''
new2 = '''function colRender(){
const cs = colSetLoad();
$('colBody').innerHTML = cs.map((c, i) =>
'| ' + (i+1) + ' | '
+ ''
+ '' + escLme(c.name) + ' | '
+ ' | '
+ ''
+ '↑ '
+ '↓ '
+ '插 '
+ '×'
+ ' |
').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")