From 78ffabae8403989548b8418ba52cfc268513d8c6 Mon Sep 17 00:00:00 2001 From: lianjianwei2024 <168657369+lianjianwei2024@users.noreply.github.com> Date: Tue, 13 Oct 2026 12:53:31 +0800 Subject: [PATCH] =?UTF-8?q?perf(=E5=88=86=E7=BB=84):=20=E7=B1=BB=E4=BC=BC?= =?UTF-8?q?=E6=B8=85=E5=8D=95=E5=88=86=E7=BB=84=E7=BB=93=E6=9E=9C=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=AB=AF=20LRU=20=E7=BC=93=E5=AD=98=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=BC=BA=E5=88=B6=E9=87=8D=E8=BD=BD=E4=B8=8E=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E5=88=97=E6=94=B6=E7=BC=96=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 服务端按「数据指纹+规则指纹」缓存 _group_v2_output 结果(LRU 上限 12 批次),大幅缩短大工程重复分组耗时;工作台新增「⟳ 重载」入口可跳过缓存按当前数据与规则重算 - 后台弹框显隐收编为 detLayout 单一写入点,修复组树与价格工具行残留 - 列定义引入 wb 声明式标记,「取消采纳」「备注」列后台剔除,工作台布局为唯一来源 - 目录树新增展开/折叠把手与宽度拖动条;会话页加载挂进度条 - 更新决策台账(决策 44-46),附一次性 profile 脚本 --- CostReview/app/server/api_server.py | 99 ++++++++-- CostReview/app/tools/_tmp_profile_grp.py | 24 +++ CostReview/app/ui/admin.html | 237 ++++++++++++++++------- CostReview/app/ui/common.js | 176 ++++++++++++++--- CostReview/app/ui/sessions.html | 4 +- CostReview/app/ui/workbench.html | 125 ++++++------ 决策台账.md | 82 ++++++++ 7 files changed, 564 insertions(+), 183 deletions(-) create mode 100644 CostReview/app/tools/_tmp_profile_grp.py diff --git a/CostReview/app/server/api_server.py b/CostReview/app/server/api_server.py index 1747777..aacdba2 100644 --- a/CostReview/app/server/api_server.py +++ b/CostReview/app/server/api_server.py @@ -5,7 +5,7 @@ M3-1 后端服务:零依赖(Python 标准库 http.server) """ import io, os, re, json, sqlite3, urllib.parse, mimetypes, hashlib, time, threading, base64 from itertools import combinations -from collections import Counter +from collections import Counter, OrderedDict from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler # ---- 路径:**一律由本文件位置推导**,不写死绝对路径 ---- @@ -3641,16 +3641,80 @@ def _group_v2_output(rows): # 行适配统一用上面的 BILLROW(两侧唯一实现,原 _billrow 已删 —— 2026-10-08 收编)。 +# ---------- 类似清单分组结果缓存(决策 46,2026-10-13 主人定方案 A)---------- +# 分组是**纯函数**:结果只取决于 ①批次可比集(bills 表数据)②全局分组规则(grp_rules / +# grp_big / grp_sig_thr 三参数全进指纹)。两者不变结果必不变 → 按「数据指纹+规则指纹」缓存, +# 南屏这类大工程 6.6s 首算后全部瞬开;前台/后台同走 _group_v2_output,缓存服务端一处、三端共享 +# (最近审核页只列会话不显示分组,不涉及)。 +# ⚠️ 失效正确性的三个前提(复核新功能时必查): +# ① bills **无就地 UPDATE** 路径(重解析/升级=删了重插换 id;采纳只写 x_remark、不进指纹也不进 +# 分组键)。将来新增「就地 UPDATE bills 的 Name/Attr/Price」的功能必须复核指纹列是否覆盖。 +# ② 规则侧三个参数(grp_rules/grp_big/grp_sig_thr)任一变化都会换指纹 → 自动按新规则重算。 +# ③ 缓存键含库标识(session/batch 前缀)——会话 sid 与批次 bid 同号也不是同一份数据。 +# 线程安全:ThreadingHTTPServer 多线程;LRU 字典读写各步靠 GIL 原子 + 锁兜底,最坏并发重复计算 +# (结果一致,无害)。缓存上限 12 个批次(LRU),内存约几十 MB。 +_GRP_CACHE = OrderedDict() # key -> json bytes(不可变,调用方改不坏) +_GRP_CACHE_MAX = 12 +_GRP_LOCK = threading.Lock() + +def _grp_fingerprint(kind, oid): + """缓存键;取不到指纹(理论不发生)返回 None = 不缓存。""" + try: + con = (sess.connect if kind == "session" else conn)() + try: + T = TBL[kind] + fp = con.execute("""SELECT COUNT(*), IFNULL(MAX(id),0), IFNULL(SUM(id),0), + IFNULL(TOTAL(Price),0), + IFNULL(SUM(LENGTH(COALESCE(Name,'')) + +LENGTH(COALESCE(Attr,''))),0) + FROM %(bl)s WHERE %(idc)s=?""" + % {"bl": T["bills"], "idc": T["idcol"]}, (oid,)).fetchone() + finally: + con.close() + rule = _grp_rule() + return (kind, int(oid), tuple(fp), _setting_get("global", "grp_rules") or "", + rule["big"], rule["sig_thr"]) + except Exception: + return None + + +def similar_payload(kind, oid, fresh=False): + """类似清单分组(前台/后台唯一入口,带缓存,决策 46)。返回 (obj, raw): + 命中 → (None, json_bytes)(HTTP 层直发);未命中 → (dict, None) 并回填缓存。 + fresh=True(前端「⟳ 重载」):跳过读缓存强制重算,算完仍回填(刷新缓存)。""" + key = None if fresh else _grp_fingerprint(kind, oid) + if key is not None: + with _GRP_LOCK: + raw = _GRP_CACHE.get(key) + if raw is not None: + _GRP_CACHE.move_to_end(key) + return None, raw + if kind == "session": + con = sess.connect() + try: + rows = _cmp_bills(con, TBL["session"], oid) + finally: + con.close() + else: + con = conn() + try: + rows = _cmp_bills(con, TBL["batch"], oid) + finally: + con.close() + d = _group_v2_output(rows) + if key is not None: + with _GRP_LOCK: + _GRP_CACHE[key] = json.dumps(d, ensure_ascii=False).encode("utf-8") + while len(_GRP_CACHE) > _GRP_CACHE_MAX: + _GRP_CACHE.popitem(last=False) + return d, None + + def api_similar(bid, profession=None): """后台「类似清单」:与工作台同一套 v2 顺序管线(决策 32:口径统一;关键词层读全局 - 「分组设置」表,后台不再有专业语境)。profession 参数废弃(保留仅为兼容调用方传参)。""" - c = conn() - try: - # 与工作台完全同口径(_cmp_bills,唯一实现):过滤措施费 + 单价空/0,并带出单位工程名 - rows = _cmp_bills(c, TBL["batch"], bid) - finally: - c.close() - return _group_v2_output(rows) + 「分组设置」表,后台不再有专业语境)。profession 参数废弃(保留仅为兼容调用方传参)。 + (2026-10-13 决策 46:similar 路由改走 similar_payload 带缓存;本函数退役,git 可寻。)""" + raise NotImplementedError("决策 46:api_similar 已由 similar_payload('batch', bid) 取代") def _bill_norms(con, T, bill_id): @@ -3846,8 +3910,9 @@ class Handler(SimpleHTTPRequestHandler): q = urllib.parse.quote(name or fallback) return "attachment; filename=\"%s\"; filename*=UTF-8''%s" % (fallback, q) - def _json(self, obj, code=200): - body = json.dumps(obj, ensure_ascii=False).encode("utf-8") + def _json(self, obj, code=200, raw=None): + # raw=json bytes(分组缓存命中,决策 46):跳过序列化直接回发 + body = raw if raw is not None else json.dumps(obj, ensure_ascii=False).encode("utf-8") self.send_response(code) self.send_header("Content-Type", "application/json; charset=utf-8") self.send_header("Content-Length", str(len(body))) @@ -4016,8 +4081,10 @@ class Handler(SimpleHTTPRequestHandler): return self._json(api_session_rows(one)) if p == "/api/session/inconsistent": # 会话内:组价不一致 return self._json(api_session_groups(int(one.get("session_id", 0)), "inconsistent")) - if p == "/api/session/similar": # 会话内:类似清单 - return self._json(api_session_groups(int(one.get("session_id", 0)), "similar")) + if p == "/api/session/similar": # 会话内:类似清单(带缓存,决策 46) + d, raw = similar_payload("session", int(one.get("session_id", 0)), + str(one.get("fresh")) in ("1", "true", "True")) + return self._json(d, raw=raw) if p == "/api/session/setting": # 分组/匹配 设置读取 scope, k = one.get("scope"), one.get("k") if not scope or not k: @@ -4063,8 +4130,10 @@ class Handler(SimpleHTTPRequestHandler): if m: return self._json(api_inconsistent(int(m.group(1)))) m = re.match(r"^/api/admin/batch/(\d+)/similar$", p) - if m: - return self._json(api_similar(int(m.group(1)), one.get("profession"))) + if m: # 类似清单(带缓存,决策 46) + d, raw = similar_payload("batch", int(m.group(1)), + str(one.get("fresh")) in ("1", "true", "True")) + return self._json(d, raw=raw) m = re.match(r"^/api/admin/batch/(\d+)/prices$", p) if m: return self._json(api_prices(int(m.group(1)), int(one.get("page", 1)), diff --git a/CostReview/app/tools/_tmp_profile_grp.py b/CostReview/app/tools/_tmp_profile_grp.py new file mode 100644 index 0000000..8ac2664 --- /dev/null +++ b/CostReview/app/tools/_tmp_profile_grp.py @@ -0,0 +1,24 @@ +# 一次性 profile 脚本(只读分析,决策 46 后方案 B 评估;测完即删,不进生产) +# 目标:南屏批次 30 的 _group_v2_output 6.6 秒热点分布 +import sys, time, cProfile, pstats, io +sys.path.insert(0, r'D:\PricingReview\CostReview\app\server') +import api_server as A + +c = A.conn() +t0 = time.time() +rows = A._cmp_bills(c, A.TBL['batch'], 30) +c.close() +print('可比集行数:', len(rows), ' 取数耗时', round(time.time() - t0, 2), 's', flush=True) + +t0 = time.time() +out = A._group_v2_output(rows) +print('_group_v2_output 总耗时:', round(time.time() - t0, 2), 's 组数:', out['total'], flush=True) + +pr = cProfile.Profile() +pr.enable() +A._group_v2_output(rows) +pr.disable() +s = io.StringIO() +ps = pstats.Stats(pr, stream=s).sort_stats('tottime') +ps.print_stats(16) +print(s.getvalue()) diff --git a/CostReview/app/ui/admin.html b/CostReview/app/ui/admin.html index 03b9b7f..3105c66 100644 --- a/CostReview/app/ui/admin.html +++ b/CostReview/app/ui/admin.html @@ -140,8 +140,8 @@ a:hover{text-decoration:underline} 必须给 #dright / #drawbox 撑出确定高度,否则 .rawbox 的 height:100% 在弹框里算不出来、整块塌陷。 */ #dright{flex:1;min-width:0;display:flex;flex-direction:column;min-height:0} #drawbox{flex:1;min-height:0} -#dside{width:300px;min-width:210px;background:#fff;border-right:1px solid var(--line); - overflow-y:auto;padding:10px 6px;flex-shrink:0} +#dside{width:300px;min-width:180px;background:#fff;border-right:1px solid var(--line); + overflow:auto;padding:10px 6px;flex-shrink:0} .treeT{font-size:14px;font-weight:700;margin:4px 8px 12px;color:#111827;line-height:1.4} .secT{padding:6px 8px;margin:1px 0;cursor:pointer;border-radius:6px;color:#374151; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:13px} @@ -180,6 +180,15 @@ a:hover{text-decoration:underline} .pnode:hover .ops,.pnode.ops-on .ops,.pnode.on .ops{display:inline-flex} /* ↑ 选中目录的按钮排常显(2026-10-13 主人找不到"+子目录"入口): 悬停可见照旧,选中的那一行不用悬停也能看到全部按钮 */ +/* 展开 / 折叠把手(2026-10-13 主人定):有子级 ▸/▾ 可点;叶子透明占位保持同级对齐 */ +.pnar{flex:none;width:14px;height:15px;line-height:13px;text-align:center;cursor:pointer; + color:#6b7280;font-size:10px;border-radius:3px;user-select:none} +.pnar:hover{background:#dbe5f2;color:var(--c1)} +.pnar.em{visibility:hidden} +.pkids{margin-left:16px;border-left:1px dotted #cbd5e1;padding-left:4px} +/* 目录栏宽度拖动条(2026-10-13 主人定:左右拖动调整目录容器宽度) */ +#presizer{width:6px;flex:none;cursor:col-resize;background:transparent} +#presizer:hover,#presizer.on{background:#c9d4e2} .pnode .ops span{min-width:17px;height:17px;padding:0 2px;border-radius:4px;background:#fff;border:1px solid #c9d4e2; color:#34506f;font-size:11px;line-height:15px;text-align:center;cursor:pointer;white-space:nowrap} .pnode .ops span:hover{background:var(--c2);color:#fff;border-color:var(--c2)} @@ -188,7 +197,7 @@ a:hover{text-decoration:underline} .pnode input.ren{width:120px;padding:1px 6px;font-size:12px;border-radius:4px;border:1px solid #9fb6d4} .pnode .cfm{display:inline-flex;gap:3px;align-items:center;background:#fff7e6;border:1px solid #f0d9a8; border-radius:4px;padding:1px 4px;font-size:11px;color:#8a6d1a;flex:none} -.pkids{margin-left:12px;border-left:1px dotted #cbd5e1;padding-left:4px} +/* .pkids 的缩进规则统一放上面把手那组(16px,2026-10-13 加深层级),这里不再重复定义 */ #ptool{display:flex;align-items:center;gap:8px;padding:9px 14px;background:#fafcff; border-bottom:1px solid var(--line);flex-wrap:wrap} #ptool .where{font-size:12px;color:#34506f;background:#eef3fa;border:1px solid #d8e0ec;border-radius:4px;padding:2px 8px} @@ -198,6 +207,8 @@ a:hover{text-decoration:underline} .btn.dis{color:#9aa4b2;background:#f4f6f9;cursor:not-allowed;border-color:#d8e0ec} tr.pedit{background:#fffbef} td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb6d4;border-radius:4px} +/* 明细表操作列:同一格里第二个链接(删除/取消)与前面的拉开 12px(2026-10-13 主人定) */ +#dtbd td a + a{margin-left:12px} .newflag{display:inline-block;margin-left:6px;padding:0 5px;border-radius:3px;background:#fff7e6; border:1px solid #f0d9a8;color:#8a6d1a;font-size:11px} @@ -279,6 +290,8 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
+ +
@@ -304,7 +317,12 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
-
+
+ + +
@@ -516,7 +534,7 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb - + diff --git a/CostReview/app/ui/common.js b/CostReview/app/ui/common.js index 532461b..efb7144 100644 --- a/CostReview/app/ui/common.js +++ b/CostReview/app/ui/common.js @@ -87,10 +87,14 @@ function WB_TAB(p) { } /* ---------------- ③ 列定义 ---------------- - 格式:[列名, 宽度px, 对齐, 标记] 对齐:c=居中 l=左 r=右 - 标记:'attr'=项目特征(可换行) 'tg'=展开把手 */ + 格式:[列名, 宽度px, 对齐, 标记, …] 对齐:c=居中 l=左 r=右 + 标记:'attr'=项目特征(可换行) 'tg'=展开把手 'F'=固定宽 'ns'=纯展示不可排序 + 'wb'=**工作台独有列**(第 6 位;取消采纳等会话交互列)—— 后台批次库只是存有 + 价值的不变数据(主人 2026-10-13 定),渲染时整列剔除(noWB(),真不输出 + col/th/td,display:none 会错位)。列定义仍以工作台布局为**唯一来源**, + 后台数组由 noWB() 派生、绝不另写一份 —— 改列只改 COLS.* 这一处。 */ const COLS = { - // 类似清单 / 组价不一致清单 共用(13 列,2026-10-11 主人定:备注列**左边**加独立「取消采纳」列, + // 类似清单 / 组价不一致清单 共用(13 列,2026-10-11 决策 39:备注列**左边**加独立「取消采纳」列, // 与项目工料机表同布局——取消采纳 | 备注;13 列 = 显示列,数据下标 0~10 不变) // ⚠️ 与后端 BILLROW() 数组下标一一对应: // 0=id 1=编码 2=名称 3=项目特征 4=单位 5=工程量 6=单价 7=合价 8=序号 9=单位工程名称 @@ -98,15 +102,20 @@ const COLS = { bill: [['', 44, 'c', 'tg'], ['序号', 52, 'c'], ['编码', 120, 'c'], ['类别', 52, 'c'], ['单位工程名称', 150, 'l'], ['名称', 210, 'l'], ['项目特征', 260, 'l', 'attr'], ['单位', 56, 'c'], ['工程量', 90, 'r'], ['单价', 100, 'r'], ['合价', 110, 'r'], - ['取消采纳', 76, 'c'], ['备注', 150, 'l']], + ['取消采纳', 76, 'c', '', '', 'wb'], ['备注', 150, 'l', '', '', 'wb']], - // 项目工料机(显示 10 列,2026-10-08 主人定:类型列不再显示,数据下标 9=类型 保持不变) - // 标记 'F' = 固定宽列;无标记 = 伸缩列(名称/规格型号/备注),平分容器剩余宽度 + // 项目工料机(工作台 11 列,2026-10-13 主人定:以工作台布局为唯一来源;「取消采纳」「备注」 + // 两列**工作台独有**(wb 标记,后台 noWB() 剔除后 9 列——采纳备注从不入历史库,后台恒空列不占位); + // 类型列不显示,数据下标 9=类型 保持不变) + // 标记 'F' = 固定宽列;无标记 = 伸缩列(名称/规格型号),平分容器剩余宽度 // —— 表宽始终贴合容器撑满屏幕,见 flexFit() / flexRedistribute()。 lme: [['序号', 52, 'c', 'F'], ['编码', 120, 'c', 'F'], ['名称', 220, 'l'], ['规格型号', 200, 'l'], ['单位', 56, 'c', 'F'], ['数量', 90, 'r', 'F'], ['除税编制价', 110, 'r', 'F'], ['税率', 70, 'r', 'F'], - ['含税编制价', 110, 'r', 'F'], ['备注', 160, 'l']] + ['含税编制价', 110, 'r', 'F'], ['取消采纳', 76, 'c', 'F', 'ns', 'wb'], ['备注', 160, 'l', '', '', 'wb']] }; +/* 后台列数组 = 工作台列剔除 wb 列(派生,不另维护)。 + 两侧共用同一份 COLS.*:工作台直接用(全量),后台一律经 noWB() 取用。 */ +function noWB(cols) { return cols.filter(c => c[5] !== 'wb'); } function colsObjs(arr) { return arr.map(c => { const o = { t: c[0], a: c[2], w: c[1] }; @@ -173,7 +182,7 @@ const BILL_ATTR_IDX = COLS.bill.findIndex(c => c[3] === 'attr'); // 项目特 const BILL_SORT_DS = { 1: 8, 2: 1, 4: 9, 5: 2, 6: 3, 7: 4, 8: 5, 9: 6, 10: 7 }; const BILL_SORT_NUM = new Set([8, 5, 6, 7]); // 序号/工程量/单价/合价 按数值比 function billHeadHTML() { - return '' + COLS.bill.map((c, i) => { + return '' + billCols().map((c, i) => { const can = BILL_SORT_DS[i] != null; const mark = (can && BILL_SORT.k === i) ? (BILL_SORT.dir > 0 ? ' ▲' : ' ▼') : ''; const click = can @@ -487,8 +496,17 @@ function sumw(tb) { /* ---------------- ④ 清单分组渲染 ---------------- 行数组 r = [id, 编码, 名称, 项目特征, 单位, 工程量, 单价, 合价, 序号, 单位工程名称] opts.rowClick:行点击回调名(工作台='pick',后台='' 表示不绑) - opts.normApi:展开定额的接口前缀(会话 /api/session/bill/,批次 /api/admin/bill/) */ -const CB_LAST = COLS.bill.length - 1, CB_TOTAL = COLS.bill.length - 2; // 组标题 colspan 随列数推导,去魔数 + opts.normApi:展开定额的接口前缀(会话 /api/session/bill/,批次 /api/admin/bill/) + opts.backend:后台标记 —— 取消采纳列(wb)整列不输出(主人 2026-10-13 定:列定义 + 维护一套、后台隐藏),组表各处 colspan 由 billCols() 按当前布局推导。 */ +/* 组表当前布局(2026-10-13 主人定:尽量维护一套系统):列定义只有 COLS.bill 一份 + (工作台全量 13 列);后台 = noWB() 剔除 wb 列(取消采纳)→ 12 列。 + 表头 / 组标题 / 分隔行 / 定额子行 / 空表占位的格数与 colspan 全由它推导。 */ +function billCols() { + const bk = (typeof WB_OPTS !== 'undefined') && WB_OPTS && WB_OPTS.backend; + return bk ? noWB(COLS.bill) : COLS.bill; +} +const CB_LAST = () => billCols().length - 1, CB_TOTAL = () => billCols().length - 2; function grpTitle(tag, g) { let t = tag + ' · ' + (g.n != null ? g.n : (g.rows ? g.rows.length : 0)) + ' 条清单'; @@ -514,12 +532,14 @@ function billTR(r, grp, hide, opts) { + '' + num(r[5], 3) + '' + '' + num(r[6]) + '' + '' + num(r[7]) + '' - + '' + billAdoptCellHTML(r) + '' - + '' + billRemarkCell(r) + ''; + + (opts.backend ? '' : '' + billAdoptCellHTML(r) + '' + + '' + billRemarkCell(r) + '') + + ''; } -/* 清单「取消采纳」列(2026-10-11 主人定:备注列**左边**独立一列,与项目工料机表同布局): +/* 清单「取消采纳」列(2026-10-11 决策 39;2026-10-13 主人定:**工作台独有**,wb 标记、 + 后台 noWB() 整列隐藏——后台批次库只是存有价值的不变数据,交互列不占列): 有采纳备注(r[10],BILLROW 尾位)= 「取消采纳」链接;无 = —。 - 后台批次行没有备注(BILLROW 尾位恒 None)→ 恒 —,链接不会出现在后台。 */ + 后台不输出该格(opts.backend),链接永远不会出现在后台。 */ function billAdoptCellHTML(r) { return (r && r[10]) ? '' + '' + (open ? '−' : '+') + '' + '' - + '' + title + '' + + '' + title + '' + '' + num(sum) + '' + ''; } @@ -592,14 +612,14 @@ function renderGroups(d, kind, opts) { }); // 落单组(决策 32:单个「其他」批)跟着组序连续编为第 N+1 组,与左树同号(决策 33 对齐口径) if (kind === 'similar' && d && d.extra && d.extra.length) { - html += '以下清单符合筛选条件,但未形成相似组'; + html += '以下清单符合筛选条件,但未形成相似组'; d.extra.forEach((g, i) => { const key = pfx + 'x' + i; const bad = (g.spread != null && Number(g.spread) >= 20) ? ' bad' : ''; html += grpTR('grp2' + bad, key, grpTitle('第 ' + (groups.length + i + 1) + ' 组', g), g.tsum, false); }); } - return html || '没有数据'; + return html || '没有数据'; } /* ---- 类似清单左目录树(2026-10-08 主人定:工作台/后台的类似清单都有;2026-10-10 决策 30 改格式)---- @@ -662,12 +682,12 @@ function grpTreeBind(box, tbId, d) { } /* ---------------- ⑤ 工料机行 ---------------- - ⚠️ 与后端 _lme_rows() 的 10 列一一对应(第 11 列「备注」:会话侧 = 采纳备注 r[10],批次侧无 → 空): + ⚠️ 与后端 _lme_rows() 的数据 11 列一一对应: 0=id 1=编码 2=名称 3=规格型号 4=单位 5=数量 6=除税编制价 7=税率 8=含税编制价 9=类型 10=备注 2026-10-08 主人定:**类型列不显示**(r[9] 照常拿到但不渲染格);备注列显示采纳写入的审核备注 (工作台 /api/session/rows 返回 r[10]=x_remark;后台批次行没有这列,留空 —— 两侧同一份渲染)。 - 2026-10-09:opts.lmeExtra(r,i) 可选钩子 —— 在「备注」格**前**插一格(工作台的「取消采纳」列; - 后台不传 = 不显示)。会话侧行渲染 11 格、批次侧仍 10 格,列序由各页自己的 cols 数组决定。 */ + 2026-10-13 主人定:「取消采纳」列**工作台独有**(COLS.lme 里 wb 标记,后台 noWB() 剔除整列; + 原工作台页内插列 + renderLme 的 lmeExtra 钩子退役)。opts.backend=后台时不输出该格。 */ function renderLme(rows, opts) { opts = opts || (typeof WB_OPTS !== 'undefined' ? WB_OPTS : {}) || {}; const click = opts.rowClick @@ -684,16 +704,26 @@ function renderLme(rows, opts) { + '' + num(r[6]) + '' + '' + num(r[7], 2) + '' + '' + num(r[8]) + '' - + (opts.lmeExtra ? opts.lmeExtra(r, i) : '') - + '' + esc(r[10] || '') + '').join(''); + + (opts.backend ? '' : '' + lmeAdoptCellHTML(r) + '' + + '' + esc(r[10] || '') + '') + + '').join(''); +} +/* 工料机「取消采纳」格(2026-10-13 收编,工作台侧唯一调用方;后台整列不输出): + 有采纳备注(r[10] 以「采纳:」开头,会话侧 s_lme_proj.x_remark)→「取消采纳」链接, + 点击清备注 + 把它收进的附件移出「询价附件」目录(cancelAdopt 由工作台页提供);其余 = 灰 —。 */ +function lmeAdoptCellHTML(r) { + return (r && /^采纳:/.test(r[10] || '')) + ? '取消采纳' + : '—'; } /* ---------------- ⑦ 定额展开交互 ---------------- 清单首列「+」→ 展开其下的定额。两侧同一份实现,只是查的库不同 (工作台 /api/session/bill/… 会话库,后台 /api/admin/bill/… 历史库), 差异**只允许**体现在 WB_OPTS.normApi 这个前缀上。 - ⚠️ 子行必须 12 个 td,和 COLS.bill 对齐 —— 早年后台写过 4 列的子行版本, - 跟工作台对不齐(也对不上列头),已废弃。 */ + ⚠️ 子行格数 = 当前布局列数(billCols():工作台 13 格 / 后台 12 格,取消采纳格 + backend 时不输出)—— 必须和列头对齐,早年后台写过 4 列的子行版本已废弃。 */ function tgNorm(el, billId) { const opts = (typeof WB_OPTS !== 'undefined' ? WB_OPTS : {}) || {}; const base = opts.normApi || '/api/session/bill/'; @@ -710,7 +740,7 @@ function tgNorm(el, billId) { const rows = (d && d.rows) || []; if (!rows.length) { frag.innerHTML = '' - + '(该清单下没有定额)'; + + '(该清单下没有定额)'; } else { // 定额 0=编码 1=名称 2=单位 3=工程量 4=单价 5=合价,其余列按清单的对应位置排空(含取消采纳/备注两空位) frag.innerHTML = rows.map(r => '' @@ -723,8 +753,8 @@ function tgNorm(el, billId) { + '' + num(r[3], 3) + '' + '' + num(r[4]) + '' + '' + num(r[5]) + '' - + '—' - + '').join(''); + + (opts.backend ? '' : '—') + + '').join(''); } let n2 = tr.nextElementSibling; while (n2 && n2.classList.contains('sub')) n2 = n2.nextElementSibling; @@ -2158,3 +2188,95 @@ function licActivate() { licLoad(); }).catch(() => { go.disabled = false; toast('网络错误:无法连接本机服务', 'err'); }); } + +/* ---------------- ⑧ 加载进度遮罩(2026-10-13 升入共享层,前后台/会话页同一份)---------------- + 来源:工作台 ldmask(2026-10-11 主人定「打开项目要有正在加载的感觉」);2026-10-13 主人定 + 「所有需要等待的进入点都要进度条:切标签卡没展开全部数据前、打开明细、前后台互切、页面初载」。 + HTML 由本模块**懒注入**(全内联样式,不依赖页面局部 .mask/.dlg 类——sessions 页没引 common.css)。 + 基础 API(与原工作台同名同义,initFromUrl 等既有调用零改动): + ldShow(名称, 阶段文案, 起始%) → ldPct(p, text) 推进 → ldCreep(from,to,text) 长活爬升 → ldHide() 收尾 + 便捷包装: + ldWrap(名称, 阶段, fn) —— 包一个 async 操作:150ms 内完成**不闪遮罩**(快操作无感); + 显示后至少停留 500ms(防一闪而过);结束时若遮罩不是我显示的(外层流程在管),只更新 + 阶段文案、不代管收尾。LD_SEQ 守卫:连续操作只有最新一次的收尾生效(慢的旧操作不许盖新的)。 + ldStage(pct, text) —— 遮罩在显示时更新阶段文案(不在显示时为 no-op),长流程内分段报进度用。 */ +(function(){ + let mounted = false; + function mount(){ + if (mounted) return; mounted = true; + const d = document.createElement('div'); + d.id = 'ldmask'; + d.style.cssText = 'position:fixed;inset:0;background:rgba(0,0,0,.35);display:none;' + + 'align-items:center;justify-content:center;z-index:130'; + d.innerHTML = '
' + + '
正在加载
' + + '
' + + '
' + + '
' + + '
准备中…
'; + document.body.appendChild(d); + } + function el(id){ return document.getElementById(id); } + window.ldShow = function(name, text, pct){ + mount(); + el('ldname').textContent = name ? ('《' + name + '》') : ''; + el('ldmask').style.display = 'flex'; + ldPct(pct, text); + }; + function ldPct(p, text){ + if (text != null) el('ldtext').textContent = text; + el('ldbar').style.width = Math.max(0, Math.min(100, p)) + '%'; + } + window.ldPct = ldPct; + window.ldStage = function(p, text){ + const m = el('ldmask'); + if (m && m.style.display !== 'none') ldPct(p, text); + }; + let LD_T = 0; + window.ldCreep = function(from, to, text){ + ldPct(from, text); + clearInterval(LD_T); + let p = from; + LD_T = setInterval(function(){ p += 0.5; if (p < to) ldPct(p); }, 300); + }; + window.ldHide = function(){ + clearInterval(LD_T); + ldPct(100, '完成'); + setTimeout(function(){ + const m = el('ldmask'); if (!m) return; + // 尾巴期间若有新加载接管(bar 已被重设 <100%),不许把人家的遮罩藏掉 + if ((parseFloat(el('ldbar').style.width) || 0) >= 99){ + m.style.display = 'none'; ldPct(0, '准备中…'); + } + }, 280); + }; + /* 遮罩是否「真在加载」:display 开着且进度 <100%。 + ⚠️ ldHide 有 280ms「完成」收尾尾巴(bar 已打到 100%、display 还没藏)——这期间 + 新操作若只看 display 会误判「有人在管」而不接管,结果没人管、长活裸奔 + (南屏 p2 实测前 0.4s 有遮罩、后 6.2s 空窗,就是这只尾巴)。所以判定看 bar。 */ + function ldActive(){ + const m = el('ldmask'); + if (!m || m.style.display === 'none') return false; + return (parseFloat(el('ldbar').style.width) || 0) < 99; + } + let LD_SEQ = 0; + window.ldWrap = async function(name, text, fn, opts){ + const seq = ++LD_SEQ; + const delay = (opts && opts.delay != null) ? opts.delay : 150; + let owner = false, shownAt = 0; + const tm = setTimeout(function(){ + if (ldActive()) return; // 已有遮罩在真加载(外层流程在管):不接管也不收尾 + ldShow(name, text, 10); owner = true; shownAt = Date.now(); + }, delay); + try { ldStage(12, text); return await fn(); } + finally { + clearTimeout(tm); + if (!owner) return; // 不是我显示的遮罩,不归我收 + const rest = 500 - (Date.now() - shownAt); + const fin = function(){ if (seq === LD_SEQ) ldHide(); }; + if (rest > 0) setTimeout(fin, rest); else fin(); + } + }; +})(); diff --git a/CostReview/app/ui/sessions.html b/CostReview/app/ui/sessions.html index b10bc02..223cf15 100644 --- a/CostReview/app/ui/sessions.html +++ b/CostReview/app/ui/sessions.html @@ -61,7 +61,7 @@ a:hover{text-decoration:underline} - + diff --git a/CostReview/app/ui/workbench.html b/CostReview/app/ui/workbench.html index a035583..cf79d4b 100644 --- a/CostReview/app/ui/workbench.html +++ b/CostReview/app/ui/workbench.html @@ -294,7 +294,13 @@ body.grptree-dragging{cursor:col-resize !important;user-select:none}
◀
-
+
+ +
+ ⟳ 重载 + 分组结果已缓存(改分组规则后自动按新规则重算) +
+
@@ -432,18 +438,8 @@ body.grptree-dragging{cursor:col-resize !important;user-select:none} 「最近审核」点打开跳 ?sid=N:重解析+首屏加载有几秒到几十秒静默期,观感像死机。 这层遮罩在 initFromUrl 里分段推进:显示**正在加载的项目名称**+阶段文案+进度条; 重解析是服务端单线程长活,用缓慢爬升的假进度占位(到 82% 封顶等真实阶段接棒)。 --> -
-
-

正在打开项目

-
-
-
-
-
-
准备中…
-
-
-
+
@@ -465,7 +461,7 @@ body.grptree-dragging{cursor:col-resize !important;user-select:none}
- +