feat(mcp): 新增 Excel 批量清单匹配工具并调整分页与采纳锚策略
This commit is contained in:
@@ -21,6 +21,7 @@ import io
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import tempfile
|
||||
import zipfile
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
@@ -172,6 +173,73 @@ def _shapes_of_blob(blob):
|
||||
return shapes
|
||||
|
||||
|
||||
def list_frames(con):
|
||||
"""骨架库列表(后台「导出设置」弹框,2026-11-02 主人定):全部骨架平铺,
|
||||
后缀聚簇排序(cos4→cos 字母序)、组内入库时间倒序——前端按后缀分组渲染
|
||||
(组间横线、后缀列组首行标件数)。"""
|
||||
_ensure_table(con)
|
||||
try:
|
||||
rows = con.execute(
|
||||
"SELECT sig, suffix, original_name, n_shapes, n_nodes, extracted_at, is_frame "
|
||||
"FROM classic_skel ORDER BY suffix DESC, extracted_at DESC, n_nodes DESC"
|
||||
).fetchall()
|
||||
except Exception:
|
||||
return []
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def delete_frame(con, sig):
|
||||
"""删除一件骨架(2026-11-02 主人定「要做删除」):硬删一行、不可逆,
|
||||
恢复=同名文件重新上传(seed_frame 同名替换会重建行)。返回删除行数。"""
|
||||
cur = con.execute("DELETE FROM classic_skel WHERE sig=?", (sig,))
|
||||
con.commit()
|
||||
return cur.rowcount
|
||||
|
||||
|
||||
def frame_blob(con, sig):
|
||||
"""取一件骨架的原件字节与原始文件名(下载用)→ (blob, original_name);无 → (None, None)。"""
|
||||
row = con.execute("SELECT blob, original_name FROM classic_skel WHERE sig=?",
|
||||
(sig,)).fetchone()
|
||||
if not row:
|
||||
return None, None
|
||||
return row["blob"], row["original_name"]
|
||||
|
||||
|
||||
def seed_pack(con, path):
|
||||
"""骨架包安装(2026-11-02 主人定两阶段架构:阶段二上市版「后台直接上传骨架包、
|
||||
租户客户端接收」——本函数是包→库的共用解包口,阶段一后台手动传包同走这里)。
|
||||
包 = zip,成员为 .cos/.cos4 原件(可带目录层),逐成员以其文件名(去扩展)为
|
||||
显示名 seed_frame;同名=升级替换。返回 [(显示名, 后缀, sig|None)](None=
|
||||
该成员不成结构,合法跳过不挡包);非 zip → None。"""
|
||||
out = []
|
||||
try:
|
||||
with zipfile.ZipFile(path) as z:
|
||||
for info in z.infolist():
|
||||
nm = info.filename
|
||||
if not _COS_RE.search(nm):
|
||||
continue
|
||||
try: # zip 成员名常见 GBK 存 KB:cp437 转回
|
||||
nm2 = nm.encode("cp437").decode("gbk")
|
||||
except Exception:
|
||||
nm2 = nm
|
||||
ext = os.path.splitext(nm2)[1]
|
||||
fd, tmp = tempfile.mkstemp(suffix=ext)
|
||||
try:
|
||||
with os.fdopen(fd, "wb") as f:
|
||||
f.write(z.read(info))
|
||||
stem = os.path.splitext(os.path.basename(nm2))[0]
|
||||
sig = seed_frame(con, tmp, stem)
|
||||
out.append({"name": stem, "suffix": suffix_of(nm2), "sig": sig})
|
||||
finally:
|
||||
try:
|
||||
os.remove(tmp)
|
||||
except OSError:
|
||||
pass
|
||||
except zipfile.BadZipFile:
|
||||
return None
|
||||
return out
|
||||
|
||||
|
||||
def pick_frame(con, suffix, src_path=None):
|
||||
"""导出骨架挑选(补记十二,主人定「按字段最近的一个」):
|
||||
①该后缀的固定骨架(is_frame=1,可多件并存)里有源文件可比 → 结构字段集 Jaccard
|
||||
|
||||
@@ -384,9 +384,11 @@ def _region3(p, c, d3):
|
||||
return "/".join(x for x in (p, c, d3) if x) or None
|
||||
|
||||
|
||||
def match_bill(hist, row, base, kinds, units, classes, limit=20, srcs=None, pfrom=None, pto=None, self_name=None, self_src=None, area=None, projs=None, pmin=None, pmax=None, att="all"):
|
||||
def match_bill(hist, row, base, kinds, units, classes, limit=20, srcs=None, pfrom=None, pto=None, self_name=None, self_src=None, area=None, projs=None, pmin=None, pmax=None, att="all", unit_free=False):
|
||||
bf, bt = span(base) # 基准期次:单月 int 或 (起, 止) 区间
|
||||
"""row: sqlite Row of s_bills"""
|
||||
"""row: sqlite Row of s_bills
|
||||
unit_free(2026-11-02 主人定,Excel 批量匹配专用):Excel 只有一列清单名称没有单位/编码 ——
|
||||
True=跳过字集档(键含单位对不齐)并放宽模糊档单位护栏,纯按名称相似度匹配;比对框不传(False)行为零变化。"""
|
||||
c = hist.cursor()
|
||||
w, args = _filters(kinds, units, [], self_src=self_src, area=area, projs=projs) # classes 只对价格库有意义,清单比对不筛目录
|
||||
# 决策 208(2026-10-26 主人定):价格范围/附件筛选清单侧同样生效(工具栏恒显最大集)——
|
||||
@@ -428,7 +430,8 @@ def match_bill(hist, row, base, kinds, units, classes, limit=20, srcs=None, pfro
|
||||
out.append(d); seen.add((d["Name"], d["Attr"])); seen_ids.add(d["id"])
|
||||
# L1.5 字集精确(2026-10-10 决策 27):名称字集+单位等价——「钢筋混凝土」=「混凝土钢筋」,
|
||||
# 不按排序的严格命中;键 = bills.x_setkey(导入落列,老库启动迁移回填)。
|
||||
if len(out) < limit:
|
||||
# unit_free(Excel 无单位)时键对不齐 → 整档跳过,交给下方模糊档纯名称相似度。
|
||||
if len(out) < limit and not unit_free:
|
||||
sqlk = """SELECT '字集' tier, b.id, b.Number, b.Name, b.Attr, b.Unit, b.Price, bt.Name proj,
|
||||
bt.x_period_start_m p1, bt.x_period_end_m p2, bt.FileKind, bt.BulidUnit, bt.x_src_hash src,
|
||||
bt.x_province, bt.x_city, bt.x_district
|
||||
@@ -451,7 +454,7 @@ def match_bill(hist, row, base, kinds, units, classes, limit=20, srcs=None, pfro
|
||||
FROM bills b JOIN batches bt ON bt.id=b.batch_id
|
||||
WHERE bt.kind='project' AND %s AND b.x_name_norm LIKE ? LIMIT 300""" % w
|
||||
for x in c.execute(sql3, args + ["%" + q + "%"]):
|
||||
if norm(x["Unit"]) != norm(row["Unit"]):
|
||||
if not unit_free and norm(x["Unit"]) != norm(row["Unit"]):
|
||||
continue
|
||||
if x["id"] in seen_ids:
|
||||
continue
|
||||
|
||||
@@ -142,9 +142,9 @@ _LME_ANCHOR_COLS = ("x_ntp0", "x_rate0", "x_taxp0") # 决策 219:第一次
|
||||
|
||||
|
||||
def ensure_lme_anchor_cols(con):
|
||||
"""老会话库 s_lme_proj 补采纳锚三列(幂等,决策 219)+ 锚空回填:按导入同款公式
|
||||
(单位级每码第一行三价,无单位行退汇总自身值)补 NULL 锚——没被改过价的码回填即真值;
|
||||
已被改过价的码回填当前值并把锚**冻住**(此后连采纳不再漂)。真值以重导/合并端点为准。"""
|
||||
"""老会话库 s_lme_proj 补采纳锚三列(幂等,只保列在——防老代码/策略表读崩)。
|
||||
决策 251(2026-11-01 主人定):采纳备注旧价改由采纳端点直读导入原件价(ntp_org/taxp_org),
|
||||
锚列停止灌值、停止回填(列保留不 DROP,数据红线)。"""
|
||||
cols = [r[1] for r in con.execute("PRAGMA table_info(s_lme_proj)")]
|
||||
if not cols:
|
||||
return
|
||||
@@ -152,17 +152,6 @@ def ensure_lme_anchor_cols(con):
|
||||
if cn not in cols:
|
||||
con.execute("ALTER TABLE s_lme_proj ADD COLUMN %s REAL" % cn)
|
||||
cols.append(cn)
|
||||
first = {}
|
||||
for r in con.execute("SELECT session_id, code, ntp, taxrate, taxp FROM s_lme_uw ORDER BY id"):
|
||||
first.setdefault((r[0], r[1]), (r[2], r[3], r[4])) # 每码导入序第一行(决策 219 同款)
|
||||
upd = []
|
||||
for r in con.execute("SELECT id, session_id, code, ntp, taxrate, taxp FROM s_lme_proj WHERE x_ntp0 IS NULL"):
|
||||
f = first.get((r[1], r[2]))
|
||||
upd.append(((f[0] if f and f[0] is not None else r[3]),
|
||||
(f[1] if f and f[1] is not None else r[4]),
|
||||
(f[2] if f and f[2] is not None else r[5]), r[0]))
|
||||
if upd:
|
||||
con.executemany("UPDATE s_lme_proj SET x_ntp0=?, x_rate0=?, x_taxp0=? WHERE id=?", upd)
|
||||
con.commit()
|
||||
|
||||
|
||||
@@ -794,19 +783,13 @@ def open_project(con, files, meta, job, sid=None):
|
||||
ntp_org, ntp_expr, taxp_org, taxp_expr)
|
||||
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
|
||||
(sid, _c, _nm, _sp, _un, _kd, _q, _ntp, _taxp, _rate) + tuple(_x))
|
||||
# 决策 219(2026-10-26 主人定):第一次计算的三价锚=单位级每码认第一行的三价
|
||||
# (无单位行退汇总自身值)。采纳备注「+旧价」恒取此,改价/再采纳/合并重放不漂;
|
||||
# 合并工料机生成的行由合并端点把锚改写为合并后首次三价。
|
||||
# 决策 251(2026-11-01 主人定,取代 219 锚取值):采纳备注「+旧价」锚=**导入时项目级
|
||||
# 三价快照**(灌库那一刻 s_lme_proj 的 ntp/taxrate/taxp,写入后冻结——合并/重放/映射源
|
||||
# 落位都不再写锚列,227 改价失效链取消,改价/再采纳永不漂)。
|
||||
# 注意:ntp_org/taxp_org(决策 183)会被映射源落位/合并重放改写,不是冻结的导入价,
|
||||
# 故锚用专用列不用 _org。合并生成的行无锚(NULL)→采纳备注退改前现值(前端兜底)。
|
||||
cur.execute("""UPDATE s_lme_proj SET
|
||||
x_ntp0=COALESCE((SELECT u.ntp FROM s_lme_uw u
|
||||
WHERE u.session_id=s_lme_proj.session_id AND u.code=s_lme_proj.code
|
||||
ORDER BY u.id LIMIT 1), ntp),
|
||||
x_rate0=COALESCE((SELECT u.taxrate FROM s_lme_uw u
|
||||
WHERE u.session_id=s_lme_proj.session_id AND u.code=s_lme_proj.code
|
||||
ORDER BY u.id LIMIT 1), taxrate),
|
||||
x_taxp0=COALESCE((SELECT u.taxp FROM s_lme_uw u
|
||||
WHERE u.session_id=s_lme_proj.session_id AND u.code=s_lme_proj.code
|
||||
ORDER BY u.id LIMIT 1), taxp)
|
||||
x_ntp0=ntp, x_rate0=taxrate, x_taxp0=taxp
|
||||
WHERE session_id=?""", (sid,))
|
||||
# 这几样都要**解析完**才知道(sessions 行在解析之前就插好了),所以这里补一笔
|
||||
if ptotal is not None or pinfo or pfeat:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
M3-1 后端服务:零依赖(Python 标准库 http.server)
|
||||
提供后台管理界面需要的接口,并托管前端页面。
|
||||
"""
|
||||
import io, os, re, json, sqlite3, urllib.parse, mimetypes, hashlib, time, threading, base64, sys, zipfile
|
||||
import io, os, re, json, sqlite3, urllib.parse, mimetypes, hashlib, time, threading, base64, sys, zipfile, tempfile
|
||||
from decimal import Decimal, ROUND_HALF_UP
|
||||
from itertools import combinations
|
||||
from collections import Counter, OrderedDict
|
||||
@@ -357,25 +357,27 @@ def api_admin_settings_save(body):
|
||||
|
||||
|
||||
def api_dict():
|
||||
"""数据源:地区(三列平铺 + 树)+ 发布单位 + 建设单位"""
|
||||
"""数据源:地区(三列平铺 + 树)+ 发布单位 + 询价单位(2026-11-02 主人定,市场价专用)+ 建设单位"""
|
||||
con = sqlite3.connect(DB)
|
||||
con.row_factory = sqlite3.Row
|
||||
regs = [{"id": r["id"], "province": r["province"], "city": r["city"], "district": r["district"]}
|
||||
for r in con.execute("SELECT * FROM dict_region ORDER BY province,city,district")]
|
||||
pubs = [{"id": r["id"], "name": r["name"]}
|
||||
for r in con.execute("SELECT * FROM dict_org WHERE cat='publisher' ORDER BY name")]
|
||||
inqs = [{"id": r["id"], "name": r["name"]}
|
||||
for r in con.execute("SELECT * FROM dict_org WHERE cat='inquirer' ORDER BY name")]
|
||||
buis = [{"id": r["id"], "name": r["name"]}
|
||||
for r in con.execute("SELECT * FROM dict_org WHERE cat='builder' ORDER BY name")]
|
||||
con.close()
|
||||
return {"ok": True, "regions": regs, "publishers": pubs, "builders": buis}
|
||||
return {"ok": True, "regions": regs, "publishers": pubs, "inquirers": inqs, "builders": buis}
|
||||
|
||||
|
||||
def api_dict_save(body):
|
||||
"""新增 / 删除字典项。body: {cat:'region'|'publisher'|'builder', act:'add'|'del', id?, ...}"""
|
||||
"""新增 / 删除字典项。body: {cat:'region'|'publisher'|'inquirer'|'builder', act:'add'|'del', id?, ...}"""
|
||||
cat = (body.get("cat") or "").strip()
|
||||
act = (body.get("act") or "").strip()
|
||||
if cat not in ("region", "publisher", "builder"):
|
||||
return {"ok": False, "msg": "cat 必须是 region / publisher / builder"}
|
||||
if cat not in ("region", "publisher", "inquirer", "builder"):
|
||||
return {"ok": False, "msg": "cat 必须是 region / publisher / inquirer / builder"}
|
||||
con = sqlite3.connect(DB)
|
||||
try:
|
||||
if act == "add":
|
||||
@@ -3809,20 +3811,7 @@ def _lme_ntp_of(sc, sid, uw_id, code):
|
||||
r = sc.execute("SELECT ntp, taxp FROM s_lme_proj WHERE session_id=? AND code=? LIMIT 1",
|
||||
(sid, code)).fetchone()
|
||||
return (r["ntp"], r["taxp"]) if r else (None, None)
|
||||
|
||||
|
||||
def _anchor_invalidate(sc, sid, code):
|
||||
"""决策 227 拍板(主人 2026-10-27):采纳只管采纳时的状态,后期修改走后期规则——
|
||||
工料机汇总改价(行级改价/合并工料机)后,本会话引用该码的采纳价锚全部失效(清 NULL),
|
||||
浮层回取价链显示汇总现价(谁后改听谁);再次采纳重落新锚。
|
||||
缺锚列的库(未走启动补列的直调/老库)无事可做,探测跳过。"""
|
||||
if "x_ntp" not in {x[1] for x in sc.execute("PRAGMA table_info(s_norm_res)")}:
|
||||
return 0
|
||||
sc.execute("""UPDATE s_norm_res SET x_ntp=NULL, x_taxp=NULL
|
||||
WHERE res_code=? AND x_ntp IS NOT NULL
|
||||
AND norm_id IN (SELECT id FROM s_norms
|
||||
WHERE bill_id IN (SELECT id FROM s_bills WHERE session_id=?))""",
|
||||
(code, sid))
|
||||
# 决策 251(2026-11-01 主人定):决策 227 的改价失效回链随锚改导入价口径取消,函数已删。
|
||||
|
||||
|
||||
def api_bill_adopt(sc, hc, body):
|
||||
@@ -4952,13 +4941,8 @@ def api_lme_merge(sc, body):
|
||||
_merged_codes_add(sc, sid, keep_code)
|
||||
sc.execute(("UPDATE s_lme_uw SET ntp=?, taxrate=?, taxp=?%s WHERE session_id=? AND code=?") % _xs,
|
||||
keep_px + tuple(_xa) + (sid, keep_code))
|
||||
if keep_code and keep_px:
|
||||
# 决策 219:合并保留下来的行——采纳旧价锚=**合并后的首次三价**(主人定)
|
||||
try:
|
||||
sc.execute("UPDATE s_lme_proj SET x_ntp0=?, x_rate0=?, x_taxp0=? WHERE session_id=? AND code=?",
|
||||
tuple(keep_px) + (sid, keep_code))
|
||||
except Exception:
|
||||
pass
|
||||
# 决策 251:锚列停止维护(旧 219「合并后首次三价」写入随退役删除)——合并生成的行
|
||||
# 无导入原件价(_org 空),采纳备注退改前现值兜底,见 api_lme_price。
|
||||
if not keep_code:
|
||||
continue
|
||||
# 决策 186 补(2026-10-24 主人提醒「项目级不是不在弹框显示了吗」定位的盲区):
|
||||
@@ -5085,8 +5069,6 @@ def api_lme_merge(sc, body):
|
||||
_inject_missing_refs(sc, sid) # 决策 186 第 5 条:Element 引用汇总行缺失→注入一次
|
||||
sess.dedupe_lme_uw(sc) # 决策 191:换码撞保留码双行收尾去重(幂等)
|
||||
_consolidate_norm_res(sc, sid) # 决策 200:换码碰撞后同定额同码并一条(消耗量相加)
|
||||
if keep_code:
|
||||
_anchor_invalidate(sc, sid, keep_code) # 决策 227:合并改价=后期规则,保留码采纳价锚失效回链
|
||||
return {"ok": True, "sid": sid, "kept": kept, "hidden": hid}
|
||||
|
||||
|
||||
@@ -5520,10 +5502,13 @@ def api_lme_price(sc, body):
|
||||
# 决策 73/75 口径:按编码同步存在该编码的单位级汇总(rowcount=同步到的单位数)
|
||||
cur = sc.execute("UPDATE s_lme_uw SET ntp=?, taxrate=?, taxp=? WHERE session_id=? AND code=?",
|
||||
(ntp, rate, taxp, sid, row["code"]))
|
||||
_anchor_invalidate(sc, sid, row["code"]) # 决策 227:汇总改价=后期规则,采纳价锚失效回链
|
||||
_merged_codes_add(sc, sid, row["code"])
|
||||
_merged_codes_add(sc, sid, row["code"]) # 决策 251:227 改价失效回链取消——旧价=导入价(历史快照),改价不碰
|
||||
dyn_lme.mark_manual_price(sc, sid, row["code"]) # 决策 191:手工改价标记(重放跳过,假库失败不挡)
|
||||
try: # 决策 219:采纳锚(第一次计算/合并后首次三价;老库列缺/空=None→前端退改前现值)
|
||||
# 决策 251(2026-11-01 主人定,取代 219 锚口径):采纳备注旧价=锚列(**导入时项目级三价
|
||||
# 冻结快照**,灌库写一次后合并/重放/改价都不再写)。锚 NULL(合并生成行/老库未灌)→
|
||||
# 返回 None,前端退改前现值(现行兜底)。
|
||||
_a = None
|
||||
try:
|
||||
_a = sc.execute("SELECT x_ntp0, x_rate0, x_taxp0 FROM s_lme_proj WHERE session_id=? AND id=?",
|
||||
(sid, rid)).fetchone()
|
||||
except Exception:
|
||||
@@ -7419,6 +7404,47 @@ def api_lme_src(b):
|
||||
(b.get("code") or "").strip())
|
||||
|
||||
|
||||
def api_dup_check(b):
|
||||
"""决策 243 补记五(2026-11-02 主人定):导入预检——前端选完文件本地算 sha256 来查,
|
||||
命中提前弹框提醒;提交后的拦截(决策 242/243)原样保留兜底。
|
||||
⚠️ 口径与提交拦截**逐字同源**(主人令「不要记忆遗留,导致误判新项目的导入」):
|
||||
src_name 段与 x_src_hash 一律 split("_",1)[0] 精确比、sha 非 64 位 hex 一律不查、
|
||||
工作台向只查 kind='project' 批次(价格批次不算工程文件重复)——绝不比拦截更宽。"""
|
||||
sha = (b.get("sha256") or "").strip().lower()
|
||||
side = "admin" if b.get("side") == "admin" else "wb"
|
||||
hits = []
|
||||
if not re.fullmatch(r"[0-9a-f]{64}", sha):
|
||||
return {"ok": True, "hits": hits}
|
||||
sc0 = sess.connect()
|
||||
try:
|
||||
for r0 in sc0.execute("SELECT name, src_name FROM sessions").fetchall():
|
||||
_segs = [s.strip() for s in (r0["src_name"] or "").split(";") if s.strip()]
|
||||
if any(s.split("_", 1)[0] == sha for s in _segs):
|
||||
_hit = (r0["name"] or "").strip() or "(未命名)"
|
||||
hits.append("与最近审核的:%s重复导入,请删除后再导入" % _hit if side == "wb"
|
||||
else "最近审核已有同一份文件:%s,必须先删除后再导入" % _hit)
|
||||
finally:
|
||||
sc0.close()
|
||||
hc0 = conn()
|
||||
try:
|
||||
if side == "wb":
|
||||
rows = hc0.execute(
|
||||
"SELECT Name, x_src_hash FROM batches WHERE kind='project' AND x_src_hash LIKE ?",
|
||||
(sha + "%",)).fetchall()
|
||||
else:
|
||||
rows = hc0.execute(
|
||||
"SELECT Name, x_src_hash FROM batches WHERE x_src_hash LIKE ?",
|
||||
(sha + "%",)).fetchall()
|
||||
for b0 in rows:
|
||||
if (b0["x_src_hash"] or "").split("_", 1)[0] == sha:
|
||||
_hit = (b0["Name"] or "").strip() or "(未命名)"
|
||||
hits.append("后台已入库同一份文件:%s,必须先删除后台的入库批次后再导入" % _hit if side == "wb"
|
||||
else "与已入库的:%s重复导入,请删除后再导入" % _hit)
|
||||
finally:
|
||||
hc0.close()
|
||||
return {"ok": True, "hits": hits}
|
||||
|
||||
|
||||
def _lme_src(con, T, oid, code):
|
||||
"""决策 243(2026-11-01 主人定):工料机「源」——追溯本码的定额/清单来源(**两侧唯一实现**,
|
||||
会话库/批次库同构,TBL 切换)。弹框字段=序号|单位工程名称|清单|数量(主人拍板:定额列去掉,
|
||||
@@ -8423,6 +8449,8 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
return self._json(_lme_skel_hit(int(one.get("session_id", 0) or 0)))
|
||||
if p == "/api/session/lme/src": # 决策 243:工料机来源(定额/清单追溯,点行穿越原数据清单)
|
||||
return self._json(api_lme_src(one))
|
||||
if p == "/api/dup_check": # 决策 243 补记五:导入预检(选文件即查重,两侧共用)
|
||||
return self._json(api_dup_check(one))
|
||||
if p == "/api/session/lme/res": # 会话内:台班/配合比的下一级组成
|
||||
sc0 = sess.connect()
|
||||
try:
|
||||
@@ -8444,6 +8472,29 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
return self._json(api_dict())
|
||||
if p == "/api/admin/settings": # 后台「设置 → 上传设置」
|
||||
return self._json(api_admin_settings())
|
||||
if p == "/api/admin/frames": # 「导出设置」骨架库列表(2026-11-02)
|
||||
_c = conn()
|
||||
try:
|
||||
return self._json({"ok": True, "rows": classic_skeleton.list_frames(_c)})
|
||||
finally:
|
||||
_c.close()
|
||||
m = re.match(r"^/api/admin/frames/file/([0-9a-f]{32})$", p) # 骨架原件下载
|
||||
if m:
|
||||
_c = conn()
|
||||
try:
|
||||
blob, fn = classic_skeleton.frame_blob(_c, m.group(1))
|
||||
finally:
|
||||
_c.close()
|
||||
if not blob:
|
||||
return self._json({"error": "骨架不存在"}, 404)
|
||||
data = bytes(blob)
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/octet-stream")
|
||||
self.send_header("Content-Length", str(len(data)))
|
||||
self.send_header("Content-Disposition", self._cd(fn or "骨架.COS", "frame.COS"))
|
||||
self.end_headers()
|
||||
self.wfile.write(data)
|
||||
return None
|
||||
if p == "/api/admin/filters":
|
||||
return self._json(api_filters())
|
||||
if p == "/api/admin/scan":
|
||||
@@ -8691,6 +8742,49 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
return self._json({"ok": True})
|
||||
if u.path == "/api/admin/upload": # 公共上传入口(工作台「打开工程」/后台「导入」共用)
|
||||
return self._json(api_upload(body))
|
||||
if u.path == "/api/admin/frames/seed": # 「导出设置」添加骨架/骨架包(2026-11-02)
|
||||
name = body.get("name") or ""
|
||||
raw = _raw_of(body)
|
||||
if not raw:
|
||||
return self._json({"ok": False, "msg": "没有文件内容"})
|
||||
if len(raw) > 200 * 1024 * 1024:
|
||||
return self._json({"ok": False, "msg": "文件超过 200 MB,太大了"})
|
||||
# extract/seed_frame 按文件名后缀识别格式——临时文件必须带原扩展名
|
||||
ext = os.path.splitext(name)[1] or ".COS"
|
||||
fd, tmp = tempfile.mkstemp(suffix=ext)
|
||||
try:
|
||||
with os.fdopen(fd, "wb") as f:
|
||||
f.write(raw)
|
||||
stem = _safe_name(os.path.splitext(os.path.basename(name))[0]) or "骨架"
|
||||
_c = conn()
|
||||
try:
|
||||
sig = classic_skeleton.seed_frame(_c, tmp, stem)
|
||||
if not sig: # 不是单件 .cos/.cos4 → 按骨架包解(阶段二同口)
|
||||
items = classic_skeleton.seed_pack(_c, tmp) or []
|
||||
items = [it for it in items if it["sig"]]
|
||||
finally:
|
||||
_c.close()
|
||||
finally:
|
||||
try:
|
||||
os.remove(tmp)
|
||||
except OSError:
|
||||
pass
|
||||
if sig:
|
||||
return self._json({"ok": True, "kind": "single", "sig": sig, "name": stem})
|
||||
if items:
|
||||
return self._json({"ok": True, "kind": "pack",
|
||||
"installed": [(it["name"], it["suffix"]) for it in items]})
|
||||
return self._json({"ok": False, "msg": "既不是有效 .cos/.cos4 原件,也不是骨架包(zip 内无 cos 族成员),未入库"})
|
||||
if u.path == "/api/admin/frames/delete": # 「导出设置」删除骨架(硬删一行,2026-11-02)
|
||||
with WRITE_LOCK:
|
||||
_c = conn()
|
||||
try:
|
||||
n = classic_skeleton.delete_frame(_c, (body.get("sig") or ""))
|
||||
finally:
|
||||
_c.close()
|
||||
if not n:
|
||||
return self._json({"ok": False, "msg": "骨架不存在或已删除"})
|
||||
return self._json({"ok": True})
|
||||
if u.path == "/api/dict/save": # 数据源字典:新增 / 删除
|
||||
with WRITE_LOCK:
|
||||
return self._json(api_dict_save(body))
|
||||
|
||||
@@ -100,11 +100,12 @@ def _sess(fn):
|
||||
|
||||
|
||||
def _paging(args):
|
||||
"""limit 归一:默认 50,1~200。"""
|
||||
"""limit 归一:默认 10,1~100。
|
||||
2026-11-02 主人定:智能体命令没说条数=只给匹配前 10 条;说了最多给到 100。"""
|
||||
try:
|
||||
return min(max(int(args.get("limit") or 50), 1), 200)
|
||||
return min(max(int(args.get("limit") or 10), 1), 100)
|
||||
except (TypeError, ValueError):
|
||||
return 50
|
||||
return 10
|
||||
|
||||
|
||||
def _need_scope(args):
|
||||
@@ -531,13 +532,82 @@ def _t_attachment_download(args):
|
||||
return {"ok": True, "files": out}
|
||||
|
||||
|
||||
def _t_excel_bill_match(args):
|
||||
"""⑩ Excel 批量清单匹配(2026-11-02 主人定,只读):Excel **只放一列清单名称**(A 列,
|
||||
首行若是「清单名称/名称」表头自动跳过),逐行在全部入库项目清单里匹配**每条最优一条**
|
||||
——期次近优先、同批次名称相似度高优先。期次/地区筛选=对比框同款:
|
||||
period_from/period_to(YYYY-MM,可选,同时是期次距离基准)、province/city/district(可选)。
|
||||
行数不限;Excel 无编码无单位 → 走名称相似匹配(match_bill unit_free),无「精确编码」档属预期。"""
|
||||
a = _api()
|
||||
b64 = (args.get("file_b64") or "").strip()
|
||||
if not b64:
|
||||
return {"ok": False, "msg": "file_b64(Excel 的 base64 内容,A 列=清单名称)必填——先向用户要 Excel 或请用户粘贴名称清单"}
|
||||
import base64 as _b64
|
||||
try:
|
||||
raw = _b64.b64decode(b64, validate=True)
|
||||
except Exception:
|
||||
return {"ok": False, "msg": "file_b64 不是合法 base64"}
|
||||
pf = _period_to_m(args.get("period_from"))
|
||||
pt = _period_to_m(args.get("period_to") or args.get("period_from"))
|
||||
prov = (args.get("province") or "").strip()
|
||||
city = (args.get("city") or "").strip()
|
||||
dist = (args.get("district") or "").strip()
|
||||
area = [(prov, city, dist)] if (prov or city or dist) else None
|
||||
try:
|
||||
import io as _io
|
||||
import openpyxl
|
||||
wb = openpyxl.load_workbook(_io.BytesIO(raw), read_only=True, data_only=True)
|
||||
except Exception as e:
|
||||
return {"ok": False, "msg": "Excel 读取失败:%s" % e}
|
||||
names = []
|
||||
try:
|
||||
ws = wb.worksheets[0]
|
||||
for i, rx in enumerate(ws.iter_rows(min_col=1, max_col=1, values_only=True)):
|
||||
v = rx[0] if rx else None
|
||||
v = str(v).strip() if v is not None else ""
|
||||
if not v:
|
||||
continue
|
||||
if i == 0 and v in ("清单名称", "名称", "项目名称", "清单"):
|
||||
continue # 表头行
|
||||
names.append(v)
|
||||
finally:
|
||||
wb.close()
|
||||
if not names:
|
||||
return {"ok": False, "msg": "Excel A 列没有读到任何清单名称"}
|
||||
hc = a.conn()
|
||||
rows_out = []
|
||||
try:
|
||||
base = pf if pf is not None else 0
|
||||
for nm in names:
|
||||
fake = {"Name": nm, "Unit": "", "Attr": "", "x_hash_exact": None, "x_hash_semi": None}
|
||||
try:
|
||||
res = a.match.match_bill(hc, fake, base, [], [], [], limit=8,
|
||||
pfrom=pf, pto=pt, area=area, unit_free=True)
|
||||
except Exception:
|
||||
res = []
|
||||
best = sorted(res, key=lambda r: (r.get("dist") or 0, -(r.get("sim") or 0)))[0] if res else None
|
||||
if best:
|
||||
rows_out.append({"name": nm, "hit": True, "tier": best.get("tier"),
|
||||
"match_name": best.get("name"), "unit": best.get("unit"),
|
||||
"price": best.get("price"), "proj": best.get("proj"),
|
||||
"region": best.get("region"), "period": best.get("period"),
|
||||
"sim": best.get("sim")})
|
||||
else:
|
||||
rows_out.append({"name": nm, "hit": False, "msg": "没有匹配到足够相似的历史清单"})
|
||||
finally:
|
||||
hc.close()
|
||||
return {"ok": True, "total": len(rows_out), "hit": sum(1 for r in rows_out if r["hit"]),
|
||||
"hint": "每行=Excel 一条清单的最优匹配:期次近优先、同批次名称相似度优先;price=该清单历史单价(未匹配行带 hit=false)",
|
||||
"rows": rows_out}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- 工具清单
|
||||
|
||||
def TOOLS():
|
||||
return [
|
||||
{"name": "bills_query",
|
||||
"description": "查入库项目的清单:编号 Number、名称 Name、项目特征 Attr、单价 Price。"
|
||||
"keyword(编号/名称关键词)或 batch_id 至少给一个;limit 默认 50 上限 200。"
|
||||
"keyword(编号/名称关键词)或 batch_id 至少给一个;limit 默认 10 上限 100(不传 limit=只返回匹配前 10 条)。"
|
||||
"响应不含附件信息。",
|
||||
"inputSchema": {"type": "object", "properties": {
|
||||
"keyword": {"type": "string"}, "batch_id": {"type": "integer"},
|
||||
@@ -622,6 +692,18 @@ def TOOLS():
|
||||
"ref": {"type": "string"}},
|
||||
"required": ["session_id", "lme_id", "ref"]},
|
||||
"run": _t_lme_adopt},
|
||||
{"name": "excel_bill_match",
|
||||
"description": "Excel 批量清单匹配(只读,数量不限)。Excel 只放一列清单名称(A 列,"
|
||||
"可有「清单名称」表头),file_b64=Excel 的 base64;逐行在全部入库项目清单里"
|
||||
"匹配每条最优一条(期次近优先、同批次名称相似度优先)。期次/地区沿用对比框"
|
||||
"筛选口径:period_from/period_to(YYYY-MM,可选)、province/city/district(可选)。"
|
||||
"适合「按某期查一批清单的历史单价」。",
|
||||
"inputSchema": {"type": "object", "properties": {
|
||||
"file_b64": {"type": "string"}, "period_from": {"type": "string"},
|
||||
"period_to": {"type": "string"}, "province": {"type": "string"},
|
||||
"city": {"type": "string"}, "district": {"type": "string"}},
|
||||
"required": ["file_b64"]},
|
||||
"run": _t_excel_bill_match},
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ from api_harness import post, server # noqa: F401
|
||||
|
||||
NEW_TOOLS = {"bills_query", "lme_prices", "market_info_prices",
|
||||
"recent_review_query", "attachment_download",
|
||||
"match_hist", "project_import", "bill_adopt", "lme_adopt"}
|
||||
"match_hist", "project_import", "bill_adopt", "lme_adopt",
|
||||
"excel_bill_match"} # 2026-11-02 主人定:Excel 批量清单匹配(只读)
|
||||
|
||||
|
||||
def _mcp(server, body, token=None):
|
||||
@@ -68,14 +69,14 @@ def test_mcp_switch_lifecycle(server):
|
||||
assert r.status_code == 403
|
||||
# 状态接口
|
||||
st = server["client"].get("/api/mcp/status").json()
|
||||
assert st["enabled"] is False and st["endpoint"] == "/mcp" and st["tools"] == 9
|
||||
assert st["enabled"] is False and st["endpoint"] == "/mcp" and st["tools"] == 10
|
||||
|
||||
|
||||
def test_mcp_readonly_toolset(server):
|
||||
t = post(server, "/api/admin/mcp", {"enabled": True})
|
||||
tok = t["token"]
|
||||
try:
|
||||
# 工具集 = 9 件套,一个不多一个不少(决策 238/239:只读 5+匹配+写入 3;旧写工具除 bill_adopt 外仍不在)
|
||||
# 工具集 = 10 件套,一个不多一个不少(决策 238/239:只读 5+匹配+写入 3,+excel_bill_match;旧写工具除 bill_adopt 外仍不在)
|
||||
r = _mcp(server, _rpc(2, "tools/list"), tok)
|
||||
names = {x["name"] for x in r.json()["result"]["tools"]}
|
||||
assert names == NEW_TOOLS, names
|
||||
@@ -116,9 +117,12 @@ def test_mcp_query_matches_db(server):
|
||||
if row:
|
||||
bid = row[0]
|
||||
want = con.execute("SELECT COUNT(*) FROM prices WHERE batch_id=?", (bid,)).fetchone()[0]
|
||||
out = _call(server, tok, 1, "market_info_prices", {"batch_id": bid, "limit": 200})
|
||||
out = _call(server, tok, 1, "market_info_prices", {"batch_id": bid, "limit": 250})
|
||||
got = len(out["rows"])
|
||||
assert out["ok"] and got == min(want, 200), (want, got)
|
||||
assert out["ok"] and got == min(want, 100), (want, got) # 2026-11-02 主人定:上限收紧 100
|
||||
# 默认口径:不传 limit = 只给匹配前 10 条
|
||||
out2 = _call(server, tok, 2, "market_info_prices", {"batch_id": bid})
|
||||
assert out2["ok"] and len(out2["rows"]) == min(want, 10), (want, len(out2["rows"]))
|
||||
if out["rows"]:
|
||||
for k in ("Code", "Name", "Unit", "NoTaxPrice", "TaxPrice"):
|
||||
assert k in out["rows"][0], out["rows"][0].keys()
|
||||
|
||||
@@ -14,7 +14,7 @@ body{font-family:"Source Han Sans SC","Noto Sans SC","Source Han Sans CN","MiSan
|
||||
用固定 height + flex 居中,而不是 padding —— 高度不再随字号 / 行高浮动,调一处就准。
|
||||
align-items:flex-end —— 右侧「设置 / 工作台」两个按钮底部与标签对齐、保持自身自然高度(≈29px),
|
||||
比标签矮 3px,一眼能分清「标签」和「按钮」,不用再靠 margin-bottom 人为错开。 */
|
||||
.tabs{display:flex;align-items:flex-end;gap:4px;border-bottom:2px solid var(--c1)}
|
||||
.tabs{display:flex;align-items:flex-end;gap:5px;border-bottom:2px solid var(--c1)}
|
||||
.tab{height:24px;display:flex;align-items:center;padding:0 22px;cursor:pointer; /* 2026-10-21 决策 151 主人定:与工作台数据页签同高(原 32px 口径取消) */
|
||||
border:1px solid var(--line);border-bottom:none;background:#e7edf5;
|
||||
color:#34506f;font-weight:600;font-size:13px;border-radius:8px 8px 0 0;user-select:none}
|
||||
@@ -54,13 +54,15 @@ body{font-family:"Source Han Sans SC","Noto Sans SC","Source Han Sans CN","MiSan
|
||||
.panel{background:#fff;border:1px solid var(--line);border-top:none}
|
||||
/* 查询栏:**强制单行**(2026-10-07 主人定:保证一行,不要 2 行)——
|
||||
可收缩控件按比例让宽,窗口放不下时查询栏内部出细横向滚动条(仍是一行)。 */
|
||||
.bar{display:flex;gap:6px;align-items:center;flex-wrap:nowrap;overflow-x:auto;
|
||||
.bar{display:flex;gap:5px;align-items:center;flex-wrap:nowrap;overflow-x:auto;
|
||||
padding:8px 12px;border-bottom:1px solid var(--line);background:#fafcff}
|
||||
.bar::-webkit-scrollbar{height:6px}
|
||||
.bar::-webkit-scrollbar-thumb{background:#c4d2e3;border-radius:3px}
|
||||
.bar input,.bar select{padding:6px 10px;border:1px solid #b8c4d4;border-radius:6px;font-size:13px}
|
||||
/* 原生 select 的行高比 input 高 2px(31 vs 29),查询栏里会显得没对齐 —— 收一帧(2026-10-08) */
|
||||
.bar select{padding-top:5px;padding-bottom:5px;line-height:1.4}
|
||||
/* 2026-11-02 主人定:输入框/下拉与按钮统一 28px 高(对齐工作台) */
|
||||
.bar input,.bar select{height:28px;padding:0 10px;border:1px solid #b8c4d4;border-radius:6px;font-size:13px;box-sizing:border-box;line-height:26px}
|
||||
/* 本页搜索框/跳页钮:common.css 全局 24px(工作台共用不动),此处随查询栏统一 28px */
|
||||
.bar .pgsrch{height:28px}
|
||||
.bar .pgsnav{height:28px;white-space:nowrap;flex:none} /* 2026-11-02 主人定:「上一个/下一个」不许换行 */
|
||||
.bar .btn,.bar .tip{flex:none}
|
||||
.bar .dlmsg{flex:0 1 auto;min-width:0}
|
||||
#fper{flex:0 1 140px;min-width:96px}
|
||||
@@ -78,13 +80,16 @@ body{font-family:"Source Han Sans SC","Noto Sans SC","Source Han Sans CN","MiSan
|
||||
.cin[data-for=fq]{flex:1 1 150px;min-width:100px;max-width:320px}
|
||||
.cin[data-for=ftotal_min],.cin[data-for=ftotal_max]{flex:0 1 92px;min-width:60px}
|
||||
/* 地区三combo收窄(可输入搜索后不需要宽下拉,主人 10-07 指出太宽) */
|
||||
.combo[data-for=fp],.combo[data-for=fc],.combo[data-for=fd]{flex:0 1 88px;min-width:60px}
|
||||
.combo[data-for=fp],.combo[data-for=fc],.combo[data-for=fd]{flex:0 1 72px;min-width:56px} /* 2026-11-02 主人定:地区三框减窄 */
|
||||
.combo[data-for=fkind]{flex:0 1 130px;min-width:90px}
|
||||
.combo[data-for=fbu],.combo[data-for=fpub]{flex:0 1 170px;min-width:90px}
|
||||
#ftotal_min,#ftotal_max{flex:0 1 92px;min-width:60px}
|
||||
.btn{padding:6px 13px;border-radius:6px;border:1px solid #b8c4d4;background:#fff;cursor:pointer;font-size:12.5px}
|
||||
/* 2026-11-02 主人定:按钮/输入框形式对齐工作台(28px 高 inline-flex 同款),间距 5px */
|
||||
.btn{display:inline-flex;align-items:center;justify-content:center;gap:4px;height:28px;padding:0 12px;border-radius:6px;border:1px solid #b8c4d4;background:#fff;cursor:pointer;font:inherit;font-size:12.5px;color:#26405e;line-height:1;white-space:nowrap;vertical-align:middle;user-select:none}
|
||||
.btn:hover{background:#eef3fa}
|
||||
.btn.pri{background:var(--c2);color:#fff;border-color:var(--c2)}
|
||||
.btn:active{background:#e0effc}
|
||||
.btn:disabled{opacity:.45;cursor:not-allowed}
|
||||
.btn.pri{background:var(--c2);color:#fff;border-color:var(--c2);font-weight:600}
|
||||
.btn.danger{color:#c0392b;border-color:#e0b4b4}
|
||||
/* ---- 询价附件弹窗(2026-10-06)----
|
||||
左 38% 上传区 / 右 62% 工料机:右边 7 列给窄了必然横滚,等于白做。
|
||||
@@ -315,14 +320,18 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
|
||||
放在标签栏最右(margin-left:auto),不参与上面三个数据标签的切换。
|
||||
2026-10-10 决策 31:按钮名「设置」让位给统一的「⚙ 设置」窗口(common.js,
|
||||
授权管理入口),本按钮改回原名「数据源」——功能一点没动。
|
||||
margin-bottom:6px —— 让它比标签条矮半截,免得看起来像第四个标签。 -->
|
||||
<button class="btn" id="btnDict" style="margin-left:auto;height:28px;padding:0 12px;display:inline-flex;align-items:center;justify-content:center;line-height:1" onclick="openDict()"
|
||||
title="字典设置:地区 / 发布单位 / 建设单位 下拉选项 + 上传大小上限">⚙ 字典</button>
|
||||
margin-bottom:5px(2026-11-02 主人定)—— 距蓝色线条的间距按工作台口径统一 5px,
|
||||
也免得看起来像第四个标签。 -->
|
||||
<button class="btn" id="btnFrames" style="margin-left:auto;margin-bottom:5px;height:28px;padding:0 12px;display:inline-flex;align-items:center;justify-content:center;line-height:1" onclick="openFrames()"
|
||||
title="导出设置:管理各格式导出文件数据结构">导出设置</button>
|
||||
<button class="btn" id="btnDict" style="margin-bottom:5px;height:28px;padding:0 12px;display:inline-flex;align-items:center;justify-content:center;line-height:1" onclick="openDict()"
|
||||
title="字典设置:地区 / 询价单位 / 发布单位 / 建设单位 下拉选项 + 上传大小上限">⚙ 字典</button>
|
||||
<!-- 工作台入口(2026-10-06 主人定):从标题行右上角搬到标签栏,排在「设置」右边。
|
||||
2026-10-19 主人定:去掉 ▶ 图标,蓝底让位,尺寸样式对齐工作台顶栏按钮
|
||||
(28px 高 / 左右 12px / 12.5px 字号白底,与工作台「打开项目」同款)。 -->
|
||||
(28px 高 / 左右 12px / 12.5px 字号白底,与工作台「打开项目」同款)。
|
||||
2026-11-02 主人定:距蓝线 5px,与「⚙ 字典」同款。 -->
|
||||
<!-- 时间戳参数:老 WebView2 对 no-store 不完全遵守,跨页跳转带新 URL 强制绕缓存(2026-10-12) -->
|
||||
<button class="btn" style="height:28px;padding:0 12px;display:inline-flex;align-items:center;justify-content:center;line-height:1"
|
||||
<button class="btn pri" style="margin-bottom:5px;height:28px;padding:0 12px;display:inline-flex;align-items:center;justify-content:center;line-height:1"
|
||||
onclick="location.href='/workbench.html?v='+Date.now()"
|
||||
title="打开工作台:导入工程、做历史比对与审核">工作台</button>
|
||||
</div>
|
||||
@@ -342,17 +351,12 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
|
||||
<input id="ftotal_min" type="text" inputmode="decimal" placeholder="总价≥" title="总价(元)下限">
|
||||
<input id="ftotal_max" type="text" inputmode="decimal" placeholder="总价≤" title="总价(元)上限">
|
||||
<select id="fpub" style="display:none" title="按发布单位筛选"><option value="">全部发布单位</option></select>
|
||||
<button class="btn pri" onclick="load(1)">查询</button>
|
||||
<button class="btn" onclick="load(1)">查询</button>
|
||||
<button class="btn" onclick="resetF()">重置</button>
|
||||
<!-- 标准模板下载:只在「市场价 / 信息价」标签下出现(工程导入用不上),
|
||||
位置固定在「导入」左边 —— 先拿模板再填再导入,是这个按钮的顺序含义 -->
|
||||
<button class="btn" id="btnTpl" style="display:none" onclick="dlTpl()"
|
||||
title="另存为 Excel 标准模板(自己选保存位置),按模板填好后回来导入">标准模板</button>
|
||||
<button class="btn pri" id="btnImp" onclick="openImp()">导入</button>
|
||||
<!-- 清空模拟数据:测试数据隔离/一键回收。danger 样式 + 二次确认,避免误触真删。 -->
|
||||
<button class="btn danger" id="btnClearMock" style="margin-left:auto" onclick="clearMock()"
|
||||
title="清空全部「模拟」测试数据(is_mock=1 的批次及其价格/附件,真删除、不可恢复)">清空模拟数据</button>
|
||||
<span class="tip" id="cnt"></span>
|
||||
<!-- 「清空模拟数据」按钮已于 2026-11-02 按主人要求去掉(clearMock 函数一并撤除;
|
||||
后端端点保留,需要时可在接口层调用)。「共 N 个」计数顶替原推右位。 -->
|
||||
<span class="tip" id="cnt" style="margin-left:auto"></span>
|
||||
<!-- 下载结果提示条(2026-10-06):替代 alert,保存成功/失败在这里说,3 秒后淡出 -->
|
||||
<span class="dlmsg" id="dlmsg"></span>
|
||||
<!-- 决策 229(2026-10-27 主人定):本页搜索(共享层)——当前页内黄底 + 上一个/下一个;
|
||||
@@ -493,12 +497,12 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
|
||||
<div class="bar" id="ibody" style="flex-direction:row;align-items:stretch;gap:16px;overflow:hidden">
|
||||
<div id="ileft" style="min-width:0;display:flex;flex-direction:column;gap:10px">
|
||||
<div id="irowFile" style="display:flex;gap:8px;align-items:center">
|
||||
<span style="width:88px">全国电子标书</span>
|
||||
<span style="width:88px">导入</span>
|
||||
<input type="file" id="ifile" style="flex:1" onchange="pickFile(this)">
|
||||
</div>
|
||||
<div id="ifileInfo" class="tip" style="padding:0 0 0 82px"></div>
|
||||
<div style="display:flex;gap:8px;align-items:center">
|
||||
<span style="width:88px">工程名称 *</span>
|
||||
<span style="width:88px">名称 *</span>
|
||||
<input id="iname" style="flex:1" placeholder="选文件后自动带出文件名,可改">
|
||||
</div>
|
||||
<div id="irowPer" style="display:flex;gap:8px;align-items:center">
|
||||
@@ -520,7 +524,7 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
|
||||
<select id="ifk" style="flex:1"></select>
|
||||
</div>
|
||||
<div id="irowPub" style="display:flex;gap:8px;align-items:center">
|
||||
<span style="width:88px">发布单位 *</span>
|
||||
<span style="width:88px" id="ipubLbl">发布单位 *</span>
|
||||
<select id="ipub" style="flex:1"></select>
|
||||
</div>
|
||||
<div id="irowPdf" style="display:flex;gap:8px;align-items:center">
|
||||
@@ -543,6 +547,8 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
|
||||
<div style="display:flex;gap:10px;align-items:center;padding:10px 16px;border-top:1px solid #e3eaf2;background:#fafcff">
|
||||
<span class="tip" id="imRemind" style="flex:1;min-width:0;color:#b03a2e;line-height:1.45">提醒:建议在打开或导入项目时,先把工程独有的增加费(暗室、超高降效、预算包干、垂直运输等)取消后再入库或工作台的审核对比,否则容易造成数据失真!</span>
|
||||
<span class="tip" id="imsg"></span>
|
||||
<button class="btn" id="btnTpl" style="display:none;margin-left:auto" onclick="dlTpl()"
|
||||
title="另存为 Excel 标准模板(自己选保存位置),按模板填好后回来导入">标准模板</button>
|
||||
<button class="btn" onclick="closeImp()">取消</button>
|
||||
<button class="btn" id="impBtnX" onclick="aimpToggle()" title="右边展开目录树:按单位工程导入 Excel 建工程(与工作台同一套模板)">导入Excel</button>
|
||||
<input type="file" id="iprojfile" accept=".xlsx" style="display:none" onchange="aimpProjFile()">
|
||||
@@ -577,7 +583,7 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
|
||||
<span style="width:74px">名称 *</span><input id="ename" style="flex:1">
|
||||
</div>
|
||||
<div id="irowEpub" style="display:flex;gap:8px;align-items:center">
|
||||
<span style="width:74px">发布单位 *</span><select id="epub" style="flex:1"></select>
|
||||
<span style="width:74px" id="epubLbl">发布单位 *</span><select id="epub" style="flex:1"></select>
|
||||
</div>
|
||||
<div id="irowEbuid" style="display:flex;gap:8px;align-items:center">
|
||||
<span style="width:74px">建设单位 *</span><select id="ebuid" style="flex:1"></select>
|
||||
@@ -617,6 +623,7 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
|
||||
<div style="padding:14px 16px;display:flex;flex-direction:column;gap:10px">
|
||||
<div style="display:flex;gap:4px;border-bottom:2px solid var(--c1)">
|
||||
<div class="dtab on" id="dtab-region" onclick="dictTab('region')">地区</div>
|
||||
<div class="dtab" id="dtab-inquirer" onclick="dictTab('inquirer')">询价单位</div>
|
||||
<div class="dtab" id="dtab-publisher" onclick="dictTab('publisher')">发布单位</div>
|
||||
<div class="dtab" id="dtab-builder" onclick="dictTab('builder')">建设单位</div>
|
||||
<div class="dtab" id="dtab-upload" onclick="dictTab('upload')">上传设置</div>
|
||||
@@ -663,10 +670,34 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
|
||||
</div>
|
||||
<input type="file" id="afile" style="display:none">
|
||||
|
||||
<!-- ================= 导出设置(导出文件数据结构库)=================
|
||||
2026-11-02 主人定:弹框开即列表(序号|后缀|上传日期|导出文件数据结构,同后缀聚簇、
|
||||
组间明显横线、组首行标件数);右上「添加」=选文件即入库(.cos/.cos4 原件或骨架包),
|
||||
同名结构入库前确认升级替换;每文件带 下载 / 删(删=二次确认,该后缀最后一件加警示不阻止)。
|
||||
阶段二(上市版)切「骨架包升级分发」时本弹框撤添加钮、客户端静默接收(决策台账 257)。 -->
|
||||
<div class="mask" id="fmask">
|
||||
<div class="dlg" style="width:min(760px,94vw)">
|
||||
<div class="dh"><b>导出设置</b><span class="close" onclick="closeFrames()">×</span></div>
|
||||
<div style="padding:14px 16px;display:flex;flex-direction:column;gap:10px">
|
||||
<div style="display:flex;justify-content:flex-end">
|
||||
<button class="btn pri" onclick="framesAdd()" title="选择 .cos / .cos4 原件或骨架包(zip 内含 cos 族件),入库后自动按后缀归类">添加</button>
|
||||
<input type="file" id="ffile" style="display:none" onchange="framesSeed(this)">
|
||||
</div>
|
||||
<div class="tw" style="max-height:52vh">
|
||||
<table><colgroup><col style="width:56px"><col style="width:110px"><col style="width:110px"><col></colgroup>
|
||||
<thead><tr><th class="c">#</th><th>后缀</th><th>上传日期</th><th>导出文件数据结构</th></tr></thead>
|
||||
<tbody id="frameBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="tip" id="fmsg" style="padding:0;min-height:18px"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===== 询价附件(2026-10-21 决策 152 主人定:左=附件目录树(根目录「附件目录」,上传/删除挂根行右侧);
|
||||
右=项目工料机/类似清单 双页签 + 行最右搜索框;两类都可绑附件,工作台对比框可下载) ===== -->
|
||||
|
||||
<script src="common.js?v=20261021e"></script>
|
||||
<script src="common.js?v=20261101a"></script>
|
||||
<script src="period.js"></script>
|
||||
<script>
|
||||
const $=id=>document.getElementById(id);
|
||||
@@ -749,21 +780,8 @@ function fitFlexByContent(cols){
|
||||
|
||||
async function J(u,o){const r=await fetch(u,o);return r.json()}
|
||||
// 清空模拟测试数据:整批删除 is_mock=1 的批次(及其价格/附件),并顺手扫掉孤儿附件文件。
|
||||
async function clearMock(){
|
||||
if(!confirm("确认清空全部模拟测试数据?\n将真删除所有 is_mock=1 的批次、价格与附件(不可恢复)。")) return;
|
||||
try{
|
||||
const r = await J('/api/admin/clear_mock',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({})});
|
||||
if(r && r.ok){
|
||||
let s = "已清空模拟数据:批次 "+r.n_batch+" 份、价格 "+r.n_price+" 条";
|
||||
if(r.n_attach_file) s += "、附件文件 "+r.n_attach_file+" 个";
|
||||
if(r.n_orphan_file) s += "、孤儿附件 "+r.n_orphan_file+" 个";
|
||||
dlmsg(s);
|
||||
load(1);
|
||||
} else {
|
||||
dlmsg("清空失败:" + ((r && r.msg) || "未知错误"), "err");
|
||||
}
|
||||
}catch(e){ dlmsg("清空请求异常:" + e, "err"); }
|
||||
}
|
||||
/* 「清空模拟数据」入口已于 2026-11-02 按主人要求撤除(按钮+本函数);
|
||||
后端 /api/admin/clear_mock 端点保留,需要时可在接口层调用。 */
|
||||
function ym(s){const m=/^(\d{4})-(\d{2})$/.exec((s||'').trim());return m?(+m[1])*12+(+m[2]):null}
|
||||
// esc / num / fmtAttr 由 common.js 提供(前后台唯一来源)。
|
||||
// ⚠️ 原先后台用 toLocaleString(undefined) 且无最小小数位,工作台用 zh-CN —— 同一数字两侧显示不一样,
|
||||
@@ -809,8 +827,10 @@ async function loadFilters(){
|
||||
fkind.innerHTML = '<option value="">全部单价类型</option>' + kindOptions(f.file_kind, null);
|
||||
fbu.innerHTML = '<option value="">全部建设单位</option>'
|
||||
+ (f.bu_rows||[]).map(u=>`<option value="${esc(u)}">${esc(u)}</option>`).join('');
|
||||
fpub.innerHTML = '<option value="">全部发布单位</option>'
|
||||
// 2026-11-02 主人定:市场价页签过滤文案=询价单位;选项=库内实际值(两字典∪不受影响)
|
||||
fpub.innerHTML = `<option value="">${KIND==='market' ? '全部询价单位' : '全部发布单位'}</option>`
|
||||
+ (f.pub_rows||[]).map(u=>`<option value="${esc(u)}">${esc(u)}</option>`).join('');
|
||||
fpub.title = KIND==='market' ? '按询价单位筛选' : '按发布单位筛选';
|
||||
// 可搜索下拉(2026-10-07 主人定):地区三级 + 建设单位 + 发布单位,输入过滤、点选精确值
|
||||
['fp','fc','fd','fbu','fpub'].forEach(id=>comboAttach($(id))); // 单价类型只有 4 个枚举值,保持普通下拉
|
||||
comboSyncAll();
|
||||
@@ -1574,8 +1594,11 @@ async function openImp(){
|
||||
document.getElementById('irowFk').style.display = isPrice?'none':'flex';
|
||||
document.getElementById('irowNote').style.display = isPrice?'flex':'none';
|
||||
document.getElementById('irowPub').style.display = isPrice?'flex':'none';
|
||||
// 2026-11-02 主人定:市场价(市场询价)用「询价单位」字典,信息价保持「发布单位」——两类主体独立
|
||||
document.getElementById('ipubLbl').textContent = (isPrice && KIND==='market') ? '询价单位 *' : '发布单位 *';
|
||||
document.getElementById('irowPdf').style.display = isPrice?'flex':'none';
|
||||
document.getElementById('impBtnX').style.display = isPrice?'none':'inline-block';
|
||||
document.getElementById('btnTpl').style.display = isPrice?'':'none'; // 标准模板只对信息价/市场价有意义
|
||||
document.getElementById('ibtnGo').textContent = isPrice ? '开始导入' : '打开';
|
||||
document.getElementById('imRemind').style.display = isPrice?'none':'block';
|
||||
if(AIOPEN) aimpToggle(); // 每次打开先收回树区(与工作台 openDlg 同款)
|
||||
@@ -1596,11 +1619,9 @@ async function openImp(){
|
||||
ifile.accept = isPrice ? '.xlsx' : '.cos4,.cos,.swt,.swz';
|
||||
document.getElementById('ifileInfo').textContent='';
|
||||
document.getElementById('ifileInfo').style.display = isPrice?'block':'none';
|
||||
document.getElementById('irowTip').textContent = isPrice
|
||||
? '信息价/市场价:只收「标准模板」Excel(.xlsx,每次一个)+ 附件原件(任意格式,选填)。'
|
||||
+ '名称留空或点文件后自动带出文件名(可改);期次留空时自动从文件名里认(如「珠海信息价_2026年7月」→ 2026-07)。'
|
||||
: '';
|
||||
document.getElementById('irowTip').textContent = '';
|
||||
imsg.textContent='';
|
||||
dupCheckSha(ifile, '', 'admin', 'ibtnGo', 'imsg'); // 决策 243 补记五:弹框每开必清预检状态——上一文件的命中结论绝不带给新文件
|
||||
await loadImpFilters();
|
||||
// 单价类型默认「预算综合单价」(与工作台打开项目弹框同一默认)
|
||||
try{ if(ifk.options.length) ifk.value='1'; }catch(e){}
|
||||
@@ -1611,8 +1632,11 @@ async function pickFile(inp){
|
||||
const info=document.getElementById('ifileInfo');
|
||||
info.textContent='正在上传到软件目录…';
|
||||
const r = await uploadFile('/api/admin/upload', f);
|
||||
if(!r.ok){ info.textContent='× '+r.msg; UPF=null; return; }
|
||||
if(!r.ok){ info.textContent='× '+r.msg; UPF=null;
|
||||
dupCheckSha(inp, '', 'admin', 'ibtnGo', 'imsg'); // 上传失败:清预检状态不残留(决策 243 补记五)
|
||||
return; }
|
||||
UPF=r;
|
||||
dupCheckSha(inp, r.sha256, 'admin', 'ibtnGo', 'imsg'); // 决策 243 补记五:选完文件即预检(命中提醒+打开钮禁用)
|
||||
// 2026-10-12 重设计:价格类只认标准模板 Excel;工程类认 .cos4/.cos;
|
||||
// 2026-10-19 加 .swt(深圳数据交换标准,classify 返回 "swt")
|
||||
const ok = (KIND!=='project') ? (r.state==='price_xlsx')
|
||||
@@ -1728,7 +1752,7 @@ async function aimpProjFile(){
|
||||
}
|
||||
function aimpCommon(){
|
||||
const name=$('iname').value.trim(), pv=PVAL($('iper'));
|
||||
if(!name){ $('aimsg').textContent='工程名称必填(左边共用字段)'; return null; }
|
||||
if(!name){ $('aimsg').textContent='名称必填(左边共用字段)'; return null; }
|
||||
if(pv.f==null||pv.t==null){ $('aimsg').textContent='基准期次必填:点开选起~止(同月就选同一个)'; return null; }
|
||||
if(!iprov.value||!icity.value||!idist.value){ $('aimsg').textContent='请填写:地区(省/市/区)'; return null; }
|
||||
if(!ibuid.value.trim()){ $('aimsg').textContent='请填写:建设单位'; return null; }
|
||||
@@ -1767,7 +1791,9 @@ async function loadImpFilters(){
|
||||
.sort((x,y)=>x.localeCompare(y,'zh'));
|
||||
window.__BU_OPTS = buOpts;
|
||||
comboFree($('ibuid'), () => window.__BU_OPTS);
|
||||
dictFillSel(ipub, dictOrgs('publisher'), '', 'publisher');
|
||||
// 2026-11-02 主人定:市场价下拉=询价单位字典(+新增也归询价单位);信息价保持发布单位
|
||||
const pubCat = (KIND==='market') ? 'inquirer' : 'publisher';
|
||||
dictFillSel(ipub, dictOrgs(pubCat), '', pubCat);
|
||||
// 单价类型:排除 0「未标注」(与工作台同口径)。历史批次本身就是 0 的,编辑时要把它带回来,
|
||||
// 否则下拉里没有对应项 → 值对不上 → 看着像"没选",一保存就把状态改没了。
|
||||
ifk.innerHTML = kindOptions(f.file_kind, null);
|
||||
@@ -1787,7 +1813,7 @@ async function doImport(){
|
||||
// 决策 245:工程类校验文案与工作台「打开项目」逐字同款(两侧同规则)
|
||||
if(!isPrice){
|
||||
if(!UPF){ imsg.textContent='请选择文件'; return; }
|
||||
if(!iname.value.trim()){ imsg.textContent='请填写:工程名称'; return; }
|
||||
if(!iname.value.trim()){ imsg.textContent='请填写:名称'; return; }
|
||||
const pv0=PVAL($('iper'));
|
||||
if(pv0.f==null||pv0.t==null){ imsg.textContent='基准期次必填:点开选起~止(同一个月就选同一个)'; return; }
|
||||
if(!iprov.value||!icity.value||!idist.value){ imsg.textContent='请填写:地区(省/市/区)'; return; }
|
||||
@@ -1796,7 +1822,7 @@ async function doImport(){
|
||||
}
|
||||
const miss=[];
|
||||
if(isPrice && !UPF) miss.push('标准模板 Excel 文件(每次只能一个)');
|
||||
if(!iname.value.trim()) miss.push('工程名称');
|
||||
if(!iname.value.trim()) miss.push('名称');
|
||||
const pv=PVAL($('iper'));
|
||||
const p1=pv.f, p2=pv.t;
|
||||
if(isPrice && (p1==null||p2==null)) miss.push('基准期次(点开选起~止,同一个月就选同一个)');
|
||||
@@ -1895,6 +1921,8 @@ async function edit(id){
|
||||
const r=d.rows.find(x=>x.id===id); if(!r){ alert('找不到这一条'); return; }
|
||||
const isP=(KIND!=='project');
|
||||
document.getElementById('irowEpub').style.display = isP?'flex':'none';
|
||||
// 2026-11-02 主人定:市场价编辑=「询价单位」,信息价=「发布单位」(随页签 KIND)
|
||||
document.getElementById('epubLbl').textContent = (isP && KIND==='market') ? '询价单位 *' : '发布单位 *';
|
||||
document.getElementById('irowEbuid').style.display = isP?'none':'flex';
|
||||
document.getElementById('irowEfk').style.display = isP?'none':'flex';
|
||||
ename.value=r.name||''; enote.value=r.note||'';
|
||||
@@ -1902,7 +1930,8 @@ async function edit(id){
|
||||
await dictLoad();
|
||||
// 地区三联动 + 单位下拉:都取自数据源字典;老数据里字典没有的值会自动补进选项,不会丢
|
||||
dictFillRegion([eprov,ecity,edist],[r.province||'',r.city||'',r.district||'']);
|
||||
dictFillSel(epub, dictOrgs('publisher'), r.publisher||'', 'publisher');
|
||||
const epubCat = (KIND==='market') ? 'inquirer' : 'publisher'; // 2026-11-02:市场价编辑用询价单位字典
|
||||
dictFillSel(epub, dictOrgs(epubCat), r.publisher||'', epubCat);
|
||||
dictFillSel(ebuid, dictOrgs('builder'), r.bulid_unit||'', 'builder');
|
||||
if(!isP){
|
||||
efk.innerHTML = kindOptions(f.file_kind, r.file_kind);
|
||||
@@ -1953,7 +1982,7 @@ document.querySelectorAll('.tab[data-kind]').forEach(t=>t.onclick=()=>{
|
||||
t.classList.add('on'); KIND=t.dataset.kind; SORT={key:'',dir:'DESC'}; syncBtns();
|
||||
XLAST=KIND;
|
||||
if(XACT>=0){ XACT=-1; renderXTabs(); showDetail(false); xsave(); } // 从明细标签切回列表区(动态标签保留)
|
||||
ldWrap('','正在加载列表…',()=>load(1)); // 列表取数期间挂进度条(快则不闪)
|
||||
ldWrap('','正在加载列表…',()=>{ load(1); loadFilters(); }); // 列表取数期间挂进度条(快则不闪);loadFilters=过滤文案随页签刷新(2026-11-02 询价单位/发布单位)
|
||||
});
|
||||
// 2026-10-13 主人定:切标签没出全数据前要有进度条 —— 走共享层 ldWrap(det() 进来的路径
|
||||
// 已有即时遮罩,ldWrap 检测到就只报阶段不接管;这里兜住「直接点标签」的路径)
|
||||
@@ -2057,8 +2086,6 @@ function inqCell(r){
|
||||
}
|
||||
|
||||
function syncBtns(){
|
||||
// 标准模板只对信息价/市场价有意义,工程标签下隐藏(显示了点了也没用)
|
||||
$('btnTpl').style.display = (KIND==='project') ? 'none' : '';
|
||||
// 新增筛选随标签显隐(2026-10-07):历史项目=单价类型/建设单位/总价区间;价格标签=发布单位
|
||||
const isP = (KIND==='project');
|
||||
// ⚠️ _combo 是组合框对象(无 .style),要切的是它的 wrap 外层;_cin 本身就是包装层
|
||||
@@ -2437,11 +2464,15 @@ async function qUnbind(){
|
||||
ids.forEach(id=>{ const ck=document.querySelector('input.qbindck[data-id="'+id+'"], #qtbl input[data-id="'+id+'"]'); if(ck) ck.checked=false; });
|
||||
}
|
||||
|
||||
/* 决策 213 补记七:组表「单位工程名称」点击 → 追踪定位到本批次明细原数据树的那条清单。 */
|
||||
window.locBill = async function(bid, uwid){
|
||||
/* 决策 213 补记七:组表「单位工程名称」点击 → 追踪定位到本批次明细原数据树的那条清单。
|
||||
决策 243 补记(2026-11-01):工料机「源」浮层行点击(from='src')从明细页发起,
|
||||
当前批次=DID;此前一律 det(QBID) —— 明细直开时 QBID=0/旧批次,定位必失败还会把 DID 拽走(主人实测报障)。 */
|
||||
window.locBill = async function(bid, uwid, from){
|
||||
const bid_batch = from === 'src' ? DID : QBID;
|
||||
showPage('detail');
|
||||
await det(QBID, QBNAME || ('批次 #' + QBID), 'project');
|
||||
onWBTab('p3');
|
||||
const _t = XTABS.find(x => x.id === bid_batch && x.kind !== 'inq');
|
||||
await det(bid_batch, (bid_batch === QBID && QBNAME) || (_t && _t.name) || ('批次 #' + bid_batch), 'project');
|
||||
await onWBTab('p3'); // loadTab 是异步,不 await 会与 rawPick 抢渲染
|
||||
await rawPick('uw', uwid, null);
|
||||
const find = () => document.querySelector('#drawbody tr.brow[data-bid="' + bid + '"]');
|
||||
let tr = find();
|
||||
@@ -2475,10 +2506,94 @@ async function qDelFile(fid){
|
||||
}
|
||||
|
||||
|
||||
/* ============ 导出设置(导出文件数据结构库)====================
|
||||
2026-11-02 主人定:四列列表(同后缀聚簇、组间明显横线、组首行标件数)、
|
||||
右上「添加」选文件即入库(同名升级替换前确认)、每文件 下载/删
|
||||
(删=二次确认,该后缀最后一件加警示不阻止)。口径详见弹框 DOM 注释。 */
|
||||
let FRAMES = [];
|
||||
|
||||
async function openFrames(){
|
||||
$('fmask').classList.add('on');
|
||||
$('fmsg').textContent='';
|
||||
await framesLoad();
|
||||
}
|
||||
function closeFrames(){ $('fmask').classList.remove('on'); }
|
||||
fmask.onclick = e => { if(e.target===fmask) closeFrames() };
|
||||
|
||||
async function framesLoad(){
|
||||
try{
|
||||
const r = await (await fetch('/api/admin/frames')).json();
|
||||
FRAMES = r.rows || [];
|
||||
}catch(e){ FRAMES = []; $('fmsg').textContent='列表读取失败:'+e; }
|
||||
framesRender();
|
||||
}
|
||||
|
||||
function framesRender(){
|
||||
const rows = FRAMES; // 后端已排:后缀聚簇(cos4 在前)、组内入库时间倒序
|
||||
const cnt = {};
|
||||
rows.forEach(r => cnt[r.suffix] = (cnt[r.suffix]||0)+1);
|
||||
let html='', last=null, no=0;
|
||||
for(const r of rows){
|
||||
no++;
|
||||
const first = r.suffix!==last;
|
||||
const sep = (first && last!==null)
|
||||
? ' style="border-top:3px double #7d92ad"' : ''; // 组间明显横线(双线)
|
||||
html += `<tr${sep}>`
|
||||
+ `<td class="c">${no}</td>`
|
||||
+ `<td>${first ? r.suffix+'('+cnt[r.suffix]+'件)' : ''}</td>`
|
||||
+ `<td>${(r.extracted_at||'').slice(0,10)}</td>`
|
||||
+ `<td>${r.original_name||''}`
|
||||
+ ` <a href="/api/admin/frames/file/${r.sig}" style="color:#26405e">下载</a>`
|
||||
+ ` <a href="javascript:framesDel('${r.sig}')" style="color:#c0392b">删</a></td>`
|
||||
+ `</tr>`;
|
||||
last = r.suffix;
|
||||
}
|
||||
$('frameBody').innerHTML = html
|
||||
|| '<tr><td colspan="4" class="c" style="color:#888">还没有导出文件数据结构,点右上「添加」导入</td></tr>';
|
||||
}
|
||||
|
||||
function framesAdd(){ $('ffile').value=''; $('ffile').click(); }
|
||||
|
||||
async function framesSeed(inp){
|
||||
const f = inp.files && inp.files[0];
|
||||
if(!f) return;
|
||||
const stem = f.name.replace(/\.[^.]*$/,'');
|
||||
if(FRAMES.some(r => r.original_name===stem)
|
||||
&& !confirm(`已存在同名结构《${stem}》,将升级替换(旧内容被覆盖)。\n继续?`)){ inp.value=''; return; }
|
||||
try{
|
||||
const res = await fetch('/api/admin/frames/seed', {method:'POST',
|
||||
headers:{'Content-Type':'application/octet-stream',
|
||||
'X-File-Name':encodeURIComponent(f.name)},
|
||||
body:f});
|
||||
const r = await res.json();
|
||||
if(!r.ok){ $('fmsg').textContent = r.msg || '入库失败'; return; }
|
||||
$('fmsg').textContent = r.kind==='pack'
|
||||
? `骨架包已安装 ${r.installed.length} 件` : `已入库《${r.name}》`;
|
||||
await framesLoad();
|
||||
}catch(e){ $('fmsg').textContent='入库请求失败:'+e; }
|
||||
finally{ inp.value=''; }
|
||||
}
|
||||
|
||||
async function framesDel(sig){
|
||||
const r = FRAMES.find(x=>x.sig===sig);
|
||||
if(!r) return;
|
||||
const isLast = FRAMES.filter(x=>x.suffix===r.suffix).length===1;
|
||||
const warn = isLast
|
||||
? `\n\n⚠ 这是 .${r.suffix} 最后一件:删除后手工导出该格式将不可用。` : '';
|
||||
if(!confirm(`确定删除《${r.original_name}》?${warn}\n\n删除后可用同名文件重新「添加」恢复。`)) return;
|
||||
try{
|
||||
const res = await fetch('/api/admin/frames/delete', {method:'POST',
|
||||
headers:{'Content-Type':'application/json'}, body: JSON.stringify({sig})});
|
||||
const j = await res.json();
|
||||
if(!j.ok){ $('fmsg').textContent = j.msg || '删除失败'; return; }
|
||||
await framesLoad();
|
||||
}catch(e){ $('fmsg').textContent='删除请求失败:'+e; }
|
||||
}
|
||||
|
||||
/* ============ 数据源面板(地区 / 发布单位 / 建设单位)====================
|
||||
这里的选项就是各页录入下拉的唯一来源。改完不需要重启,下次打开弹窗即生效。 */
|
||||
let DCUR = 'region'; // region | publisher | builder
|
||||
const DORG_TITLE = {publisher:'发布单位', builder:'建设单位'};
|
||||
let DCUR = 'region'; // region | inquirer | publisher | builder
|
||||
const DORG_TITLE = {publisher:'发布单位', inquirer:'询价单位', builder:'建设单位'}; // 2026-11-02 主人定:加询价单位(市场价专用)
|
||||
|
||||
function openDict(){ dmask.classList.add('on'); dmsg.textContent=''; dictTab(DCUR); }
|
||||
/* 关闭前补一次保存:上传设置是「即改即存」,而 onchange 要等失焦才触发 ——
|
||||
@@ -2498,14 +2613,14 @@ async function closeDict(){
|
||||
|
||||
function dictTab(cat){
|
||||
DCUR = cat;
|
||||
['region','publisher','builder','upload'].forEach(c=>{
|
||||
['region','inquirer','publisher','builder','upload'].forEach(c=>{
|
||||
const t=document.getElementById('dtab-'+c);
|
||||
if(t) t.classList.toggle('on', c===cat);
|
||||
});
|
||||
document.getElementById('dpane-region').style.display = (cat==='region')?'':'none';
|
||||
// ⚠️ org 面板只有「发布单位 / 建设单位」两个标签用;写成 cat!=='region' 会让 upload 也带上它,
|
||||
// ⚠️ org 面板只有「询价单位 / 发布单位 / 建设单位」三个标签用;写成 cat!=='region' 会让 upload 也带上它,
|
||||
// 于是上传设置里凭空多出一张表和一个「新增」按钮(2026-10-06 修)
|
||||
document.getElementById('dpane-org').style.display = (cat==='publisher'||cat==='builder')?'':'none';
|
||||
document.getElementById('dpane-org').style.display = (cat==='publisher'||cat==='inquirer'||cat==='builder')?'':'none';
|
||||
// 「上传设置」不是字典,切过去时不渲染字典表(dictRender 会读 /api/dict,白跑一次)
|
||||
document.getElementById('dpane-upload').style.display = (cat==='upload')?'':'none';
|
||||
const bAdd = document.getElementById('btnDictAdd');
|
||||
@@ -2597,7 +2712,8 @@ async function dictRender(){
|
||||
}).join('');
|
||||
rg.innerHTML = (DICT_ADD === 'region' ? dictAddRowRegion() : '') + rows;
|
||||
} else {
|
||||
const list = (DCUR === 'publisher' ? DICT.publishers : DICT.builders) || [];
|
||||
const list = (DCUR === 'publisher' ? DICT.publishers
|
||||
: DCUR === 'inquirer' ? DICT.inquirers : DICT.builders) || [];
|
||||
DICT_ROWS = dictSort(list);
|
||||
const rows = DICT_ROWS.map((o, i) => {
|
||||
if (DICT_EDIT && DICT_EDIT.id === o.id) return dictEditRowOrg(o);
|
||||
|
||||
@@ -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)优先原生另存为对话框——
|
||||
|
||||
@@ -103,7 +103,7 @@ a:hover{text-decoration:underline}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="common.js?v=20261021e"></script>
|
||||
<script src="common.js?v=20261101a"></script>
|
||||
<script>
|
||||
/* 会话管理页:照后台「项目界面」的版式,管的是**还没入库**的工作台会话。
|
||||
会话库不自动清(SESSION_KEEP_DAYS=0),要删只能在这里手动删。
|
||||
|
||||
@@ -566,7 +566,7 @@ body.histdrag{user-select:none}
|
||||
<div class="mbody" data-page-node-id="OoZAOtJ0ridSwFtXLChDyg" style="display:flex;flex-direction:row;gap:16px;align-items:stretch">
|
||||
<!-- 左栏:宽由 CSS 管(#oleft 604;展开 .exp 388 等比缩小),行距补回 .mbody 的 column gap:10px -->
|
||||
<div id="oleft" style="flex:none;min-width:0;display:flex;flex-direction:column;gap:10px">
|
||||
<div class="row" id="ofileRow" data-page-node-id="TgF4geYkFIZIFYQD6sNZHB"><span data-page-node-id="Ve3MJBmbfhkGXf26tQdqAA">全国电子标书</span><input type="file" id="ofile" onchange="autoName()" data-page-node-id="I2kkcqsdiXGL40535vRd25"></div>
|
||||
<div class="row" id="ofileRow" data-page-node-id="TgF4geYkFIZIFYQD6sNZHB"><span data-page-node-id="Ve3MJBmbfhkGXf26tQdqAA">全国电子标书</span><input type="file" id="ofile" onchange="autoName();dupScanFile(this,'wb','obtnGo','omsg')" data-page-node-id="I2kkcqsdiXGL40535vRd25"></div>
|
||||
<div class="row" data-page-node-id="uWAVJwQc4PGXMkVwrLTAWX"><span data-page-node-id="A69LDfDYOD8sJ9RNmYrp7u">工程名称 *</span><input id="oname" placeholder="选文件后自动带出文件名,可改" data-page-node-id="M0HGCQ9uGkUnRnXEshiiDD"></div>
|
||||
<div class="row" data-page-node-id="3Yg2dLI3BNEr0iDvHyyFZR"><span data-page-node-id="a4VMhIZdcf8l3z3znIflbI">基准期次 *</span><input id="oper" placeholder="点这里选起~止(同月就选同一个)" data-page-node-id="NZlB1CroFZvcWL0CyQTZDE"></div>
|
||||
<div class="row" data-page-node-id="chlcT8xdVI2rRjz4HZDVWA"><span data-page-node-id="x8RmHqmvGQTydhqMUR8xAP">地区 *</span>
|
||||
@@ -656,7 +656,6 @@ body.histdrag{user-select:none}
|
||||
<div class="dlg" style="width:min(880px,94vw)">
|
||||
<div class="dh"><b>附件</b><span class="close" onclick="closeInq()">×</span></div>
|
||||
<div style="padding:14px 16px;display:flex;flex-direction:column;gap:10px">
|
||||
<div class="tip" style="padding:0">附件来自对比框点「采纳」的清单或工料机行——同一附件被采纳多次只显示一个。清单采纳的进「清单附件」,工料机采纳的进「工料机附件」。点附件名,右侧显示它对应的项目;勾选后点「批量下载」,选一次位置即可全部存入。</div>
|
||||
<div class="inqtabs" id="inqTabs">
|
||||
<button class="inqtab on" id="inqTabBill" onclick="inqTab('bill')">清单附件(0)</button>
|
||||
<button class="inqtab" id="inqTabLme" onclick="inqTab('lme')">工料机附件(0)</button>
|
||||
@@ -676,10 +675,12 @@ body.histdrag{user-select:none}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="common.js?v=20261021e"></script>
|
||||
<script src="common.js?v=20261101a"></script>
|
||||
<script src="period.js"></script>
|
||||
<script>
|
||||
let SID=0, CUR=null, CURTYPE='lme', HROWS=[];
|
||||
let CUR_ADOPT=''; // 决策 250(2026-11-01 主人定):当前选中行的采纳备注(pick 时从行备注格取,
|
||||
// 采纳/取消/手工编辑同步)——对比框「已采纳」标记按它反推,与库同源不漂
|
||||
let MANUAL=false; // 2026-10-19:当前是手工工程(无源文件)→ 禁止原格式导出/重新解析
|
||||
/* 当前渲染进历史表的那份(已按精确度过滤 + 按时间/价格排序)。
|
||||
「采纳」必须从这里取值,不能用 HROWS —— HROWS 未过滤未排序,下标对不上会采纳错历史价。 */
|
||||
@@ -818,7 +819,8 @@ const _apPick = () => {
|
||||
const cur = document.querySelector('.tab.on') ? document.querySelector('.tab.on').dataset.p : null;
|
||||
const cont = { p0: '#tb0', p1: '#tb1', p2: '#tb2', p3: '#rawbody' }[cur];
|
||||
if (!cont) return;
|
||||
if (document.querySelector(cont + ' tr.sel')) return; // 本页已有选中行不抢
|
||||
// 决策 252:定额 subsel 也算「本页已有选中」——切回只恢复定额时,_apPick 不再抢点第一行清单
|
||||
if (document.querySelector(cont + ' tr.sel, ' + cont + ' tr.subsel')) return;
|
||||
const cand = [...document.querySelectorAll(cont + ' tr')]
|
||||
.find(tr => tr.offsetParent && /pick\(/i.test(tr.getAttribute('onclick') || ''));
|
||||
if (cand) cand.click();
|
||||
@@ -1437,6 +1439,7 @@ function lmeRmkSync(tr, lmeid, v){
|
||||
if(typeof RV_CACHE !== 'undefined')
|
||||
Object.keys(RV_CACHE).forEach(k=>{ if(String(k).indexOf(SID+'|')===0) delete RV_CACHE[k]; });
|
||||
if(typeof rvCachePut === 'function') rvCachePut();
|
||||
if(CUR && CURTYPE === 'lme' && String(CUR.id) === String(lmeid)) CUR_ADOPT = v; // 决策 250:判定源同步
|
||||
}
|
||||
|
||||
/* 规格 2026-10-16 ③:定额子行点选=纯视觉选中(.subsel 与清单行 tr.sel 同配色整套)。
|
||||
@@ -1765,6 +1768,7 @@ async function openDlg(){
|
||||
$('omask').classList.add('on'); // 规格 打开工程BUG2:先显示弹框再清值——清值派发的 input 事件在隐藏态测量会出错
|
||||
if(IOPEN) impExcelToggle(); // 决策 233:每次打开先收回导入面板,回默认打开模式
|
||||
$('ofile').value=''; $('oname').value=''; $('oname').dataset.auto=''; $('omsg').textContent='';
|
||||
dupScanFile($('ofile'),'wb','obtnGo','omsg'); // 决策 243 补记五:弹框每开必清预检状态——上一文件的命中结论绝不带给新文件
|
||||
// 决策 50 补漏(2026-11-01 主人拍板):期次连 dataset.pf/pt 一起清——PVAL 读 dataset,只清 .value
|
||||
// 是「假清空」:重开看着空、点打开仍带旧期次提交;地区清 select 后补 comboSyncAll 刷新镜像框显示
|
||||
setPeriod($('oper'),'',''); $('oprov').value=''; $('ocity').value=''; $('odist').value='';
|
||||
@@ -1809,7 +1813,9 @@ async function doOpen(){
|
||||
if(!r.ok){
|
||||
let m=r.msg||'打开失败';
|
||||
if(/无法识别|不是计价文件|不再支持 xml|文件头/.test(m)) m='本文件暂不支持,请与软件商联系';
|
||||
$('omsg').textContent=m; return;
|
||||
$('omsg').textContent=m;
|
||||
if(/同一份文件|重复导入|必须先删除/.test(m)) alert(m); // 决策 243 补记五:重复类失败弹框兜底(预检漏网时)
|
||||
return;
|
||||
}
|
||||
SID=r.session_id;
|
||||
setManualMode(false);
|
||||
@@ -2112,7 +2118,7 @@ rawPick = async function(k, id, el){
|
||||
RVTAB=rec.rvtab; _rvStateSave(); rawTabs(); await rawDraw(); // 决策 219 修:等**真实渲染**完成(原 rawTab+盲等600ms 与 _apPick 250ms 抢跑)
|
||||
tr=find();
|
||||
}
|
||||
if(tr){
|
||||
if(tr && !(rec && rec.normsel)){ // 决策 252:最后点的是定额→切回只恢复定额(sel 由 guard 清,不在此恢复清单)
|
||||
document.querySelectorAll('#rawbody tr.sel').forEach(x=>x.classList.remove('sel')); // 决策 219 修:清后加,与 pick() 同单选语义(原直接 add 造成双选中)
|
||||
tr.classList.add('sel');
|
||||
const sp=_scrollAncestor(document.querySelector('#rawbody'));
|
||||
@@ -2218,6 +2224,9 @@ async function pick(type,id,tr){
|
||||
const ptd=window.__lastPickedTd;
|
||||
if(ptd && tr.contains(ptd)) ptd.classList.add('cellhit');
|
||||
CURTYPE=type; CUR={id};
|
||||
// 决策 250:随手取本行备注格(工料机/清单/原数据行都渲染 td.rmk)——已采纳标记的判定源
|
||||
const _rmk = tr.querySelector ? tr.querySelector('td.rmk') : null;
|
||||
CUR_ADOPT = _rmk ? ((_rmk.getAttribute('title') || _rmk.textContent || '') + '').trim() : '';
|
||||
histCtxUI(); // 决策 208:行类型变了,工具栏上下文差异(来源置灰/单位框提示)即时跟随
|
||||
// 搜索框/屏蔽词框**非粘性**(2026-10-11 主人定):所在行换了 → 必须清除上一次遗留的
|
||||
// **所有**信息(关键字模式/检索结果状态/屏蔽词/框内文字),再带入本行名称——每行都从
|
||||
@@ -2284,34 +2293,9 @@ function curPrice(){
|
||||
结果里定位——在就提到第一条;不在(关键词过滤/检索分页)就把快照取回来放在第一条;
|
||||
第二条起仍按正常搜索逻辑排序。取消采纳同步删除记忆;再采纳=覆盖(连续采纳认最后一次)。
|
||||
开发阶段不做存量兼容。 */
|
||||
const ADOPT_SRC_KEY='wb_adopt_src_v1';
|
||||
function adoptSrcMap(){
|
||||
try{ return JSON.parse(localStorage.getItem(ADOPT_SRC_KEY))||{}; }catch(e){ return {}; }
|
||||
}
|
||||
function adoptSrcStore(map){
|
||||
try{ localStorage.setItem(ADOPT_SRC_KEY, JSON.stringify(map)); }catch(e){}
|
||||
}
|
||||
function rowSig(x){
|
||||
return [x.name,x.attr,x.unit,x.price,x.proj,x.period_m].map(v=>(v==null?'':String(v))).join('|');
|
||||
}
|
||||
function adoptSrcSave(row){
|
||||
if(!SID||!CUR||!CUR.id||!row) return;
|
||||
const m=adoptSrcMap();
|
||||
m[SID+':'+(CURTYPE==='lme'?'L':'B')+CUR.id]={
|
||||
id:(CURTYPE==='lme'?null:row.bill_id), sig:rowSig(row), row:row};
|
||||
adoptSrcStore(m);
|
||||
}
|
||||
function adoptSrcDrop(rowId){
|
||||
if(!SID||rowId==null) return;
|
||||
const m=adoptSrcMap();
|
||||
delete m[SID+':'+(CURTYPE==='lme'?'L':'B')+rowId];
|
||||
adoptSrcStore(m);
|
||||
}
|
||||
function curAdoptSrc(){
|
||||
if(!SID||!CUR||!CUR.id) return null;
|
||||
const e=adoptSrcMap()[SID+':'+(CURTYPE==='lme'?'L':'B')+CUR.id];
|
||||
return (e&&e.row)?e:null;
|
||||
}
|
||||
/* 决策 250(2026-11-01 主人定):已采纳标记的判定源=**后端采纳备注**(CUR_ADOPT,随 pick 取自
|
||||
行备注格、随采纳/取消/手工编辑同步)——原 adoptSrc localStorage 记忆机制(决策 138/139 的
|
||||
id/签名定位)整组退役:换浏览器/清缓存记忆即丢,「已采纳」显示成「采纳」,与库分叉。 */
|
||||
/* 采纳备注格式(决策 138,2026-10-20 主人定):采纳:名称+(项目名称)——有加号和中文括号,
|
||||
价格不再写进备注。已采纳定位/置顶以 adoptSrc 的 id/签名为准,不再按备注文本反推。 */
|
||||
function adoptTxtFor(x,isLme,old){
|
||||
@@ -2372,15 +2356,17 @@ function renderHist(){
|
||||
// 第二条起仍按正常搜索逻辑的顺序展示。取消采纳 = 记忆删除 → 复原为「采纳」。
|
||||
// ⚠️ 引用 isLme —— 必须在其 const 声明之后(TDZ),故放表头渲染之后。
|
||||
const adoptedBadge='<span class="tg tg-lo" title="已采纳——取消请点上方该行的「取消采纳」">已采纳</span>';
|
||||
// 决策 250(2026-11-01 主人定):已采纳标记/置顶按后端采纳备注反推——备注以
|
||||
// 「采纳:行名+行项目+」开头(adoptTxtFor 格式)即命中;同键多行取排序首条(精确档在前)。
|
||||
// 当前结果没有匹配行(关键词过滤/翻页)就不置顶不标记——不再凭本地记忆凭空插行。
|
||||
let adoptedIdx=-1;
|
||||
const asrc=curAdoptSrc();
|
||||
if(asrc){
|
||||
const want=asrc.id!=null ? (x=>x.bill_id===asrc.id) : (x=>rowSig(x)===asrc.sig);
|
||||
const pi=rows.findIndex(want);
|
||||
if(pi>0) rows=[rows[pi]].concat(rows.slice(0,pi), rows.slice(pi+1));
|
||||
else if(pi<0) rows=[Object.assign({},asrc.row)].concat(rows);
|
||||
VISIBLE_ROWS=rows;
|
||||
adoptedIdx=0;
|
||||
if(/^采纳:/.test(CUR_ADOPT||'')){
|
||||
const pi=rows.findIndex(x=>CUR_ADOPT.indexOf('采纳:'+(x.name||'')+'+'+(x.proj||'')+'+')===0);
|
||||
if(pi>=0){
|
||||
if(pi>0) rows=[rows[pi]].concat(rows.slice(0,pi), rows.slice(pi+1));
|
||||
VISIBLE_ROWS=rows;
|
||||
adoptedIdx=0;
|
||||
}
|
||||
}
|
||||
const selfMode=$('fself') && $('fself').value==='yes';
|
||||
const emptyMsg=selfMode
|
||||
@@ -2625,8 +2611,7 @@ async function adopt(i){
|
||||
body:JSON.stringify({bill_id:CUR.id,remark:txt})});
|
||||
}catch(e){ r=null; }
|
||||
if(!r || !r.ok){ dlMsg('备注写入失败:'+(r&&r.msg?r.msg:'服务未响应'),'err'); return; }
|
||||
adoptSrcSave(x); // 决策 139:记住采纳来源(id/签名+行快照),永远置顶
|
||||
// ③ 刷新当前视图(9.1 清单行字段被覆盖、9.3 追加定额带临删——重拉才是真状态)
|
||||
CUR_ADOPT=txt; // 决策 250:判定源同步(已采纳标记立即点亮)
|
||||
// keepView:采纳后停在原组原行(规格 2026-10-16:点采纳跳至第一组 = bug,修复)
|
||||
const cur=document.querySelector('.tab.on');
|
||||
const p=cur?cur.dataset.p:'p2';
|
||||
@@ -2655,7 +2640,7 @@ async function cancelBillAdopt(billId, el){
|
||||
body:JSON.stringify({bill_id:billId,remark:''})});
|
||||
}catch(e){ r2=null; }
|
||||
if(!r2 || !r2.ok){ dlMsg('取消采纳失败:'+(r2&&r2.msg?r2.msg:'备注清空未响应'),'err'); return; }
|
||||
adoptSrcDrop(billId); // 决策 139:取消采纳=删除来源记忆
|
||||
if(CUR && String(CUR.id)===String(billId)) CUR_ADOPT=''; // 决策 250:判定源同步(标记立即复原)
|
||||
// ③ 刷新当前视图(原数据/组表都可能是取消来源;撤缓存重拉即真状态;keepView 停在原地)
|
||||
Object.keys(RV_CACHE).forEach(k=>{ if(String(k).indexOf(SID+'|')===0) delete RV_CACHE[k]; });
|
||||
const cur=document.querySelector('.tab.on');
|
||||
@@ -2704,19 +2689,19 @@ async function adoptLme(i){
|
||||
if(prow){ prow[6]=rp.ntp; prow[7]=rp.taxrate; prow[8]=rp.taxp; }
|
||||
const trp=document.querySelector(`#tb0 tr[data-id="${CUR.id}"]`);
|
||||
if(trp){
|
||||
if(trp.children[6]) trp.children[6].textContent=rm(rp.ntp);
|
||||
if(trp.children[7]) trp.children[7].textContent=rm(rp.taxrate);
|
||||
if(trp.children[8]) trp.children[8].textContent=rm(rp.taxp);
|
||||
if(trp.children[7]) trp.children[7].textContent=rm(rp.ntp); // 决策 243 源列后:7=除税 8=税率 9=含税
|
||||
if(trp.children[8]) trp.children[8].textContent=rm(rp.taxrate);
|
||||
if(trp.children[9]) trp.children[9].textContent=rm(rp.taxp);
|
||||
}
|
||||
const trR0=document.querySelector(`#rawbody tr.lmerow[data-id="${CUR.id}"]`);
|
||||
if(trR0){
|
||||
const d6=trR0.children[6], d7=trR0.children[7], d8=trR0.children[8];
|
||||
if(d6) d6.textContent=rm(rp.ntp);
|
||||
if(d7) d7.textContent=rm(rp.taxrate);
|
||||
if(d8) d8.textContent=rm(rp.taxp);
|
||||
const d7=trR0.children[7], d8=trR0.children[8], d9=trR0.children[9]; // 决策 243 源列后同款
|
||||
if(d7) d7.textContent=rm(rp.ntp);
|
||||
if(d8) d8.textContent=rm(rp.taxrate);
|
||||
if(d9) d9.textContent=rm(rp.taxp);
|
||||
}
|
||||
}
|
||||
const txt=adoptTxtFor(x,true,_lmeAnchor||_oldLme); // 决策 219:旧价优先锚(第一次计算/合并后首次三价),无锚退改前现值
|
||||
const txt=adoptTxtFor(x,true,_lmeAnchor||_oldLme); // 决策 251:旧价=导入时项目级原件三价(锚),锚空退改前现值
|
||||
let r=null;
|
||||
try{
|
||||
r=await J('/api/session/remark',{method:'POST',headers:{'Content-Type':'application/json'},
|
||||
@@ -2726,20 +2711,21 @@ async function adoptLme(i){
|
||||
// 决策 172:采纳改价+备注落库后撤原数据取数缓存——否则切到原数据页命中旧缓存
|
||||
//(价格/备注旧值,实测报障「项目级工料机汇总没同步更新」;与定额采纳/取消采纳同口径)
|
||||
Object.keys(RV_CACHE).forEach(k=>{ if(String(k).indexOf(SID+'|')===0) delete RV_CACHE[k]; });
|
||||
adoptSrcSave(x); // 决策 139:记住采纳来源(签名+行快照),永远置顶
|
||||
CUR_ADOPT=txt; // 决策 250:判定源同步(已采纳标记立即点亮)
|
||||
const row=(LME_ROWS||[]).find(y=>y[0]===CUR.id); // 数据先行:排序/重画后备注与取消采纳不丢
|
||||
if(row){ row[10]=txt;
|
||||
// 就地更新两格(不整表重画——重画会丢 tr.sel 选中态);取消采纳格口径=备注以「采纳:」开头(lmeAdoptCellHTML)
|
||||
// 决策 243 源列后行 12 格:10=取消采纳 11=备注(原 9/10 顺延一位)
|
||||
const tr0=document.querySelector(`#tb0 tr[data-id="${CUR.id}"]`);
|
||||
const c9=tr0&&tr0.children[9], c10=tr0&&tr0.children[10];
|
||||
if(c10){ c10.textContent=txt; c10.title=txt; }
|
||||
if(c9) c9.innerHTML=`<a class="lk" onclick="cancelAdopt(${CUR.id})">取消采纳</a>`;
|
||||
const c10=tr0&&tr0.children[10], c11=tr0&&tr0.children[11];
|
||||
if(c11){ c11.textContent=txt; c11.title=txt; }
|
||||
if(c10) c10.innerHTML=`<a class="lk" onclick="cancelAdopt(${CUR.id})">取消采纳</a>`;
|
||||
// 决策 147/149:原数据·项目级卡同款两格原位同步(两表一体,改一处=改两处)
|
||||
const trR=document.querySelector(`#rawbody tr.lmerow[data-id="${CUR.id}"]`);
|
||||
if(trR){
|
||||
const d9=trR.children[9], d10=trR.children[10];
|
||||
if(d10){ d10.textContent=txt; d10.title=txt; }
|
||||
if(d9) d9.innerHTML=`<a class="lk" onclick="cancelAdopt(${CUR.id})">取消采纳</a>`;
|
||||
const d10=trR.children[10], d11=trR.children[11];
|
||||
if(d11){ d11.textContent=txt; d11.title=txt; }
|
||||
if(d10) d10.innerHTML=`<a class="lk" onclick="cancelAdopt(${CUR.id})">取消采纳</a>`;
|
||||
}
|
||||
}
|
||||
renderHist(); // 已采纳灰标记:传递到本行
|
||||
@@ -2757,20 +2743,20 @@ async function cancelAdopt(lmeId){
|
||||
body:JSON.stringify({session_id:SID,lme_id:lmeId})});
|
||||
}catch(e){ r=null; }
|
||||
if(!r || !r.ok){ dlMsg('取消采纳失败:'+(r&&r.msg?r.msg:'服务未响应'),'err'); return; }
|
||||
adoptSrcDrop(lmeId); // 决策 139:取消采纳=删除来源记忆
|
||||
if(CUR && String(CUR.id)===String(lmeId)) CUR_ADOPT=''; // 决策 250:判定源同步(标记立即复原)
|
||||
const row=(LME_ROWS||[]).find(y=>y[0]===lmeId);
|
||||
if(row) row[10]='';
|
||||
const tr0=document.querySelector(`#tb0 tr[data-id="${lmeId}"]`);
|
||||
if(tr0){
|
||||
const c9=tr0.children[9], c10=tr0.children[10];
|
||||
if(c10){ c10.textContent=''; c10.title=''; }
|
||||
if(c9) c9.innerHTML='<span style="color:#b9c4d2">—</span>';
|
||||
const c10=tr0.children[10], c11=tr0.children[11]; // 决策 243 源列后:10=取消采纳 11=备注
|
||||
if(c11){ c11.textContent=''; c11.title=''; }
|
||||
if(c10) c10.innerHTML='<span style="color:#b9c4d2">—</span>';
|
||||
}
|
||||
const trR=document.querySelector(`#rawbody tr.lmerow[data-id="${lmeId}"]`); // 决策 147:原数据卡同款两格原位刷新
|
||||
if(trR){
|
||||
const c9=trR.children[9], c10=trR.children[10];
|
||||
if(c10){ c10.textContent=''; c10.title=''; }
|
||||
if(c9) c9.innerHTML='<span style="color:#b9c4d2">—</span>';
|
||||
const c10=trR.children[10], c11=trR.children[11]; // 决策 243 源列后同款
|
||||
if(c11){ c11.textContent=''; c11.title=''; }
|
||||
if(c10) c10.innerHTML='<span style="color:#b9c4d2">—</span>';
|
||||
}
|
||||
loadAdopt();
|
||||
renderHist();
|
||||
@@ -2833,8 +2819,10 @@ function lmeSort(i){
|
||||
lmeRenderRows();
|
||||
}
|
||||
function lmeRenderRows(){
|
||||
// 显示位→数据位:取消采纳列(显示 9)不可排序;备注显示 10 = 数据 r[10],其余显示位与数据位同下标
|
||||
const view=sortRows(LME_ROWS, LME_SORT.k, LME_SORT.dir, LME_NUM);
|
||||
// 显示位→数据位:决策 243 加「源」列(显示 1)后整体错一位——2编码..9含税=数据1..8,
|
||||
// 11备注=数据10;0序号/1源/10取消采纳无数据位=不排序(LME_VIEW_DS 见 common.js,与 COLS.lme 同步改)
|
||||
const _dk=LME_VIEW_DS[LME_SORT.k];
|
||||
const view=sortRows(LME_ROWS, _dk==null?-1:_dk, LME_SORT.dir, LME_NUM);
|
||||
LME_VIEW=view;
|
||||
// 决策 209:0 量行整行不显示后,全临删场景=0 行是**新口径常态**——提示语与「未打开工程」分开
|
||||
$('tb0').innerHTML=renderLme(view,WB_OPTS)
|
||||
|
||||
Reference in New Issue
Block a user