From 7cf957b4be5b25bdebf00371fbe0f01e509d8532 Mon Sep 17 00:00:00 2001 From: "Zhenfei.Li" Date: Sun, 18 Oct 2020 01:48:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=9A=E8=BF=87=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E6=89=80=E6=9C=89data=E8=AF=B7=E6=B1=82=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=AE=9E=E7=8E=B0=E8=AF=B7=E6=B1=82=E7=9A=84=E6=89=93?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 28 ++++- .../java/com/fr/plugin/pack/ReportDef.java | 6 +- src/main/java/com/fr/plugin/pack/ShowDef.java | 6 +- .../com/fr/plugin/pack/{report.js => req.js} | 103 +++++++++--------- src/main/resources/com/fr/plugin/pack/show.js | 5 - 5 files changed, 81 insertions(+), 67 deletions(-) rename src/main/resources/com/fr/plugin/pack/{report.js => req.js} (82%) delete mode 100644 src/main/resources/com/fr/plugin/pack/show.js diff --git a/README.md b/README.md index 932bc3e..d48c35c 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,30 @@ ![image.png](https://upload-images.jianshu.io/upload_images/4968021-364bdcc061f6007e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 2. idea的ant直接添加工程中的build.xml即可 ![image.png](https://upload-images.jianshu.io/upload_images/4968021-510012c5932a1e6f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) -3. build后会生成classes,然后直接打包即可 \ No newline at end of file +3. build后会生成classes,然后直接打包即可 +### 接口约定 +url: /app/decision/v5/plugin/design/widgets/data + +method: POST + +请求体 +``` +{ + widgets: { + 组件id: 之前发送的组件信息 + } +} +``` +返回体 +``` +{ + status: 200, + ... + data: { + 组件id: { + status: 200, + data: 之前的组件数据 + } + } +} +``` \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/pack/ReportDef.java b/src/main/java/com/fr/plugin/pack/ReportDef.java index 0516ff0..0107d1c 100644 --- a/src/main/java/com/fr/plugin/pack/ReportDef.java +++ b/src/main/java/com/fr/plugin/pack/ReportDef.java @@ -10,11 +10,7 @@ public class ReportDef extends Component { public static final ReportDef KEY = new ReportDef(); public ReportDef(){} public ScriptPath script(RequestClient client ) { - return ScriptPath.build("com/fr/plugin/pack/report.js"); - } - - public StylePath style(RequestClient client ) { - return StylePath.build("com/fr/plugin/pack/report.css"); + return ScriptPath.build("com/fr/plugin/pack/req.js"); } public Filter filter() { diff --git a/src/main/java/com/fr/plugin/pack/ShowDef.java b/src/main/java/com/fr/plugin/pack/ShowDef.java index ff582ec..7ffcb7b 100644 --- a/src/main/java/com/fr/plugin/pack/ShowDef.java +++ b/src/main/java/com/fr/plugin/pack/ShowDef.java @@ -11,11 +11,7 @@ public class ShowDef extends Component { public ShowDef(){} public ScriptPath script( RequestClient client ) { - return ScriptPath.build("com/fr/plugin/enadaptation/show.js"); - } - - public StylePath style( RequestClient client ) { - return StylePath.build("com/fr/plugin/enadaptation/show.css"); + return ScriptPath.build("com/fr/plugin/pack/req.js"); } public Filter filter() { diff --git a/src/main/resources/com/fr/plugin/pack/report.js b/src/main/resources/com/fr/plugin/pack/req.js similarity index 82% rename from src/main/resources/com/fr/plugin/pack/report.js rename to src/main/resources/com/fr/plugin/pack/req.js index 94e109f..9f1bae4 100644 --- a/src/main/resources/com/fr/plugin/pack/report.js +++ b/src/main/resources/com/fr/plugin/pack/req.js @@ -1,51 +1,52 @@ -;(function() { - - console.log("edit js loaded"); - - // ajaxhook.min.js - !function(t,e){for(var n in e)t[n]=e[n]}(window,function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=3)}([function(t,e,n){"use strict";function r(t,e){var n={};for(var r in t)n[r]=t[r];return n.target=n.currentTarget=e,n}function o(t){function e(e){return function(){var n=this.hasOwnProperty(e+"_")?this[e+"_"]:this.xhr[e],r=(t[e]||{}).getter;return r&&r(n,this)||n}}function n(e){return function(n){var o=this.xhr,i=this,u=t[e];if("on"===e.substring(0,2))i[e+"_"]=n,o[e]=function(u){u=r(u,i),t[e]&&t[e].call(i,o,u)||n.call(i,u)};else{var s=(u||{}).setter;n=s&&s(n,i)||n,this[e+"_"]=n;try{o[e]=n}catch(t){}}}}function o(e){return function(){var n=[].slice.call(arguments);if(t[e]){var r=t[e].call(this,n,this.xhr);if(r)return r}return this.xhr[e].apply(this.xhr,n)}}return window[s]=window[s]||XMLHttpRequest,XMLHttpRequest=function(){var t=new window[s];for(var r in t){var i="";try{i=u(t[r])}catch(t){}"function"===i?this[r]=o(r):Object.defineProperty(this,r,{get:e(r),set:n(r),enumerable:!0})}var a=this;t.getProxy=function(){return a},this.xhr=t},window[s]}function i(){window[s]&&(XMLHttpRequest=window[s]),window[s]=void 0}Object.defineProperty(e,"__esModule",{value:!0});var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};e.configEvent=r,e.hook=o,e.unHook=i;var s="_rxhr"},function(t,e,n){"use strict";function r(t){if(h)throw"Proxy already exists";return h=new f(t)}function o(){h=null,(0,d.unHook)()}function i(t){return t.replace(/^\s+|\s+$/g,"")}function u(t){return t.watcher||(t.watcher=document.createElement("a"))}function s(t,e){var n=t.getProxy(),r="on"+e+"_",o=(0,d.configEvent)({type:e},n);n[r]&&n[r](o);var i;"function"==typeof Event?i=new Event(e,{bubbles:!1}):(i=document.createEvent("Event"),i.initEvent(e,!1,!0)),u(t).dispatchEvent(i)}function a(t){this.xhr=t,this.xhrProxy=t.getProxy()}function c(t){function e(t){a.call(this,t)}return e[b]=Object.create(a[b]),e[b].next=t,e}function f(t){function e(t,e){var n=new P(t);if(!f)return n.resolve();var r={response:e.response,status:e.status,statusText:e.statusText,config:t.config,headers:t.resHeader||t.getAllResponseHeaders().split("\r\n").reduce(function(t,e){if(""===e)return t;var n=e.split(":");return t[n.shift()]=i(n.join(":")),t},{})};f(r,n)}function n(t,e,n){var r=new H(t),o={config:t.config,error:n};h?h(o,r):r.next(o)}function r(){return!0}function o(t,e){return n(t,this,e),!0}function a(t,n){return 4===t.readyState&&0!==t.status?e(t,n):4!==t.readyState&&s(t,w),!0}var c=t.onRequest,f=t.onResponse,h=t.onError;return(0,d.hook)({onload:r,onloadend:r,onerror:o,ontimeout:o,onabort:o,onreadystatechange:function(t){return a(t,this)},open:function(t,e){var r=this,o=e.config={headers:{}};o.method=t[0],o.url=t[1],o.async=t[2],o.user=t[3],o.password=t[4],o.xhr=e;var i="on"+w;e[i]||(e[i]=function(){return a(e,r)});var u=function(t){n(e,r,(0,d.configEvent)(t,r))};if([x,y,g].forEach(function(t){var n="on"+t;e[n]||(e[n]=u)}),c)return!0},send:function(t,e){var n=e.config;if(n.withCredentials=e.withCredentials,n.body=t[0],c){var r=function(){c(n,new m(e))};return!1===n.async?r():setTimeout(r),!0}},setRequestHeader:function(t,e){return e.config.headers[t[0].toLowerCase()]=t[1],!0},addEventListener:function(t,e){var n=this;if(-1!==l.indexOf(t[0])){var r=t[1];return u(e).addEventListener(t[0],function(e){var o=(0,d.configEvent)(e,n);o.type=t[0],o.isTrusted=!0,r.call(n,o)}),!0}},getAllResponseHeaders:function(t,e){var n=e.resHeader;if(n){var r="";for(var o in n)r+=o+": "+n[o]+"\r\n";return r}},getResponseHeader:function(t,e){var n=e.resHeader;if(n)return n[(t[0]||"").toLowerCase()]}})}Object.defineProperty(e,"__esModule",{value:!0}),e.proxy=r,e.unProxy=o;var h,d=n(0),l=["load","loadend","timeout","error","readystatechange","abort"],v=l[0],p=l[1],y=l[2],x=l[3],w=l[4],g=l[5],b="prototype";a[b]=Object.create({resolve:function(t){var e=this.xhrProxy,n=this.xhr;e.readyState=4,n.resHeader=t.headers,e.response=e.responseText=t.response,e.statusText=t.statusText,e.status=t.status,s(n,w),s(n,v),s(n,p)},reject:function(t){this.xhrProxy.status=0,s(this.xhr,t.type),s(this.xhr,p)}});var m=c(function(t){var e=this.xhr;t=t||e.config,e.withCredentials=t.withCredentials,e.open(t.method,t.url,!1!==t.async,t.user,t.password);for(var n in t.headers)e.setRequestHeader(n,t.headers[n]);e.send(t.body)}),P=c(function(t){this.resolve(t)}),H=c(function(t){this.reject(t)})},,function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ah=void 0;var r=n(0),o=n(1);e.ah={proxy:o.proxy,unProxy:o.unProxy,hook:r.hook,unHook:r.unHook}}])); - - // 拦截请求 - ah.proxy({ - //请求发起前进入 - onRequest: function (config, handler) { - if (config.url.indexOf("widget/data") > -1) { - console.log("拦截data请求"); - handler.resolve({ - config: config, - status: 200, - headers: {'content-type': 'text/text'}, - response: 'test' - }) - // handler.next(config); - } else { - handler.next(config); - } - // handler.next(config); - }, - onError: function (err, handler) { - // if (err.config.url === 'https://bb/') { - // handler.resolve({ - // config: err.config, - // status: 200, - // headers: {'content-type': 'text/text'}, - // response: 'hi world' - // }) - // } else { - // handler.next(err) - // } - handler.next(err) - }, - onResponse: function (response, handler) { - // if (response.config.url === location.href) { - // handler.reject({ - // config: response.config, - // type: 'error' - // }) - // } else { - // handler.next(response) - // } - handler.next(response) - } - }); -})(); +;(function() { + + console.log("pack request plugin js loaded"); + + // ajaxhook.min.js + !function(t,e){for(var n in e)t[n]=e[n]}(window,function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=3)}([function(t,e,n){"use strict";function r(t,e){var n={};for(var r in t)n[r]=t[r];return n.target=n.currentTarget=e,n}function o(t){function e(e){return function(){var n=this.hasOwnProperty(e+"_")?this[e+"_"]:this.xhr[e],r=(t[e]||{}).getter;return r&&r(n,this)||n}}function n(e){return function(n){var o=this.xhr,i=this,u=t[e];if("on"===e.substring(0,2))i[e+"_"]=n,o[e]=function(u){u=r(u,i),t[e]&&t[e].call(i,o,u)||n.call(i,u)};else{var s=(u||{}).setter;n=s&&s(n,i)||n,this[e+"_"]=n;try{o[e]=n}catch(t){}}}}function o(e){return function(){var n=[].slice.call(arguments);if(t[e]){var r=t[e].call(this,n,this.xhr);if(r)return r}return this.xhr[e].apply(this.xhr,n)}}return window[s]=window[s]||XMLHttpRequest,XMLHttpRequest=function(){var t=new window[s];for(var r in t){var i="";try{i=u(t[r])}catch(t){}"function"===i?this[r]=o(r):Object.defineProperty(this,r,{get:e(r),set:n(r),enumerable:!0})}var a=this;t.getProxy=function(){return a},this.xhr=t},window[s]}function i(){window[s]&&(XMLHttpRequest=window[s]),window[s]=void 0}Object.defineProperty(e,"__esModule",{value:!0});var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};e.configEvent=r,e.hook=o,e.unHook=i;var s="_rxhr"},function(t,e,n){"use strict";function r(t){if(h)throw"Proxy already exists";return h=new f(t)}function o(){h=null,(0,d.unHook)()}function i(t){return t.replace(/^\s+|\s+$/g,"")}function u(t){return t.watcher||(t.watcher=document.createElement("a"))}function s(t,e){var n=t.getProxy(),r="on"+e+"_",o=(0,d.configEvent)({type:e},n);n[r]&&n[r](o);var i;"function"==typeof Event?i=new Event(e,{bubbles:!1}):(i=document.createEvent("Event"),i.initEvent(e,!1,!0)),u(t).dispatchEvent(i)}function a(t){this.xhr=t,this.xhrProxy=t.getProxy()}function c(t){function e(t){a.call(this,t)}return e[b]=Object.create(a[b]),e[b].next=t,e}function f(t){function e(t,e){var n=new P(t);if(!f)return n.resolve();var r={response:e.response,status:e.status,statusText:e.statusText,config:t.config,headers:t.resHeader||t.getAllResponseHeaders().split("\r\n").reduce(function(t,e){if(""===e)return t;var n=e.split(":");return t[n.shift()]=i(n.join(":")),t},{})};f(r,n)}function n(t,e,n){var r=new H(t),o={config:t.config,error:n};h?h(o,r):r.next(o)}function r(){return!0}function o(t,e){return n(t,this,e),!0}function a(t,n){return 4===t.readyState&&0!==t.status?e(t,n):4!==t.readyState&&s(t,w),!0}var c=t.onRequest,f=t.onResponse,h=t.onError;return(0,d.hook)({onload:r,onloadend:r,onerror:o,ontimeout:o,onabort:o,onreadystatechange:function(t){return a(t,this)},open:function(t,e){var r=this,o=e.config={headers:{}};o.method=t[0],o.url=t[1],o.async=t[2],o.user=t[3],o.password=t[4],o.xhr=e;var i="on"+w;e[i]||(e[i]=function(){return a(e,r)});var u=function(t){n(e,r,(0,d.configEvent)(t,r))};if([x,y,g].forEach(function(t){var n="on"+t;e[n]||(e[n]=u)}),c)return!0},send:function(t,e){var n=e.config;if(n.withCredentials=e.withCredentials,n.body=t[0],c){var r=function(){c(n,new m(e))};return!1===n.async?r():setTimeout(r),!0}},setRequestHeader:function(t,e){return e.config.headers[t[0].toLowerCase()]=t[1],!0},addEventListener:function(t,e){var n=this;if(-1!==l.indexOf(t[0])){var r=t[1];return u(e).addEventListener(t[0],function(e){var o=(0,d.configEvent)(e,n);o.type=t[0],o.isTrusted=!0,r.call(n,o)}),!0}},getAllResponseHeaders:function(t,e){var n=e.resHeader;if(n){var r="";for(var o in n)r+=o+": "+n[o]+"\r\n";return r}},getResponseHeader:function(t,e){var n=e.resHeader;if(n)return n[(t[0]||"").toLowerCase()]}})}Object.defineProperty(e,"__esModule",{value:!0}),e.proxy=r,e.unProxy=o;var h,d=n(0),l=["load","loadend","timeout","error","readystatechange","abort"],v=l[0],p=l[1],y=l[2],x=l[3],w=l[4],g=l[5],b="prototype";a[b]=Object.create({resolve:function(t){var e=this.xhrProxy,n=this.xhr;e.readyState=4,n.resHeader=t.headers,e.response=e.responseText=t.response,e.statusText=t.statusText,e.status=t.status,s(n,w),s(n,v),s(n,p)},reject:function(t){this.xhrProxy.status=0,s(this.xhr,t.type),s(this.xhr,p)}});var m=c(function(t){var e=this.xhr;t=t||e.config,e.withCredentials=t.withCredentials,e.open(t.method,t.url,!1!==t.async,t.user,t.password);for(var n in t.headers)e.setRequestHeader(n,t.headers[n]);e.send(t.body)}),P=c(function(t){this.resolve(t)}),H=c(function(t){this.reject(t)})},,function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ah=void 0;var r=n(0),o=n(1);e.ah={proxy:o.proxy,unProxy:o.unProxy,hook:r.hook,unHook:r.unHook}}])); + + var widgets = {}; + var handlers = {}; + + // 防抖机制,0.3s无新的data请求,才向后端发送。否则会先打包并等待0.3s + var requestFunc = BI.debounce(function () { + BI.reqPost("plugin/design/widgets/data", { + widgets: widgets + }, 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]) + }); + }); + }); + widgets = {}; + handlers = {}; + }, 300); + + // 不通过改写bi组件的方式去做,工作量太大且可维护性太差。使用巧妙的办法,直接通过拦截所有data请求,将其打包成一个请求发送到后端。 + ah.proxy({ + //请求发起前进入 + onRequest: function (config, handler) { + if (config.url.indexOf("widget/data") > -1) { + console.log("拦截所有data请求,打包成一个请求"); + var widget = JSON.parse(config.body); + var wId = widget.wId; + widgets[wId] = widget; + handlers[wId] = handler; + requestFunc(); + } else { + handler.next(config); + } + }, + onError: function (err, handler) { + handler.next(err) + }, + onResponse: function (response, handler) { + handler.next(response) + } + }); +})(); diff --git a/src/main/resources/com/fr/plugin/pack/show.js b/src/main/resources/com/fr/plugin/pack/show.js deleted file mode 100644 index f1ec72b..0000000 --- a/src/main/resources/com/fr/plugin/pack/show.js +++ /dev/null @@ -1,5 +0,0 @@ -;(function() { - - console.log("show js loaded"); - -})(); \ No newline at end of file