feat:新增代码注释
This commit is contained in:
@@ -7,14 +7,23 @@ from app.schemas.screen import Layout, Screen
|
||||
|
||||
class ResizeHandler(BaseActionHandler[ResizeAction]):
|
||||
def apply(self, screen: Screen, action: ResizeAction) -> Screen:
|
||||
# 确认目标存在,并取得大屏副本及副本中的目标节点
|
||||
result, target = self.copy_target(screen, action.target_id)
|
||||
# 将原布局转成字典,便于替换尺寸后重新校验
|
||||
layout = target.layout.model_dump()
|
||||
|
||||
# 仅替换提供的尺寸,位置和其他布局字段保持不变
|
||||
if action.width is not None:
|
||||
layout["width"] = action.width
|
||||
|
||||
# 如果提供了高度,则替换为指定值,否则沿用原高度
|
||||
if action.height is not None:
|
||||
layout["height"] = action.height
|
||||
|
||||
# 重新校验完整布局,确保更新后的宽高等字段仍满足协议约束
|
||||
target.layout = Layout.model_validate(layout)
|
||||
|
||||
# 返回调整尺寸后的大屏副本
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user