65 lines
3.2 KiB
Python
65 lines
3.2 KiB
Python
from __future__ import annotations
|
|
|
|
import tkinter as tk
|
|
|
|
from . import theme
|
|
from .data import DashboardData, fmt_ts
|
|
from .page_context import PageContext
|
|
from .page_helpers import reservation_rows
|
|
from .widgets import card, flow_grid, mini_table, section, stat_tile, table_panel, text_panel
|
|
|
|
|
|
def build_home(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "数据看板", "运行状态 / 截图 / 队列 / 记录")
|
|
metrics = flow_grid(parent, 3)
|
|
values = [
|
|
("运行日志", len(data.run_log), "最近记录", theme.TEAL, theme.TEAL_SOFT),
|
|
("行为日志", len(data.action_log), "动作流", theme.BLUE, theme.BLUE_SOFT),
|
|
("预约队列", len(data.reservations), "等待处理", theme.AMBER, theme.AMBER_SOFT),
|
|
("高价值房间", len(data.high_value_rooms), "本地记录", theme.GREEN, theme.GREEN_SOFT),
|
|
("中奖截图", len(data.win_images), "pic/lottery", theme.RED, theme.RED_SOFT),
|
|
("映射条目", len(data.mapping_rows), "room_pos", theme.TEAL_DARK, theme.TEAL_SOFT),
|
|
]
|
|
for idx, item in enumerate(values):
|
|
stat_tile(metrics, *item[:3], color=item[3], soft=item[4]).grid(row=idx // 3, column=idx % 3, sticky="ew", padx=5, pady=5)
|
|
|
|
body = tk.Frame(parent, bg=theme.BG)
|
|
body.pack(fill="both", expand=True)
|
|
body.grid_columnconfigure(0, weight=1, minsize=520)
|
|
body.grid_columnconfigure(1, weight=0, minsize=320)
|
|
|
|
left = tk.Frame(body, bg=theme.BG)
|
|
right = tk.Frame(body, bg=theme.BG)
|
|
left.grid(row=0, column=0, sticky="nsew", padx=(0, 8))
|
|
right.grid(row=0, column=1, sticky="nsew", padx=(8, 0))
|
|
|
|
rows = reservation_rows(data)
|
|
for row in rows:
|
|
row["time"] = fmt_ts(row["time"])
|
|
table_panel(left, "预约队列", (
|
|
("idx", "#", 28), ("title", "直播间", 110), ("content", "内容", 180),
|
|
("value", "价值", 52), ("status", "状态", 58), ("time", "时间", 96),
|
|
), rows, height=8).pack(fill="both", expand=True, pady=(0, 12))
|
|
|
|
high_rows = []
|
|
for item in data.high_value_rooms[:8]:
|
|
high_rows.append((
|
|
str(item.get("room_title") or item.get("title") or "-")[:18],
|
|
str(item.get("prize_value_yuan") or item.get("value") or "-"),
|
|
str(item.get("status") or "已记录"),
|
|
))
|
|
mini_table(left, "高价值房间", high_rows, color=theme.GREEN).pack(fill="x", pady=(0, 12))
|
|
text_panel(left, "运行日志", data.run_log[-80:], height=9).pack(fill="both", expand=True)
|
|
|
|
snap = card(right, "当前截图")
|
|
snap.pack(fill="x", pady=(0, 12))
|
|
snap_name = data.screenshot_path.name if data.screenshot_path else "暂无截图"
|
|
tk.Label(snap, text=snap_name, bg="#fbfcfa", fg=theme.TEXT, font=theme.FONT_UI, anchor="w").pack(fill="x", padx=12, pady=(4, 6))
|
|
tk.Label(snap, text="完整预览请打开“截图预览”界面", bg=theme.TEAL_SOFT, fg=theme.TEAL_DARK, font=theme.FONT_SMALL, padx=8, pady=3).pack(anchor="w", padx=12, pady=(0, 12))
|
|
text_panel(right, "实时动作", data.action_log[-80:], height=9).pack(fill="both", expand=True)
|
|
|
|
|
|
def build_statistics(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
|
|
section(parent, "统计信息", "本地运行统计看板")
|
|
build_home(parent, data, ctx)
|