PUGE vor 3 Wochen
Ursprung
Commit
a52aadc0bc
2 geänderte Dateien mit 100 neuen und 7 gelöschten Zeilen
  1. 5 1
      config.json
  2. 95 6
      三一平台.py

+ 5 - 1
config.json

@@ -1,4 +1,8 @@
 {
     "username": "深金川",
-    "folder_path": "C:/Users/mail/Documents/GitHub/pythonTest"
+    "folder_path": "C:/Users/mail/Documents/GitHub/pythonTest",
+    "last_load_client": "",
+    "last_unload_client": "",
+    "last_load_region": "",
+    "last_unload_region": ""
 }

+ 95 - 6
三一平台.py

@@ -356,6 +356,12 @@ class MainWindow(QMainWindow):
         self.regions = []
         self.region_cars = {}
         
+        # 保存上次选择的配置
+        self.last_load_client = ""  # 上次选择的装车客户端userID
+        self.last_unload_client = ""  # 上次选择的卸车客户端userID
+        self.last_load_region = ""  # 上次选择的装车区域ID
+        self.last_unload_region = ""  # 上次选择的卸车区域ID
+        
         self.initUI()
         self.load_config()
     
@@ -772,9 +778,11 @@ class MainWindow(QMainWindow):
         self.receive_client_combo.clear()
         
         # 添加默认选项
-        self.send_client_combo.addItem("请选择装车客户端")
-        self.receive_client_combo.addItem("请选择卸车客户端")
+        self.send_client_combo.addItem("请选择装车客户端", "")
+        self.receive_client_combo.addItem("请选择卸车客户端", "")
         
+        # 保存所有客户端的显示名称和userID映射
+        client_map = {}
         for client in clients:
             # 过滤掉 admin 为 true 的客户端(这些是管理端,不是扫码客户端)
             if client.get('admin', False):
@@ -787,13 +795,38 @@ class MainWindow(QMainWindow):
             if client_id and user_id and is_active:
                 # 使用 userID 作为键存储客户端信息
                 self.online_clients[user_id] = client
-                # 显示时显示 id,但存储 userID
                 display_name = f"{client_id}"
+                client_map[user_id] = display_name
                 self.send_client_combo.addItem(display_name, user_id)
                 self.receive_client_combo.addItem(display_name, user_id)
                 self.add_log(f"发现客户端: {client_id} (userID: {user_id})")
         
         self.add_log(f"✅ 已加载 {len(self.online_clients)} 个在线扫码客户端")
+        
+        # 尝试恢复上次选择的客户端
+        self.restore_client_selection()
+    
+    def restore_client_selection(self):
+        """恢复上次选择的客户端"""
+        # 恢复装车客户端
+        if self.last_load_client:
+            index = self.send_client_combo.findData(self.last_load_client)
+            if index >= 0:
+                self.send_client_combo.setCurrentIndex(index)
+                self.add_log(f"🔄 恢复装车客户端选择: {self.send_client_combo.currentText()}")
+            else:
+                self.add_log(f"⚠️ 上次选择的装车客户端 (userID: {self.last_load_client}) 不在线,请重新选择")
+                self.last_load_client = ""  # 清空无效的选择
+        
+        # 恢复卸车客户端
+        if self.last_unload_client:
+            index = self.receive_client_combo.findData(self.last_unload_client)
+            if index >= 0:
+                self.receive_client_combo.setCurrentIndex(index)
+                self.add_log(f"🔄 恢复卸车客户端选择: {self.receive_client_combo.currentText()}")
+            else:
+                self.add_log(f"⚠️ 上次选择的卸车客户端 (userID: {self.last_unload_client}) 不在线,请重新选择")
+                self.last_unload_client = ""  # 清空无效的选择
     
     def refresh_client_list(self):
         """刷新客户端列表"""
@@ -912,13 +945,16 @@ class MainWindow(QMainWindow):
         
         self.load_region_combo.clear()
         self.unload_region_combo.clear()
-        self.load_region_combo.addItem("请选择装车区域")
-        self.unload_region_combo.addItem("请选择卸车区域")
+        self.load_region_combo.addItem("请选择装车区域", "")
+        self.unload_region_combo.addItem("请选择卸车区域", "")
         
