26 lines
770 B
Python
26 lines
770 B
Python
"""设置组件的绝对尺寸"""
|
|
|
|
from typing import Literal, Self
|
|
|
|
from pydantic import Field, model_validator
|
|
|
|
from app.schemas.screen import PositiveNumber
|
|
|
|
from .base import BaseAction
|
|
|
|
|
|
class ResizeAction(BaseAction):
|
|
type: Literal["resize"] = "resize"
|
|
width: PositiveNumber | None = Field(
|
|
default=None, description="目标宽度,单位 px,省略或 null 表示保持原值"
|
|
)
|
|
height: PositiveNumber | None = Field(
|
|
default=None, description="目标高度,单位 px,省略或 null 表示保持原值"
|
|
)
|
|
|
|
@model_validator(mode="after")
|
|
def require_size(self) -> Self:
|
|
if self.width is None and self.height is None:
|
|
raise ValueError("resize 至少提供 width 或 height")
|
|
return self
|