|
|
@ -7,9 +7,16 @@ |
|
|
|
|
|
|
|
|
|
|
|
var widgets = {}; |
|
|
|
var widgets = {}; |
|
|
|
var handlers = {}; |
|
|
|
var handlers = {}; |
|
|
|
|
|
|
|
var count = 0; |
|
|
|
|
|
|
|
|
|
|
|
// 防抖机制,0.3s无新的data请求,才向后端发送。否则会先打包并等待0.3s
|
|
|
|
// 防抖机制,0.3s无新的data请求,才打包向后端发送。
|
|
|
|
var requestFunc = BI.debounce(function () { |
|
|
|
var requestFunc = BI.debounce(function (config) { |
|
|
|
|
|
|
|
if (count < 6) { |
|
|
|
|
|
|
|
// 发送请求时小于6则不打包,还跟之前的一样发
|
|
|
|
|
|
|
|
BI.each(handlers, function (wId, handler) { |
|
|
|
|
|
|
|
handler.next(config); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
BI.asyncAjax({ |
|
|
|
BI.asyncAjax({ |
|
|
|
url: "widgets/data", |
|
|
|
url: "widgets/data", |
|
|
|
type: "POST", |
|
|
|
type: "POST", |
|
|
@ -31,8 +38,10 @@ |
|
|
|
opt: {}, |
|
|
|
opt: {}, |
|
|
|
version: "url" |
|
|
|
version: "url" |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
widgets = {}; |
|
|
|
widgets = {}; |
|
|
|
handlers = {}; |
|
|
|
handlers = {}; |
|
|
|
|
|
|
|
count = 0; |
|
|
|
}, 300); |
|
|
|
}, 300); |
|
|
|
|
|
|
|
|
|
|
|
// 不通过改写bi组件的方式去做,工作量太大且可维护性太差。使用巧妙的办法,直接通过拦截所有data请求,将其打包成一个请求发送到后端。
|
|
|
|
// 不通过改写bi组件的方式去做,工作量太大且可维护性太差。使用巧妙的办法,直接通过拦截所有data请求,将其打包成一个请求发送到后端。
|
|
|
@ -45,7 +54,8 @@ |
|
|
|
var wId = widget.wId; |
|
|
|
var wId = widget.wId; |
|
|
|
widgets[wId] = widget; |
|
|
|
widgets[wId] = widget; |
|
|
|
handlers[wId] = handler; |
|
|
|
handlers[wId] = handler; |
|
|
|
requestFunc(); |
|
|
|
count++; |
|
|
|
|
|
|
|
requestFunc(config); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
handler.next(config); |
|
|
|
handler.next(config); |
|
|
|
} |
|
|
|
} |
|
|
|