From 92627c9c96d1c9c0bc0a41c97c5c300ccfbde8c1 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 28 May 2026 15:03:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=8B=E6=9C=BA=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81tab=E6=94=B9=E7=94=A8VBox+=E7=8B=AC=E7=AB=8BButton?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8Dtoolbar=20tool=E8=A7=A6=E5=8F=91subm?= =?UTF-8?q?it=E5=AF=BC=E8=87=B4tab=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:Form toolbar tool点击会同时触发Form的submit事件, submit的urlwidget替换Form后TabPanel重置到第一个tab。 改为VBox包裹Form和独立Button,Button通过bricks.getWidgetById 读取Form值,fetch加_webbricks_=1确保返回纯JSON。 --- wwwroot/user/login.ui | 87 +++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/wwwroot/user/login.ui b/wwwroot/user/login.ui index 53accfb..1b169c1 100644 --- a/wwwroot/user/login.ui +++ b/wwwroot/user/login.ui @@ -55,54 +55,59 @@ "name": "checkcode", "label": "手机验证码", "content": { - "widgettype": "Form", - "options": { - "description": "限中国国内手机", - "fields": [ - { - "name": "cell_no", - "label": "手机号", - "uitype": "str" + "widgettype": "VBox", + "subwidgets": [ + { + "widgettype": "Form", + "id": "phone_form", + "options": { + "description": "限中国国内手机", + "fields": [ + { + "name": "cell_no", + "label": "手机号", + "uitype": "str" + }, + { + "name": "codeid", + "uitype": "hide", + "value": "" + }, + { + "name": "check_code", + "label": "验证码", + "uitype": "str" + } + ] }, - { - "name": "codeid", - "uitype": "hide", - "value": "" - }, - { - "name": "check_code", - "label": "验证码", - "uitype": "str" - } - ], - "toolbar": { - "tools": [ + "binds": [ { - "name": "gen_code", - "label": "发送验证码" + "wid": "self", + "event": "submit", + "actiontype": "urlwidget", + "target": "self", + "options": { + "method": "POST", + "url": "{{entire_url('code_login.dspy')}}" + } } ] - } - }, - "binds": [ - { - "wid": "self", - "event": "gen_code", - "actiontype": "script", - "datawidget": "self", - "datamethod": "getValue", - "target": "self", - "script": "var cell=params.cell_no;if(!cell){alert('请输入手机号');return;}fetch(bricks.app.baseUrl+'/rbac/gen_sms_code.dspy?cellphone='+encodeURIComponent(cell)).then(function(r){return r.json()}).then(function(d){if(d.status==='ok'){this.setValue({codeid:d.data.key});alert('验证码已发送')}else{alert(d.data.message)}}.bind(this)).catch(function(e){alert('发送失败:'+e)})" }, { - "wid": "self", - "event": "submit", - "actiontype": "urlwidget", - "target": "self", + "widgettype": "Button", + "id": "gen_code_btn", "options": { - "method": "POST", - "url": "{{entire_url('code_login.dspy')}}" - } + "label": "发送验证码" + }, + "binds": [ + { + "wid": "self", + "event": "click", + "actiontype": "script", + "target": "self", + "script": "var form=bricks.getWidgetById('phone_form',bricks.app);if(!form){alert('form not found');return;}var vals=form.getValue();var cell=vals.cell_no;if(!cell){alert('请输入手机号');return;}this.options.label='发送中...';this.el&&(this.el.disabled=true);fetch(bricks.app.baseUrl+'/rbac/gen_sms_code.dspy?_webbricks_=1&cellphone='+encodeURIComponent(cell)).then(function(r){return r.json()}).then(function(d){var btn=bricks.getWidgetById('gen_code_btn',bricks.app);if(d.status==='ok'){form.setValue({codeid:d.data.key});if(btn){btn.options.label='已发送';btn.el&&(btn.el.disabled=false)}}else{alert(d.data.message);if(btn){btn.options.label='发送验证码';btn.el&&(btn.el.disabled=false)}}}).catch(function(e){alert('发送失败:'+e);var btn=bricks.getWidgetById('gen_code_btn',bricks.app);if(btn){btn.options.label='发送验证码';btn.el&&(btn.el.disabled=false)}})" + } + ] } ] }