feat: 优化托盘号加载逻辑,简化下拉框项目添加方式,确保未找到托盘号时下拉框保持为空
This commit is contained in:
parent
584f98a1a2
commit
443dc2d416
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -322,34 +322,28 @@ class MainWindow(MainWindowUI):
|
|||||||
|
|
||||||
if pallet_codes and len(pallet_codes) > 0:
|
if pallet_codes and len(pallet_codes) > 0:
|
||||||
# 添加托盘号到下拉框
|
# 添加托盘号到下拉框
|
||||||
for code in pallet_codes:
|
self.tray_edit.addItems(pallet_codes)
|
||||||
self.tray_edit.addItem(code)
|
|
||||||
|
|
||||||
# 如果有之前的选择,尝试恢复它
|
# 如果有之前的选择,尝试恢复它
|
||||||
if current_text:
|
index = self.tray_edit.findText(current_text)
|
||||||
index = self.tray_edit.findText(current_text)
|
if index != -1:
|
||||||
if index >= 0:
|
self.tray_edit.setCurrentIndex(index)
|
||||||
self.tray_edit.setCurrentIndex(index)
|
else:
|
||||||
|
self.tray_edit.setCurrentIndex(-1)
|
||||||
|
self.tray_edit.setCurrentText("")
|
||||||
|
|
||||||
logging.info(f"已加载托盘号,共 {len(pallet_codes)} 个")
|
logging.info(f"已加载托盘号,共 {len(pallet_codes)} 个")
|
||||||
else:
|
else:
|
||||||
# 如果没有托盘号,添加默认项
|
# 如果没有托盘号,则不添加任何项目,保持为空
|
||||||
default_codes = ["托盘1", "托盘2", "托盘3", "托盘4", "托盘5", "托盘6"]
|
logging.warning("未找到托盘号,托盘号列表将为空")
|
||||||
for code in default_codes:
|
self.tray_edit.setCurrentText("")
|
||||||
self.tray_edit.addItem(code)
|
|
||||||
logging.warning("未找到托盘号,使用默认值")
|
|
||||||
|
|
||||||
# 尝试恢复之前的选择
|
|
||||||
if current_text:
|
|
||||||
index = self.tray_edit.findText(current_text)
|
|
||||||
if index >= 0:
|
|
||||||
self.tray_edit.setCurrentIndex(index)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"加载托盘号失败: {str(e)}")
|
logging.error(f"加载托盘号失败: {str(e)}")
|
||||||
# 如果加载失败,添加默认项
|
# 如果加载失败,确保下拉框为空
|
||||||
self.tray_edit.clear()
|
self.tray_edit.clear()
|
||||||
default_codes = ["托盘1", "托盘2", "托盘3", "托盘4", "托盘5", "托盘6"]
|
self.tray_edit.setCurrentText("")
|
||||||
for code in default_codes:
|
|
||||||
self.tray_edit.addItem(code)
|
|
||||||
|
|
||||||
def show_settings_page(self):
|
def show_settings_page(self):
|
||||||
"""显示设置页面"""
|
"""显示设置页面"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user