perf: 计划费用保存/删除性能优化

- 后端新增/api/<resource>/list轻量级列表接口
- plan_expense.js保存/删除后改为轻量刷新,不再调load()
- 避免全量bootstrap+7模块渲染,只刷新费用列表
- 版本号 v1.0.0.37
This commit is contained in:
mac
2026-07-09 16:03:30 +08:00
parent 236d43052e
commit 296917456c
3 changed files with 29 additions and 5 deletions

View File

@@ -666,6 +666,26 @@ def bootstrap():
# ---------- 通用 CRUD ----------
@bp.route("/api/<resource>/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/<resource>", methods=["POST"])
@login_required
def create_resource(resource):