From 219350a48ac3bc1b2e17e388355da2d6133d2563 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 18 Sep 2026 14:42:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(secrets):=20=E5=BC=B9=E7=AA=97/=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E6=94=B9bricks=E5=B7=B2=E9=AA=8C=E6=A8=A1=E5=BC=8F(Bu?= =?UTF-8?q?tton=E7=94=A8binds=E9=9D=9Escript=E9=94=AE,=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=8C=85VBox=E5=B8=A6padding,=E5=8F=96=E5=80=BCresultValue,Mes?= =?UTF-8?q?sage=E6=8F=90=E7=A4=BA)=E2=80=94=E2=80=94=E9=A6=96=E7=89=88?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E5=B8=83=E5=B1=80=E5=B4=A9+=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E6=97=A0=E5=93=8D=E5=BA=94=E5=AE=9E=E9=94=A4=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/secrets/index.ui | 3 +- wwwroot/secrets/new_secret_popup.dspy | 97 ++++++++++++++++----------- 2 files changed, 58 insertions(+), 42 deletions(-) diff --git a/wwwroot/secrets/index.ui b/wwwroot/secrets/index.ui index 5150520..9667222 100644 --- a/wwwroot/secrets/index.ui +++ b/wwwroot/secrets/index.ui @@ -9,7 +9,8 @@ "widgettype": "Button", "id": "btn_new_secret", "options": {"label": "🔑 新增凭据", "css": "primary", "i18n": true}, - "script": "var r=await fetch('{{entire_url('./new_secret_popup.dspy')}}?op=form');var d=await r.json();if(d){bricks.widgetBuild(d,bricks.app);}" + "binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", + "script": "var r=await fetch('{{entire_url('./new_secret_popup.dspy')}}?op=form');var d=await r.json();if(d){bricks.widgetBuild(d,bricks.app);}"}] }, { "widgettype": "Text", "options": {"text": "值永不显示(密文存储);改值请删除后重存。", "i18n": true, "cfontsize": 0.85} diff --git a/wwwroot/secrets/new_secret_popup.dspy b/wwwroot/secrets/new_secret_popup.dspy index 8c33b8d..18b2566 100644 --- a/wwwroot/secrets/new_secret_popup.dspy +++ b/wwwroot/secrets/new_secret_popup.dspy @@ -27,59 +27,74 @@ if (params_kw or {}).get('op') != 'form': return json.dumps({"success": False, "error": r.get("message", "保存失败")}, ensure_ascii=False) -# GET op=form:返回弹窗 widget +# GET op=form:返回弹窗 widget(结构对齐 agent_project_popup 已验模式) if not uid: return json.dumps({"widgettype": "PopupWindow", "id": "new_secret_pw", - "options": {"title": "新增凭据", "cwidth": 26, "cheight": 14, + "options": {"title": "新增凭据", "cwidth": 26, "cheight": 8, "auto_open": True}, - "subwidgets": [{"widgettype": "Text", - "options": {"text": "请先登录", "cfontsize": 1}}]}, + "subwidgets": [{"widgettype": "VBox", + "options": {"width": "100%", "gap": "10px", + "padding": "16px 20px"}, + "subwidgets": [ + {"widgettype": "Text", + "options": {"text": "请先登录", + "cfontsize": 1}}]}]}, ensure_ascii=False) _self_url = entire_url("/pipeline_core/secrets/new_secret_popup.dspy") -def _field(fid, label, ftype, placeholder=""): +def _field(fid, label, wtype, placeholder=""): # bricks 控件名:UiStr=单行 / UiPassword=口令掩码 / UiText=多行 textarea - wtype = {"text": "UiStr", "pass": "UiPassword", "area": "UiText"}[ftype] - return {"widgettype": "VBox", "options": {"css": "field-row"}, "subwidgets": [ - {"widgettype": "Text", "options": {"text": label, "cfontsize": 0.9}}, - {"widgettype": wtype, - "id": fid, - "options": {"placeholder": placeholder, - "cheight": 3 if ftype != "area" else 5}}]} + return {"widgettype": "VBox", "options": {"width": "100%", "gap": "2px"}, + "subwidgets": [ + {"widgettype": "Text", + "options": {"text": label, "cfontsize": 0.85, "color": "#64748b"}}, + {"widgettype": wtype, "id": fid, + "options": {"placeholder": placeholder, "width": "100%"}}]} -_save_js = ( - "var body=new URLSearchParams();" - "body.append('name',bricks.getWidgetById('ns_name',bricks.app).get_value());" - "body.append('value',bricks.getWidgetById('ns_value',bricks.app).get_value());" - "body.append('label',bricks.getWidgetById('ns_label',bricks.app).get_value());" - "body.append('remark',bricks.getWidgetById('ns_remark',bricks.app).get_value());" - "body.append('secret_type',bricks.getWidgetById('ns_type',bricks.app).get_value());" - "var rp=await fetch(" + json.dumps(_self_url) + ",{method:'POST'," - "headers:{'Content-Type':'application/x-www-form-urlencoded'},body:body});" - "var d=await rp.json();" - "if(d&&d.success){bricks.show_message({title:'凭据',message:d.message||'已保存'});" - "var pw=bricks.getWidgetById('new_secret_pw',bricks.app);if(pw){pw.destroy();}" - "location.reload();}" - "else{bricks.show_message({title:'凭据',message:(d&&d.error)||'保存失败'});}" -) +_get_val = ("function _gv(i){var w=bricks.getWidgetById(i,bricks.app);if(!w)return '';" + "var v=(typeof w.resultValue==='function')?w.resultValue():" + "((w.dom_element&&w.dom_element.value)||'');" + "return (v===null||v===undefined)?'':String(v);}") + +_save_js = (_get_val + + "var nm=_gv('ns_name').trim(), vv=_gv('ns_value');" + "if(!nm||!vv){var m0=new bricks.Message({title:'凭据',message:'名称与值必填'});m0.open();return;}" + "var body=new URLSearchParams();" + "body.append('name',nm);body.append('value',vv);" + "body.append('label',_gv('ns_label'));body.append('remark',_gv('ns_remark'));" + "body.append('secret_type',_gv('ns_type'));" + "var rp=await fetch(" + json.dumps(_self_url) + ",{method:'POST'," + "headers:{'Content-Type':'application/x-www-form-urlencoded'},body:body});" + "var d=await rp.json();" + "if(d&&d.success){" + "var pw=bricks.getWidgetById('new_secret_pw',bricks.app);if(pw){pw.destroy();}" + "var m1=new bricks.Message({title:'凭据',message:d.message||'已保存'});m1.open();" + "location.reload();" + "}else{var m2=new bricks.Message({title:'凭据',message:(d&&d.error)||'保存失败'});m2.open();}") return json.dumps({ "widgettype": "PopupWindow", "id": "new_secret_pw", - "options": {"title": "🔑 新增凭据", "cwidth": 26, "cheight": 20, "auto_open": True}, - "subwidgets": [ - {"widgettype": "Text", "options": { - "text": "值加密存储、永不回显;会话用 @@sec:名称@@ 引用,命令用 $PIPELINE_SEC_名称。", - "cfontsize": 0.85}}, - _field("ns_name", "名称(大写字母/数字/下划线)", "text", "如 GITHUB_TOKEN"), - _field("ns_value", "值(明文,仅本次传输)", "pass", "粘贴 apikey/token/口令"), - _field("ns_label", "标签(可选)", "text", "如 我的GitHub"), - _field("ns_type", "类型(可选)", "text", "如 api_key/password/token"), - _field("ns_remark", "备注(可选)", "area", "用途说明"), - {"widgettype": "Button", - "options": {"label": "保存", "css": "primary"}, - "script": _save_js}, - ]}, ensure_ascii=False) + "options": {"title": "🔑 新增凭据", "cwidth": 34, "cheight": 22, "auto_open": True}, + "subwidgets": [{ + "widgettype": "VBox", + "options": {"width": "100%", "gap": "10px", "padding": "16px 20px"}, + "subwidgets": [ + {"widgettype": "Text", "options": { + "text": "值加密存储、永不回显;会话用 @@sec:名称@@ 引用,命令用 $PIPELINE_SEC_名称。", + "cfontsize": 0.85, "color": "#64748b"}}, + _field("ns_name", "名称(大写字母/数字/下划线)", "UiStr", "如 GITHUB_TOKEN"), + _field("ns_value", "值(明文,仅本次传输)", "UiPassword", "粘贴 apikey/token/口令"), + _field("ns_label", "标签(可选)", "UiStr", "如 我的GitHub"), + _field("ns_type", "类型(可选)", "UiStr", "如 api_key/password/token"), + _field("ns_remark", "备注(可选)", "UiText", "用途说明"), + {"widgettype": "HBox", "options": {"width": "100%", "gap": "10px"}, + "subwidgets": [ + {"widgettype": "Button", + "options": {"label": "保存", "css": "primary"}, + "binds": [{"wid": "self", "event": "click", "actiontype": "script", + "target": "self", "script": _save_js}]}]} + ]}]}, ensure_ascii=False)