feat: 优化托盘号加载逻辑,简化下拉框项目添加方式,确保未找到托盘号时下拉框保持为空

This commit is contained in:
zhu-mengmeng 2025-06-24 17:30:22 +08:00
parent 584f98a1a2
commit 443dc2d416
2 changed files with 15 additions and 21 deletions

Binary file not shown.

View File

@ -322,34 +322,28 @@ class MainWindow(MainWindowUI):
if pallet_codes and len(pallet_codes) > 0:
# 添加托盘号到下拉框
for code in pallet_codes:
self.tray_edit.addItem(code)
self.tray_edit.addItems(pallet_codes)
# 如果有之前的选择,尝试恢复它
if current_text:
index = self.tray_edit.findText(current_text)
if index >= 0:
if index != -1:
self.tray_edit.setCurrentIndex(index)
else:
self.tray_edit.setCurrentIndex(-1)
self.tray_edit.setCurrentText("")
logging.info(f"已加载托盘号,共 {len(pallet_codes)}")
else:
# 如果没有托盘号,添加默认项
default_codes = ["托盘1", "托盘2", "托盘3", "托盘4", "托盘5", "托盘6"]
for code in default_codes:
self.tray_edit.addItem(code)
logging.warning("未找到托盘号,使用默认值")
# 如果没有托盘号,则不添加任何项目,保持为空
logging.warning("未找到托盘号,托盘号列表将为空")
self.tray_edit.setCurrentText("")
# 尝试恢复之前的选择
if current_text:
index = self.tray_edit.findText(current_text)
if index >= 0:
self.tray_edit.setCurrentIndex(index)
except Exception as e:
logging.error(f"加载托盘号失败: {str(e)}")
# 如果加载失败,添加默认项
# 如果加载失败,确保下拉框为空
self.tray_edit.clear()
default_codes = ["托盘1", "托盘2", "托盘3", "托盘4", "托盘5", "托盘6"]
for code in default_codes:
self.tray_edit.addItem(code)
self.tray_edit.setCurrentText("")
def show_settings_page(self):
"""显示设置页面"""