feat: 优化预约逻辑,增强映射表记录功能,提升用户体验

This commit is contained in:
Your Name committed 2026-01-17 18:46:13 +08:00
1 parent 54a99d4bbd
commit 3488624b8f
3 files changed
+382 -109

No files matched your search

+153 -29
View File
@@ -145,6 +145,9 @@ def main():
root = tk.Tk()
# 常量兜底:部分主题常量未提供时使用字符串
BOTTOM = "bottom"
root.title("抖音福袋挂机 - 可视化控制台")
root.geometry("1400x900") # 增大窗口尺寸,提供更多空间
@@ -2757,7 +2760,7 @@ def main():
# 将运行时映射表加入右侧 Notebook
mapping_tab = ttk.Frame(notebook)
map_box = ttk.LabelFrame(
mapping_tab, text="运行时映射表(room_pos -> (title, title_raw))"
mapping_tab, text="运行时映射表(包含福袋详情)"
)
map_box.pack(fill=X, padx=10, pady=(10, 10))
@@ -2774,44 +2777,76 @@ def main():
mapping_source_var = tk.StringVar(value="未加载")
ttk.Label(map_ctrl, textvariable=mapping_source_var).pack(side=LEFT, padx=(8, 0))
mapping_tree_box = ttk.Frame(mapping_tab)
mapping_tree_box.pack(fill=BOTH, expand=True, padx=10, pady=(6, 10))
mapping_tree = ttk.Treeview(
mapping_tab,
mapping_tree_box,
columns=(
"pos",
"title",
"title_raw",
"has_fudai",
"fudai_content",
"fudai_time",
"task_list",
"countdown",
"fudai_value",
"participants",
"copies",
"button_text",
"is_reserved",
),
show="headings",
height=12,
)
mapping_tree.heading("pos", text="位置")
mapping_tree.heading("title", text="标题")
mapping_tree.heading("title_raw", text="原始标题")
mapping_tree.heading("has_fudai", text="有福袋")
mapping_tree.heading("fudai_content", text="福袋内容")
mapping_tree.heading("fudai_time", text="开奖时间")
mapping_tree.heading("fudai_value", text="价值(元)")
mapping_tree.heading("participants", text="参与人数")
mapping_tree.heading("copies", text="份数")
mapping_tree.heading("is_reserved", text="已预约")
mapping_tree.column("pos", width=50, anchor="e")
mapping_tree.column("title", width=150, anchor="w")
mapping_tree.column("title_raw", width=150, anchor="w")
mapping_tree.column("has_fudai", width=60, anchor="center")
mapping_tree.column("fudai_content", width=150, anchor="w")
mapping_tree.column("fudai_time", width=120, anchor="center")
mapping_tree.column("fudai_value", width=80, anchor="e")
mapping_tree.column("participants", width=80, anchor="e")
mapping_tree.column("copies", width=60, anchor="e")
mapping_tree.column("is_reserved", width=60, anchor="center")
mapping_tree.pack(fill=BOTH, expand=True, padx=10, pady=(6, 10))
# 为表头指定对齐,便于阅读;长列允许 stretch 以便在窗口拉伸时扩展
mapping_tree.heading("pos", text="位置", anchor="center")
mapping_tree.heading("title", text="标题", anchor="w")
mapping_tree.heading("title_raw", text="原始标题", anchor="w")
mapping_tree.heading("has_fudai", text="有福袋", anchor="center")
mapping_tree.heading("fudai_content", text="福袋内容", anchor="w")
mapping_tree.heading("task_list", text="任务列表", anchor="w")
mapping_tree.heading("countdown", text="倒计时", anchor="center")
mapping_tree.heading("fudai_value", text="价值(元)", anchor="e")
mapping_tree.heading("participants", text="参与人数", anchor="e")
mapping_tree.heading("copies", text="份数", anchor="e")
mapping_tree.heading("button_text", text="按钮文本", anchor="w")
mapping_tree.heading("is_reserved", text="已预约", anchor="center")
# 优化列宽与伸缩行为:让标题/内容类列随窗口拉伸,数值列保持固定宽度
mapping_tree.column("pos", width=50, anchor="e", stretch=False)
mapping_tree.column("title", width=220, anchor="w", stretch=True)
mapping_tree.column("title_raw", width=220, anchor="w", stretch=True)
mapping_tree.column("has_fudai", width=60, anchor="center", stretch=False)
mapping_tree.column("fudai_content", width=300, anchor="w", stretch=True)
mapping_tree.column("task_list", width=240, anchor="w", stretch=True)
mapping_tree.column("countdown", width=90, anchor="center", stretch=False)
mapping_tree.column("fudai_value", width=90, anchor="e", stretch=False)
mapping_tree.column("participants", width=90, anchor="e", stretch=False)
mapping_tree.column("copies", width=70, anchor="e", stretch=False)
mapping_tree.column("button_text", width=180, anchor="w", stretch=True)
mapping_tree.column("is_reserved", width=70, anchor="center", stretch=False)
mapping_tree.tag_configure("odd", background="#fafafa")
mapping_tree.tag_configure("even", background="#ffffff")
map_scroll_y = ttk.Scrollbar(
mapping_tree_box, orient="vertical", command=mapping_tree.yview
)
map_scroll_x = ttk.Scrollbar(
mapping_tree_box, orient="horizontal", command=mapping_tree.xview
)
mapping_tree.configure(
yscrollcommand=map_scroll_y.set, xscrollcommand=map_scroll_x.set
)
# 使用 grid 布局使横向/纵向滚动条与 Treeview 精确对齐
mapping_tree_box.grid_rowconfigure(0, weight=1)
mapping_tree_box.grid_columnconfigure(0, weight=1)
mapping_tree.grid(row=0, column=0, sticky="nsew")
map_scroll_y.grid(row=0, column=1, sticky="ns")
map_scroll_x.grid(row=1, column=0, sticky="ew")
# 加载映射表到表格(尝试多个可能的路径)
def _load_mapping_to_view():
@@ -2863,6 +2898,7 @@ def main():
]
found = False
row_index = 0
for p in possible_paths:
try:
if os.path.exists(p):
@@ -2891,7 +2927,10 @@ def main():
"",
"",
"",
"",
"",
),
tags=("even",),
)
else:
# 移除元信息
@@ -2921,7 +2960,54 @@ def main():
# 提取福袋详细信息
fudai_detail = v.get("fudai_detail")
if (
task_list = "-"
button_text = "-"
countdown_text = "-"
if isinstance(fudai_detail, dict):
task_list = (
str(fudai_detail.get("task_list") or "")
.strip()
or "-"
)
button_text = (
str(fudai_detail.get("button_text") or "")
.strip()
or "-"
)
fudai_time = (
str(fudai_detail.get("time_text") or "")
.strip()
or "-"
)
fudai_value = (
f"{float(fudai_detail.get('prize_value_yuan') or 0):.2f}"
if fudai_detail.get("prize_value_yuan")
else "-"
)
participants = (
str(fudai_detail.get("participants") or 0)
if fudai_detail.get("participants")
else "-"
)
copies = (
str(fudai_detail.get("copies") or 0)
if fudai_detail.get("copies")
else "-"
)
mm = str(fudai_detail.get("countdown_mm") or "").strip()
ss = str(fudai_detail.get("countdown_ss") or "").strip()
if fudai_time and fudai_time != "-":
countdown_text = fudai_time
elif mm or ss:
if mm.isdigit() and len(mm) == 1:
mm = f"0{mm}"
if ss.isdigit() and len(ss) == 1:
ss = f"0{ss}"
if mm and ss:
countdown_text = f"{mm}:{ss}"
else:
countdown_text = mm or ss
elif (
fudai_detail
and isinstance(fudai_detail, (tuple, list))
and len(fudai_detail) >= 5
@@ -2943,11 +3029,13 @@ def main():
if fudai_detail[3]
else "-"
) # copies
countdown_text = fudai_time or "-"
else:
fudai_time = "-"
fudai_value = "-"
participants = "-"
copies = "-"
countdown_text = "-"
# 检查是否已预约
is_reserved = (
@@ -2961,9 +3049,12 @@ def main():
has_fudai = ""
fudai_content = "-"
fudai_time = "-"
countdown_text = "-"
fudai_value = "-"
participants = "-"
copies = "-"
task_list = "-"
button_text = "-"
is_reserved = (
"✓" if int(k) in reservations_data else ""
)
@@ -2973,12 +3064,27 @@ def main():
title_raw,
has_fudai,
fudai_content,
fudai_time,
task_list,
countdown_text,
fudai_value,
participants,
copies,
button_text,
is_reserved,
) = ("-", "-", "", "-", "-", "-", "-", "-", "-")
) = (
"-",
"-",
"",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
)
row_tag = "even" if row_index % 2 == 0 else "odd"
mapping_tree.insert(
"",
"end",
@@ -2988,13 +3094,17 @@ def main():
title_raw,
has_fudai,
fudai_content,
fudai_time,
task_list,
countdown_text,
fudai_value,
participants,
copies,
button_text,
is_reserved,
),
tags=(row_tag,),
)
row_index += 1
found = True
break
@@ -3007,7 +3117,21 @@ def main():
mapping_tree.insert(
"",
"end",
values=("-", "未找到映射表文件", "", "", "", "", "", "", "", ""),
values=(
"-",
"未找到映射表文件",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
),
tags=("even",),
)
# 绑定刷新按钮与自动刷新