初始提交:造价审核系统源码(不含数据库与生成物)
This commit is contained in:
121
造价审核/app/tools/_patch_combo_x.py
Normal file
121
造价审核/app/tools/_patch_combo_x.py
Normal file
@@ -0,0 +1,121 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""一次性补丁:组合框/自由输入的关键属性改内联钉死(防页面本地 .combo 样式覆盖),comboFree 补 × 清空。"""
|
||||
import io
|
||||
|
||||
p = r"D:\Pricing review\造价审核\app\ui\common.js"
|
||||
src = io.open(p, encoding="utf-8").read()
|
||||
|
||||
# ① comboAttach:输入框关键样式内联(右留 × 空间),不受页面本地 .combo input 样式影响
|
||||
a = """ const inp = document.createElement('input');
|
||||
inp.type = 'text'; inp.autocomplete = 'off'; inp.spellcheck = false;
|
||||
const clr = document.createElement('span');
|
||||
clr.className = 'combo-x'; clr.textContent = '×'; clr.title = '清空';
|
||||
wrap.append(inp, clr);
|
||||
if (sel.style.flex) { wrap.style.flex = sel.style.flex; sel.style.flex = ''; } // 弹框布局槽位交接
|
||||
sel.style.display = 'none';"""
|
||||
b = """ const inp = document.createElement('input');
|
||||
inp.type = 'text'; inp.autocomplete = 'off'; inp.spellcheck = false;
|
||||
// 关键样式内联钉死:工作台/后台本地可能有旧的 .combo input 样式(width:150px 等)会盖掉 common.css
|
||||
inp.style.padding = '6px 24px 6px 10px';
|
||||
inp.style.boxSizing = 'border-box';
|
||||
inp.style.width = '100%';
|
||||
const clr = document.createElement('span');
|
||||
clr.className = 'combo-x'; clr.textContent = '×'; clr.title = '清空';
|
||||
wrap.append(inp, clr);
|
||||
if (sel.style.flex) { wrap.style.flex = sel.style.flex; sel.style.flex = ''; } // 弹框布局槽位交接
|
||||
sel.style.display = 'none';"""
|
||||
assert a in src, "comboAttach input"
|
||||
src = src.replace(a, b, 1)
|
||||
|
||||
# ② comboFree:包一层 .combo(relative)+ × 清空(有值才显示)+ 输入框内联样式
|
||||
a = """function comboFree(inp, getOptions){
|
||||
if (inp._cfree) return;
|
||||
const panel = document.createElement('div');
|
||||
panel.className = 'combo-panel';
|
||||
document.body.appendChild(panel);
|
||||
FREE_PANELS.push(panel);
|
||||
let items = [], hit = -1;
|
||||
const closePanel = () => { panel.style.display = 'none'; };"""
|
||||
b = """function comboFree(inp, getOptions){
|
||||
if (inp._cfree) return;
|
||||
const wrap = document.createElement('span');
|
||||
wrap.className = 'combo'; wrap.dataset.for = inp.id || '';
|
||||
inp.parentNode.insertBefore(wrap, inp);
|
||||
wrap.append(inp);
|
||||
// 关键样式内联钉死(同上,防页面本地样式覆盖);× 清空:有值才显示
|
||||
inp.style.padding = '6px 24px 6px 10px';
|
||||
inp.style.boxSizing = 'border-box';
|
||||
inp.style.width = '100%';
|
||||
const clr = document.createElement('span');
|
||||
clr.className = 'combo-x'; clr.textContent = '×'; clr.title = '清空';
|
||||
clr.style.display = 'none';
|
||||
wrap.append(clr);
|
||||
const panel = document.createElement('div');
|
||||
panel.className = 'combo-panel';
|
||||
document.body.appendChild(panel);
|
||||
FREE_PANELS.push(panel);
|
||||
let items = [], hit = -1;
|
||||
const closePanel = () => { panel.style.display = 'none'; };"""
|
||||
assert a in src, "comboFree head"
|
||||
src = src.replace(a, b, 1)
|
||||
|
||||
# ③ comboFree:× 显隐同步 + 点 × 清空
|
||||
a = """ inp.addEventListener('focus', openPanel);
|
||||
inp.addEventListener('input', openPanel);
|
||||
inp.addEventListener('blur', () => setTimeout(closePanel, 150)); // 自由文本:输入保留,不还原"""
|
||||
b = """ const syncX = () => { clr.style.display = inp.value ? 'block' : 'none'; };
|
||||
inp.addEventListener('focus', openPanel);
|
||||
inp.addEventListener('input', () => { openPanel(); syncX(); });
|
||||
inp.addEventListener('blur', () => setTimeout(() => { closePanel(); syncX(); }, 150)); // 自由文本:输入保留,不还原
|
||||
clr.addEventListener('mousedown', e => { e.preventDefault(); inp.value = ''; syncX(); inp.focus(); });"""
|
||||
assert a in src, "comboFree events"
|
||||
src = src.replace(a, b, 1)
|
||||
|
||||
# ④ comboFree 键盘 Enter/选择后同步 × 显隐
|
||||
a = """ if (e.key === 'ArrowDown') { hit = Math.min(items.length - 1, hit + 1); e.preventDefault(); }
|
||||
else if (e.key === 'ArrowUp') { hit = Math.max(0, hit - 1); e.preventDefault(); }
|
||||
else if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
if (hit >= 0 && items[hit]) inp.value = items[hit];
|
||||
closePanel();
|
||||
return;
|
||||
}
|
||||
else if (e.key === 'Escape') { closePanel(); return; }
|
||||
else return;
|
||||
panel.querySelectorAll('.combo-it').forEach((el, i) => el.classList.toggle('on', i === hit));
|
||||
const on = panel.querySelector('.combo-it.on');
|
||||
if (on) on.scrollIntoView({ block: 'nearest' });
|
||||
});
|
||||
panel.addEventListener('mousedown', e => {
|
||||
const it = e.target.closest('.combo-it');
|
||||
if (it) { e.preventDefault(); inp.value = items[+it.dataset.i] || inp.value; closePanel(); }
|
||||
});
|
||||
inp._cfree = { panel, close: closePanel };
|
||||
return inp;
|
||||
}"""
|
||||
b = """ if (e.key === 'ArrowDown') { hit = Math.min(items.length - 1, hit + 1); e.preventDefault(); }
|
||||
else if (e.key === 'ArrowUp') { hit = Math.max(0, hit - 1); e.preventDefault(); }
|
||||
else if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
if (hit >= 0 && items[hit]) inp.value = items[hit];
|
||||
closePanel(); syncX();
|
||||
return;
|
||||
}
|
||||
else if (e.key === 'Escape') { closePanel(); syncX(); return; }
|
||||
else return;
|
||||
panel.querySelectorAll('.combo-it').forEach((el, i) => el.classList.toggle('on', i === hit));
|
||||
const on = panel.querySelector('.combo-it.on');
|
||||
if (on) on.scrollIntoView({ block: 'nearest' });
|
||||
});
|
||||
panel.addEventListener('mousedown', e => {
|
||||
const it = e.target.closest('.combo-it');
|
||||
if (it) { e.preventDefault(); inp.value = items[+it.dataset.i] || inp.value; closePanel(); syncX(); }
|
||||
});
|
||||
inp._cfree = { panel, close: closePanel };
|
||||
return inp;
|
||||
}"""
|
||||
assert a in src, "comboFree key"
|
||||
src = src.replace(a, b, 1)
|
||||
|
||||
io.open(p, "w", encoding="utf-8", newline="\n").write(src)
|
||||
print("common.js round3 ok")
|
||||
Reference in New Issue
Block a user