feat(manual): 手工工程导入导出(决策229/230)与本页搜索共享层

This commit is contained in:
lianjianwei2024
2026-10-27 23:07:25 +08:00
parent 2726454298
commit 34b14e74ec
20 changed files with 3412 additions and 578 deletions

View File

@@ -3391,3 +3391,136 @@ function wbApplyLang() {
else appBoot();
setTimeout(appBoot, 350); // 晚渲染的页签/表头补一次
})();
/* ==================== 本页搜索共享层(决策 229,2026-10-27 主人定)====================
决策 172/209 的「本页搜索」(输入即搜黄底 + 上一个/下一个 + 五态灰)从 workbench.html
上移到这里:工作台四页 + 后台三处(入库项目列表 / 明细页 / 附件页双页签)共用一套。
页面用 pgReg(key, area, expander) 注册内容区:area = 元素 id 或 ()=>Element(后台明细
随页签切换);expander(mark) 可选——定位时命中行被 ± 把手收起(display:none 藏着)
先展开再滚动居中(决策 229 主人报「搜索内容是把手收起状态,定位应展开并显示」)。
收起 = 从 DOM 移除的内容(定额子行 tgNorm、组表懒渲染未展开过的组)不在搜索范围
(主人 2026-10-27 定「定额不在搜索范围」,组懒渲染同口径);历史对比框检索不迁移、
行为不变(主人 2026-10-27 定),只继续复用 hlContainer。 */
const PG_AREAS = {}; // key -> 元素 id 或 ()=>Element
const PG_EXPAND = {}; // key -> expander(mark)
const PAGESRCH = {}; // key -> 当前关键词
const PG_TIMER = {}; // key -> 300ms 防抖句柄
const PGS_NAV = {}; // key -> { i: 当前命中序号(-1=未定位) }
function pgReg(key, area, expander) {
PG_AREAS[key] = area;
if (expander) PG_EXPAND[key] = expander;
PAGESRCH[key] = '';
PGS_NAV[key] = { i: -1 };
}
function pgArea(key) {
const a = PG_AREAS[key];
return (typeof a === 'function') ? a() : document.getElementById(a);
}
/* 决策 229:原数据 ± 把手展开器(工作台原数据 / 后台明细 p3 共用)——命中行的 data-vis
祖先链上有收起的 根/分部/清单 → 逐个展开再整表重算可见性。只改 display 不重建 DOM,
pageSearchNav 里的 marks 引用保持有效。 */
function pgRawExpand(mark) {
const tr = mark.closest && mark.closest('tr[data-vis]');
if (!tr || tr.style.display !== 'none') return;
let changed = false;
(tr.dataset.vis || '').split('/').forEach(k => {
if (k === 'uw') { if (!RV_TREE.root) { RV_TREE.root = true; changed = true; } }
else if (k && k !== 'loose') {
if (k.charAt(0) === 'd' && RV_TREE.divs[k] === false) { RV_TREE.divs[k] = true; changed = true; }
if (k.charAt(0) === 'b' && RV_TREE.bills[k] === false) { RV_TREE.bills[k] = true; changed = true; }
}
});
if (changed) { rawTreeSync(null); _rvStateSave(); }
}
/* 决策 229:组表 ± 把手展开器(工作台 t1/t2、后台明细 p1/p2、附件 qsim 共用)——
渲染过再收起的组行是 display:none 藏着的,定位前把所在组点开(懒渲染组不在搜索范围)。 */
function pgGrpExpand(mark) {
const tr = mark.closest && mark.closest('tr[data-grp]');
if (!tr || tr.style.display !== 'none') return;
const tg = document.getElementById('gt_' + tr.dataset.grp);
if (tg && tg.dataset.open !== '1') tgGrp(tr.dataset.grp, tg.closest('tr'));
}
/* 决策 209:搜索框右边「上一个/下一个」两枚的 HTML(初始灰,由 pgsSetNav 刷新) */
function pgsNavBtnsHtml(key) {
return '<button class="pgsnav" data-pg="' + key + '" data-dir="-1" title="上一个命中"'
+ ' onclick="pageSearchNav(\'' + key + '\',-1)" disabled>上一个</button>'
+ '<button class="pgsnav" data-pg="' + key + '" data-dir="1" title="下一个命中(首击=从头查找)"'
+ ' onclick="pageSearchNav(\'' + key + '\',1)" disabled>下一个</button>';
}
/* 决策 209:五态灰活唯一入口(框空/无命中/唯一已定位/第1处/末尾) */
function pgsSetNav(key) {
const el = pgArea(key);
const n = el ? el.querySelectorAll('mark.pghl').length : 0;
const i = PGS_NAV[key] ? PGS_NAV[key].i : -1;
document.querySelectorAll('button.pgsnav[data-pg="' + key + '"]').forEach(b => {
const d = Number(b.dataset.dir);
b.disabled = !PAGESRCH[key] ? true
: d < 0 ? (i <= 0)
: (i < 0 ? n < 1 : i >= n - 1);
});
}
/* 决策 209:命中间跳转;缺高亮(重画后)先补挂再跳;决策 229:命中被把手收起先展开再滚 */
function pageSearchNav(key, dir) {
const kw = PAGESRCH[key];
if (!kw) return;
const el = pgArea(key);
if (!el) return;
let marks = el.querySelectorAll('mark.pghl');
if (!marks.length) { if (PGS_NAV[key]) PGS_NAV[key].i = -1; hlContainer(el, kw); marks = el.querySelectorAll('mark.pghl'); }
const n = marks.length;
if (!n) { pgsSetNav(key); return; }
let i = PGS_NAV[key] ? PGS_NAV[key].i : -1;
if (dir > 0) { if (i >= n - 1) return; i = i < 0 ? 0 : i + 1; }
else { if (i <= 0) return; i -= 1; }
if (PGS_NAV[key]) PGS_NAV[key].i = i;
marks.forEach(m => m.classList.remove('pghlcur'));
marks[i].classList.add('pghlcur');
if (PG_EXPAND[key]) PG_EXPAND[key](marks[i]); // 决策 229:先展开收起的把手(只改 display,marks 仍有效)
marks[i].scrollIntoView({ block: 'center' });
pgsSetNav(key);
}
window.pageSearchBox = function(){ // 原数据标签卡行用(rawTabs 渲染;工作台原数据 + 后台明细 p3 同款)
return '<input class="mi pgsrch" placeholder="搜索本页数据"'
+ ' title="搜索本页数据,命中黄底(目录树不参与)" value="' + esc(PAGESRCH.raw || '') + '"'
+ ' oninput="pageSearchGo(\'raw\', this.value)"'
+ ' onkeydown="if(event.key===\'Enter\')pageSearchNav(\'raw\',1)">'
+ pgsNavBtnsHtml('raw');
};
function hlContainer(root, kw){
root.querySelectorAll('mark.pghl').forEach(m => { m.replaceWith(document.createTextNode(m.textContent)); });
root.normalize();
if (!kw) return 0;
const kwU = kw.toUpperCase();
const bad = { SCRIPT:1, STYLE:1, MARK:1, INPUT:1, TEXTAREA:1, SELECT:1 };
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
acceptNode: nd => {
if (!nd.nodeValue || !nd.nodeValue.trim()) return NodeFilter.FILTER_REJECT;
if (bad[nd.parentNode.nodeName]) return NodeFilter.FILTER_REJECT;
return nd.nodeValue.toUpperCase().indexOf(kwU) >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
}});
const hits = []; let nd;
while ((nd = walker.nextNode())) hits.push(nd);
hits.forEach(node => {
const s = node.nodeValue, up = s.toUpperCase();
const frag = document.createDocumentFragment();
let i = 0, j;
while ((j = up.indexOf(kwU, i)) >= 0) {
if (j > i) frag.appendChild(document.createTextNode(s.slice(i, j)));
const m = document.createElement('mark'); m.className = 'pghl'; m.textContent = s.slice(j, j + kw.length);
frag.appendChild(m); i = j + kw.length;
}
if (i < s.length) frag.appendChild(document.createTextNode(s.slice(i)));
node.replaceWith(frag);
});
return hits.length;
}
function pageSearchGo(key, val){
PAGESRCH[key] = val || '';
clearTimeout(PG_TIMER[key]);
PG_TIMER[key] = setTimeout(() => {
const el = pgArea(key);
if (el) hlContainer(el, PAGESRCH[key]);
if (PGS_NAV[key]) PGS_NAV[key].i = -1; // 决策 209:改词=回未查找态,首击「下一个」重新从头定位
pgsSetNav(key);
}, 300);
}