fix: 手机验证码tab改用VBox+独立Button,避免toolbar tool触发submit导致tab跳转

根因:Form toolbar tool点击会同时触发Form的submit事件,
submit的urlwidget替换Form后TabPanel重置到第一个tab。
改为VBox包裹Form和独立Button,Button通过bricks.getWidgetById
读取Form值,fetch加_webbricks_=1确保返回纯JSON。
This commit is contained in:
yumoqing 2026-05-28 15:03:50 +08:00
parent 7200ee43a0
commit 92627c9c96

View File

@ -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)}})"
}
]
}
]
}