+        # 保存区域ID到显示名称的映射
+        region_map = {}
         for region in self.regions:
             region_name = region.get('regionName', '未知')
             region_id = region.get('regionId', '')
             display = f"{region_name}"
+            region_map[region_id] = display
             self.load_region_combo.addItem(display, region_id)
             self.unload_region_combo.addItem(display, region_id)
             self.region_cars[region_id] = region.get('carList', [])
@@ -926,6 +962,31 @@ class MainWindow(QMainWindow):
         self.update_region_status()
         self.statusBar().showMessage(f"加载了 {len(self.regions)} 个区域")
         self.add_log(f"✅ 加载了 {len(self.regions)} 个区域")
+        
+        # 尝试恢复上次选择的区域
+        self.restore_region_selection()
+    
+    def restore_region_selection(self):
+        """恢复上次选择的区域"""
+        # 恢复装车区域
+        if self.last_load_region:
+            index = self.load_region_combo.findData(self.last_load_region)
+            if index >= 0:
+                self.load_region_combo.setCurrentIndex(index)
+                self.add_log(f"🔄 恢复装车区域选择: {self.load_region_combo.currentText()}")
+            else:
+                self.add_log(f"⚠️ 上次选择的装车区域已不存在,请重新选择")
+                self.last_load_region = ""  # 清空无效的选择
+        
+        # 恢复卸车区域
+        if self.last_unload_region:
+            index = self.unload_region_combo.findData(self.last_unload_region)
+            if index >= 0:
+                self.unload_region_combo.setCurrentIndex(index)
+                self.add_log(f"🔄 恢复卸车区域选择: {self.unload_region_combo.currentText()}")
+            else:
+                self.add_log(f"⚠️ 上次选择的卸车区域已不存在,请重新选择")
+                self.last_unload_region = ""  # 清空无效的选择
     
     def on_regions_error(self, error_msg):
         self.refresh_region_btn.setEnabled(True)
@@ -1175,6 +1236,9 @@ class MainWindow(QMainWindow):
             if reply == QMessageBox.No:
                 return
         
+        # 保存当前选择到配置
+        self.save_current_selections()
+        
         self.is_monitoring = True
         self.start_btn.setEnabled(False)
         self.stop_btn.setEnabled(True)
@@ -1202,6 +1266,19 @@ class MainWindow(QMainWindow):
         
         self.statusBar().showMessage("监控运行中...")
     
+    def save_current_selections(self):
+        """保存当前选择的客户端和区域"""
+        # 保存客户端选择
+        self.last_load_client = self.send_client_combo.currentData() or ""
+        self.last_unload_client = self.receive_client_combo.currentData() or ""
+        
+        # 保存区域选择
+        self.last_load_region = self.load_region_combo.currentData() or ""
+        self.last_unload_region = self.unload_region_combo.currentData() or ""
+        
+        # 保存到配置文件
+        self.save_config()
+    
     def stop_monitoring(self):
         self.is_monitoring = False
         self.refresh_timer.stop()
@@ -1377,7 +1454,11 @@ class MainWindow(QMainWindow):
     def save_config(self):
         config = {
             'username': self.username_input.text(),
-            'folder_path': self.folder_path_input.text()
+            'folder_path': self.folder_path_input.text(),
+            'last_load_client': self.last_load_client,
+            'last_unload_client': self.last_unload_client,
+            'last_load_region': self.last_load_region,
+            'last_unload_region': self.last_unload_region
         }
         try:
             with open('config.json', 'w', encoding='utf-8') as f:
@@ -1395,6 +1476,14 @@ class MainWindow(QMainWindow):
                     if folder_path:
                         self.folder_path_input.setText(folder_path)
                         self.folder_path = folder_path
+                    
+                    # 加载上次选择的客户端
+                    self.last_load_client = config.get('last_load_client', '')
+                    self.last_unload_client = config.get('last_unload_client', '')
+                    
+                    # 加载上次选择的区域
+                    self.last_load_region = config.get('last_load_region', '')
+                    self.last_unload_region = config.get('last_unload_region', '')
             except:
                 pass