dy-dashboard/fix_fields2.py
2026-10-28 11:14:17 +08:00

173 lines
7.6 KiB
Python
Raw Permalink 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.

#!/usr/bin/env python3
"""添加字段设置弹窗 + 列可见性控制"""
with open('static/js/app.js', 'r') as f:
js = f.read()
# 列定义
DOMESTIC_COLUMNS = [
('日期','日期',True),('计划下单时间','计划下单时间',True),('新旧品','新旧品',True),
('编码','编码',True),('名称','名称',True),('下单备注','下单备注',True),
('单价','单价',True),('是否审核价格','审核价格',True),('数量','数量',True),
('金额','金额',True),('供货商','供货商',True),('仓库','仓库',True),
('金蝶采购单','金蝶采购单',True),('采购员','采购员',True),('下单人','下单人',True),
('进度','进度',True),('旺店通生产单号','旺店通单号',True),('是否已录入旺店通','录入旺店通',True),
('采购开发','采购开发',True),('实际到货日期','实际到货日期',True),('实际到货数量辅助','到货数量辅',True),
('辅助1','辅助1',True),('实际到货数量','实到数量',True),('未到货数','未到货数',True),
('预计到货日期','预计到货日期',True),('金蝶入库','金蝶入库',True),('状态','状态',True),
]
for i in range(1, 32):
DOMESTIC_COLUMNS.append((str(i), str(i), False))
DOMESTIC_COLUMNS.append(('父记录','父记录',False))
OVERSEAS_COLUMNS = [
('日期','日期',True),('计划下单时间','计划下单时间',True),('产品编码','产品编码',True),
('单价','单价',True),('是否审核价格','审核价格',True),('数量','数量',True),
('金额','金额',True),('供应商','供应商',True),('仓库','仓库',True),
('货品名称','货品名称',True),('新旧品','新旧品',True),('是否已做采购单','已做采购单',True),
('是否做入库','已入库',True),('采购员','采购员',True),('下单人','下单人',True),
('进度','进度',True),('下单备注','下单备注',True),('采购开发','采购开发',True),
('旺店通生产单号','旺店通单号',True),('是否已录入到旺店通','录入旺店通',True),
('实际到货日期','实际到货日期',True),('实际到货数量辅助','到货数量辅',True),
('辅助','辅助',True),('实际到货数量','实到数量',True),('预计到货日期','预计到货日期',True),
('未到货数','未到货数',True),('状态','状态',True),
]
for i in range(1, 32):
OVERSEAS_COLUMNS.append((str(i), str(i), False))
# Generate JS code
cols_js = []
for field, label, default in DOMESTIC_COLUMNS:
cols_js.append(f" {{field:'{field}',label:'{label}',defShow:{str(default).lower()}}}")
dom_cols_code = "const DOMESTIC_COLUMNS = [\n" + ",\n".join(cols_js) + "\n];"
cols_js = []
for field, label, default in OVERSEAS_COLUMNS:
cols_js.append(f" {{field:'{field}',label:'{label}',defShow:{str(default).lower()}}}")
ov_cols_code = "const OVERSEAS_COLUMNS = [\n" + ",\n".join(cols_js) + "\n];"
# 字段设置弹窗函数
modal_code = f"""
// ─── 字段设置功能 ───
{dom_cols_code}
{ov_cols_code}
function getDomesticVisible() {{
var stored = localStorage.getItem('domesticColVisible');
if (stored) {{
try {{ var m = JSON.parse(stored); return m; }} catch(e) {{}}
}}
var m = {{}};
DOMESTIC_COLUMNS.forEach(function(c) {{ m[c.field] = c.defShow; }});
return m;
}}
function getOverseasVisible() {{
var stored = localStorage.getItem('overseasColVisible');
if (stored) {{
try {{ var m = JSON.parse(stored); return m; }} catch(e) {{}}
}}
var m = {{}};
OVERSEAS_COLUMNS.forEach(function(c) {{ m[c.field] = c.defShow; }});
return m;
}}
function saveDomesticVisible(m) {{
localStorage.setItem('domesticColVisible', JSON.stringify(m));
}}
function saveOverseasVisible(m) {{
localStorage.setItem('overseasColVisible', JSON.stringify(m));
}}
function openDomesticColModal() {{
openColSettingsModal('domestic', DOMESTIC_COLUMNS, getDomesticVisible(), saveDomesticVisible);
}}
function openOverseasColModal() {{
openColSettingsModal('overseas', OVERSEAS_COLUMNS, getOverseasVisible(), saveOverseasVisible);
}}
function openColSettingsModal(type, columns, visibleMap, saveFn) {{
var overlay = document.createElement('div');
overlay.className = 'modal-overlay';
overlay.style.cssText = 'display:flex;z-index:9999';
var html = '<div class="modal" style="width:650px;max-height:80vh">';
html += '<div class="modal-header"><h3>⚙ 字段设置</h3>';
html += '<span class="modal-close" onclick="this.closest(\\'.modal-overlay\\').remove()">&times;</span></div>';
html += '<div class="modal-body" style="max-height:60vh;overflow-y:auto;padding:12px 20px">';
html += '<div style="margin-bottom:10px">';
html += '<label><input type="checkbox" id="colSelectAll" onchange="toggleColAll(this.checked)" checked> 全选</label>';
html += ' <button class="btn btn-sm btn-outline" onclick="resetColDefaults(\\'' + type + '\\')">恢复默认</button>';
html += '</div>';
html += '<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:6px">';
columns.forEach(function(c) {{
var checked = visibleMap[c.field] ? 'checked' : '';
html += '<label style="font-size:13px;padding:4px 6px;border:1px solid #f0f0f0;border-radius:4px;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">';
html += '<input type="checkbox" class="col-checkbox" value="' + c.field + '" ' + checked + ' onchange="updateColSelectAll()"> ';
html += c.label;
html += '</label>';
}});
html += '</div></div>';
html += '<div class="modal-footer">';
html += '<button class="btn" onclick="this.closest(\\'.modal-overlay\\').remove()">取消</button> ';
html += '<button class="btn btn-primary" onclick="applyColSettings(\\'' + type + '\\',\\'' + '\\')">应用</button>';
html += '</div></div>';
overlay.innerHTML = html;
document.body.appendChild(overlay);
}}
window.toggleColAll = function(checked) {{
document.querySelectorAll('.col-checkbox').forEach(function(cb) {{ cb.checked = checked; }});
}};
window.updateColSelectAll = function() {{
var all = document.querySelectorAll('.col-checkbox');
var checked = document.querySelectorAll('.col-checkbox:checked');
var selectAll = document.getElementById('colSelectAll');
if (selectAll) selectAll.checked = (all.length === checked.length);
}};
window.resetColDefaults = function(type) {{
var cols = type === 'domestic' ? DOMESTIC_COLUMNS : OVERSEAS_COLUMNS;
document.querySelectorAll('.col-checkbox').forEach(function(cb) {{
var col = cols.find(function(c) {{ return c.field === cb.value; }});
cb.checked = col ? col.defShow : false;
}});
updateColSelectAll();
}};
window.applyColSettings = function(type) {{
var cols = type === 'domestic' ? DOMESTIC_COLUMNS : OVERSEAS_COLUMNS;
var visible = {{}};
document.querySelectorAll('.col-checkbox').forEach(function(cb) {{
visible[cb.value] = cb.checked;
}});
if (type === 'domestic') {{
saveDomesticVisible(visible);
domesticLoadOrders(1);
}} else {{
saveOverseasVisible(visible);
overseasLoadOrders(1);
}}
document.querySelector('.modal-overlay').remove();
}};
"""
# 在 editRemark 前插入
target = "window.editRemark = function(td, id, field, apiEndpoint) {"
if target in js:
js = js.replace(target, modal_code + "\n" + target)
print("✅ 添加字段设置弹窗代码")
else:
print("❌ 未找到插入点")
# 也把 each 的 polyfill 加上(IE兼容) - 不需要,现代浏览器都支持
with open('static/js/app.js', 'w') as f:
f.write(js)
print("✅ 完成")