feat:图表交互
This commit is contained in:
@@ -8,6 +8,7 @@ from app.resources.material_fields import identifying_texts
|
||||
from app.schemas.base import JsonObject
|
||||
from app.schemas.data_file import RequestDataFile
|
||||
from app.schemas.input_context import InputContext
|
||||
from app.schemas.screen import Canvas, ScreenNode
|
||||
|
||||
# 每张表在摘要里最多列出的列名,完整的列用 describe_data 查看
|
||||
SUMMARY_COLUMNS = 30
|
||||
@@ -27,6 +28,7 @@ def request_summary(context: InputContext) -> JsonObject:
|
||||
# 新物料不用在这里加判断。物料目录没载入时为空
|
||||
"titles": identifying_texts(catalog, node.model_dump(mode="json")),
|
||||
"layout": node.layout.model_dump(mode="json", exclude_unset=True),
|
||||
**interaction_summary(node),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -35,11 +37,7 @@ def request_summary(context: InputContext) -> JsonObject:
|
||||
"clarification_history": context.clarification_history,
|
||||
"context": context.context.model_dump(mode="json", exclude_unset=True),
|
||||
"screen_summary": {
|
||||
"canvas": context.screen.canvas.model_dump(
|
||||
mode="json",
|
||||
include={"width", "height", "theme", "backgroundColor"},
|
||||
exclude_none=True,
|
||||
),
|
||||
"canvas": canvas_summary(context.screen.canvas),
|
||||
"nodes": nodes,
|
||||
# 数据源只保留标识、名称和类型
|
||||
"data_sources": [
|
||||
@@ -57,6 +55,36 @@ def request_summary(context: InputContext) -> JsonObject:
|
||||
}
|
||||
|
||||
|
||||
def canvas_summary(canvas: Canvas) -> JsonObject:
|
||||
"""画布尺寸、主题和大屏变量;没有变量时不出现,变量的默认值为 null 也照样给出"""
|
||||
result = canvas.model_dump(
|
||||
mode="json",
|
||||
include={"width", "height", "theme", "backgroundColor"},
|
||||
exclude_none=True,
|
||||
)
|
||||
if canvas.variables:
|
||||
result["variables"] = [
|
||||
item.model_dump(mode="json") for item in canvas.variables
|
||||
]
|
||||
return result
|
||||
|
||||
|
||||
def interaction_summary(node: ScreenNode) -> JsonObject:
|
||||
"""组件的显示条件、数据筛选和写变量的事件;事件代码不给,没有时不出现"""
|
||||
result: JsonObject = {}
|
||||
if node.visibleWhen is not None:
|
||||
result["visibleWhen"] = node.visibleWhen.model_dump(mode="json")
|
||||
if node.filters:
|
||||
result["filters"] = [item.model_dump(mode="json") for item in node.filters]
|
||||
if events := [
|
||||
{"type": event.get("type"), "action": event["action"]}
|
||||
for event in node.events or []
|
||||
if "action" in event
|
||||
]:
|
||||
result["events"] = events
|
||||
return result
|
||||
|
||||
|
||||
def data_file_summary(item: RequestDataFile) -> JsonObject:
|
||||
"""每个文件只给表名、label、行数和列名;列概况由 describe_data 按需查看。问答节点也用它
|
||||
|
||||
|
||||
Reference in New Issue
Block a user