feat(mcp): 新增 Excel 批量清单匹配工具并调整分页与采纳锚策略
This commit is contained in:
@@ -1121,6 +1121,9 @@ let RV_LME_ROWS = null, RV_LME_TIP = '', RV_LME_QL = '', RV_LME_IDS = null;
|
||||
const RV_LME_NUM = new Set([5, 6, 7, 8]); // 数据下标:消耗量/除税编制价/税率/含税编制价 按数值比
|
||||
let RV_LME_DS = null; // 视图列下标 → 数据 r[] 下标(rawLmeTbl 每次重建)
|
||||
let RV_LME_O2V = null; // 原始列下标 → 视图列下标(rawTbl 表头 onclick 传原始下标)
|
||||
/* 决策 243(2026-11-01)项目级视图 12 列(0序号 1源 2编码…9含税 10取消采纳 11备注)→ 数据 r[](0=id…10=备注)。
|
||||
⚠️ 与 COLS.lme 列序联动改:原数据卡映射/排序 + p3 页签排序(workbench lmeRenderRows)共用这一张表。 */
|
||||
const LME_VIEW_DS = { 2: 1, 3: 2, 4: 3, 5: 4, 6: 5, 7: 6, 8: 7, 9: 8, 11: 10 };
|
||||
const RAW_LME_SUB_TIP = '原软件按子级组成重算,改母价可能不生效';
|
||||
function rawLmeSort(k) {
|
||||
if (RV_LME_SORT.k === k) RV_LME_SORT.dir = -RV_LME_SORT.dir;
|
||||
@@ -1148,8 +1151,9 @@ function rawLmeTbl(rows, tip, qtyLabel, extra) {
|
||||
数据集差异按主人原文保留:项目工料机走单位过滤,此处全量(含台班/配合比)。
|
||||
列头恒=COLS.lme(决策 148 统一「数量」);单位工程级卡走下方原路径,列头亦统一「数量」(决策 190)。 */
|
||||
RV_LME_IDS = null; RV_LME_DS = {}; RV_LME_O2V = null;
|
||||
for (let i = 1; i <= 10; i++) RV_LME_DS[i] = i; // 恒等映射:视图位=数据位(双击改价 lmePriceCells 用)
|
||||
const view = sortRows(rows, RV_LME_SORT.k, RV_LME_SORT.dir, RV_LME_NUM);
|
||||
for (const k in LME_VIEW_DS) RV_LME_DS[k] = LME_VIEW_DS[k]; // 决策 243 源列后视图位→数据位(单击编辑/lmePriceCells/找格共用)
|
||||
const _sk = RV_LME_DS[RV_LME_SORT.k]; // 排序键翻译成数据位(RV_LME_SORT.k 存视图位,表头 ▲/▼ 靠它对位)
|
||||
const view = sortRows(rows, _sk == null ? -1 : _sk, RV_LME_SORT.dir, RV_LME_NUM);
|
||||
const backend = !!RVO.lmeBackend; // 决策 147/149:后台=后台项目工料机列集(剔除 wb 专列)
|
||||
const cols = backend ? COLS.lme.filter(c => c[5] !== 'wb') : COLS.lme; // 决策 148:列头统一「数量」,与行格严格同列
|
||||
const body = renderLme(view, { rowClass: 'lmerow', subSet: subSet,
|
||||
@@ -1380,7 +1384,16 @@ function rvCachePutNow() { // 立即把当前 DOM 写回缓存(
|
||||
if (RV_CACHE_PUT_T) { clearTimeout(RV_CACHE_PUT_T); RV_CACHE_PUT_T = null; }
|
||||
const b = document.getElementById(RVO.bodyEl);
|
||||
const k = _rvCacheKey();
|
||||
if (b && RV_CACHE[k]) RV_CACHE[k] = { html: b.innerHTML, scroll: b.scrollTop };
|
||||
if (b && RV_CACHE[k]) {
|
||||
// 决策 252(2026-11-01 主人定):选中态(sel/subsel)不入缓存——它是易变状态,恢复
|
||||
// 全权归 _p3RestoreSel/_rawSceneGuard(含「只选定额不清单」口径)。否则切回时缓存 html
|
||||
// 自带旧 sel「复活」,与定额恢复叠加成双选中(实测报障)。
|
||||
const h = b.innerHTML
|
||||
.replace(/(class="[^"]*?)\bsel\b/g, '$1')
|
||||
.replace(/(class="[^"]*?)\bsubsel\b/g, '$1')
|
||||
.replace(/class="\s*"/g, '');
|
||||
RV_CACHE[k] = { html: h, scroll: b.scrollTop };
|
||||
}
|
||||
}
|
||||
function rvCachePut() { // DOM 变化(排序/树折叠)后把最新状态写回缓存
|
||||
// 决策 204(2026-10-26 主人定,修把手 ± 卡顿):改防抖——停 250ms 才序列化一次整表 HTML。
|
||||
@@ -1946,7 +1959,8 @@ function lmeSrcPop(btn, code) {
|
||||
function lmeSrcGo(tr) {
|
||||
haoPopClose();
|
||||
const bid = Number(tr.dataset.bid), uwid = tr.dataset.uwid;
|
||||
if (typeof locBill === 'function') locBill(bid, uwid === '' ? null : Number(uwid));
|
||||
// 第 3 参 'src':源钮从明细页发起(后台当前批次=DID,与组表入口的 QBID 不同)——后台 locBill 据此选批次
|
||||
if (typeof locBill === 'function') locBill(bid, uwid === '' ? null : Number(uwid), 'src');
|
||||
}
|
||||
/* 按按钮右下角定位:默认浮层左上角贴按钮右下角;下方放不下翻转成浮层左下角贴按钮右下角;
|
||||
右边溢出则整体收进视口。数据到货后尺寸会变,须再 place 一次。 */
|
||||
@@ -1972,19 +1986,23 @@ function _normSceneCapture(bodyEl) {
|
||||
const sub = bodyEl.querySelector('tr.subsel');
|
||||
return { normsel: sub ? (sub.dataset.nid || null) : null };
|
||||
}
|
||||
/* 一次 apply:sel + 定额 subsel(子行不在则点展开钮)+ 滚动定位。返回是否全部到位。 */
|
||||
/* 一次 apply:sel + 定额 subsel(子行不在则点展开钮)+ 滚动定位。返回是否全部到位。
|
||||
决策 252(2026-11-01 主人定):带 normsel(最后点的是定额)→ **只恢复定额 subsel**,
|
||||
清单行只作展开宿主(保证子行能渲染出来),不点 sel、不滚动清单——不同时选中定额和清单。 */
|
||||
function _rawSceneApply(bodyEl, bid, normsel) {
|
||||
let subDone = !normsel;
|
||||
let billEl = null;
|
||||
if (bid) {
|
||||
billEl = bodyEl.querySelector('tr.brow[data-bid="' + bid + '"]');
|
||||
if (!billEl) return false; // 重画中,行还没回来
|
||||
if (!billEl.classList.contains('sel')) {
|
||||
if (!normsel && !billEl.classList.contains('sel')) {
|
||||
bodyEl.querySelectorAll('tr.sel').forEach(x => x.classList.remove('sel'));
|
||||
billEl.classList.add('sel');
|
||||
}
|
||||
}
|
||||
if (normsel) {
|
||||
// 决策 252:渲染缓存(rvCachePut)会把历史 sel 带回来——只选定额时先清掉,保单选
|
||||
bodyEl.querySelectorAll('tr.sel').forEach(x => x.classList.remove('sel'));
|
||||
const sub = bodyEl.querySelector('tr.sub[data-nid="' + normsel + '"]');
|
||||
if (sub) {
|
||||
if (!sub.classList.contains('subsel')) {
|
||||
@@ -1998,7 +2016,7 @@ function _rawSceneApply(bodyEl, bid, normsel) {
|
||||
if (btn) btn.click(); // 展开定额区(rawTog/tgNorm 通吃),下轮 guard 补 subsel
|
||||
}
|
||||
}
|
||||
if (billEl) billEl.scrollIntoView({ block: 'center' });
|
||||
if (billEl && !normsel) billEl.scrollIntoView({ block: 'center' });
|
||||
return subDone;
|
||||
}
|
||||
/* 守窗自愈:切页签后 rawbody 仍会被异步重画(骨架条/搜索重高亮/对比联动)洗掉 sel/subsel——
|
||||
@@ -2014,8 +2032,9 @@ function _rawSceneGuard(bodyEl, bid, normsel, ms) {
|
||||
const cur = bodyEl.querySelector('tr.sel');
|
||||
if (cur && bid && cur.dataset.bid && cur.dataset.bid !== bid) return;
|
||||
const subEl = normsel ? bodyEl.querySelector('tr.subsel') : null;
|
||||
const ok = (!bid || (billEl && billEl.classList.contains('sel'))) &&
|
||||
(!normsel || (subEl && subEl.dataset.nid === normsel));
|
||||
// 决策 252:定额模式只守 subsel,且 sel 必须不在(被重画带回就再清)
|
||||
const ok = (!bid || normsel || (billEl && billEl.classList.contains('sel'))) &&
|
||||
(!normsel || (!cur && subEl && subEl.dataset.nid === normsel));
|
||||
if (!ok) {
|
||||
mark.tries++;
|
||||
_rawSceneApply(bodyEl, bid, normsel);
|
||||
@@ -2558,7 +2577,9 @@ function dictRegions(level) {
|
||||
}
|
||||
/** 单位名列表。cat: publisher | builder */
|
||||
function dictOrgs(cat) {
|
||||
return (cat === 'publisher' ? DICT.publishers : DICT.builders || []).map(o => o.name);
|
||||
// 2026-11-02 主人定:加「询价单位」(inquirer,市场价专用,与信息价的发布单位分开)
|
||||
const key = { publisher: 'publishers', inquirer: 'inquirers', builder: 'builders' }[cat] || 'builders';
|
||||
return (DICT[key] || []).map(o => o.name);
|
||||
}
|
||||
/** 字典口径的地区三联动(导入 / 编辑 / 打开工程这类**录入**下拉都走这里)。
|
||||
签名沿用旧 dictFillRegion(els, cur),新增第三参 opt 透传给 regFill。 */
|
||||
@@ -2696,6 +2717,79 @@ async function uploadFile(url, f) {
|
||||
return r.json();
|
||||
}
|
||||
|
||||
/* ---- 导入预检(决策 243 补记五,2026-11-02 主人定「选完文件就提醒」)----
|
||||
选完工程文件本地算 SHA-256(不上传文件字节)→ /api/dup_check 查两侧已有 →
|
||||
命中=弹框内红字提醒 +「打开」钮禁用;文案与提交拦截(决策 242/243)逐字同源。
|
||||
⚠️ 防遗留误判铁律(主人 2026-11-02 令「不要记忆遗留,导致误判新项目的导入」):
|
||||
检测状态严格绑定本次所选文件——每次进入令牌+1,旧异步结果一律丢弃;
|
||||
清空选择即清全部状态恢复按钮;预检接口故障**不拦导入**(提交后服务端拦截兜底)。 */
|
||||
function _dupReset(inp, btnId, msgId) {
|
||||
delete inp.dataset.dupHit;
|
||||
const btn = document.getElementById(btnId);
|
||||
if (btn) { btn.disabled = false; if (btn.dataset.dupLabel) { btn.textContent = btn.dataset.dupLabel; delete btn.dataset.dupLabel; } }
|
||||
const msg = document.getElementById(msgId);
|
||||
if (msg && msg.dataset.dupErr === '1') { msg.textContent = ''; msg.style.color = ''; delete msg.dataset.dupErr; }
|
||||
}
|
||||
function _dupToken(inp) {
|
||||
inp.dataset.dupToken = String(Number(inp.dataset.dupToken || 0) + 1);
|
||||
const tk = inp.dataset.dupToken;
|
||||
return () => inp.dataset.dupToken === tk; // false=期间又选了别的文件,本次结果作废
|
||||
}
|
||||
function _dupHitShow(inp, btnId, msgId, text) {
|
||||
inp.dataset.dupHit = '1';
|
||||
const btn = document.getElementById(btnId);
|
||||
if (btn) btn.disabled = true;
|
||||
const msg = document.getElementById(msgId);
|
||||
if (msg) { msg.textContent = text; msg.style.color = '#d33'; msg.dataset.dupErr = '1'; }
|
||||
}
|
||||
function _dupBusy(btnId, msgId) { // 检测中:按钮占位防呆,返回还原函数
|
||||
const btn = document.getElementById(btnId);
|
||||
if (btn) { btn.dataset.dupLabel = btn.textContent; btn.textContent = '检测中…'; btn.disabled = true; }
|
||||
return () => {
|
||||
const b = document.getElementById(btnId);
|
||||
if (b) { b.disabled = false; if (b.dataset.dupLabel) { b.textContent = b.dataset.dupLabel; delete b.dataset.dupLabel; } }
|
||||
};
|
||||
}
|
||||
function _fileSha256(file) {
|
||||
return file.arrayBuffer().then(buf => crypto.subtle.digest('SHA-256', buf))
|
||||
.then(d => Array.prototype.map.call(new Uint8Array(d), b => ('0' + b.toString(16)).slice(-2)).join(''));
|
||||
}
|
||||
/* 给定 sha 直接查(后台用:pickFile 上传响应里就带 sha256,不必本地重算)。
|
||||
sha 为空 = 上传失败等拿不到哈希 → 只清状态不查,绝不凭空判重复。 */
|
||||
function dupCheckSha(inp, sha, side, btnId, msgId) {
|
||||
_dupReset(inp, btnId, msgId);
|
||||
const fresh = _dupToken(inp);
|
||||
sha = String(sha || '').toLowerCase();
|
||||
if (!/^[0-9a-f]{64}$/.test(sha)) return; // 与服务端同门槛:不是完整 sha256 不查(防误判)
|
||||
const restore = _dupBusy(btnId, msgId);
|
||||
fetch('/api/dup_check?side=' + side + '&sha256=' + encodeURIComponent(sha))
|
||||
.then(r => r.json())
|
||||
.then(r => {
|
||||
if (!fresh()) return; // 遗留结果丢弃:期间已换文件
|
||||
restore();
|
||||
if (r && r.ok && r.hits && r.hits.length) _dupHitShow(inp, btnId, msgId, r.hits[0]);
|
||||
})
|
||||
.catch(() => { if (fresh()) restore(); }); // 故障不拦:静默放行,提交后服务端兜底
|
||||
}
|
||||
/* 工作台用:提交时才上传 → 选文件时本地算哈希预检(file input 的 onchange 调)。 */
|
||||
function dupScanFile(inp, side, btnId, msgId) {
|
||||
const fresh = _dupToken(inp); // 先领令牌再清状态:算哈希期间换文件=本次作废
|
||||
_dupReset(inp, btnId, msgId);
|
||||
const f = inp.files && inp.files[0];
|
||||
if (!f) return; // 清空选择:状态已清,不残留任何旧结论
|
||||
const restore = _dupBusy(btnId, msgId);
|
||||
_fileSha256(f).then(sha => {
|
||||
if (!fresh()) return; // 期间换了文件:本次哈希作废
|
||||
return fetch('/api/dup_check?side=' + side + '&sha256=' + encodeURIComponent(sha))
|
||||
.then(r => r.json())
|
||||
.then(r => {
|
||||
if (!fresh()) return;
|
||||
restore();
|
||||
if (r && r.ok && r.hits && r.hits.length) _dupHitShow(inp, btnId, msgId, r.hits[0]);
|
||||
});
|
||||
}).catch(() => { if (fresh()) restore(); }); // 哈希算不出/接口故障:放行,服务端兜底
|
||||
}
|
||||
|
||||
async function saveAs(url, name) {
|
||||
const nm = name || '下载文件';
|
||||
// 决策 91(主人定「全部是另存为」):壳内(pywebview)优先原生另存为对话框——
|
||||
|
||||
Reference in New Issue
Block a user