Initial commit: 公示系统集合 Flask 项目
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
|||||||
|
# Python
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.egg-info/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# 虚拟环境
|
||||||
|
venv/
|
||||||
|
.env/
|
||||||
|
env/
|
||||||
|
.venv/
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Trae 临时文件
|
||||||
|
.trae/
|
||||||
|
|
||||||
|
# 日志
|
||||||
|
*.log
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
from flask import Flask, abort, jsonify, render_template, request
|
||||||
|
|
||||||
|
from config import APP_CONFIG, PROJECTS
|
||||||
|
from query_service import query_project_stats, safe_date
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def get_project_or_404(project_key: str):
|
||||||
|
project = PROJECTS.get(project_key)
|
||||||
|
if not project:
|
||||||
|
abort(404)
|
||||||
|
return project
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def home():
|
||||||
|
user_uuid = str(request.args.get("uuid", "") or "").strip()
|
||||||
|
return render_template(
|
||||||
|
"home.html",
|
||||||
|
app_name=APP_CONFIG["app_name"],
|
||||||
|
projects=PROJECTS,
|
||||||
|
user_uuid=user_uuid,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/project/<project_key>")
|
||||||
|
def project_page(project_key: str):
|
||||||
|
project = get_project_or_404(project_key)
|
||||||
|
user_uuid = str(request.args.get("uuid", "") or "").strip()
|
||||||
|
today = safe_date(request.args.get("date", ""))
|
||||||
|
return render_template(
|
||||||
|
"project.html",
|
||||||
|
project_key=project_key,
|
||||||
|
project=project,
|
||||||
|
user_uuid=user_uuid,
|
||||||
|
today=today,
|
||||||
|
app_name=APP_CONFIG["app_name"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/project/<project_key>/stats")
|
||||||
|
def api_project_stats(project_key: str):
|
||||||
|
project = get_project_or_404(project_key)
|
||||||
|
date_str = safe_date(request.args.get("date", ""))
|
||||||
|
user_uuid = str(request.args.get("uuid", "") or "").strip()
|
||||||
|
result = query_project_stats(project, date_str, user_uuid)
|
||||||
|
if not result.get("success"):
|
||||||
|
return jsonify(
|
||||||
|
{
|
||||||
|
"success": False,
|
||||||
|
"project_key": project_key,
|
||||||
|
"date": date_str,
|
||||||
|
"uuid": user_uuid,
|
||||||
|
"error": result.get("error") or "查询失败",
|
||||||
|
}
|
||||||
|
), 500
|
||||||
|
return jsonify(
|
||||||
|
{
|
||||||
|
"success": True,
|
||||||
|
"configured": bool(result.get("configured")),
|
||||||
|
"message": str(result.get("message") or ""),
|
||||||
|
"project_key": project_key,
|
||||||
|
"project_title": project.get("title", ""),
|
||||||
|
"date": date_str,
|
||||||
|
"uuid": user_uuid,
|
||||||
|
"total": len(result["rows"]),
|
||||||
|
"sum_count": result["sum_count"],
|
||||||
|
"has_current_user": result["has_current_user"],
|
||||||
|
"breakdowns": result.get("breakdowns") or [],
|
||||||
|
"rows": result["rows"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(f"访问地址: http://127.0.0.1:{APP_CONFIG['port']}")
|
||||||
|
app.run(
|
||||||
|
host=APP_CONFIG["host"],
|
||||||
|
port=APP_CONFIG["port"],
|
||||||
|
debug=APP_CONFIG["debug"],
|
||||||
|
)
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
DATABASES = {
|
||||||
|
"wfj_old": {
|
||||||
|
"DB_HOST": "183.6.7.91",
|
||||||
|
"DB_PORT": 33016,
|
||||||
|
"DB_USER": "root",
|
||||||
|
"DB_PASSWORD": "Aliyun@7646!",
|
||||||
|
"DB_NAME": "travel_project",
|
||||||
|
},
|
||||||
|
"wfj_pyui": {
|
||||||
|
"DB_HOST": "183.6.7.91",
|
||||||
|
"DB_PORT": 6890,
|
||||||
|
"DB_USER": "root",
|
||||||
|
"DB_PASSWORD": "Aliyun@7646!",
|
||||||
|
"DB_NAME": "project_pdd",
|
||||||
|
},
|
||||||
|
"project_menus": {
|
||||||
|
"DB_HOST": "192.168.5.2",
|
||||||
|
"DB_PORT": 3307,
|
||||||
|
"DB_USER": "root",
|
||||||
|
"DB_PASSWORD": "Aliyun@7646!",
|
||||||
|
"DB_NAME": "project_menus",
|
||||||
|
},
|
||||||
|
"wfj_h5": {
|
||||||
|
"DB_HOST": "192.168.5.5",
|
||||||
|
"DB_PORT": 3306,
|
||||||
|
"DB_USER": "root",
|
||||||
|
"DB_PASSWORD": "Aliyun@7646!",
|
||||||
|
"DB_NAME": "elm_meishi",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PROJECTS = {
|
||||||
|
"travel_task_board": {
|
||||||
|
"title": "出行任务公示",
|
||||||
|
"subtitle": "按日期统计出行任务完成情况,需使用日期选择器筛选指定日期数据。",
|
||||||
|
"db_key": "wfj_old",
|
||||||
|
"table_name": "target_input",
|
||||||
|
"query_sql": "SELECT workid, COUNT(1) AS cnt FROM target_input WHERE updated_at LIKE %s AND hl_car IS NOT NULL AND gd_car IS NOT NULL GROUP BY workid ORDER BY cnt DESC",
|
||||||
|
"status": "已配置",
|
||||||
|
"theme": "teal",
|
||||||
|
"enable_date_filter": True,
|
||||||
|
"enable_uuid_filter": True,
|
||||||
|
},
|
||||||
|
"elm_task_1": {
|
||||||
|
"title": "饿了么1任务",
|
||||||
|
"subtitle": "按日期统计饿了么1任务完成情况,数据来源于 elm_meishi.ele_project_input。",
|
||||||
|
"db_key": "wfj_h5",
|
||||||
|
"table_name": "elm_meishi.ele_project_input",
|
||||||
|
"query_sql": "SELECT workid, COUNT(`index`) AS cnt FROM elm_meishi.ele_project_input WHERE created_at >= %s AND created_at < %s AND is_ok IN (3, 4) GROUP BY workid ORDER BY COUNT(`index`) DESC",
|
||||||
|
"status": "已配置",
|
||||||
|
"theme": "emerald",
|
||||||
|
"enable_date_filter": True,
|
||||||
|
"date_filter_mode": "day_range",
|
||||||
|
"enable_uuid_filter": True,
|
||||||
|
},
|
||||||
|
"elm_task_2": {
|
||||||
|
"title": "饿了么2_小程序",
|
||||||
|
"subtitle": "按日期统计饿了么2_小程序任务完成情况,数据来源于 elm_meishi.target_ele_work2。",
|
||||||
|
"db_key": "wfj_old",
|
||||||
|
"table_name": "elm_meishi.target_ele_work2",
|
||||||
|
"query_sql": "SELECT workid, COUNT(`index_id`) AS cnt FROM elm_meishi.target_ele_work2 WHERE create_time > %s AND workid IS NOT NULL AND (`len_head` <> '206' AND len_body <> 206) GROUP BY workid ORDER BY COUNT(`index_id`) DESC",
|
||||||
|
"status": "已配置",
|
||||||
|
"theme": "amber",
|
||||||
|
"enable_date_filter": True,
|
||||||
|
"date_filter_mode": "raw",
|
||||||
|
"enable_uuid_filter": True,
|
||||||
|
},
|
||||||
|
"elm_task_2_h5": {
|
||||||
|
"title": "饿了么2_h5",
|
||||||
|
"subtitle": "按日期统计饿了么2_h5任务完成情况,数据来源于 elm_meishi.target_ele_work_h5(192.168.5.5:3306)。",
|
||||||
|
"db_key": "wfj_h5",
|
||||||
|
"table_name": "elm_meishi.target_ele_work_h5",
|
||||||
|
"query_sql": "SELECT workid, COUNT(`index_id`) AS cnt FROM elm_meishi.target_ele_work_h5 WHERE create_time > %s AND workid IS NOT NULL AND len_head > 1000 AND len_body > 1000 AND len_operate > 1000 GROUP BY workid ORDER BY COUNT(`index_id`) DESC",
|
||||||
|
"status": "已配置",
|
||||||
|
"theme": "orange",
|
||||||
|
"enable_date_filter": True,
|
||||||
|
"date_filter_mode": "raw",
|
||||||
|
"enable_uuid_filter": True,
|
||||||
|
},
|
||||||
|
"pinxixi_task": {
|
||||||
|
"title": "拼嘻嘻任务",
|
||||||
|
"subtitle": "按日期统计拼嘻嘻任务完成情况,数据来源于 return_share_new。",
|
||||||
|
"db_key": "wfj_pyui",
|
||||||
|
"table_name": "return_share_new",
|
||||||
|
"query_sql": "SELECT workid, COUNT(id) AS cnt FROM return_share_new WHERE create_time LIKE %s GROUP BY workid ORDER BY COUNT(id) DESC",
|
||||||
|
"status": "已配置",
|
||||||
|
"theme": "blue",
|
||||||
|
"enable_date_filter": True,
|
||||||
|
"enable_uuid_filter": True,
|
||||||
|
},
|
||||||
|
"dewu_shared": {
|
||||||
|
"title": "得物分享公示",
|
||||||
|
"subtitle": "按日期统计得物分享完成情况,数据来源于 project_pdd.dewu_shared 表,c_time 匹配所选日期。",
|
||||||
|
"db_key": "wfj_pyui",
|
||||||
|
"table_name": "dewu_shared",
|
||||||
|
"query_sql": "SELECT user_uuid, COUNT(1) AS cnt FROM dewu_shared WHERE id > '393' AND c_time LIKE %s GROUP BY user_uuid ORDER BY COUNT(1) DESC",
|
||||||
|
"status": "已配置",
|
||||||
|
"theme": "red",
|
||||||
|
"enable_date_filter": True,
|
||||||
|
"enable_uuid_filter": True,
|
||||||
|
"identifier_field": "user_uuid",
|
||||||
|
},
|
||||||
|
"model_task_board": {
|
||||||
|
"title": "模型任务公示",
|
||||||
|
"subtitle": "展示模型任务账号池统计结果,每次直接按固定 SQL 查询,无需按日期筛选。",
|
||||||
|
"db_key": "wfj_pyui",
|
||||||
|
"table_name": "sketchfab_account_pool",
|
||||||
|
"query_sql": "select account_name, count(api_token) as total FROM sketchfab_account_pool GROUP BY account_name ORDER BY total DESC",
|
||||||
|
"status": "已配置",
|
||||||
|
"theme": "violet",
|
||||||
|
"enable_date_filter": False,
|
||||||
|
"enable_uuid_filter": True,
|
||||||
|
"identifier_field": "account_name",
|
||||||
|
"count_field": "total",
|
||||||
|
"identifier_label": "账号名称",
|
||||||
|
"summary_total_label": "账号数",
|
||||||
|
"summary_count_label": "Token 总量",
|
||||||
|
"empty_text": "当前暂无模型任务公示数据",
|
||||||
|
},
|
||||||
|
"meishi_task_3": {
|
||||||
|
"title": "美食3任务",
|
||||||
|
"subtitle": "按日期统计美食3任务完成情况,数据来源于 project_menus.shop_list,合并 OK=1 与 OK=99 展示。",
|
||||||
|
"db_key": "project_menus",
|
||||||
|
"table_name": "shop_list",
|
||||||
|
"query_sql_list": [
|
||||||
|
{
|
||||||
|
"key": "ok_1",
|
||||||
|
"label": "OK=1",
|
||||||
|
"sql": "SELECT workid, COUNT(`index`) AS cnt FROM shop_list WHERE updated_at > %s AND is_ok = 1 GROUP BY workid",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "ok_99",
|
||||||
|
"label": "OK=99",
|
||||||
|
"sql": "SELECT workid, COUNT(`index`) AS cnt FROM shop_list WHERE updated_at > %s AND is_ok = 99 GROUP BY workid",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"status": "已配置",
|
||||||
|
"theme": "cyan",
|
||||||
|
"enable_date_filter": True,
|
||||||
|
"date_filter_mode": "raw",
|
||||||
|
"enable_uuid_filter": True,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
APP_CONFIG = {
|
||||||
|
"app_name": "公示系统集合",
|
||||||
|
"host": "0.0.0.0",
|
||||||
|
"port": 9180,
|
||||||
|
"debug": False,
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
from datetime import date, datetime, timedelta
|
||||||
|
|
||||||
|
import pymysql
|
||||||
|
|
||||||
|
from config import DATABASES
|
||||||
|
|
||||||
|
|
||||||
|
def safe_date(date_str: str) -> str:
|
||||||
|
value = str(date_str or "").strip()
|
||||||
|
if len(value) == 10 and value[4] == "-" and value[7] == "-":
|
||||||
|
return value
|
||||||
|
return date.today().isoformat()
|
||||||
|
|
||||||
|
|
||||||
|
def next_date(date_str: str) -> str:
|
||||||
|
value = datetime.strptime(date_str, "%Y-%m-%d").date()
|
||||||
|
return (value + timedelta(days=1)).isoformat()
|
||||||
|
|
||||||
|
|
||||||
|
def get_db_connection(db_key: str):
|
||||||
|
db_conf = DATABASES.get(db_key) or {}
|
||||||
|
db_name = str(db_conf.get("DB_NAME") or "").strip()
|
||||||
|
if not db_name:
|
||||||
|
raise ValueError(f"数据库 {db_key} 未配置 DB_NAME")
|
||||||
|
return pymysql.connect(
|
||||||
|
host=db_conf["DB_HOST"],
|
||||||
|
port=int(db_conf["DB_PORT"]),
|
||||||
|
user=db_conf["DB_USER"],
|
||||||
|
password=db_conf["DB_PASSWORD"],
|
||||||
|
database=db_name,
|
||||||
|
charset="utf8mb4",
|
||||||
|
cursorclass=pymysql.cursors.DictCursor,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def query_project_stats(project_config: dict, date_str: str, user_uuid: str):
|
||||||
|
query_sql = str(project_config.get("query_sql") or "").strip()
|
||||||
|
query_sql_list = project_config.get("query_sql_list") or []
|
||||||
|
db_key = str(project_config.get("db_key") or "").strip()
|
||||||
|
enable_date_filter = bool(project_config.get("enable_date_filter", True))
|
||||||
|
date_filter_mode = str(project_config.get("date_filter_mode") or "like").strip().lower()
|
||||||
|
enable_uuid_filter = bool(project_config.get("enable_uuid_filter", True))
|
||||||
|
identifier_field = str(project_config.get("identifier_field") or "workid").strip()
|
||||||
|
count_field = str(project_config.get("count_field") or "count").strip()
|
||||||
|
if not query_sql and not query_sql_list:
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"configured": False,
|
||||||
|
"message": "当前项目尚未配置查询 SQL,请先补充配置。",
|
||||||
|
"rows": [],
|
||||||
|
"sum_count": 0,
|
||||||
|
"has_current_user": False,
|
||||||
|
"breakdowns": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
conn = None
|
||||||
|
try:
|
||||||
|
conn = get_db_connection(db_key)
|
||||||
|
with conn.cursor() as cur:
|
||||||
|
if enable_date_filter:
|
||||||
|
if date_filter_mode == "raw":
|
||||||
|
date_param = date_str
|
||||||
|
elif date_filter_mode == "day_range":
|
||||||
|
date_param = (date_str, next_date(date_str))
|
||||||
|
else:
|
||||||
|
date_param = f"%{date_str}%"
|
||||||
|
else:
|
||||||
|
date_param = None
|
||||||
|
|
||||||
|
if query_sql_list:
|
||||||
|
breakdowns = [
|
||||||
|
{
|
||||||
|
"key": str(item.get("key") or "").strip(),
|
||||||
|
"label": str(item.get("label") or item.get("key") or "").strip(),
|
||||||
|
}
|
||||||
|
for item in query_sql_list
|
||||||
|
if str(item.get("sql") or "").strip()
|
||||||
|
]
|
||||||
|
merged = {}
|
||||||
|
for item in query_sql_list:
|
||||||
|
sql = str(item.get("sql") or "").strip()
|
||||||
|
key = str(item.get("key") or "").strip()
|
||||||
|
if not sql:
|
||||||
|
continue
|
||||||
|
if date_param is None:
|
||||||
|
cur.execute(sql)
|
||||||
|
elif date_filter_mode == "day_range":
|
||||||
|
cur.execute(sql, date_param)
|
||||||
|
else:
|
||||||
|
cur.execute(sql, (date_param,))
|
||||||
|
for row in cur.fetchall() or []:
|
||||||
|
identifier_value = str(row.get(identifier_field) or row.get("workid") or "")
|
||||||
|
if not identifier_value:
|
||||||
|
continue
|
||||||
|
count_val = int(row.get(count_field) or row.get("cnt") or row.get("count") or 0)
|
||||||
|
merged.setdefault(identifier_value, {})[key] = count_val
|
||||||
|
|
||||||
|
mapped_rows = []
|
||||||
|
for identifier_value, parts in merged.items():
|
||||||
|
is_current_user = bool(enable_uuid_filter and user_uuid) and identifier_value == user_uuid
|
||||||
|
item = {
|
||||||
|
"workid": identifier_value,
|
||||||
|
"count": sum(parts.values()),
|
||||||
|
"is_current_user": is_current_user,
|
||||||
|
}
|
||||||
|
for breakdown in breakdowns:
|
||||||
|
item[f"count_{breakdown['key']}"] = parts.get(breakdown["key"], 0)
|
||||||
|
mapped_rows.append(item)
|
||||||
|
mapped_rows.sort(key=lambda x: x["count"], reverse=True)
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"configured": True,
|
||||||
|
"message": "",
|
||||||
|
"rows": mapped_rows,
|
||||||
|
"sum_count": sum(item["count"] for item in mapped_rows),
|
||||||
|
"has_current_user": any(item["is_current_user"] for item in mapped_rows),
|
||||||
|
"breakdowns": breakdowns,
|
||||||
|
}
|
||||||
|
|
||||||
|
if date_param is None:
|
||||||
|
cur.execute(query_sql)
|
||||||
|
elif date_filter_mode == "day_range":
|
||||||
|
cur.execute(query_sql, date_param)
|
||||||
|
else:
|
||||||
|
cur.execute(query_sql, (date_param,))
|
||||||
|
rows = cur.fetchall() or []
|
||||||
|
|
||||||
|
mapped_rows = []
|
||||||
|
for row in rows:
|
||||||
|
identifier_value = str(row.get(identifier_field) or row.get("workid") or "")
|
||||||
|
count_val = int(row.get(count_field) or row.get("count") or row.get("cnt") or 0)
|
||||||
|
is_current_user = bool(enable_uuid_filter and user_uuid) and identifier_value == user_uuid
|
||||||
|
mapped_rows.append(
|
||||||
|
{
|
||||||
|
"workid": identifier_value,
|
||||||
|
"count": count_val,
|
||||||
|
"is_current_user": is_current_user,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"configured": True,
|
||||||
|
"message": "",
|
||||||
|
"rows": mapped_rows,
|
||||||
|
"sum_count": sum(item["count"] for item in mapped_rows),
|
||||||
|
"has_current_user": any(item["is_current_user"] for item in mapped_rows),
|
||||||
|
"breakdowns": [],
|
||||||
|
}
|
||||||
|
except Exception as exc:
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"configured": True,
|
||||||
|
"error": str(exc),
|
||||||
|
"rows": [],
|
||||||
|
"sum_count": 0,
|
||||||
|
"has_current_user": False,
|
||||||
|
"breakdowns": [],
|
||||||
|
}
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
if conn:
|
||||||
|
conn.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
@echo off
|
||||||
|
title gongshi_task_board
|
||||||
|
setlocal
|
||||||
|
cd /d "%~dp0"
|
||||||
|
python app.py
|
||||||
|
endlocal
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||||
|
<title>{{ app_name }}</title>
|
||||||
|
<style>
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
||||||
|
background: linear-gradient(180deg, #f2f7ff 0%, #f7f9fc 100%);
|
||||||
|
color: #1c2740;
|
||||||
|
}
|
||||||
|
.shell {
|
||||||
|
max-width: 1100px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px 16px 40px;
|
||||||
|
}
|
||||||
|
.hero {
|
||||||
|
background: linear-gradient(135deg, #1f3a5f 0%, #2f80ff 100%);
|
||||||
|
color: #fff;
|
||||||
|
border-radius: 24px;
|
||||||
|
padding: 24px 20px;
|
||||||
|
box-shadow: 0 18px 40px rgba(31, 58, 95, 0.22);
|
||||||
|
}
|
||||||
|
.eyebrow {
|
||||||
|
font-size: 13px;
|
||||||
|
opacity: 0.86;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
margin: 10px 0 8px;
|
||||||
|
font-size: 30px;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
.hero p {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 14px;
|
||||||
|
margin-top: 18px;
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
display: block;
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit;
|
||||||
|
background: rgba(255, 255, 255, 0.94);
|
||||||
|
border: 1px solid rgba(47, 128, 255, 0.08);
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 18px;
|
||||||
|
box-shadow: 0 12px 28px rgba(31, 58, 95, 0.08);
|
||||||
|
transition: transform 0.16s ease, box-shadow 0.2s ease, border-color 0.2s ease;
|
||||||
|
}
|
||||||
|
.card:active {
|
||||||
|
transform: scale(0.99);
|
||||||
|
}
|
||||||
|
.card:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 18px 36px rgba(31, 58, 95, 0.12);
|
||||||
|
border-color: rgba(47, 128, 255, 0.2);
|
||||||
|
}
|
||||||
|
.card-top {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
.card-title {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.card-tag {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-width: 72px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 12px;
|
||||||
|
background: #eaf2ff;
|
||||||
|
color: #1f5fff;
|
||||||
|
}
|
||||||
|
.card-desc {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.card-foot {
|
||||||
|
margin-top: 14px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #7b89a6;
|
||||||
|
}
|
||||||
|
.note {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
@media (min-width: 860px) {
|
||||||
|
.shell {
|
||||||
|
padding: 28px 20px 48px;
|
||||||
|
}
|
||||||
|
.hero {
|
||||||
|
padding: 32px 30px;
|
||||||
|
}
|
||||||
|
.grid {
|
||||||
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
gap: 18px;
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
min-height: 220px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="shell">
|
||||||
|
<section class="hero">
|
||||||
|
<div class="eyebrow">TASK PUBLIC BOARD</div>
|
||||||
|
<h1>公示系统集成</h1>
|
||||||
|
<p>统一承载多个任务公示项目的入口页面。当前先提供导航首页和统一查询骨架,后续新增项目时只需补充数据库配置、表名和 SQL。</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="grid">
|
||||||
|
{% for key, project in projects.items() %}
|
||||||
|
<a class="card" href="/project/{{ key }}{% if user_uuid %}?uuid={{ user_uuid|urlencode }}{% endif %}">
|
||||||
|
<div class="card-top">
|
||||||
|
<h2 class="card-title">{{ project.title }}</h2>
|
||||||
|
<span class="card-tag">{{ project.status }}</span>
|
||||||
|
</div>
|
||||||
|
<p class="card-desc">{{ project.subtitle }}</p>
|
||||||
|
<div class="card-foot">进入统一查询页</div>
|
||||||
|
</a>
|
||||||
|
{% endfor %}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div class="note">
|
||||||
|
后续接入新项目时,只需在 <strong>config.py</strong> 中补充项目配置,并为该项目填写数据库标识、表名和查询 SQL,即可复用统一项目页和统一查询接口。
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||||
|
<title>{{ project.title }}</title>
|
||||||
|
<style>
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
body { margin: 0; font-family: Arial, sans-serif; background: #f5f7fa; color: #222; }
|
||||||
|
.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
|
||||||
|
.card { background: #fff; border-radius: 10px; box-shadow: 0 4px 14px rgba(0,0,0,0.06); padding: 14px; margin-bottom: 12px; }
|
||||||
|
h1 { margin: 0; font-size: 20px; }
|
||||||
|
.toolbar { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-top: 12px; }
|
||||||
|
label { display: block; font-size: 13px; color: #666; margin-bottom: 6px; }
|
||||||
|
input { width: 100%; border: 1px solid #d9d9d9; border-radius: 8px; padding: 10px; }
|
||||||
|
button { border: none; border-radius: 8px; background: #1677ff; color: #fff; padding: 10px 14px; cursor: pointer; }
|
||||||
|
.meta { font-size: 13px; color: #666; margin-top: 8px; line-height: 1.7; }
|
||||||
|
table { width: 100%; border-collapse: collapse; }
|
||||||
|
th, td { border-bottom: 1px solid #f0f0f0; padding: 10px 8px; text-align: left; font-size: 14px; }
|
||||||
|
th { color: #555; font-weight: 600; background: #fafafa; }
|
||||||
|
tr.current-user { border: 2px solid #52c41a; }
|
||||||
|
tr.current-user td { background: #f6ffed; }
|
||||||
|
.tag { display: inline-block; font-size: 12px; color: #237804; border: 1px solid #95de64; background: #f6ffed; border-radius: 999px; padding: 2px 8px; }
|
||||||
|
.empty { color: #999; font-size: 14px; padding: 16px 0; }
|
||||||
|
.ok-tip { color: #237804; font-size: 13px; margin-top: 8px; }
|
||||||
|
.muted { color: #888; }
|
||||||
|
.back-link { display:inline-block; margin-bottom:8px; color:#1677ff; text-decoration:none; font-size:13px; }
|
||||||
|
.project-subtitle { font-size:13px; color:#666; margin-top:8px; line-height:1.7; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="wrap">
|
||||||
|
<div class="card">
|
||||||
|
<a class="back-link" href="/{% if user_uuid %}?uuid={{ user_uuid|urlencode }}{% endif %}">返回主页</a>
|
||||||
|
<h1>{{ project.title }}</h1>
|
||||||
|
<div class="project-subtitle">{{ project.subtitle }}</div>
|
||||||
|
<div class="toolbar">
|
||||||
|
<div>
|
||||||
|
<label for="dateInput">选择日期</label>
|
||||||
|
<input id="dateInput" type="date" value="{{ today }}">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="uuidInput">用户 UUID(从页面链接自动带入)</label>
|
||||||
|
<input id="uuidInput" value="{{ user_uuid }}" placeholder="可手动输入查询定位">
|
||||||
|
</div>
|
||||||
|
<div style="display:flex; align-items:flex-end;">
|
||||||
|
<button id="queryBtn" type="button">查询</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="meta" id="metaText">-</div>
|
||||||
|
<div class="ok-tip" id="userTip"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="width: 52px;">序号</th>
|
||||||
|
<th>workid</th>
|
||||||
|
{% if project.get('query_sql_list') %}
|
||||||
|
{% for b in project.get('query_sql_list') %}
|
||||||
|
<th style="width: 100px;">{{ b.get('label') or b.get('key', '') }}</th>
|
||||||
|
{% endfor %}
|
||||||
|
<th style="width: 110px;">总量</th>
|
||||||
|
{% else %}
|
||||||
|
<th style="width: 120px;">完成量</th>
|
||||||
|
{% endif %}
|
||||||
|
<th style="width: 120px;">标记</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="tableBody"></tbody>
|
||||||
|
</table>
|
||||||
|
<div class="empty" id="emptyText" style="display:none;">当前日期暂无数据</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function $(id) { return document.getElementById(id); }
|
||||||
|
|
||||||
|
function getQueryParam(name) {
|
||||||
|
try {
|
||||||
|
var usp = new URLSearchParams(window.location.search || '');
|
||||||
|
return String(usp.get(name) || '').trim();
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderRows(rows, breakdowns) {
|
||||||
|
var tb = $('tableBody');
|
||||||
|
var empty = $('emptyText');
|
||||||
|
tb.innerHTML = '';
|
||||||
|
if (!rows || !rows.length) {
|
||||||
|
empty.style.display = 'block';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
empty.style.display = 'none';
|
||||||
|
var hasCurrentUserRow = false;
|
||||||
|
breakdowns = breakdowns || [];
|
||||||
|
rows.forEach(function(row, idx) {
|
||||||
|
var tr = document.createElement('tr');
|
||||||
|
if (row.is_current_user) {
|
||||||
|
tr.className = 'current-user';
|
||||||
|
tr.id = 'currentUserRow';
|
||||||
|
hasCurrentUserRow = true;
|
||||||
|
}
|
||||||
|
var mark = row.is_current_user ? '<span class="tag">当前用户</span>' : '<span class="muted">-</span>';
|
||||||
|
var cells = '<td>' + (idx + 1) + '</td>' + '<td>' + (row.workid || '') + '</td>';
|
||||||
|
if (breakdowns.length) {
|
||||||
|
breakdowns.forEach(function(b) {
|
||||||
|
cells += '<td>' + (row['count_' + b.key] || 0) + '</td>';
|
||||||
|
});
|
||||||
|
cells += '<td>' + (row.count || 0) + '</td>';
|
||||||
|
} else {
|
||||||
|
cells += '<td>' + (row.count || 0) + '</td>';
|
||||||
|
}
|
||||||
|
cells += '<td>' + mark + '</td>';
|
||||||
|
tr.innerHTML = cells;
|
||||||
|
tb.appendChild(tr);
|
||||||
|
});
|
||||||
|
return hasCurrentUserRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function queryData() {
|
||||||
|
var dateVal = String(($('dateInput').value || '')).trim();
|
||||||
|
var uuidVal = String(($('uuidInput').value || '')).trim();
|
||||||
|
var meta = $('metaText');
|
||||||
|
var tip = $('userTip');
|
||||||
|
tip.textContent = '';
|
||||||
|
meta.textContent = '查询中...';
|
||||||
|
try {
|
||||||
|
var qs = new URLSearchParams();
|
||||||
|
if (dateVal) { qs.set('date', dateVal); }
|
||||||
|
if (uuidVal) { qs.set('uuid', uuidVal); }
|
||||||
|
var resp = await fetch('/api/project/{{ project_key }}/stats?' + qs.toString(), { method: 'GET' });
|
||||||
|
var data = await resp.json();
|
||||||
|
if (!data || !data.success) {
|
||||||
|
meta.textContent = '查询失败:' + ((data && data.error) ? data.error : '未知错误');
|
||||||
|
renderRows([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta.textContent = '日期:' + data.date + ',总人数:' + data.total + ',总完成量:' + data.sum_count;
|
||||||
|
var hasCurrentUserRow = renderRows(data.rows || [], data.breakdowns || []);
|
||||||
|
if (uuidVal) {
|
||||||
|
if (data.has_current_user) {
|
||||||
|
tip.textContent = '已定位到你的数据,绿色高亮行即当前登录 UUID 的统计。';
|
||||||
|
if (hasCurrentUserRow) {
|
||||||
|
var targetRow = $('currentUserRow');
|
||||||
|
if (targetRow && typeof targetRow.scrollIntoView === 'function') {
|
||||||
|
targetRow.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tip.textContent = '未匹配到当前 UUID 的数据。';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
meta.textContent = '查询失败:网络或服务异常';
|
||||||
|
renderRows([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(function init() {
|
||||||
|
var fromUrlUuid = getQueryParam('uuid');
|
||||||
|
if (fromUrlUuid && !$('uuidInput').value) {
|
||||||
|
$('uuidInput').value = fromUrlUuid;
|
||||||
|
}
|
||||||
|
$('queryBtn').addEventListener('click', queryData);
|
||||||
|
queryData();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user