Browse Source

feat: 小于6个请求时不打包

pull/1/head
Zhenfei.Li 4 years ago
parent
commit
671d8301cf
  1. 56
      src/main/resources/com/fr/plugin/pack/req.js

56
src/main/resources/com/fr/plugin/pack/req.js

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

Loading…
Cancel
Save