Files
pricing_review/_analysis/定额单价专题/patch_admin2.py

255 lines
12 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""设置弹框 v2 手术:①标签卡行共用「添加」按钮(导出卡=选文件入库/工料机卡=列设置)
②工料机卡撤列设置按钮 ③列设置无确定/取消(即时保存)④插=往后面一行插入
⑤# /后缀/起点 固定最前、不进列设置——列设置只管自定义列;新建时固定送一行空列;
自定义列有值不可删、无值可删。"""
import io
p = r"D:\PricingReview\CostReview\app\ui\admin.html"
s = io.open(p, encoding="utf-8").read()
# ---- ① 标签卡行加共用「添加」按钮 ----
old = ''' <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>
</div>
</div>'''
new = ''' <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>'''
assert old in s, "tabs NOT FOUND"
s = s.replace(old, new)
# ---- ② 工料机面板撤「列设置」按钮行 ----
old2 = ''' <div id="fpaneLme" style="display:none">
<div style="display:flex;justify-content:flex-end">
<button class="btn" onclick="openColSet()" title="配置工料机表的列:显隐/顺序/增删">列设置</button>
</div>
<div class="tw" style="max-height:52vh">'''
new2 = ''' <div id="fpaneLme" style="display:none">
<div class="tw" style="max-height:52vh">'''
assert old2 in s, "lme pane NOT FOUND"
s = s.replace(old2, new2)
# ---- ③ 列设置弹框撤确定/取消按钮行 ----
old3 = ''' <div style="display:flex;justify-content:flex-end;gap:8px">
<button class="btn pri" onclick="colSetApply()">确定</button>
<button class="btn" onclick="closeColSet()">取消</button>
</div>
</div>
</div>
</div>'''
new3 = ''' </div>
</div>
</div>'''
assert old3 in s, "colset btns NOT FOUND"
s = s.replace(old3, new3)
# ---- ④ JS:fsetAdd + 即时保存 + 插=后插 + 自定义列有值不可删 ----
old4 = '''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();
}'''
new4 = '''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();
}'''
assert old4 in s, "ftabSet NOT FOUND"
s = s.replace(old4, new4)
old5 = '''/* ---- 列设置弹框 ---- */
let WORKCOLS = null; // 列设置弹框的工作副本(确定才写回)
function openColSet(){
WORKCOLS = JSON.parse(JSON.stringify(colSetLoad()));
colRender();
$('colmask').classList.add('on');
}
function closeColSet(){ $('colmask').classList.remove('on'); }
colmask.onclick = e => { if(e.target===colmask) closeColSet() };
function colRender(){
$('colBody').innerHTML = WORKCOLS.map((c, i) =>
'<tr><td class="c">' + (i+1) + '</td>'
+ '<td><input type="text" value="' + escLme(c.name) + '" style="width:100%;border:1px solid #c9d4e2;padding:2px 6px"'
+ ' onchange="WORKCOLS[' + i + '].name=this.value"></td>'
+ '<td class="c"><input type="checkbox" ' + (c.on?'checked':'') + ' onchange="WORKCOLS[' + i + '].on=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('') || '<tr><td colspan="4" class="c" style="color:#888">空</td></tr>';
}
function colMove(i, d){
const j = i + d;
if(j < 0 || j >= WORKCOLS.length) return;
const t = WORKCOLS[i]; WORKCOLS[i] = WORKCOLS[j]; WORKCOLS[j] = t;
colRender();
}
function colInsert(i){
WORKCOLS.splice(i, 0, { key: 'c' + Date.now(), name: '', on: true });
colRender();
}
function colDel(i){
if(WORKCOLS.length <= 1) return; // 至少留一列
WORKCOLS.splice(i, 1);
colRender();
}
function colSetApply(){
const on = WORKCOLS.filter(c => c.on).map((c, i) => ({ key: c.key,
name: c.name || ('列' + (i+1)), on: true }));
const off = WORKCOLS.filter(c => !c.on).map(c => ({ key: c.key, name: c.name, on: false }));
colSetSave(on.concat(off)); // 未勾选列保留定义(不丢配置)
closeColSet();
lmeSetRender();
$('fmsg').textContent = '列设置已应用';
}'''
new5 = '''/* ---- 列设置弹框(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><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('');
}
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();
}'''
assert old5 in s, "colset js NOT FOUND"
s = s.replace(old5, new5)
# ---- ⑤ colSetLoad 只存自定义列 + 工料机表固定 # /后缀 /起点 ----
old6 = '''function colSetLoad(){ // 列设置(localStorage 持久;损坏回默认)
try{ const v = JSON.parse(localStorage.getItem('lme_colset')||'null');
if(Array.isArray(v) && v.length && v.every(c => c && c.key && 'name' in c))
return v; }catch(e){}
return [{key:'suffix', name:'后缀', on:true},{key:'start', name:'起点', on:true}];
}'''
new6 = '''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 [];
}'''
assert old6 in s, "colSetLoad NOT FOUND"
s = s.replace(old6, new6)
old7 = '''function lmeSetRender(){ // 工料机卡:行=导出卡后缀去重;列=colSet 勾选列按序
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">#</th>' + cols.map(c => '<th>' + escLme(c.name) + '</th>').join('');
let html = '';
suffixes.forEach((sfx, i) => {
html += '<tr><td class="c">' + (i+1) + '</td>' + cols.map(c => {
if(c.key === 'suffix') return '<td>' + escLme(sfx) + '</td>';
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('') + '</tr>';
});
$('lmeSetBody').innerHTML = html
|| '<tr><td colspan="9" class="c" style="color:#888">还没有骨架:先在「导出」卡添加,后缀会带到这里</td></tr>';
}'''
new7 = '''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>';
}'''
assert old7 in s, "lmeSetRender NOT FOUND"
s = s.replace(old7, new7)
io.open(p, "w", encoding="utf-8").write(s)
print("surgery v2 done")