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
+41
View File
@@ -0,0 +1,41 @@
"""移动组件的后端模拟执行"""
from app.actions.base import BaseActionHandler
from app.schemas.actions import MoveAction
from app.schemas.screen import Layout, Screen
class MoveHandler(BaseActionHandler[MoveAction]):
def apply(self, screen: Screen, action: MoveAction) -> Screen:
result, target = self.copy_target(screen, action.target_id)
layout = target.layout.model_dump()
layout["x"] += action.delta_x
layout["y"] += action.delta_y
# 重新校验计算结果,防止浮点溢出产生无效坐标
target.layout = Layout.model_validate(layout)
return result
if __name__ == "__main__":
screen = Screen.model_validate(
{
"canvas": {"width": 1920, "height": 1080},
"nodes": [
{
"id": "sales-chart",
"type": "chart",
"layout": {"x": 100, "y": 200, "width": 400, "height": 300},
}
],
}
)
action = MoveAction(target_id="sales-chart", delta_x=50)
handler = MoveHandler()
final_screen = handler.apply(screen, action)
print(final_screen.model_dump_json(indent=2))
print("原始坐标:", screen.nodes[0].layout.x, screen.nodes[0].layout.y)
try:
handler.apply(screen, MoveAction(target_id="missing", delta_x=50))
except ValueError as error:
print("无效目标:", error)