From 296917456c230a7d49d8b0d94e816c294ff7f7b8 Mon Sep 17 00:00:00 2001 From: mac Date: Thu, 9 Jul 2026 16:03:30 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=AE=A1=E5=88=92=E8=B4=B9=E7=94=A8?= =?UTF-8?q?=E4=BF=9D=E5=AD=98/=E5=88=A0=E9=99=A4=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 后端新增/api//list轻量级列表接口 - plan_expense.js保存/删除后改为轻量刷新,不再调load() - 避免全量bootstrap+7模块渲染,只刷新费用列表 - 版本号 v1.0.0.37 --- backend/routes.py | 20 ++++++++++++++++++++ static/modules/plan_expense.js | 12 ++++++++---- templates/index.html | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/backend/routes.py b/backend/routes.py index c8712e0..1acf410 100644 --- a/backend/routes.py +++ b/backend/routes.py @@ -666,6 +666,26 @@ def bootstrap(): # ---------- 通用 CRUD ---------- +@bp.route("/api//list", methods=["GET"]) +@login_required +def list_resource(resource): + """轻量级列表接口,只返回指定 tenant 的记录""" + if resource not in TABLES: + return jsonify({"error": "unknown resource"}), 404 + table, _ = TABLES[resource] + tenant = request.args.get("tenant", session.get("tenants", [""])[0]) + allowed = session.get("tenants", []) + allowed = [t if t != "总工作台" else "总览" for t in allowed] + allowed = [t if t != "学会·无界" else "学术·无界" for t in allowed] + if tenant not in allowed: + tenant = allowed[0] if allowed else "" + conn = db() + try: + result = rows(conn, f"SELECT * FROM {table} WHERE tenant=? ORDER BY id DESC", [tenant]) + return jsonify(result) + finally: + conn.close() + @bp.route("/api/", methods=["POST"]) @login_required def create_resource(resource): diff --git a/static/modules/plan_expense.js b/static/modules/plan_expense.js index 88b6312..98e2129 100644 --- a/static/modules/plan_expense.js +++ b/static/modules/plan_expense.js @@ -199,8 +199,10 @@ window.savePlanExpense = async function(event) { return; } closePlanExpModal(); - await load(); - renderPlanExpense(); + try { + state.data.planExpense = await api("/api/planExpense/list?tenant=" + encodeURIComponent(state.tenant)); + renderPlanExpense(); + } catch (e) { /* non-critical */ } }; window.deletePlanExpItem = async function() { @@ -213,6 +215,8 @@ window.deletePlanExpItem = async function() { return; } closePlanExpModal(); - await load(); - renderPlanExpense(); + try { + state.data.planExpense = await api("/api/planExpense/list?tenant=" + encodeURIComponent(state.tenant)); + renderPlanExpense(); + } catch (e) { /* non-critical */ } }; diff --git a/templates/index.html b/templates/index.html index 0b6da50..97d2007 100644 --- a/templates/index.html +++ b/templates/index.html @@ -76,7 +76,7 @@
-

OPC Manager v1.0.0.36

+

OPC Manager v1.0.0.37

科普 OPC 工作台