|  | @@ -89,6 +89,8 @@ class EquipmentManagerV3(View):
 | 
	
		
			
				|  |  |              return self.verify_code(request_dict, response)
 | 
	
		
			
				|  |  |          elif operation == 'viewDevicePassword':
 | 
	
		
			
				|  |  |              return self.view_device_password(request_dict, response)
 | 
	
		
			
				|  |  | +        elif operation == 'editSortOrder':
 | 
	
		
			
				|  |  | +            return self.edit_sort_order(request_dict, response)
 | 
	
		
			
				|  |  |          else:
 | 
	
		
			
				|  |  |              return response.json(414)
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -823,6 +825,7 @@ class EquipmentManagerV3(View):
 | 
	
		
			
				|  |  |          if tko.code != 0:
 | 
	
		
			
				|  |  |              return response.json(tko.code)
 | 
	
		
			
				|  |  |          userID = tko.userID
 | 
	
		
			
				|  |  | +        UserDeviceService.init_device_sort_order(userID)
 | 
	
		
			
				|  |  |          group_id = int(request_dict.get('groupId', 0))
 | 
	
		
			
				|  |  |          # 查询设备列表以及设备uid集合
 | 
	
		
			
				|  |  |          dv_list, uid_list = UserDeviceService.query_device_list(userID, uid, NickName, page, line, group_id)
 | 
	
	
		
			
				|  | @@ -1416,3 +1419,46 @@ class EquipmentManagerV3(View):
 | 
	
		
			
				|  |  |              return response.json(0, res)
 | 
	
		
			
				|  |  |          except Exception as e:
 | 
	
		
			
				|  |  |              return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @staticmethod
 | 
	
		
			
				|  |  | +    def edit_sort_order(request_dict, response):
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +        修改设备排序
 | 
	
		
			
				|  |  | +        ids: 选中的设备id列表(单选或多选)
 | 
	
		
			
				|  |  | +        action: 操作类型(move/top/bottom)
 | 
	
		
			
				|  |  | +        target_id: 拖动目标id(仅单选拖动时用)
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +        ids = request_dict.get('ids', None)
 | 
	
		
			
				|  |  | +        action = request_dict.get('action', None)
 | 
	
		
			
				|  |  | +        target_id = request_dict.get('target_id', None)
 | 
	
		
			
				|  |  | +        if not ids or not action:
 | 
	
		
			
				|  |  | +            return response.json(444, 'ids or action missing')
 | 
	
		
			
				|  |  | +        try:
 | 
	
		
			
				|  |  | +            # 查询所有设备,按sort_order排序
 | 
	
		
			
				|  |  | +            all_devices = list(Device_Info.objects.all().order_by('-sort_order', '-data_joined'))
 | 
	
		
			
				|  |  | +            id_to_device = {str(d.id): d for d in all_devices}
 | 
	
		
			
				|  |  | +            # 单选拖动排序
 | 
	
		
			
				|  |  | +            if action == 'move' and len(ids) == 1 and target_id:
 | 
	
		
			
				|  |  | +                moving_id = ids[0]
 | 
	
		
			
				|  |  | +                moving_device = id_to_device.get(str(moving_id))
 | 
	
		
			
				|  |  | +                target_device = id_to_device.get(str(target_id))
 | 
	
		
			
				|  |  | +                if not moving_device or not target_device:
 | 
	
		
			
				|  |  | +                    return response.json(173, 'device not found')
 | 
	
		
			
				|  |  | +                target_index = all_devices.index(target_device)
 | 
	
		
			
				|  |  | +                all_devices.remove(moving_device)
 | 
	
		
			
				|  |  | +                all_devices.insert(target_index, moving_device)
 | 
	
		
			
				|  |  | +            # 勾选框批量置顶/置底
 | 
	
		
			
				|  |  | +            elif action in ('top', 'bottom'):
 | 
	
		
			
				|  |  | +                selected_devices = [id_to_device[i] for i in ids if i in id_to_device]
 | 
	
		
			
				|  |  | +                other_devices = [d for d in all_devices if str(d.id) not in ids]
 | 
	
		
			
				|  |  | +                if action == 'top':
 | 
	
		
			
				|  |  | +                    all_devices = selected_devices + other_devices
 | 
	
		
			
				|  |  | +                else:
 | 
	
		
			
				|  |  | +                    all_devices = other_devices + selected_devices
 | 
	
		
			
				|  |  | +            # 重新赋值sort_order
 | 
	
		
			
				|  |  | +            for idx, device in enumerate(all_devices):
 | 
	
		
			
				|  |  | +                device.sort_order = len(all_devices) - idx
 | 
	
		
			
				|  |  | +                device.save(update_fields=['sort_order'])
 | 
	
		
			
				|  |  | +            return response.json(0)
 | 
	
		
			
				|  |  | +        except Exception as e:
 | 
	
		
			
				|  |  | +            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 |