fix: 手机验证码gen_code按钮用datawidget/datamethod传表单值给script

原script中this.getValue()在toolbar tool事件上下文中拿不到表单数据,
改用datawidget/datamethod机制将表单值通过params传入script。
回写codeid用.bind(this)保持Form引用。
This commit is contained in:
yumoqing 2026-05-28 14:10:37 +08:00
parent de21b9fd38
commit 7200ee43a0

View File

@ -89,8 +89,10 @@
"wid": "self",
"event": "gen_code",
"actiontype": "script",
"datawidget": "self",
"datamethod": "getValue",
"target": "self",
"script": "var form=this;var vals=form.getValue();if(!vals.cell_no){alert('请输入手机号');return;}fetch(form.app.baseUrl+'/rbac/gen_sms_code.dspy?cellphone='+encodeURIComponent(vals.cell_no)).then(function(r){return r.json()}).then(function(d){if(d.status==='ok'){form.setValue({codeid:d.data.key});alert('验证码已发送')}else{alert(d.data.message)}}).catch(function(e){alert('发送失败:'+e)})"
"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",