feat: 功能菜单按钮改urlwidget事件+通用弹窗agent_menu_open控制大小+固定工作空间按钮
This commit is contained in:
parent
c55a01241b
commit
b62390ccde
33
wwwroot/api/agent_menu_open.dspy
Normal file
33
wwwroot/api/agent_menu_open.dspy
Normal file
@ -0,0 +1,33 @@
|
||||
# agent_menu_open.dspy - 通用功能弹窗:返回 PopupWindow,内嵌 urlwidget 加载目标 .ui
|
||||
# 供 AgentIO 上方功能菜单按钮用(按钮 actiontype=urlwidget 打开本 dspy,通过参数控制弹窗大小)
|
||||
# 参数:url(必填) title cwidth cheight
|
||||
|
||||
import json
|
||||
|
||||
url = (params_kw or {}).get('url', '') or ''
|
||||
title = (params_kw or {}).get('title', '') or '功能'
|
||||
cwidth = (params_kw or {}).get('cwidth', '') or '62'
|
||||
cheight = (params_kw or {}).get('cheight', '') or '32'
|
||||
|
||||
if not url:
|
||||
return json.dumps({
|
||||
"widgettype": "Text",
|
||||
"options": {"text": "缺少 url 参数", "cfontsize": 1, "color": "#64748b", "padding": "20px"}
|
||||
}, ensure_ascii=False)
|
||||
|
||||
try:
|
||||
cw = float(cwidth)
|
||||
except Exception:
|
||||
cw = 62
|
||||
try:
|
||||
ch = float(cheight)
|
||||
except Exception:
|
||||
ch = 32
|
||||
|
||||
return json.dumps({
|
||||
"widgettype": "PopupWindow",
|
||||
"options": {"title": title, "cwidth": cw, "cheight": ch, "auto_open": True},
|
||||
"subwidgets": [
|
||||
{"widgettype": "urlwidget", "options": {"url": url}}
|
||||
]
|
||||
}, ensure_ascii=False)
|
||||
@ -38,30 +38,39 @@ try:
|
||||
except Exception:
|
||||
menus = []
|
||||
|
||||
# 3. 构建菜单按钮(点击 → Popup 打开功能 .ui)
|
||||
# 3. 构建菜单按钮(actiontype=urlwidget 打开通用弹窗 agent_menu_open,控制弹窗大小)
|
||||
import urllib.parse as _urlparse
|
||||
|
||||
buttons = []
|
||||
|
||||
# 固定「工作空间」按钮(通用能力,所有 agent 都有)
|
||||
buttons.append({
|
||||
"widgettype": "Button",
|
||||
"options": {"label": "🗂 工作空间", "css": "small", "id": "menu_btn_ws"},
|
||||
"binds": [{
|
||||
"wid": "self", "event": "click", "actiontype": "urlwidget",
|
||||
"target": "self", "options": {"url": "/pipeline-sdlc/api/workspace_popup.dspy"},
|
||||
}],
|
||||
})
|
||||
|
||||
for i, m in enumerate(menus):
|
||||
label = str(m.get("label", "") or "")
|
||||
url = str(m.get("url", "") or "")
|
||||
if not url:
|
||||
continue
|
||||
script = (
|
||||
"var pw=new bricks.PopupWindow({title:" + _json.dumps(label) +
|
||||
",cwidth:62,cheight:32,auto_open:true});"
|
||||
"pw.content_w.add_widget(new bricks.urlwidget({url:" + _json.dumps(url) + "}));"
|
||||
)
|
||||
cwidth = str(m.get("cwidth", "62") or "62")
|
||||
cheight = str(m.get("cheight", "32") or "32")
|
||||
query = _urlparse.urlencode({"url": url, "title": label, "cwidth": cwidth, "cheight": cheight})
|
||||
open_url = "/pipeline_core/api/agent_menu_open.dspy?" + query
|
||||
buttons.append({
|
||||
"widgettype": "Button",
|
||||
"options": {"label": label, "css": "small", "id": "menu_btn_%d" % i},
|
||||
"binds": [{
|
||||
"wid": "self", "event": "click", "actiontype": "script",
|
||||
"target": "self", "script": script,
|
||||
"wid": "self", "event": "click", "actiontype": "urlwidget",
|
||||
"target": "self", "options": {"url": open_url},
|
||||
}],
|
||||
})
|
||||
|
||||
if not buttons:
|
||||
return _json.dumps({"widgettype": "HBox", "options": {"cheight": 0}, "subwidgets": []})
|
||||
|
||||
return _json.dumps({
|
||||
"widgettype": "HBox",
|
||||
"options": {"width": "100%", "padding": "0 24px 8px 24px", "gap": "8px", "alignItems": "center"},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user