This commit is contained in:
yumoqing 2024-05-13 13:32:18 +08:00
parent 5060f20ba8
commit 5cf93522ee
4 changed files with 51 additions and 12 deletions

View File

@ -144,29 +144,24 @@ bricks.widgetBuild = async function(desc, widget, data){
} }
if (desc.hasOwnProperty('binds')){ if (desc.hasOwnProperty('binds')){
for (var i=0;i<desc.binds.length; i++){ for (var i=0;i<desc.binds.length; i++){
bricks.buildBind(w, desc.binds[i]); await bricks.buildBind(w, desc.binds[i]);
} }
} }
return w; return w;
} }
bricks.buildBind = function(w, desc){ bricks.buildBind = async function(w, desc){
var widget = bricks.getWidgetById(desc.wid, w); var widget = bricks.getWidgetById(desc.wid, w);
if (!widget){ if (!widget){
cnsole.log('desc wid not find', desc); cnsole.log('desc wid not find', desc);
return; return;
} }
var event = desc.event; var event = desc.event;
bricks.buildEventBind(w, widget, event, desc); await bricks.buildEventBind(w, widget, event, desc);
} }
bricks.buildEventBind = function(from_widget, widget, event, desc){ bricks.buildEventBind = async function(from_widget, widget, event, desc){
var handler = bricks.universal_handler.bind(null,from_widget, widget, desc); var handler = bricks.universal_handler.bind(null,from_widget, widget, desc);
if (desc.conform){
var conform_widget = await (bricks.widgetBuild(desc.conform, widget));
conform_widget.bind('on_conform', handler);
handler = conform_widget.open.bind(conform_widget);
}
widget.bind(event, handler); widget.bind(event, handler);
} }
@ -174,7 +169,17 @@ bricks.buildEventBind = function(from_widget, widget, event, desc){
bricks.universal_handler = async function(from_widget, widget, desc, event){ bricks.universal_handler = async function(from_widget, widget, desc, event){
var f = await bricks.buildEventHandler(from_widget, desc, event); var f = await bricks.buildEventHandler(from_widget, desc, event);
if (f){ if (f){
return await f(event); if (desc.conform){
var c_desc = {
"widgettype":"Conform",
"options":desc.conform
}
var conform_widget = await bricks.widgetBuild(c_desc, widget);
conform_widget.bind('conformed', f);
// handler = conform_widget.open.bind(conform_widget);
} else {
return await f(event);
}
} }
bricks.debug('universal_handler() error', 'from_widget=', bricks.debug('universal_handler() error', 'from_widget=',
from_widget, from_widget,

View File

@ -3,6 +3,7 @@ bricks.Conform = class extends bricks.Message {
constructor(opts){ constructor(opts){
opts.auto_open = true; opts.auto_open = true;
opts.auto_close = false; opts.auto_close = false;
opts.timeout = 0;
super(opts); super(opts);
this.create_toolbar(); this.create_toolbar();
} }
@ -29,10 +30,11 @@ bricks.Conform = class extends bricks.Message {
} }
conform_hndl(event){ conform_hndl(event){
this.dismiss(); this.dismiss();
this.dispatch('conform'); this.dispatch('conformed');
} }
discard_hndl(event){ discard_hndl(event){
this.dismiss(); this.dismiss();
this.dispatch('cancelled');
} }
} }

View File

@ -42,7 +42,7 @@ datamethod 优先datascript从datawidget控件中通过datamethod
### target ### target
字符串或控件实例目标控件实例如果是字符串使用”getWidgetById“函数获得目标控件实例 字符串或控件实例目标控件实例如果是字符串使用”getWidgetById“函数获得目标控件实例
### confform ### conform
如果一个事件处理需要用户确认可以在事件处理中指定一个conform属性来引发当此事件发生时会弹出一个确认窗口用户确认后才会处理此事件否则不处理 如果一个事件处理需要用户确认可以在事件处理中指定一个conform属性来引发当此事件发生时会弹出一个确认窗口用户确认后才会处理此事件否则不处理
### urlwidget绑定 ### urlwidget绑定
@ -449,4 +449,32 @@ params传递给事件的参数处理函数可以使用evemt.params获得
``` ```
上述例子中在主控件的binds区域定义了btn1的按钮点击后使用event处理类型来处理btn1的click事件即转而触发“txt1”正文控件的“gpc”事件并定义了当”txt1“正文控件在gpc事件发生后使用script事件处理方法alert一个消息 上述例子中在主控件的binds区域定义了btn1的按钮点击后使用event处理类型来处理btn1的click事件即转而触发“txt1”正文控件的“gpc”事件并定义了当”txt1“正文控件在gpc事件发生后使用script事件处理方法alert一个消息
## 定义需要确认的事件处理
有时候我们需要客户确认后在处理事件,如果用户不确认,则放弃处理事件,比如在删除数据时我们通常需要用户确认一下
例子
```
{
"id":"insert",
"widgettype":"Button",
"options":{
"width":"80px",
"i18n":true,
"label":"click me"
},
"binds":[
{
"wid":"self",
"event":"click",
"actiontype":"script",
"conform":{
"title":"conformtest",
"message":"测试事件处理前的用户确认功能,确认码?"
},
"target":"self",
"script":"alert('确认过眼神!')"
}
]
}
```
上述例子中定义了Button的click事件使用script事件处理方式来处理但是在处理前需要显示信息让用户确认是否继续如果用户放弃则不处理事件确认后正常的处理事件。

View File

@ -11,6 +11,10 @@
"wid":"self", "wid":"self",
"event":"click", "event":"click",
"actiontype":"script", "actiontype":"script",
"conform":{
"title":"conformtest",
"message":"测试事件处理前的用户确认功能,确认码?"
},
"target":"self", "target":"self",
"script":"console.log(this, params, event);" "script":"console.log(this, params, event);"
} }