feat: 添加判断修改范围、规划和资源需求节点

This commit is contained in:
2026-09-23 16:51:10 +08:00
parent 5ef873bfe9
commit 5f5d733a9b
11 changed files with 566 additions and 1 deletions
+24
View File
@@ -0,0 +1,24 @@
"""动作处理器公共接口"""
from abc import ABC, abstractmethod
from typing import Generic, TypeVar
from app.schemas.actions import BaseAction
from app.schemas.screen import Screen, ScreenNode
ActionT = TypeVar("ActionT", bound=BaseAction)
class BaseActionHandler(ABC, Generic[ActionT]):
@abstractmethod
def apply(self, screen: Screen, action: ActionT) -> Screen:
"""校验并在副本上执行动作,返回新的大屏"""
raise NotImplementedError
def copy_target(self, screen: Screen, target_id: str) -> tuple[Screen, ScreenNode]:
# 先确认目标存在,再复制,避免修改原始快照
for index, node in enumerate(screen.nodes):
if node.id == target_id:
result = screen.model_copy(deep=True)
return result, result.nodes[index]
raise ValueError(f"目标组件不存在: {target_id}")