@wdslib/go-utils 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import e from"axios";import t from"lodash";import r from"crypto-js";var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};function o(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{c(n.next(e))}catch(e){a(e)}}function s(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}c((n=n.apply(e,t||[])).next())}))}function a(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}function i(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var s=3e4,c=3e4,u=function(t,r){void 0===t&&(t="");var n=e.create({baseURL:t,timeout:s,headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"}});return n.interceptors.request.use((function(e){return sessionStorage.getItem("anov-go-token")&&"null"!=sessionStorage.getItem("anov-go-token")&&(e.headers["X-ANOV-ACCESS-TOKEN"]=sessionStorage.getItem("anov-go-token")),sessionStorage.getItem("unify-access-token")&&"null"!=sessionStorage.getItem("unify-access-token")&&(e.headers["X-UNIFY-ACCESS-TOKEN"]=sessionStorage.getItem("unify-access-token")),sessionStorage.getItem("dgcc_authorization")&&"null"!=sessionStorage.getItem("dgcc_authorization")&&(e.headers.dgcc_authorization=sessionStorage.getItem("dgcc_authorization")),"post"===e.method?(e.headers["Content-Type"]="application/json;",e):"get"===e.method?e:"put"===e.method?(e.headers["Content-Type"]="application/json; charset=UTF-8",e):"delete"===e.method?e:void 0}),(function(e){return Promise.reject(e)})),n.interceptors.response.use((function(e){return 200===e.status||e.data.code,r&&r(e),e.data}),(function(e){return r&&r(null==e?void 0:e.response),Promise.reject(e.response)})),n};var d=function(e){if("string"==typeof e)try{var t=JSON.parse(e);return"object"==typeof t&&null!==t}catch(e){return!1}return!1},l=function(e){for(var t=0,r=e;t<r.length;t++){var n=r[t];n.code&&(n.code=n.code.replace(/&gt;/g,">").replace(/&lt;/g,"<"))}},v=function(e,t){e instanceof Map?e.forEach((function(e){t([e])})):Array.isArray(e)&&e.forEach((function(e){t(e.children)}))},f=function(e,t){var r=function(e){var n,o,a;if(e)for(var i=0,s=e;i<s.length;i++){var c=s[i],u=null===(a=null===(o=null===(n=null==c?void 0:c.tmpData)||void 0===n?void 0:n.source)||void 0===o?void 0:o.converse)||void 0===a?void 0:a.data;(null==u?void 0:u.length)&&l(u),t(c),c.children?r(c.children):c.dynamicChildren?v(c.dynamicChildren,r):c.stateChildren&&r(c.stateChildren)}};r(e)},p=function(e,t,r){if(!e)throw new Error("Share variable tree is not defined");if("string"!=typeof t)throw new Error("Variable name should be a string");if(!r)throw new Error("ID is required");Array.isArray(e[t])||(e[t]=[]),e[t].includes(r)||e[t].push(r)},h=function(e,t,r){var n,o=!1,a=null==t?void 0:t.converse;if(a&&a.use&&a.data.length)for(var i=0,s=a.data;i<s.length;i++){var c=s[i];if((null==c?void 0:c.dependVars)&&c.dependVars.includes(e))return!0}var u=null==t?void 0:t[null==t?void 0:t.type];return((null==u?void 0:u.inputSql)||(null==u?void 0:u.url)||(null==u?void 0:u.headers)||(null==u?void 0:u.params))&&(o=function(e,t,r,n){var o=e.match(/({{[\w]*}})|((@)[\w]*)/gm);if(o)for(var a=function(e){return!e||!t||t.findIndex((function(t){return t.mapField===e}))<0?"continue":(r&&n&&p(n,e,r.cid),{value:!0})},i=0,s=o.map((function(e){return e.replace(/{{|}}|@/gm,"")}));i<s.length;i++){var c=a(s[i]);if("object"==typeof c)return c.value}return!1}(u.inputSql||u.url||(null===(n=u.headers)||void 0===n?void 0:n.value)||u.params,r)),o},m="anov@2019:helloX",y="anov@2020:helloX";function g(e){var t=r.enc.Utf8.parse(m),n=r.enc.Utf8.parse(y);return r.AES.encrypt(e,t,{iv:n,mode:r.mode.CBC,padding:r.pad.Pkcs7}).toString()}var w,b,S,E=new Blob(["\nfunction proxyObj(originObj) {\n const exposeObj = new Proxy(originObj, {\n has: (target, key) => {\n if (['fetch', 'XMLHttpRequest', 'postMessage'].indexOf(key) >= 0) {\n throw new Error('Illegal operation for key'+key)\n } else {\n return target[key]\n }\n },\n })\n return exposeObj\n}\nfunction compileCode(src) {\n src = 'with (exposeObj) {'+src+'}'\n //console.log(src)\n return new Function('exposeObj', src)\n}\nfunction run(code) {\n let proxy = proxyObj({})\n let result = compileCode(code)(proxy)\n return result\n}\n\nonmessage = (e) => {\n try {\n let result = run(e.data.code)\n postMessage({\n code: 1,\n result,\n })\n } catch (err) {\n postMessage({\n code: -1,\n err,\n })\n }\n}\n"]),D=URL.createObjectURL(E);function T(e,t){return void 0===t&&(t=5e3),o(this,void 0,void 0,(function(){var r;return a(this,(function(n){return r=new Worker(D),[2,new Promise((function(n,o){var a=function(){clearTimeout(s),r.removeEventListener("message",i),r.terminate(),r=null},i=function(e){var t=e.data,r=t.code,i=t.result,s=t.err;a(),1===r?n(i):o(s)};r.postMessage({code:e}),r.addEventListener("message",i);var s=setTimeout((function(){a(),o("timeout")}),t)}))]}))}))}function k(e,t,r,n){return void 0===r&&(r={}),void 0===n&&(n="worker"),o(this,void 0,void 0,(function(){var o,s,c,u,d,l,v,f,p;return a(this,(function(a){switch(a.label){case 0:return a.trys.push([0,4,,5]),"window"!=n?[3,1]:(s=(o=[["data"],[t]])[0],c=o[1],"object"==typeof r&&Object.keys(r).forEach((function(e){s.push(e),c.push(r[e])})),u=new(Function.bind.apply(Function,i(i([void 0],s,!1),[e],!1))),[2,{success:!0,data:u.apply(void 0,c)}]);case 1:return v=(d=[t,r,""])[1],f=d[2],"object"==typeof(l=d[0])&&(l=JSON.stringify(t)),"object"==typeof r&&(v=JSON.stringify(r)),Object.keys(r).forEach((function(e){return f+="".concat(e,",")})),p="let data=eval(".concat(l,"); \n             let app=").concat(JSON.stringify({}),";"),p+=f?"let {".concat(f,"} = eval(").concat(v,"); "):"",[4,T(p+="".concat(e))];case 2:return[2,{success:!0,data:a.sent()}];case 3:return[3,5];case 4:return[2,{success:!1,error:a.sent(),data:t}];case 5:return[2]}}))}))}!function(e){e.StaticFile="staticFile",e.DataSource="datasource"}(w||(w={})),function(e){e.json="application/json;charset=UTF-8",e.form="application/x-www-form-urlencoded; charset=UTF-8"}(b||(b={})),function(e){e.get="GET",e.post="POST",e.put="PUT",e.patch="PATCH",e.delete="DELETE"}(S||(S={}));var O=function(e,t){return"string"!=typeof e?Promise.reject(new Error("URL should be a string")):u(e,t)},j=u(),N=u();function C(e){return o(this,void 0,void 0,(function(){var t;return a(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,j(e)];case 1:return[2,{code:2e4,data:r.sent().data}];case 2:throw t=r.sent(),console.error("请求数据发生错误-Error:",t),t;case 3:return[2]}}))}))}function P(e){return o(this,void 0,void 0,(function(){var t;return a(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,j({method:"get",url:e})];case 1:return[2,r.sent().data];case 2:throw t=r.sent(),console.error("JSON 数据请求:",t),t;case 3:return[2]}}))}))}function q(e,r,n,i){return void 0===r&&(r="get"),void 0===n&&(n={}),void 0===i&&(i={}),o(this,void 0,void 0,(function(){var o;return a(this,(function(a){try{return o={method:S[r],url:e,headers:i,timeout:c},["post","put"].includes(r.toLowerCase())?o.data=t.cloneDeep(n):o.params=t.cloneDeep(n),[2,/.json$/.test(e)?P(e):C(o)]}catch(e){throw console.error("获取数据:Error:",e),e}return[2]}))}))}function I(e,t,r,n){return o(this,void 0,void 0,(function(){var o,i,s,c,u;return a(this,(function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),o=window.anUrl||"",i=window.agentPath||"/ds/v1/api-proxy/v1/query",s=o+i,l=r,void 0===(v=!0)&&(v=!1),c=v?d(l)?l:JSON.stringify(l):d(l)?JSON.parse(l):l,[4,j({url:s,method:"post",headers:{"Content-Type":"application/json;charset=UTF-8"},data:{body:"post"===e?c:void 0,headers:d(n)?JSON.parse(n):n,method:e,url:t}})];case 1:return[2,a.sent()];case 2:throw u=a.sent(),console.error("代理请求数据:Error:",u),u;case 3:return[2]}var l,v}))}))}function x(e,t,r,n,i){return o(this,void 0,void 0,(function(){return a(this,(function(o){return[2,i?I(t,e,r,n):q(e,t,r,n)]}))}))}function F(e,t,r){var n,o,a;void 0===t&&(t="");var i=null!==(o=null===(n=null===window||void 0===window?void 0:window.BaseUrl)||void 0===n?void 0:n.replace("/management",""))&&void 0!==o?o:"",c=X("YZH_EXCHANGE_TOKEN")||(null===(a=null===window||void 0===window?void 0:window.yzhAuth)||void 0===a?void 0:a.getToken()),u=null===window||void 0===window?void 0:window.gdPassid,d=null===window||void 0===window?void 0:window.BASE_RELEASE,l="token=".concat(c,"&passid=").concat(u),v=d?"&preview=1":"",f="".concat(i,"/ds/data-engine/v1/").concat(e,"/zb-query?").concat(l).concat(v),p={};try{p=t?JSON.parse(t):{}}catch(e){p=t||{}}return j({method:"POST",url:f,data:{headers:r,param:p},timeout:s})}var U=function(e,t){return o(void 0,void 0,void 0,(function(){var r,n,o,i,c,u,d,l,v,f;return a(this,(function(a){return r=window.BaseUrl,n=t.dateType,o=void 0===n?"":n,i=t.endPeriod,c=void 0===i?"":i,u=t.metricsName,d=void 0===u?e:u,l=t.startPeriod,v=void 0===l?"":l,f="".concat(r,"ds/v1/metrics/v1/data-alarm?dateType=").concat(o,"&endPeriod=").concat(c,"&metricsName=").concat(d,"&startPeriod=").concat(v),[2,N({method:"GET",url:f,timeout:s})]}))}))},A=function(e,t,r){return o(void 0,void 0,void 0,(function(){var o,i,c,u;return a(this,(function(a){if(o=(null===(u=window.BaseUrl)||void 0===u?void 0:u.replace("/management",""))||"",t.newEncryption=!0,i={staticFile:{method:"get",params:t,url:"".concat(o,"/ds/v1/file/v1/").concat(e,"/query")},datasource:{method:"post",url:"".concat(o,"/ds/v1/database/v1/").concat(e,"/query"),data:n({},t)}},!(c=i[r]))throw new Error("Invalid data type provided");return[2,j(n({timeout:s},c))]}))}))},z=function(e){return new Promise((function(t,r){var n;void 0!==(n=e.originData&&Object.keys(e.originData).length?e.originData:e.data)?t({data:n}):r("Failed to retrieve cdata")}))},J=function(e,t,r){try{switch(t){case"api":var n=G(e,r);return{requestType:n.requestType,url:n.url,params:n.params,headers:n.headers,agency:n.agency};case"static":return{data:e};case"datasource":var o=Q(e.inputSql,r);return{dsName:e.dsName,dsType:"1",sql:g(o),filter:e.sqlFilter};case"staticFile":return{dsName:e.dsName,dsType:e.dsType,sql:""};case"indicator":return{zbId:e.zbId,params:e.params,headers:e.headers};case"indicatorCQ":return{zbName:e.zbName,params:e.params};case"packData":return{};default:throw new Error("Invalid type")}}catch(t){console.log("准备请求数据发生错误",t,e)}},L=function(e,t){return o(void 0,void 0,void 0,(function(){var r,n;return a(this,(function(o){switch(o.label){case 0:switch(o.trys.push([0,16,,18]),t){case"api":return[3,1];case"static":return[3,3];case"datasource":return[3,5];case"staticFile":return[3,7];case"indicator":return[3,9];case"indicatorCQ":return[3,11];case"packData":return[3,13]}return[3,14];case 1:return[4,x(e.url,e.requestType,e.params,e.headers,e.agency)];case 2:case 4:case 6:case 8:case 10:case 17:return[2,o.sent()];case 3:return[4,z(e.data)];case 5:return[4,A(e.dsName,{dsType:e.dsType,sql:e.sql,filter:e.filter},"datasource")];case 7:return[4,A(e.dsName,{dsType:e.dsType,sql:e.sql},"staticFile")];case 9:return[4,F(e.zbId,e.params,e.headers)];case 11:return[4,U(e.zbName,e.params)];case 12:return r=o.sent(),console.log(r,12222),[2,r];case 13:return[2,{}];case 14:throw new Error("Invalid type");case 15:return[3,18];case 16:return n=o.sent(),console.warn(n,"执行请求并获取数据发生错误","requestData:"+e),[4,new Promise((function(e,t){e({error:!0})}))];case 18:return[2]}}))}))},R=function(e,t,r,n,i){return void 0===n&&(n=[]),void 0===i&&(i=!1),o(void 0,void 0,void 0,(function(){var o,s,c,u,d,l,v,f;return a(this,(function(a){switch(a.label){case 0:return o=t||e.tmpData.source.dataType,s=e.tmpData.source["indicatorCQ"==o?"indicator":o],"globalData"!==o?[3,3]:(c=n.find((function(e){return e.key===s.id||e.key===s.key})),u=function(e){var t=sessionStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(t){console.error("Error parsing session data for key ".concat(e,":"),t)}return null}(s.id),u&&!i?[2,u.data]:c?[4,_(c,r)]:[3,2]);case 1:return d=a.sent(),l={key:s.id,data:d},function(e,t){try{var r=JSON.stringify(t);sessionStorage.setItem(e,r)}catch(t){console.error("Error setting session data for key ".concat(e,":"),t)}}(s.id,l),[2,d];case 2:return[2];case 3:return v=J(s,o,r),[4,L(v,o)];case 4:return[2,(null==(f=a.sent())?void 0:f.data)?f.data:f]}}))}))},_=function(e,t){return o(void 0,void 0,void 0,(function(){var r,n,o,i,s;return a(this,(function(a){switch(a.label){case 0:return r=Object.assign({},{tmpData:{source:e.value}}),n=r.tmpData.source.type,o=r.tmpData.source[n],i=J(o,n,t),[4,L(i,n)];case 1:return s=a.sent(),[4,B(s.data,r,!0,t)];case 2:return[2,a.sent()]}}))}))},B=function(e,r,n,i){return void 0===n&&(n=!0),o(void 0,void 0,void 0,(function(){var s,c,u;return a(this,(function(d){switch(d.label){case 0:return d.trys.push([0,5,,7]),s=r.tmpData.source,c=s.converse,s.mapFields,c&&c.use&&n?[4,new Promise((function(r,n){var s=function(e,r,n,i,s){return o(this,void 0,void 0,(function(){var n,o,s,c,u,d,l;return a(this,(function(v){switch(v.label){case 0:if(n=e,o=t.cloneDeep(r),s=o.use,c=o.data,!s)return[3,4];d=function(e){var r,o;return a(this,(function(a){switch(a.label){case 0:return c[e].use?(r=c[e].dependVars,o={},i&&o&&r&&r.length&&r.map((function(e){var r=t.cloneDeep(i).filter((function(t){var r=t.mapField==e;return r&&(o[e]=t.value),r}));r&&0!=r.length||(o[e]="")})),[4,k(c[e].code,n,o,c[e].mode?c[e].mode:"worker")]):[3,2];case 1:u=a.sent(),n=u.data,a.label=2;case 2:return[2]}}))},l=0,v.label=1;case 1:return l<c.length?[5,d(l)]:[3,4];case 2:v.sent(),v.label=3;case 3:return l++,[3,1];case 4:return[2,n]}}))}))}(e,c,0,i);r(s)}))]:[3,2];case 1:case 3:case 6:return[2,d.sent()];case 2:return[4,new Promise((function(t,r){t(e)}))];case 4:return[3,7];case 5:return u=d.sent(),console.error("执行过滤器发生错误:"+u),[4,new Promise((function(t,r){t(e)}))];case 7:return[2]}}))}))},M=function(e,t,r){var n=e.tmpData.source,o=n.type;r?("static"===o&&n[o]&&(n[o].originData=r),"indicatorCQ"===o?n.indicator.data=t:n[o].data=t):"indicatorCQ"===o?n.indicator.data=t:n[o].data=t,e.source=t},V=function(e,t,r,n,i,s){return void 0===r&&(r=[]),o(void 0,void 0,void 0,(function(){var o,c,u,d;return a(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),o=e.tmpData.source.type,[4,R(e,o,r,n,s||!1)];case 1:return null!=(c=a.sent())&&c?[4,B(c,e,t,r)]:(i&&i({error:!0}),[2,Promise.resolve({error:!0})]);case 2:return u=a.sent(),M(e,u),i&&i(u),[2,Promise.resolve(u)];case 3:return d=a.sent(),i&&i(d),console.error("Error in updateComData:",d),[2,Promise.reject(d)];case 4:return[2]}}))}))},X=function(e){var t={};if(e&&e.includes("?"))for(var r=0,n=e.split("?")[1].split("&");r<n.length;r++){var o=n[r].split("=").map(decodeURIComponent),a=o[0],i=o[1];t[a]=i}return t},Q=function(e,t){if(!t)return e;if("string"==typeof e)return""===e.trim()?"":e.replace(/@(\w+)|{{(\w+)}}/g,(function(e,r,n){var o=r||n,a=t.find((function(e){return e.mapField===o}));return a?a.value||a.originalValue||"":e}));if(Array.isArray(e))return e.map((function(e){return Q(e,t)}));if("object"==typeof e&&null!==e){var r={};for(var n in e)r[n]=Q(e[n],t);return r}return e},G=function(e,t){var r=e.agency,n=e,o=n.url,a=void 0===o?null:o,i=n.headers,s=n.params,c=n.requestType,u=a?Q(a,t):void 0,d=i&&i.use?Q(i.value,t):{};return{url:u,requestType:c,params:s?Q(s,t):{},headers:d,agency:r}},H=function(e,t,r,n,i){return o(void 0,void 0,void 0,(function(){var o,s,c,u;return a(this,(function(d){switch(d.label){case 0:if(!e||!e.length)return[2];o=function(o){return a(this,(function(a){switch(a.label){case 0:return h(t,o.value,r)?[4,V({tmpData:{source:{type:"globalData",globalData:{id:o.key}}}},!0,r,e,(function(e){console.log("数据更新成功-变量改变全局数据跟新")}),!0)]:[3,2];case 1:a.sent(),f(n,(function(t){var n,a,s;"globalData"===(null===(a=null===(n=null==t?void 0:t.tmpData)||void 0===n?void 0:n.source)||void 0===a?void 0:a.type)&&((null===(s=null==t?void 0:t.tmpData)||void 0===s?void 0:s.source.globalData).id===o.key&&V(t,!0,r,e,(function(e){i(t,e)}),!1))})),a.label=2;case 2:return[2]}}))},s=0,c=e,d.label=1;case 1:return s<c.length?(u=c[s],[5,o(u)]):[3,4];case 2:d.sent(),d.label=3;case 3:return s++,[3,1];case 4:return[2]}}))}))},K=function(e,t,r,n,i){return o(void 0,void 0,void 0,(function(){return a(this,(function(o){switch(o.label){case 0:return e?[4,V({tmpData:{source:{type:"globalData",globalData:{id:e.key}}}},!0,t,r,(function(e){console.log("数据更新成功-数据源编辑")}),!0)]:[2];case 1:return o.sent(),f(n,(function(n){var o,a,s;"globalData"===(null===(a=null===(o=null==n?void 0:n.tmpData)||void 0===o?void 0:o.source)||void 0===a?void 0:a.type)&&((null===(s=null==n?void 0:n.tmpData)||void 0===s?void 0:s.source.globalData).id===e.key&&V(n,!0,t,r,(function(e){i(n,e)}),!1))})),[2]}}))}))};export{O as Http,I as agentData,M as editItem,_ as fetchDataByGlobal,R as fetchDataByType,B as filterData,q as getData,x as getDataForApi,A as getDataForSource,z as getDataForStatic,F as getDataForZb,U as getDataForZbCQ,H as updataGlobalDataSourceForVar,V as updateComData,K as updateGlobalDataSource};
1
+ import e from"axios";import n from"lodash";import t from"crypto-js";var r=function(){return r=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},r.apply(this,arguments)};function o(e,n,t,r){return new(t||(t=Promise))((function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function c(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(i,c)}u((r=r.apply(e,n||[])).next())}))}function a(e,n){var t,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(u){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(t=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=n.call(e,i)}catch(e){c=[6,e],r=0}finally{t=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}function i(e,n,t){if(t||2===arguments.length)for(var r,o=0,a=n.length;o<a;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}"function"==typeof SuppressedError&&SuppressedError;var c=3e4,u=3e4,s=function(n,t){void 0===n&&(n="");var r=e.create({baseURL:n,timeout:c,headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"}});return r.interceptors.request.use((function(e){return sessionStorage.getItem("anov-go-token")&&"null"!=sessionStorage.getItem("anov-go-token")&&(e.headers["X-ANOV-ACCESS-TOKEN"]=sessionStorage.getItem("anov-go-token")),sessionStorage.getItem("unify-access-token")&&"null"!=sessionStorage.getItem("unify-access-token")&&(e.headers["X-UNIFY-ACCESS-TOKEN"]=sessionStorage.getItem("unify-access-token")),sessionStorage.getItem("dgcc_authorization")&&"null"!=sessionStorage.getItem("dgcc_authorization")&&(e.headers.dgcc_authorization=sessionStorage.getItem("dgcc_authorization")),"post"===e.method?(e.headers["Content-Type"]="application/json;",e):"get"===e.method?e:"put"===e.method?(e.headers["Content-Type"]="application/json; charset=UTF-8",e):"delete"===e.method?e:void 0}),(function(e){return Promise.reject(e)})),r.interceptors.response.use((function(e){return 200===e.status||e.data.code,t&&t(e),e.data}),(function(e){return t&&t(null==e?void 0:e.response),Promise.reject(e.response)})),r};function l(e,n){return void 0===n&&(n=!1),n?d(e)?e:JSON.stringify(e):d(e)?JSON.parse(e):e}var d=function(e){if("string"==typeof e)try{var n=JSON.parse(e);return"object"==typeof n&&null!==n}catch(e){return!1}return!1},f=function(e,n){try{var t=JSON.stringify(n);sessionStorage.setItem(e,t)}catch(n){console.error("Error setting session data for key ".concat(e,":"),n)}},v=function(e){var n=sessionStorage.getItem(e);if(n)try{return JSON.parse(n)}catch(n){console.error("Error parsing session data for key ".concat(e,":"),n)}return null},p=function(e){for(var n=0,t=e;n<t.length;n++){var r=t[n];r.code&&(r.code=r.code.replace(/&gt;/g,">").replace(/&lt;/g,"<"))}},h=function(e,n){e instanceof Map?e.forEach((function(e){n([e])})):Array.isArray(e)&&e.forEach((function(e){n(e.children)}))},m=function(e,n){var t=function(e){var r,o,a;if(e)for(var i=0,c=e;i<c.length;i++){var u=c[i],s=null===(a=null===(o=null===(r=null==u?void 0:u.tmpData)||void 0===r?void 0:r.source)||void 0===o?void 0:o.converse)||void 0===a?void 0:a.data;(null==s?void 0:s.length)&&p(s),n(u),u.children?t(u.children):u.dynamicChildren?h(u.dynamicChildren,t):u.stateChildren&&t(u.stateChildren)}};t(e)},y=function(e,n,t,r){var o=e.match(/({{[\w]*}})|((@)[\w]*)/gm);if(o)for(var a=function(e){return!e||!n||n.findIndex((function(n){return n.mapField===e}))<0?"continue":(t&&r&&g(r,e,t.cid),{value:!0})},i=0,c=o.map((function(e){return e.replace(/{{|}}|@/gm,"")}));i<c.length;i++){var u=a(c[i]);if("object"==typeof u)return u.value}return!1},g=function(e,n,t){if(!e)throw new Error("Share variable tree is not defined");if("string"!=typeof n)throw new Error("Variable name should be a string");if(!t)throw new Error("ID is required");Array.isArray(e[n])||(e[n]=[]),e[n].includes(t)||e[n].push(t)},w=function(e,n,t){var r,o=!1,a=null==n?void 0:n.converse;if(a&&a.use&&a.data.length)for(var i=0,c=a.data;i<c.length;i++){var u=c[i];if((null==u?void 0:u.dependVars)&&u.dependVars.includes(e))return!0}var s=null==n?void 0:n[null==n?void 0:n.type];return((null==s?void 0:s.inputSql)||(null==s?void 0:s.url)||(null==s?void 0:s.headers)||(null==s?void 0:s.params))&&(o=y(s.inputSql||s.url||(null===(r=s.headers)||void 0===r?void 0:r.value)||s.params,t)),o},b=function(e,t,r){void 0===r&&(r=!1);var o=null,a=function(e){for(var i=0,c=e;i<c.length;i++){var u=c[i];if(u.cid===t){o=u,r&&n.remove(e,(function(e){return e.cid===t}));break}if(u.children&&a(u.children),u.dynamicChildren&&Array.isArray(u.dynamicChildren))for(var s=0,l=Array.from(u.dynamicChildren);s<l.length;s++){var d=l[s][1];a(d)}u.stateChildren&&a(u.stateChildren)}};return a(e),o},k=function(e,t,r){var o=!1,a=function(e){for(var i=0;i<e.length;i++){if(e[i].cid==t){o=e[i],r&&n.remove(e,(function(e){return e.cid==t}));break}if(e[i].children)a(e[i].children);else if(e[i].dynamicChildren){if(e[i].dynamicChildren instanceof Map){for(var c=Array.from(e[i].dynamicChildren),u=0;u<c.length;u++)if(c[u]instanceof Array){var s=c[u][1];a(s)}}else if(e[i].dynamicChildren instanceof Array)for(c=e[i].dynamicChildren,u=0;u<c.length;u++)if(c[u]instanceof Array){s=c[u][1];a(s)}}else e[i].stateChildren&&a(e[i].stateChildren)}};return a(e),o||!1};function E(e,n,t){var r={};t.forEach((function(e){(null==e?void 0:e.name)&&(r[e.name]=e.value||e.originvalue)}));try{return new Function("data","vars",e)(n,r)}catch(e){return console.error(e),n}}var N="anov@2019:helloX",D="anov@2020:helloX";function S(e){var n=t.enc.Utf8.parse(N),r=t.enc.Utf8.parse(D);return t.AES.encrypt(e,n,{iv:r,mode:t.mode.CBC,padding:t.pad.Pkcs7}).toString()}var C,A,O,T=new Blob(["\nfunction proxyObj(originObj) {\n const exposeObj = new Proxy(originObj, {\n has: (target, key) => {\n if (['fetch', 'XMLHttpRequest', 'postMessage'].indexOf(key) >= 0) {\n throw new Error('Illegal operation for key'+key)\n } else {\n return target[key]\n }\n },\n })\n return exposeObj\n}\nfunction compileCode(src) {\n src = 'with (exposeObj) {'+src+'}'\n //console.log(src)\n return new Function('exposeObj', src)\n}\nfunction run(code) {\n let proxy = proxyObj({})\n let result = compileCode(code)(proxy)\n return result\n}\n\nonmessage = (e) => {\n try {\n let result = run(e.data.code)\n postMessage({\n code: 1,\n result,\n })\n } catch (err) {\n postMessage({\n code: -1,\n err,\n })\n }\n}\n"]),F=URL.createObjectURL(T);function I(e,n){return void 0===n&&(n=5e3),o(this,void 0,void 0,(function(){var t;return a(this,(function(r){return t=new Worker(F),[2,new Promise((function(r,o){var a=function(){clearTimeout(c),t.removeEventListener("message",i),t.terminate(),t=null},i=function(e){var n=e.data,t=n.code,i=n.result,c=n.err;a(),1===t?r(i):o(c)};t.postMessage({code:e}),t.addEventListener("message",i);var c=setTimeout((function(){a(),o("timeout")}),n)}))]}))}))}function j(e,n,t,r){return void 0===t&&(t={}),void 0===r&&(r="worker"),o(this,void 0,void 0,(function(){var o,c,u,s,l,d,f,v,p;return a(this,(function(a){switch(a.label){case 0:return a.trys.push([0,4,,5]),"window"!=r?[3,1]:(c=(o=[["data"],[n]])[0],u=o[1],"object"==typeof t&&Object.keys(t).forEach((function(e){c.push(e),u.push(t[e])})),s=new(Function.bind.apply(Function,i(i([void 0],c,!1),[e],!1))),[2,{success:!0,data:s.apply(void 0,u)}]);case 1:return f=(l=[n,t,""])[1],v=l[2],"object"==typeof(d=l[0])&&(d=JSON.stringify(n)),"object"==typeof t&&(f=JSON.stringify(t)),Object.keys(t).forEach((function(e){return v+="".concat(e,",")})),p="let data=eval(".concat(d,"); \n             let app=").concat(JSON.stringify({}),";"),p+=v?"let {".concat(v,"} = eval(").concat(f,"); "):"",[4,I(p+="".concat(e))];case 2:return[2,{success:!0,data:a.sent()}];case 3:return[3,5];case 4:return[2,{success:!1,error:a.sent(),data:n}];case 5:return[2]}}))}))}!function(e){e.StaticFile="staticFile",e.DataSource="datasource"}(C||(C={})),function(e){e.json="application/json;charset=UTF-8",e.form="application/x-www-form-urlencoded; charset=UTF-8"}(A||(A={})),function(e){e.get="GET",e.post="POST",e.put="PUT",e.patch="PATCH",e.delete="DELETE"}(O||(O={}));var P,x=function(){function e(e){this.db=null,this.dbName=e.databaseName,this.tableName=e.tableName,this.keyPath=e.keyPath}return e.getInstance=function(n){return e.instance||(e.instance=new e(n)),e.instance},e.prototype.init=function(){return o(this,void 0,void 0,(function(){var e=this;return a(this,(function(n){return[2,new Promise((function(n,t){var r=indexedDB.open(e.dbName,1);r.onerror=function(e){t(e.target.error)},r.onupgradeneeded=function(n){e.db=n.target.result,e.db.objectStoreNames.contains(e.tableName)||e.db.createObjectStore(e.tableName,{keyPath:e.keyPath})},r.onsuccess=function(t){e.db=t.target.result,n()}}))]}))}))},e.prototype.addRecord=function(e){return o(this,void 0,void 0,(function(){var n=this;return a(this,(function(t){if(!this.db)throw new Error("数据库未初始化。");return[2,new Promise((function(t,r){var o=n.db.transaction([n.tableName],"readwrite").objectStore(n.tableName).add(e);o.onsuccess=function(){t()},o.onerror=function(e){r(e.target.error)}}))]}))}))},e.prototype.deleteRecord=function(e){return o(this,void 0,void 0,(function(){var n=this;return a(this,(function(t){if(!this.db)throw new Error("数据库未初始化。");return[2,new Promise((function(t,r){var o=n.db.transaction([n.tableName],"readwrite").objectStore(n.tableName).delete(e);o.onsuccess=function(){t()},o.onerror=function(e){r(e.target.error)}}))]}))}))},e.prototype.updateRecord=function(e){return o(this,void 0,void 0,(function(){var n=this;return a(this,(function(t){if(!this.db)throw new Error("数据库未初始化。");return[2,new Promise((function(t,r){var o=n.db.transaction([n.tableName],"readwrite").objectStore(n.tableName).put(e);o.onsuccess=function(){t()},o.onerror=function(e){r(e.target.error)}}))]}))}))},e.prototype.getRecord=function(e){return o(this,void 0,void 0,(function(){var n=this;return a(this,(function(t){if(!this.db)throw new Error("数据库未初始化。");return[2,new Promise((function(t,r){var o=n.db.transaction([n.tableName],"readonly").objectStore(n.tableName).get(e);o.onsuccess=function(){t(o.result)},o.onerror=function(e){r(e.target.error)}}))]}))}))},e.prototype.getAllRecords=function(){return o(this,void 0,void 0,(function(){var e=this;return a(this,(function(n){if(!this.db)throw new Error("数据库未初始化。");return[2,new Promise((function(n,t){var r=e.db.transaction([e.tableName],"readonly").objectStore(e.tableName).getAll();r.onsuccess=function(){n(r.result)},r.onerror=function(e){t(e.target.error)}}))]}))}))},e.instance=null,e}();!function(e){e[e.FATAL=0]="FATAL",e[e.ERROR=1]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=3]="INFO",e[e.DEBUG=4]="DEBUG",e[e.TRACE=5]="TRACE"}(P||(P={}));var R={databaseName:"GODB",tableName:"go-log",keyPath:"time"},q=function(){function e(){this.logLevel=P.INFO,this.indexedDBInstance=x.getInstance(R);try{this.indexedDBInstance.init(),console.log("IndexedDB 初始化成功。")}catch(e){console.error("初始化 IndexedDB 时出错:",e)}}return e.getInstance=function(){return e.instance||(e.instance=new e),e.instance},e.prototype.setLogLevel=function(e){this.logLevel=e},e.prototype.getColor=function(e){switch(e){case P.FATAL:return"";case P.ERROR:return"";case P.WARN:return"";case P.INFO:return"";case P.DEBUG:return"";case P.TRACE:return"";default:return""}},e.prototype.log=function(e,n){if(n<=this.logLevel){var t=(new Date).toISOString(),r="[".concat(t,"] [").concat(P[n],"]"),o=this.getColor(n);if(null===window||void 0===window?void 0:window.goDev)console.log("".concat(o).concat(r," ").concat(e,""));else{var a=v("anov-go-userInfo"),i=v("anov-go-proid"),c=" [操作人:".concat(null==a?void 0:a.userName," 项目ID:").concat(i,"] "),u={time:t,value:"".concat(e)};try{this.indexedDBInstance.addRecord(u)}catch(e){console.error("添加记录时出错:",e)}console.log("".concat(o).concat(r," ").concat(c," ").concat(e,""))}}},e.prototype.fatal=function(e){this.log(e,P.FATAL)},e.prototype.error=function(e){this.log(e,P.ERROR)},e.prototype.warn=function(e){this.log(e,P.WARN)},e.prototype.info=function(e){this.log(e,P.INFO)},e.prototype.debug=function(e){this.log(e,P.DEBUG)},e.prototype.trace=function(e){this.log(e,P.TRACE)},e}().getInstance(),U=function(e,n){return"string"!=typeof e?Promise.reject(new Error("URL should be a string")):s(e,n)},V=s(),L=s();function B(e){return o(this,void 0,void 0,(function(){var n;return a(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,V(e)];case 1:return[2,{code:2e4,data:t.sent().data}];case 2:throw n=t.sent(),console.error("请求数据发生错误-Error:",n),n;case 3:return[2]}}))}))}function z(e){return o(this,void 0,void 0,(function(){var n;return a(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,V({method:"get",url:e})];case 1:return[2,t.sent().data];case 2:throw n=t.sent(),console.error("JSON 数据请求:",n),n;case 3:return[2]}}))}))}function J(e,t,r,i){return void 0===t&&(t="get"),void 0===r&&(r={}),void 0===i&&(i={}),o(this,void 0,void 0,(function(){var o;return a(this,(function(a){try{return o={method:O[t],url:e,headers:i,timeout:u},["post","put"].includes(t.toLowerCase())?o.data=n.cloneDeep(r):o.params=n.cloneDeep(r),[2,/.json$/.test(e)?z(e):B(o)]}catch(e){throw console.error("获取数据:Error:",e),e}return[2]}))}))}function G(e,n,t,r){return o(this,void 0,void 0,(function(){var o,i,c,u,s;return a(this,(function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),o=window.anUrl||"",i=window.agentPath||"/ds/v1/api-proxy/v1/query",c=o+i,u=l(t,!0),[4,V({url:c,method:"post",headers:{"Content-Type":"application/json;charset=UTF-8"},data:{body:"post"===e?u:void 0,headers:d(r)?JSON.parse(r):r,method:e,url:n}})];case 1:return[2,a.sent()];case 2:throw s=a.sent(),console.error("代理请求数据:Error:",s),s;case 3:return[2]}}))}))}function M(e,n,t,r,i){return o(this,void 0,void 0,(function(){return a(this,(function(o){return[2,i?G(n,e,t,r):J(e,n,t,r)]}))}))}function _(e,n,t){var r,o,a;void 0===n&&(n="");var i=null!==(o=null===(r=null===window||void 0===window?void 0:window.BaseUrl)||void 0===r?void 0:r.replace("/management",""))&&void 0!==o?o:"",u=te("YZH_EXCHANGE_TOKEN")||(null===(a=null===window||void 0===window?void 0:window.yzhAuth)||void 0===a?void 0:a.getToken()),s=null===window||void 0===window?void 0:window.gdPassid,l=null===window||void 0===window?void 0:window.BASE_RELEASE,d="token=".concat(u,"&passid=").concat(s),f=l?"&preview=1":"",v="".concat(i,"/ds/data-engine/v1/").concat(e,"/zb-query?").concat(d).concat(f),p={};try{p=n?JSON.parse(n):{}}catch(e){p=n||{}}return V({method:"POST",url:v,data:{headers:t,param:p},timeout:c})}var X=function(e,n){return o(void 0,void 0,void 0,(function(){var t,r,o,i,u,s,l,d,f,v;return a(this,(function(a){return t=window.BaseUrl,r=n.dateType,o=void 0===r?"":r,i=n.endPeriod,u=void 0===i?"":i,s=n.metricsName,l=void 0===s?e:s,d=n.startPeriod,f=void 0===d?"":d,v="".concat(t,"ds/v1/metrics/v1/data-alarm?dateType=").concat(o,"&endPeriod=").concat(u,"&metricsName=").concat(l,"&startPeriod=").concat(f),[2,L({method:"GET",url:v,timeout:c})]}))}))},Q=function(e,n,t){return o(void 0,void 0,void 0,(function(){var o,i,u,s;return a(this,(function(a){if(o=(null===(s=window.BaseUrl)||void 0===s?void 0:s.replace("/management",""))||"",n.newEncryption=!0,i={staticFile:{method:"get",params:n,url:"".concat(o,"/ds/v1/file/v1/").concat(e,"/query")},datasource:{method:"post",url:"".concat(o,"/ds/v1/database/v1/").concat(e,"/query"),data:r({},n)}},!(u=i[t]))throw new Error("Invalid data type provided");return[2,V(r({timeout:c},u))]}))}))},W=function(e){return new Promise((function(n,t){var r;void 0!==(r=e.originData&&Object.keys(e.originData).length?e.originData:e.data)?n({data:r}):t("Failed to retrieve cdata")}))},H=function(e,n,t){try{switch(n){case"api":var r=oe(e,t);return{requestType:r.requestType,url:r.url,params:r.params,headers:r.headers,agency:r.agency};case"static":return{data:e};case"datasource":var o=re(e.inputSql,t);return{dsName:e.dsName,dsType:"1",sql:S(o),filter:e.sqlFilter};case"staticFile":return{dsName:e.dsName,dsType:e.dsType,sql:""};case"indicator":return{zbId:e.zbId,params:e.params,headers:e.headers};case"indicatorCQ":return{zbName:e.zbName,params:e.params};case"packData":return{};default:throw new Error("Invalid type")}}catch(n){console.log("准备请求数据发生错误",n,e)}},K=function(e,n){return o(void 0,void 0,void 0,(function(){var t;return a(this,(function(r){switch(r.label){case 0:switch(r.trys.push([0,16,,18]),n){case"api":return[3,1];case"static":return[3,3];case"datasource":return[3,5];case"staticFile":return[3,7];case"indicator":return[3,9];case"indicatorCQ":return[3,11];case"packData":return[3,13]}return[3,14];case 1:return[4,M(e.url,e.requestType,e.params,e.headers,e.agency)];case 2:case 4:case 6:case 8:case 10:case 17:return[2,r.sent()];case 3:return[4,W(e.data)];case 5:return[4,Q(e.dsName,{dsType:e.dsType,sql:e.sql,filter:e.filter},"datasource")];case 7:return[4,Q(e.dsName,{dsType:e.dsType,sql:e.sql},"staticFile")];case 9:return[4,_(e.zbId,e.params,e.headers)];case 11:return[4,X(e.zbName,e.params)];case 12:return[2,r.sent()];case 13:return[2,{}];case 14:throw new Error("Invalid type");case 15:return[3,18];case 16:return t=r.sent(),console.warn(t,"执行请求并获取数据发生错误"),[4,new Promise((function(e,n){e({error:!0})}))];case 18:return[2]}}))}))},Y=function(e,n,t,r,i){return void 0===r&&(r=[]),void 0===i&&(i=!1),o(void 0,void 0,void 0,(function(){var o,c,u,s,l,d,p,h;return a(this,(function(a){switch(a.label){case 0:return o=n||e.tmpData.source.dataType,c=e.tmpData.source["indicatorCQ"==o?"indicator":o],"globalData"!==o?[3,3]:(u=r.find((function(e){return e.key===c.id||e.key===c.key})),(s=v(c.id))&&!i?[2,s.data]:u?[4,Z(u,t)]:[3,2]);case 1:return l=a.sent(),d={key:c.id,data:l},f(c.id,d),[2,l];case 2:return[2];case 3:return p=H(c,o,t),[4,K(p,o)];case 4:return[2,(null==(h=a.sent())?void 0:h.data)?h.data:h]}}))}))},Z=function(e,n){return o(void 0,void 0,void 0,(function(){var t,r,o,i,c;return a(this,(function(a){switch(a.label){case 0:return t=Object.assign({},{tmpData:{source:e.value}}),r=t.tmpData.source.type,o=t.tmpData.source[r],i=H(o,r,n),[4,K(i,r)];case 1:return c=a.sent(),[4,$(c.data,t,!0,n)];case 2:return[2,a.sent()]}}))}))},$=function(e,t,r,i){return void 0===r&&(r=!0),o(void 0,void 0,void 0,(function(){var c,u,s;return a(this,(function(l){switch(l.label){case 0:return l.trys.push([0,5,,7]),c=t.tmpData.source,u=c.converse,c.mapFields,u&&u.use&&r?[4,new Promise((function(t,r){var c=function(e,t,r,i,c){return o(this,void 0,void 0,(function(){var r,o,c,u,s,l,d;return a(this,(function(f){switch(f.label){case 0:if(r=e,o=n.cloneDeep(t),c=o.use,u=o.data,!c)return[3,4];l=function(e){var t,o;return a(this,(function(a){switch(a.label){case 0:return u[e].use?(t=u[e].dependVars,o={},i&&o&&t&&t.length&&t.map((function(e){var t=n.cloneDeep(i).filter((function(n){var t=n.mapField==e;return t&&(o[e]=n.value),t}));t&&0!=t.length||(o[e]="")})),[4,j(u[e].code,r,o,u[e].mode?u[e].mode:"worker")]):[3,2];case 1:s=a.sent(),r=s.data,a.label=2;case 2:return[2]}}))},d=0,f.label=1;case 1:return d<u.length?[5,l(d)]:[3,4];case 2:f.sent(),f.label=3;case 3:return d++,[3,1];case 4:return[2,r]}}))}))}(e,u,0,i);t(c)}))]:[3,2];case 1:case 3:case 6:return[2,l.sent()];case 2:return[4,new Promise((function(n,t){n(e)}))];case 4:return[3,7];case 5:return s=l.sent(),console.error("执行过滤器发生错误:"+s),[4,new Promise((function(n,t){n(e)}))];case 7:return[2]}}))}))},ee=function(e,n,t){var r=e.tmpData.source,o=r.type;t?("static"===o&&r[o]&&(r[o].originData=t),"indicatorCQ"===o?r.indicator.data=n:r[o].data=n):"indicatorCQ"===o?r.indicator.data=n:r[o].data=n,e.source=n},ne=function(e,n,t,r,i,c){return void 0===t&&(t=[]),o(void 0,void 0,void 0,(function(){var o,u,s,l;return a(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),o=e.tmpData.source.type,[4,Y(e,o,t,r,c||!1)];case 1:return null!=(u=a.sent())&&u?[4,$(u,e,n,t)]:(i&&i({error:!0}),[2,Promise.resolve({error:!0})]);case 2:return s=a.sent(),ee(e,s),i&&i(s),[2,Promise.resolve(s)];case 3:return l=a.sent(),i&&i(l),q.error("Error in updateComData"),console.error("Error in updateComData:",l),[2,Promise.reject(l)];case 4:return[2]}}))}))},te=function(e){var n={};if(e&&e.includes("?"))for(var t=0,r=e.split("?")[1].split("&");t<r.length;t++){var o=r[t].split("=").map(decodeURIComponent),a=o[0],i=o[1];n[a]=i}return n},re=function(e,n){if(!n)return e;if("string"==typeof e)return""===e.trim()?"":e.replace(/@(\w+)|{{(\w+)}}/g,(function(e,t,r){var o=t||r,a=n.find((function(e){return e.mapField===o}));return a?a.value||a.originalValue||"":e}));if(Array.isArray(e))return e.map((function(e){return re(e,n)}));if("object"==typeof e&&null!==e){var t={};for(var r in e)t[r]=re(e[r],n);return t}return e},oe=function(e,n){var t=e.agency,r=e,o=r.url,a=void 0===o?null:o,i=r.headers,c=r.params,u=r.requestType,s=a?re(a,n):void 0,l=i&&i.use?re(i.value,n):{};return{url:s,requestType:u,params:c?re(c,n):{},headers:l,agency:t}},ae=function(e,n,t,r,i){return o(void 0,void 0,void 0,(function(){var o,c,u,s;return a(this,(function(l){switch(l.label){case 0:if(!e||!e.length)return[2];o=function(o){return a(this,(function(a){switch(a.label){case 0:return w(n,o.value,t)?[4,ne({tmpData:{source:{type:"globalData",globalData:{id:o.key}}}},!0,t,e,(function(e){console.log("数据更新成功-变量改变全局数据跟新")}),!0)]:[3,2];case 1:a.sent(),m(r,(function(n){var r,a,c;"globalData"===(null===(a=null===(r=null==n?void 0:n.tmpData)||void 0===r?void 0:r.source)||void 0===a?void 0:a.type)&&((null===(c=null==n?void 0:n.tmpData)||void 0===c?void 0:c.source.globalData).id===o.key&&ne(n,!0,t,e,(function(e){i(n,e)}),!1))})),a.label=2;case 2:return[2]}}))},c=0,u=e,l.label=1;case 1:return c<u.length?(s=u[c],[5,o(s)]):[3,4];case 2:l.sent(),l.label=3;case 3:return c++,[3,1];case 4:return[2]}}))}))},ie=function(e,n,t,r,i){return o(void 0,void 0,void 0,(function(){return a(this,(function(o){switch(o.label){case 0:return e?[4,ne({tmpData:{source:{type:"globalData",globalData:{id:e.key}}}},!0,n,t,(function(e){console.log("数据更新成功-数据源编辑")}),!0)]:[2];case 1:return o.sent(),m(r,(function(r){var o,a,c;"globalData"===(null===(a=null===(o=null==r?void 0:r.tmpData)||void 0===o?void 0:o.source)||void 0===a?void 0:a.type)&&((null===(c=null==r?void 0:r.tmpData)||void 0===c?void 0:c.source.globalData).id===e.key&&ne(r,!0,n,t,(function(e){i(r,e)}),!1))})),[2]}}))}))},ce=function(e,n){return e.id===n&&!(null==e?void 0:e.forkValue)},ue=function(e,n){return Array.isArray(n)?n.some((function(n){return e&&(void 0!==e[n]||e.hasOwnProperty(n))})):"string"==typeof n&&(e&&(void 0!==e[n]||e.hasOwnProperty(n)))},se=function(e,n,t,r){var o,a;if(ue(e,null==n?void 0:n.field)||ue(e,null==n?void 0:n.forkValue))a=e[null==n?void 0:n.field]||"";else if(ue(e.data,null==n?void 0:n.field)||ue(e.data,null==n?void 0:n.forkValue))a=e.data[null==n?void 0:n.field]||"";else for(var i=b(t,r),c=0,u=(null===(o=null==i?void 0:i.tmpData)||void 0===o?void 0:o.actions)||[];c<u.length;c++){var s=u[c].vars.find((function(e){return(null==e?void 0:e.mapField)===(null==n?void 0:n.mapField)}));if(s){a=s.value;break}}return a},le=function(e,n,t){e.value=n,e.converter&&e.converterCode?(e.originalValue=n,e.value=E(e.converterCode,n,t)):(e.originalValue=n,e.value=n)},de=function(e,n,t,r,o,a,i,c,u){switch(e.type){case"link":window.open(e.link,e.target);break;case"page":u&&u(e);break;case"dynamic":!function(e,n,t,r,o){for(var a=0,i=e.dynamic||[];a<i.length;a++){var c=i[a];if(e.id===n.cid){var u=b(t,c.pid);u&&(u.activeDynamic=c.name,u.isShow=c.visible||!r||e.index===n.index-1,o({cid:u.cid,flag:c.visible}))}}}(e,n,t,r,o);break;case"toggle":!function(e,n,t,r,o){for(var a=0,i=e.children||[];a<i.length;a++){var c=i[a],u=c.visible&&(!r||e.index===n.index-1);o({cid:c.cid,flag:u})}}(e,n,0,r,o);break;case"update":!function(e,n,t,r,o){for(var a=function(e){var a=b(n,e.cid);a&&ne(a,!0,t,r,(function(e){o({cid:a.cid,data:e})}))},i=0,c=e.children||[];i<c.length;i++)a(c[i])}(e,t,a,i,c)}},fe=function(e,t,r,o,a,i,c,u,s){var l=a.cid,d=a.actions,f=a.index,v=d.eventName,p=2===d.mode;!function(e,t,r,o,a,i,c){for(var u=[],s=0,l=e;s<l.length;s++){var d=l[s];if(ce(d,a)&&d.type==t){var f=se(r,d,o,a),v=void 0!==f?f:d.value;le(d,v,e);for(var p=0,h=e;p<h.length;p++){var m=h[p];if(m.id!=a&&!(null==d?void 0:d.forkValue)&&m.mapField==d.mapField){var y=void 0!==f?f:m.value;le(m,y,e)}}u.push(d)}}for(var g=e.filter((function(e){return u&&(u.find((function(n){return n.mapField==e.mapField}))||u.find((function(n){return n.mapField==e.forkValue}))||u.find((function(n){return Array.isArray(e.forkValue)&&e.forkValue.includes(n.mapField)})))})),w=function(n){if(!i)return"break";var t=i[n.mapField]||[];if(n.fork)if(Array.isArray(n.forkValue))n.originalValue=n.forkValue.map((function(n){var t=e.find((function(e){return e.mapField==n}));if(t)return t.value}));else{var r=e.find((function(e){return e.mapField==n.forkValue}));r&&(n.originalValue=r.value)}n.converter&&n.converterCode?n.value=E(n.converterCode,n.originalValue,e):n.value=n.originalValue,c&&c(n,t)},b=0,k=g=n.uniqBy(g,"mapField");b<k.length&&"break"!==w(d=k[b]);b++);}(t,v,a,o,l,r,(function(e,n){if(ae(s,e.mapFile,t,o,(function(e,n){c({cid:e.cid,data:n})})),null==n?void 0:n.length)for(var r=function(n){e.eventSourceId=n;var r=b(o,n);!(null==e?void 0:e.delayUpdate)&&r&&ne(r,!0,t,s,(function(e){c({cid:r.cid,data:e})}))},a=0,i=n;a<i.length;a++){r(i[a])}}));for(var h=function(e,n,t,r,o){return e.filter((function(e){return e.id===n&&e.eventType===t&&(!o||parseInt(e.index||"0")+1===parseInt(r||"0"))}))}(e,l,v,f,p),m=0,y=h;m<y.length;m++){var g=y[m];de(g,a,o,p,i,t,s,c,u)}};export{U as Http,q as Log,G as agentData,ee as editItem,fe as emitEvent,Z as fetchDataByGlobal,Y as fetchDataByType,$ as filterData,b as findItemDeep,k as findItemDeep2,J as getData,M as getDataForApi,Q as getDataForSource,W as getDataForStatic,_ as getDataForZb,X as getDataForZbCQ,v as getSessionData,l as getStandardData,y as getStringVars,w as hasVar,d as isJSON,m as recursion,E as safeEval,f as setSessionData,ae as updataGlobalDataSourceForVar,ne as updateComData,ie as updateGlobalDataSource};
@@ -1,4 +1,4 @@
1
- import { IndexedDBConfig, Record } from './type';
1
+ import { IndexedDBConfig, Record } from "./type";
2
2
  /**
3
3
  * IndexedDB 封装类,实现了初始化表、增加记录、删除记录、更新记录和查询记录的功能。
4
4
  * 采用单例模式确保全局只有一个实例。
@@ -0,0 +1 @@
1
+ export declare const changeVar: (globalVars: any, eventName: string, element: any, list: any, cid: string, shareVariableTree: any, callback: (mapFild: string, ids: any[]) => void) => void;
@@ -0,0 +1,52 @@
1
+ import { GlobalEvent, GlobalVar } from './type';
2
+ import { GlobalDataSourceItem, GoComponent } from '../fetchUtils/type';
3
+ export declare const filterCurrentEvent: (globalEvents: GlobalEvent[], cid: string, eventName: string, index: any, isMode2: boolean) => GlobalEvent[];
4
+ /**
5
+ * 处理 dynamic 类型事件
6
+ * @param {Object} item - dynamic 类型事件
7
+ * @param {GoComponent} element - 当前组件
8
+ * @param {Object} list - 组件列表
9
+ * @param {boolean} isMode2 - 是否为模式2
10
+ * @param {Function} changeShow - 更新组件显示状态的函数
11
+ */
12
+ export declare const handleDynamicEvent: (item: any, element: GoComponent, list: any, isMode2: boolean, changeShow: (props: {
13
+ cid: string;
14
+ flag: boolean;
15
+ }) => void) => void;
16
+ /**
17
+ * 处理 toggle 类型事件
18
+ * @param {Object} item - toggle 类型事件
19
+ * @param {GoComponent} element - 当前组件
20
+ * @param {Object} list - 组件列表
21
+ * @param {boolean} isMode2 - 是否为模式2
22
+ * @param {Function} changeShow - 更新组件显示状态的函数
23
+ */
24
+ export declare const handleToggleEvent: (item: any, element: GoComponent, list: any, isMode2: boolean, changeShow: (props: {
25
+ cid: string;
26
+ flag: boolean;
27
+ }) => void) => void;
28
+ /**
29
+ * 处理 update 类型事件
30
+ * @param {Object} item - update 类型事件
31
+ * @param {Object} list - 组件列表
32
+ * @param {GlobalVar[]} globalVars - 全局变量列表
33
+ * @param {GlobalDataSourceItem[]} globalSource - 全局数据源列表
34
+ * @param {Function} updataSourceForComponent - 更新组件数据的函数
35
+ */
36
+ export declare const handleUpdateEvent: (item: any, list: any, globalVars: GlobalVar[], globalSource?: GlobalDataSourceItem[], updataSourceForComponent?: any) => void;
37
+ /**
38
+ * 处理不同类型的事件
39
+ * @param {Object} item - 当前事件
40
+ * @param {GoComponent} element - 当前组件
41
+ * @param {Object} list - 组件列表
42
+ * @param {boolean} isMode2 - 是否为模式2
43
+ * @param {Function} changeShow - 更新组件显示状态的函数
44
+ * @param {Function} callback - 回调函数
45
+ * @param {GlobalVar[]} globalVars - 全局变量列表
46
+ * @param {GlobalDataSourceItem[]} globalSource - 全局数据源列表
47
+ * @param {Function} updataSourceForComponent - 更新组件数据的函数
48
+ */
49
+ export declare const handleEventType: (item: any, element: GoComponent, list: any, isMode2: boolean, changeShow: (props: {
50
+ cid: string;
51
+ flag: boolean;
52
+ }) => void, globalVars: GlobalVar[], globalSource?: GlobalDataSourceItem[], updataSourceForComponent?: any, callback?: any) => void;
@@ -0,0 +1,18 @@
1
+ import { GlobalEvent, GlobalVar } from './type';
2
+ import { GlobalDataSourceItem, GoComponent } from '../fetchUtils/type';
3
+ /**
4
+ * 触发并处理组件事件
5
+ * @param {GlobalEvent[]} globalEvents - 全局事件列表
6
+ * @param {GlobalVar[]} globalVars - 全局变量列表
7
+ * @param {Object} shareVariableTree - 共享变量树
8
+ * @param {Object} list - 组件列表
9
+ * @param {GoComponent} element - 当前组件
10
+ * @param {Function} changeShow - 更新组件显示状态的函数
11
+ * @param {Function} updataSourceForComponent - 更新组件数据的函数
12
+ * @param {Function} [callback] - 回调函数
13
+ * @param {GlobalDataSourceItem[]} [globalSource] - 全局数据源列表
14
+ */
15
+ export declare const emitEvent: (globalEvents: GlobalEvent[], globalVars: GlobalVar[], shareVariableTree: any, list: any, element: GoComponent, changeShow: (props: {
16
+ cid: string;
17
+ flag: boolean;
18
+ }) => void, updataSourceForComponent: any, callback?: any, globalSource?: GlobalDataSourceItem[]) => void;
@@ -0,0 +1,48 @@
1
+ export interface GlobalVar {
2
+ des: string;
3
+ key: number;
4
+ mapField: string;
5
+ mapping: string;
6
+ model: 2;
7
+ name: string;
8
+ value: any;
9
+ originalValue: any;
10
+ [prop: string]: any;
11
+ }
12
+ export interface EventData {
13
+ cid: string;
14
+ element: any;
15
+ globalVars: GlobalVar[];
16
+ list: any;
17
+ }
18
+ export interface EventHandler {
19
+ execute(): void;
20
+ }
21
+ interface EventChildren {
22
+ cid: string;
23
+ visible: boolean;
24
+ }
25
+ interface EventDynamic {
26
+ visible: true;
27
+ pid: string;
28
+ pname: string;
29
+ cid: string;
30
+ name: string;
31
+ }
32
+ interface EventParams {
33
+ field: string;
34
+ mapField: string;
35
+ value: any;
36
+ }
37
+ export interface GlobalEvent {
38
+ index: number;
39
+ eventType: string;
40
+ type: string;
41
+ id: string;
42
+ target?: string;
43
+ children?: EventChildren[];
44
+ dynamic?: EventDynamic[];
45
+ params?: EventParams[];
46
+ [prop: string]: any;
47
+ }
48
+ export {};
@@ -116,7 +116,7 @@ export declare const updateComData: (element: GoComponent, filterFlag: boolean,
116
116
  * @param list - 待处理的组件列表
117
117
  * @param callback - 回调函数
118
118
  */
119
- export declare const updataGlobalDataSourceForVar: (globalSource: GlobalDataSourceItem[], mapField: string, globalVars: any[], list: any[], callback: CallbackFunction) => Promise<void>;
119
+ export declare const updataGlobalDataSourceForVar: (globalSource: GlobalDataSourceItem[] | undefined, mapField: string, globalVars: any[], list: any[], callback: CallbackFunction) => Promise<void>;
120
120
  /**
121
121
  * 更新全局数据源并更新引用该数据源的组件
122
122
  * @param {GlobalDataSourceItem} globalSourceItem - 全局数据源项
@@ -1,8 +1,4 @@
1
- /**
2
- * 数据引擎
3
- * @param baseURL 基础路径
4
- * @param callback 回掉函数
5
- * @returns
6
- */
7
- declare const xhr: (baseURL?: string, callback?: Function) => import("axios").AxiosInstance;
1
+ import { AxiosInstance } from "axios";
2
+ import { CallbackFunction } from './type';
3
+ declare const xhr: (baseURL?: string, callback?: CallbackFunction) => AxiosInstance;
8
4
  export default xhr;
@@ -1,4 +1,4 @@
1
- import { CallbackFunction } from './type';
1
+ import { CallbackFunction } from "./type";
2
2
  /**
3
3
  * 数据引擎
4
4
  * @param baseURL 基础路径
@@ -1 +1,4 @@
1
- export * from './fetchUtils';
1
+ export * from "./fetchUtils";
2
+ export * from "./log";
3
+ export * from "./event";
4
+ export * from './tool';
@@ -0,0 +1,2 @@
1
+ import Logger from "./log";
2
+ export declare const Log: Logger;
@@ -1 +1,25 @@
1
- export {};
1
+ declare enum LogLevel {
2
+ FATAL = 0,
3
+ ERROR = 1,
4
+ WARN = 2,
5
+ INFO = 3,
6
+ DEBUG = 4,
7
+ TRACE = 5
8
+ }
9
+ declare class Logger {
10
+ private static instance;
11
+ private logLevel;
12
+ indexedDBInstance: any;
13
+ private constructor();
14
+ static getInstance(): Logger;
15
+ setLogLevel(level: LogLevel): void;
16
+ private getColor;
17
+ private log;
18
+ fatal(message: string): void;
19
+ error(message: string): void;
20
+ warn(message: string): void;
21
+ info(message: string): void;
22
+ debug(message: string): void;
23
+ trace(message: string): void;
24
+ }
25
+ export default Logger;
@@ -32,19 +32,36 @@ export declare const getSessionData: (key: string) => any;
32
32
  */
33
33
  export declare const recursion: (array: GoComponent[], callback: (args: any) => void) => void;
34
34
  /**
35
- * 处理字符串中的变量
36
- * @param url - 包含变量的字符串
37
- * @param globalVars - 全局变量
38
- * @param item - 可选项,用于特定情况下的处理
39
- * @param shareVariableTree - 可选项,用于特定情况下的处理
40
- * @returns 是否包含变量
41
- */
35
+ * 处理字符串中的变量
36
+ * @param url - 包含变量的字符串
37
+ * @param globalVars - 全局变量
38
+ * @param item - 可选项,用于特定情况下的处理
39
+ * @param shareVariableTree - 可选项,用于特定情况下的处理
40
+ * @returns 是否包含变量
41
+ */
42
42
  export declare const getStringVars: (url: string, globalVars: any, item?: any, shareVariableTree?: any) => boolean;
43
43
  /**
44
- * 判断数据源是否包含该变量
45
- * @param _varName - 变量名称
46
- * @param data - 数据
47
- * @param globalVars - 全局变量
48
- * @returns 是否包含变量
49
- */
44
+ * 判断数据源是否包含该变量
45
+ * @param _varName - 变量名称
46
+ * @param data - 数据
47
+ * @param globalVars - 全局变量
48
+ * @returns 是否包含变量
49
+ */
50
50
  export declare const hasVar: (_varName: string, data: any, globalVars: any) => boolean;
51
+ /**
52
+ * 查找组件树中某一个元素(递归)
53
+ * @param {Array<GoComponent>} array - 组件树
54
+ * @param {string | number} cid - 组件ID
55
+ * @param {boolean} del - 是否删除找到的元素
56
+ * @return {GoComponent | null} 返回选中的组件实例对象或者 null
57
+ */
58
+ export declare const findItemDeep: (array: GoComponent[], cid: string, del?: boolean) => GoComponent | null;
59
+ export declare const findItemDeep2: (array: GoComponent[], cid: string, del?: boolean) => any;
60
+ /**
61
+ * 安全执行 JavaScript 代码的函数
62
+ * @param {string} code - 待执行的 JavaScript 代码
63
+ * @param {any} params - 执行代码时的参数
64
+ * @param {any} globalVars - 执行代码时的变量
65
+ * @returns {any} - 执行结果或默认参数值
66
+ */
67
+ export declare function safeEval(code: string, params: any, globalVars: any): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdslib/go-utils",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "go-core utils",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/types/index.d.ts",
@@ -9,13 +9,6 @@
9
9
  "dist/code.es5.js",
10
10
  "dist/types"
11
11
  ],
12
- "scripts": {
13
- "build": "rimraf dist && rollup -c",
14
- "serve": "rimraf dist && rollup -c -w",
15
- "lint": "eslint .",
16
- "format": "prettier --write .",
17
- "docs": "typedoc --out docs --theme default src"
18
- },
19
12
  "keywords": [],
20
13
  "author": "ws880321",
21
14
  "license": "ISC",
@@ -42,11 +35,20 @@
42
35
  "@rollup/plugin-json": "^6.1.0",
43
36
  "@rollup/plugin-node-resolve": "^15.2.3",
44
37
  "axios": "^1.6.2",
38
+ "bunyan": "^1.8.15",
39
+ "chalk": "^5.3.0",
45
40
  "crypto-js": "^4.1.1",
46
41
  "lodash": "^4.17.21",
47
42
  "rollup-plugin-typescript": "^1.0.1",
48
43
  "ts-indexdb": "^0.0.8",
49
44
  "tslib": "^2.6.2",
50
45
  "typedoc": "^0.25.4"
46
+ },
47
+ "scripts": {
48
+ "build": "rimraf dist && rollup -c",
49
+ "serve": "rimraf dist && rollup -c -w",
50
+ "lint": "eslint .",
51
+ "format": "prettier --write .",
52
+ "docs": "typedoc --out docs --theme default --tsconfig ./tsconfig.json src"
51
53
  }
52
- }
54
+ }