feat: 接入新动作 update_canvas
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ def plan_block_reason(state: QueryState) -> str | None:
|
||||
if state["requirement"].needs_clarification:
|
||||
return "需求尚未澄清,不能生成规划动作"
|
||||
if plan.canvas_changes:
|
||||
return "规划包含画布修改,当前尚未接入对应动作"
|
||||
return "规划中的画布修改尚未接入,当前仅支持无需规划的画布修改"
|
||||
if plan.resource_needs:
|
||||
return "规划仍有待获取资源,不能直接生成动作"
|
||||
additions = [item for item in plan.components if item.disposition == "add"]
|
||||
|
||||
@@ -8,6 +8,7 @@ from app.actions.delete import DeleteHandler
|
||||
from app.actions.move import MoveHandler
|
||||
from app.actions.resize import ResizeHandler
|
||||
from app.actions.update import UpdateHandler
|
||||
from app.actions.update_canvas import UpdateCanvasHandler
|
||||
from app.schemas.actions import Action
|
||||
from app.schemas.screen import Screen
|
||||
|
||||
@@ -18,6 +19,7 @@ ACTION_HANDLERS: dict[str, BaseActionHandler[Any]] = {
|
||||
"move": MoveHandler(),
|
||||
"resize": ResizeHandler(),
|
||||
"update": UpdateHandler(),
|
||||
"update_canvas": UpdateCanvasHandler(),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
"""在大屏副本上更新画布属性,检查修改后的 Canvas 是否有效"""
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
from app.actions.base import BaseActionHandler
|
||||
from app.schemas.actions import UpdateCanvasAction
|
||||
from app.schemas.screen import Canvas, Screen
|
||||
|
||||
|
||||
class UpdateCanvasHandler(BaseActionHandler[UpdateCanvasAction]):
|
||||
def apply(self, screen: Screen, action: UpdateCanvasAction) -> Screen:
|
||||
properties = screen.canvas.model_dump()
|
||||
# 顶层字段整体替换,嵌套对象不做深度合并
|
||||
properties.update(deepcopy(action.properties))
|
||||
canvas = Canvas.model_validate(properties)
|
||||
result = screen.model_copy(deep=True)
|
||||
result.canvas = canvas
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
screen = Screen.model_validate(
|
||||
{"canvas": {"width": 1920, "height": 1080}, "nodes": []}
|
||||
)
|
||||
action = UpdateCanvasAction(
|
||||
properties={"backgroundColor": "#000000", "width": 1600}
|
||||
)
|
||||
result = UpdateCanvasHandler().apply(screen, action)
|
||||
print(result.model_dump_json(indent=2))
|
||||
print("原始画布:", screen.canvas.model_dump())
|
||||
Reference in New Issue
Block a user