Skip to content

Commit e16209d

Browse files
committed
一些bug修复
1 parent 29ed522 commit e16209d

7 files changed

Lines changed: 99 additions & 0 deletions

File tree

CHANGELOG/v2.3.0-beta.2/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ v2.3 - Shiroko (砂狼白子) beta 2
1313
## 🐛 修复问题
1414

1515
- 修复 **点名/抽奖**,剩余不足时不再重置抽取
16+
- 修复 **点名/抽奖**,重置后人数标签不更新
17+
- 修复 **半重复**,重置后历史缓存未刷新
1618

1719
## 🔧 其它变更
1820

app/Language/modules/more_settings.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@
246246
behind_scenes_settings = {
247247
"ZH_CN": {
248248
"title": {"name": "内幕设置", "description": "设置特定人员的抽取概率"},
249+
"enabled_global": {
250+
"name": "内幕总开关",
251+
"description": "开启后启用内幕权重与必中规则",
252+
"switchbutton_name": {"enable": "", "disable": ""},
253+
},
249254
"select_mode": {"name": "选择模式", "description": "选择点名或抽奖模式"},
250255
"mode_options": {"combo_items": ["点名", "抽奖"]},
251256
"select_list": {"name": "选择名单", "description": "选择要设置概率的名单"},
@@ -268,6 +273,11 @@
268273
"name": "Behind the Scenes Settings",
269274
"description": "Set draw probability for specific persons",
270275
},
276+
"enabled_global": {
277+
"name": "Master switch",
278+
"description": "Enable behind-scenes weights and guaranteed rules",
279+
"switchbutton_name": {"enable": "", "disable": ""},
280+
},
271281
"select_mode": {
272282
"name": "Select Mode",
273283
"description": "Select roll call or lottery mode",
@@ -302,6 +312,11 @@
302312
"name": "裏設定",
303313
"description": "特定の人物の抽選確率を設定",
304314
},
315+
"enabled_global": {
316+
"name": "裏設定の総スイッチ",
317+
"description": "オンにすると重み付けと必中ルールを有効化",
318+
"switchbutton_name": {"enable": "", "disable": ""},
319+
},
305320
"select_mode": {
306321
"name": "モード選択",
307322
"description": "点呼または抽選モードを選択",

app/common/behind_scenes/behind_scenes_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def get_probability_settings(name, mode, pool_name=None):
6262
"""
6363
try:
6464
settings = BehindScenesUtils.get_behind_scenes_settings()
65+
if (
66+
settings
67+
and isinstance(settings, dict)
68+
and not settings.get("enabled_global", True)
69+
):
70+
return {"enabled": False, "probability": 1.0}
6571
if name in settings:
6672
if mode == 0:
6773
# 点名模式
@@ -100,6 +106,12 @@ def apply_probability_weights(
100106
"""
101107
try:
102108
settings = BehindScenesUtils.get_behind_scenes_settings()
109+
if (
110+
settings
111+
and isinstance(settings, dict)
112+
and not settings.get("enabled_global", True)
113+
):
114+
return students_dict_list, [1.0] * len(students_dict_list)
103115

104116
# 构建抽中奖品集合(用于快速查找)
105117
drawn_prizes = set(prize_list) if prize_list else set()
@@ -193,6 +205,12 @@ def apply_probability_weights_to_items(items, mode, pool_name):
193205
"""
194206
try:
195207
settings = BehindScenesUtils.get_behind_scenes_settings()
208+
if (
209+
settings
210+
and isinstance(settings, dict)
211+
and not settings.get("enabled_global", True)
212+
):
213+
return items, [1.0] * len(items)
196214

197215
filtered_items = []
198216
weights = []

app/common/lottery/lottery_manager.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,14 @@ def stop_animation(widget):
879879
)
880880

881881
if isinstance(result, dict) and result.get("reset_required"):
882+
update_many_count_label(widget)
883+
if (
884+
hasattr(widget, "remaining_list_page")
885+
and widget.remaining_list_page is not None
886+
and hasattr(widget.remaining_list_page, "count_changed")
887+
):
888+
widget.remaining_list_page.count_changed.emit(widget.remaining_count)
889+
QTimer.singleShot(APP_INIT_DELAY, widget._update_remaining_list_delayed)
882890
return
883891

884892
widget.final_selected_students = result.get("selected_prizes") or result.get(

app/common/roll_call/roll_call_manager.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,16 @@ def stop_animation(widget):
560560

561561
result = widget.manager.finalize_draw(widget.current_count, parent=widget)
562562
if isinstance(result, dict) and result.get("reset_required"):
563+
update_many_count_label(widget)
564+
if (
565+
hasattr(widget, "remaining_list_page")
566+
and widget.remaining_list_page is not None
567+
and hasattr(widget.remaining_list_page, "count_changed")
568+
):
569+
widget.remaining_list_page.count_changed.emit(widget.remaining_count)
570+
QTimer.singleShot(
571+
APP_INIT_DELAY, lambda: _update_remaining_list_delayed(widget)
572+
)
563573
return
564574

565575
widget.final_selected_students = result.get("selected_students") or []

app/common/roll_call/roll_call_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,9 @@ def reset_drawn_records(window, class_name, gender_filter, group_filter):
468468
group_filter: 小组过滤器
469469
"""
470470
reset_drawn_record(window, class_name, gender_filter, group_filter)
471+
record_key = f"{class_name}_{gender_filter}_{group_filter}"
472+
if record_key in RollCallUtils._drawn_record_cache:
473+
del RollCallUtils._drawn_record_cache[record_key]
471474

472475
@staticmethod
473476
def update_start_button_state(button, total_count):

app/view/settings/more_settings/behind_scenes_settings.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
read_behind_scenes_settings,
2020
write_behind_scenes_settings,
2121
)
22+
from app.common.behind_scenes.behind_scenes_utils import BehindScenesUtils
2223
from app.view.settings.list_management.shared_file_watcher import (
2324
get_shared_file_watcher,
2425
)
@@ -116,6 +117,22 @@ def __init__(self, parent=None):
116117

117118
def create_class_selection(self):
118119
"""创建班级选择区域"""
120+
self.enabled_global_switch = SwitchButton()
121+
self.enabled_global_switch.setOffText(
122+
get_content_switchbutton_name_async(
123+
"behind_scenes_settings", "enabled_global", "disable"
124+
)
125+
)
126+
self.enabled_global_switch.setOnText(
127+
get_content_switchbutton_name_async(
128+
"behind_scenes_settings", "enabled_global", "enable"
129+
)
130+
)
131+
self.enabled_global_switch.setChecked(self._get_enabled_global_value())
132+
self.enabled_global_switch.checkedChanged.connect(
133+
self.on_enabled_global_changed
134+
)
135+
119136
# 模式选择(点名/抽奖)
120137
self.mode_comboBox = ComboBox()
121138
self.mode_comboBox.addItems(
@@ -144,6 +161,12 @@ def create_class_selection(self):
144161
self.pool_comboBox.setVisible(False)
145162
self.pool_comboBox.currentIndexChanged.connect(self.refresh_data)
146163

164+
self.addGroup(
165+
get_theme_icon("ic_fluent_power_20_filled"),
166+
get_content_name_async("behind_scenes_settings", "enabled_global"),
167+
get_content_description_async("behind_scenes_settings", "enabled_global"),
168+
self.enabled_global_switch,
169+
)
147170
self.addGroup(
148171
get_theme_icon("ic_fluent_lottery_20_filled"),
149172
get_content_name_async("behind_scenes_settings", "select_mode"),
@@ -163,6 +186,26 @@ def create_class_selection(self):
163186
self.pool_comboBox,
164187
)
165188

189+
def _get_enabled_global_value(self) -> bool:
190+
try:
191+
settings = read_behind_scenes_settings()
192+
if not settings or not isinstance(settings, dict):
193+
return True
194+
return bool(settings.get("enabled_global", True))
195+
except Exception:
196+
return True
197+
198+
def on_enabled_global_changed(self):
199+
try:
200+
settings = read_behind_scenes_settings()
201+
if not settings or not isinstance(settings, dict):
202+
settings = {}
203+
settings["enabled_global"] = bool(self.enabled_global_switch.isChecked())
204+
write_behind_scenes_settings(settings)
205+
BehindScenesUtils.clear_cache()
206+
except Exception as e:
207+
logger.exception(f"保存内幕总开关失败: {e}")
208+
166209
def on_mode_changed(self):
167210
"""当模式改变时,更新名单下拉框"""
168211
mode = self.mode_comboBox.currentIndex()

0 commit comments

Comments
 (0)