feat:图表交互

This commit is contained in:
2026-10-15 03:38:20 -07:00
parent 565ecf4558
commit 9b64f9fc0b
43 changed files with 1537 additions and 727 deletions
+46
View File
@@ -0,0 +1,46 @@
"""在大屏副本上设置组件的显示条件、数据筛选和事件;引用的变量是否存在由 interaction.py 在整批执行后检查"""
from copy import deepcopy
from app.actions.base import BaseActionHandler
from app.schemas.actions import SetInteractionAction
from app.schemas.actions.set_interaction import INTERACTION_KEYS
from app.schemas.screen import Screen
class SetInteractionHandler(BaseActionHandler[SetInteractionAction]):
def apply(self, screen: Screen, action: SetInteractionAction) -> Screen:
result, target = self.copy_target(screen, action.target_id)
# 只处理写出的键,写 null 删除节点上的该字段;节点上的事件是开放的 JSON,按序列化结果存
written = action.model_dump(mode="json", include=set(INTERACTION_KEYS))
for key in INTERACTION_KEYS:
if key in written:
value = getattr(action, key)
setattr(
target,
key,
written[key] if key == "events" else deepcopy(value),
)
return result
if __name__ == "__main__":
screen = Screen.model_validate(
{
"canvas": {"width": 1920, "height": 1080},
"nodes": [
{
"id": "detail",
"type": "stat-card",
"layout": {"x": 0, "y": 0, "width": 320, "height": 150},
"filters": [{"field": "model", "var": "model"}],
}
],
}
)
action = SetInteractionAction(
target_id="detail", visibleWhen={"var": "page", "equals": "stock"}
)
print(
SetInteractionHandler().apply(screen, action).nodes[0].model_dump_json(indent=2)
)