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)