From ec140bf105c7db0752d99d52f5aa8ddaa096f3f9 Mon Sep 17 00:00:00 2001 From: mac Date: Tue, 7 Jul 2026 17:02:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B9=B4=E4=BB=BD=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=20+=20=E9=A6=96=E9=A1=B5=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 后端所有硬编码2026替换为date.today().year动态计算 - 首页移除4个快捷跳转卡片 - 首页新增时间段筛选下拉框 - 版本号更新至v1.0.0.3 --- backend/helpers.py | 4 +++- backend/routes.py | 27 ++++++++++++++------------- static/modules/home.js | 17 +++++++++-------- templates/index.html | 2 +- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/backend/helpers.py b/backend/helpers.py index 87fddaa..90a8d12 100644 --- a/backend/helpers.py +++ b/backend/helpers.py @@ -2,6 +2,7 @@ # 依赖:db.py;被 routes.py 和 migrations/seed_data.py 调用 import json +from datetime import date from pathlib import Path from db import _exec, rows, one @@ -61,7 +62,8 @@ def attach_common(conn, resource, items): def monthly_finance(conn, tenant="科普·无界"): - months = [f"2026-{m:02d}" for m in range(1, 13)] + _year = date.today().year + months = [f"{_year}-{m:02d}" for m in range(1, 13)] pfs = rows(conn, "SELECT sign_amount, sign_month, status, budget_data, expense_data FROM project_finances WHERE tenant=? AND status='已签约'", [tenant]) diff --git a/backend/routes.py b/backend/routes.py index bbd4b1f..39ca7e3 100644 --- a/backend/routes.py +++ b/backend/routes.py @@ -228,6 +228,7 @@ def index(): def bootstrap(): if "user_id" not in session: return jsonify({"error": "未登录"}), 401 + _year = date.today().year tenant = request.args.get("tenant", session.get("tenants", ["科普·无界"])[0]) allowed = session.get("tenants", []) if "总工作台" not in allowed: @@ -262,7 +263,7 @@ def bootstrap(): for pf in t_pfs: bm = t_bm.get(pf["id"], {}) for m in months_range: - b = bm.get(f"2026_{m:02d}") + b = bm.get(f"{_year}_{m:02d}") if b: total += float(b.get(field) or 0) return total @@ -281,7 +282,7 @@ def bootstrap(): for pf in t_pfs: em = t_em.get(pf["id"], {}) for m in months_range: - e = em.get(f"2026_{m:02d}") + e = em.get(f"{_year}_{m:02d}") if e: total += float(e.get(field) or 0) return total @@ -289,10 +290,10 @@ def bootstrap(): _now_month = date.today().month _q_start = ((_now_month - 1) // 3) * 3 + 1 _q_range = range(_q_start, _q_start + 3) - _q_months = [f"2026-{m:02d}" for m in _q_range] + _q_months = [f"{_year}-{m:02d}" for m in _q_range] _prev_q_start = ((_now_month - 4) // 3) * 3 + 1 _prev_q_range = range(max(_prev_q_start, 1), _prev_q_start + 3) - _prev_q_months = [f"2026-{m:02d}" for m in _prev_q_range] + _prev_q_months = [f"{_year}-{m:02d}" for m in _prev_q_range] _prev_month = _now_month - 1 if _now_month > 1 else None all_metrics.append({ "total_projects": len(t_signed_pfs), @@ -302,9 +303,9 @@ def bootstrap(): "signed_amount": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约"), "signed_annual": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约"), "signed_q2": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _q_months), - "signed_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"2026-{_now_month:02d}"), + "signed_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}"), "signed_prev_q": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _prev_q_months), - "signed_prev_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"2026-{_prev_month:02d}") if _prev_month else 0, + "signed_prev_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0, "revenue_annual": t_sum_budget("rev", range(1, 13)), "revenue_q2": t_sum_budget("rev", _q_range), "monthly_revenue": t_sum_budget("rev", [_now_month]), @@ -369,7 +370,7 @@ def bootstrap(): agg[key] = sum(m.get(key, 0) for m in all_metrics) merged_monthly = [] for i in range(12): - m = {"month": all_monthly[0][i]["month"] if all_monthly and len(all_monthly[0]) > i else f"2026-{i+1:02d}"} + m = {"month": all_monthly[0][i]["month"] if all_monthly and len(all_monthly[0]) > i else f"{_year}-{i+1:02d}"} for field in ["revenue","gross","payment","cost","paid","sign"]: m[field] = sum(tl[i][field] if i < len(tl) else 0 for tl in all_monthly) merged_monthly.append(m) @@ -415,7 +416,7 @@ def bootstrap(): total = 0 for pf, bm in budget_maps: for m in months_range: - b = bm.get(f"2026_{m:02d}") + b = bm.get(f"{_year}_{m:02d}") if b: total += float(b.get(field) or 0) return total @@ -424,7 +425,7 @@ def bootstrap(): total = 0 for pf, em in expense_maps: for m in months_range: - e = em.get(f"2026_{m:02d}") + e = em.get(f"{_year}_{m:02d}") if e: total += float(e.get(field) or 0) return total @@ -494,12 +495,12 @@ def bootstrap(): return sum(x["sign_amount"] or 0 for x in pfs if x["status"] == status) signed_amount = pf_status_sum("已签约") signed_annual = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约") - _q_months = [f"2026-{m:02d}" for m in _q_range] + _q_months = [f"{_year}-{m:02d}" for m in _q_range] signed_q2 = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _q_months) - signed_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"2026-{_now_month:02d}") - _prev_q_months = [f"2026-{m:02d}" for m in _prev_q_range] + signed_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}") + _prev_q_months = [f"{_year}-{m:02d}" for m in _prev_q_range] signed_prev_q = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _prev_q_months) - signed_prev_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"2026-{_prev_month:02d}") if _prev_month else 0 + signed_prev_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0 pipeline_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] not in ["已签约","已丢单","已归档","已完成"]) signed_not_executed = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_type"] == "execution" and x["execution_progress"] < 100) summary = { diff --git a/static/modules/home.js b/static/modules/home.js index 09cf137..bcae3df 100644 --- a/static/modules/home.js +++ b/static/modules/home.js @@ -105,14 +105,15 @@ function renderHome() { } document.querySelector("#home").innerHTML = `
- ${state.tenant === "总工作台" ? "" : `
- ${[ - ["项目管理", m.total_projects, "finance"], - ["重点工作与台账", m.total_proposals, "projects"], - ["业务方案", m.total_products, "proposals"], - ["产品迭代", m.upcoming_products, "products"], - ].map(([label, value, tab]) => ``).join("")} -
`} +
+ 筛选: + +
${card(`

部门经营情况

${(() => { var d = [ diff --git a/templates/index.html b/templates/index.html index b72d2d6..570b54c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -76,7 +76,7 @@
-

OPC Manager v1.0.0.2

+

OPC Manager v1.0.0.3

科普 OPC 工作台

指标年度累计上季度累计上月累计本季度累计季环比本月累计月环比