@wdslib/go-utils 0.1.5 → 0.1.6
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 +1 -1
- package/dist/types/event/changeVar.d.ts +1 -1
- package/dist/types/event/index.d.ts +1 -1
- package/dist/types/fetchUtils/config.d.ts +2 -2
- package/dist/types/globalVars/BasicVariable.d.ts +44 -0
- package/dist/types/globalVars/index.d.ts +24 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/tool/index.d.ts +9 -1
- package/package.json +9 -9
- package/dist/types/fetchUtils/xhr.back.d.ts +0 -4
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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(/>/g,">").replace(/</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"[31;1m";case P.ERROR:return"[31m";case P.WARN:return"[33m";case P.INFO:return"[32m";case P.DEBUG:return"[36m";case P.TRACE:return"[34m";default:return"[0m"}},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,"[0m"));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,"[0m"))}}},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
|
+
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{s(n.next(e))}catch(e){a(e)}}function c(e){try{s(n.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,c)}s((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:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(s){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=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++,n=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=t.call(e,i)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}}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 c=5e3,s=5e3,u=function(t,r){void 0===t&&(t="");var n=e.create({baseURL:t,timeout:c,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};function l(e,t){return void 0===t&&(t=!1),t?d(e)?e:JSON.stringify(e):d(e)?JSON.parse(e):e}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},f=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)}},v=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},p=function(e){for(var t=0,r=e;t<r.length;t++){var n=r[t];n.code&&(n.code=n.code.replace(/>/g,">").replace(/</g,"<"))}},h=function(e,t){e instanceof Map?e.forEach((function(e){t([e])})):Array.isArray(e)&&e.forEach((function(e){t(e.children)}))},m=function(e,t){var r=function(e){var n,o,a;if(e)for(var i=0,c=e;i<c.length;i++){var s=c[i],u=null===(a=null===(o=null===(n=null==s?void 0:s.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)&&p(u),t(s),s.children?r(s.children):s.dynamicChildren?h(s.dynamicChildren,r):s.stateChildren&&r(s.stateChildren)}};r(e)},g=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&&y(n,e,r.cid),{value:!0})},i=0,c=o.map((function(e){return e.replace(/{{|}}|@/gm,"")}));i<c.length;i++){var s=a(c[i]);if("object"==typeof s)return s.value}return!1},y=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)},b=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,c=a.data;i<c.length;i++){var s=c[i];if((null==s?void 0:s.dependVars)&&s.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=g(u.inputSql||u.url||(null===(n=u.headers)||void 0===n?void 0:n.value)||u.params,r)),o},w=function(e,r,n){void 0===n&&(n=!1);var o=null,a=function(e){for(var i=0,c=e;i<c.length;i++){var s=c[i];if(s.cid===r){o=s,n&&t.remove(e,(function(e){return e.cid===r}));break}if(s.children&&a(s.children),s.dynamicChildren&&Array.isArray(s.dynamicChildren))for(var u=0,l=Array.from(s.dynamicChildren);u<l.length;u++){var d=l[u][1];a(d)}s.stateChildren&&a(s.stateChildren)}};return a(e),o},k=function(e,r,n){var o=!1,a=function(e){for(var i=0;i<e.length;i++){if(e[i].cid==r){o=e[i],n&&t.remove(e,(function(e){return e.cid==r}));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),s=0;s<c.length;s++)if(c[s]instanceof Array){var u=c[s][1];a(u)}}else if(e[i].dynamicChildren instanceof Array)for(c=e[i].dynamicChildren,s=0;s<c.length;s++)if(c[s]instanceof Array){u=c[s][1];a(u)}}else e[i].stateChildren&&a(e[i].stateChildren)}};return a(e),o||!1};function V(e,t,r){var n={};r&&r.forEach((function(e){(null==e?void 0:e.name)&&(n[e.name]=e.value||e.originvalue)}));try{return new Function("data","vars",e)(t,n)}catch(e){return console.error(e),t}}function E(e,t){try{return console.log(e,t,"1222"),new Function("data",e)(t)}catch(e){return console.error(e),t}}var F="anov@2019:helloX",N="anov@2020:helloX";function C(e){var t=r.enc.Utf8.parse(F),n=r.enc.Utf8.parse(N);return r.AES.encrypt(e,t,{iv:n,mode:r.mode.CBC,padding:r.pad.Pkcs7}).toString()}var O,A,D,S=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"]),I=URL.createObjectURL(S);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(I),[2,new Promise((function(n,o){var a=function(){clearTimeout(c),r.removeEventListener("message",i),r.terminate(),r=null},i=function(e){var t=e.data,r=t.code,i=t.result,c=t.err;a(),1===r?n(i):o(c)};r.postMessage({code:e}),r.addEventListener("message",i);var c=setTimeout((function(){a(),o("timeout")}),t)}))]}))}))}function j(e,t,r,n){return void 0===r&&(r={}),void 0===n&&(n="worker"),o(this,void 0,void 0,(function(){var o,c,s,u,l,d,f,v,p;return a(this,(function(a){switch(a.label){case 0:return a.trys.push([0,4,,5]),"window"!=n?[3,1]:(c=(o=[["data"],[t]])[0],s=o[1],"object"==typeof r&&Object.keys(r).forEach((function(e){c.push(e),s.push(r[e])})),u=new(Function.bind.apply(Function,i(i([void 0],c,!1),[e],!1))),[2,{success:!0,data:u.apply(void 0,s)}]);case 1:return f=(l=[t,r,""])[1],v=l[2],"object"==typeof(d=l[0])&&(d=JSON.stringify(t)),"object"==typeof r&&(f=JSON.stringify(r)),Object.keys(r).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,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"}(O||(O={})),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"}(D||(D={}));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(t){return e.instance||(e.instance=new e(t)),e.instance},e.prototype.init=function(){return o(this,void 0,void 0,(function(){var e=this;return a(this,(function(t){return[2,new Promise((function(t,r){var n=indexedDB.open(e.dbName,1);n.onerror=function(e){r(e.target.error)},n.onupgradeneeded=function(t){e.db=t.target.result,e.db.objectStoreNames.contains(e.tableName)||e.db.createObjectStore(e.tableName,{keyPath:e.keyPath})},n.onsuccess=function(r){e.db=r.target.result,t()}}))]}))}))},e.prototype.addRecord=function(e){return o(this,void 0,void 0,(function(){var t=this;return a(this,(function(r){if(!this.db)throw new Error("数据库未初始化。");return[2,new Promise((function(r,n){var o=t.db.transaction([t.tableName],"readwrite").objectStore(t.tableName).add(e);o.onsuccess=function(){r()},o.onerror=function(e){n(e.target.error)}}))]}))}))},e.prototype.deleteRecord=function(e){return o(this,void 0,void 0,(function(){var t=this;return a(this,(function(r){if(!this.db)throw new Error("数据库未初始化。");return[2,new Promise((function(r,n){var o=t.db.transaction([t.tableName],"readwrite").objectStore(t.tableName).delete(e);o.onsuccess=function(){r()},o.onerror=function(e){n(e.target.error)}}))]}))}))},e.prototype.updateRecord=function(e){return o(this,void 0,void 0,(function(){var t=this;return a(this,(function(r){if(!this.db)throw new Error("数据库未初始化。");return[2,new Promise((function(r,n){var o=t.db.transaction([t.tableName],"readwrite").objectStore(t.tableName).put(e);o.onsuccess=function(){r()},o.onerror=function(e){n(e.target.error)}}))]}))}))},e.prototype.getRecord=function(e){return o(this,void 0,void 0,(function(){var t=this;return a(this,(function(r){if(!this.db)throw new Error("数据库未初始化。");return[2,new Promise((function(r,n){var o=t.db.transaction([t.tableName],"readonly").objectStore(t.tableName).get(e);o.onsuccess=function(){r(o.result)},o.onerror=function(e){n(e.target.error)}}))]}))}))},e.prototype.getAllRecords=function(){return o(this,void 0,void 0,(function(){var e=this;return a(this,(function(t){if(!this.db)throw new Error("数据库未初始化。");return[2,new Promise((function(t,r){var n=e.db.transaction([e.tableName],"readonly").objectStore(e.tableName).getAll();n.onsuccess=function(){t(n.result)},n.onerror=function(e){r(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"[31;1m";case P.ERROR:return"[31m";case P.WARN:return"[33m";case P.INFO:return"[32m";case P.DEBUG:return"[36m";case P.TRACE:return"[34m";default:return"[0m"}},e.prototype.log=function(e,t){if(t<=this.logLevel){var r=(new Date).toISOString(),n="[".concat(r,"] [").concat(P[t],"]"),o=this.getColor(t);if(null===window||void 0===window?void 0:window.goDev)console.log("".concat(o).concat(n," ").concat(e,"[0m"));else{var a=v("anov-go-userInfo"),i=v("anov-go-proid"),c=" [操作人:".concat(null==a?void 0:a.userName," 项目ID:").concat(i,"] "),s={time:r,value:"".concat(e)};try{this.indexedDBInstance.addRecord(s)}catch(e){console.error("添加记录时出错:",e)}console.log("".concat(o).concat(n," ").concat(c," ").concat(e,"[0m"))}}},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,t){return"string"!=typeof e?Promise.reject(new Error("URL should be a string")):u(e,t)},L=u(),B=u();function G(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,L(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 z(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,L({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 J(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:D[r],url:e,headers:i,timeout:s},["post","put"].includes(r.toLowerCase())?o.data=t.cloneDeep(n):o.params=t.cloneDeep(n),[2,/.json$/.test(e)?z(e):G(o)]}catch(e){throw console.error("获取数据:Error:",e),e}return[2]}))}))}function M(e,t,r,n){return o(this,void 0,void 0,(function(){var o,i,c,s,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",c=o+i,s=l(r,!0),[4,L({url:c,method:"post",headers:{"Content-Type":"application/json;charset=UTF-8"},data:{body:"post"===e?s: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]}}))}))}function _(e,t,r,n,i){return o(this,void 0,void 0,(function(){return a(this,(function(o){return[2,i?M(t,e,r,n):J(e,t,r,n)]}))}))}function X(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:"",s=ne("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,l=null===window||void 0===window?void 0:window.BASE_RELEASE,d="token=".concat(s,"&passid=").concat(u),f=l?"&preview=1":"",v="".concat(i,"/ds/data-engine/v1/").concat(e,"/zb-query?").concat(d).concat(f),p={};try{p=t?JSON.parse(t):{}}catch(e){p=t||{}}return L({method:"POST",url:v,data:{headers:r,param:p},timeout:c})}var Q=function(e,t){return o(void 0,void 0,void 0,(function(){var r,n,o,i,s,u,l,d,f,v;return a(this,(function(a){return r=window.BaseUrl,n=t.dateType,o=void 0===n?"":n,i=t.endPeriod,s=void 0===i?"":i,u=t.metricsName,l=void 0===u?e:u,d=t.startPeriod,f=void 0===d?"":d,v="".concat(r,"ds/v1/metrics/v1/data-alarm?dateType=").concat(o,"&endPeriod=").concat(s,"&metricsName=").concat(l,"&startPeriod=").concat(f),[2,B({method:"GET",url:v,timeout:c})]}))}))},W=function(e,t,r){return o(void 0,void 0,void 0,(function(){var o,i,s,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)}},!(s=i[r]))throw new Error("Invalid data type provided");return[2,L(n({timeout:c},s))]}))}))},H=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")}))},K=function(e,t,r){try{switch(t){case"api":var n=ae(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=oe(e.inputSql,r);return{dsName:e.dsName,dsType:"1",sql:C(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)}},Y=function(e,t){return o(void 0,void 0,void 0,(function(){var r;return a(this,(function(n){switch(n.label){case 0:switch(n.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,_(e.url,e.requestType,e.params,e.headers,e.agency)];case 2:case 4:case 6:case 8:case 10:case 17:return[2,n.sent()];case 3:return[4,H(e.data)];case 5:return[4,W(e.dsName,{dsType:e.dsType,sql:e.sql,filter:e.filter},"datasource")];case 7:return[4,W(e.dsName,{dsType:e.dsType,sql:e.sql},"staticFile")];case 9:return[4,X(e.zbId,e.params,e.headers)];case 11:return[4,Q(e.zbName,e.params)];case 12:return[2,n.sent()];case 13:return[2,{}];case 14:throw new Error("Invalid type");case 15:return[3,18];case 16:return r=n.sent(),console.warn(r,"执行请求并获取数据发生错误"),[4,new Promise((function(e,t){e({error:!0})}))];case 18:return[2]}}))}))},Z=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,c,s,u,l,d,p,h;return a(this,(function(a){switch(a.label){case 0:return o=t||e.tmpData.source.dataType,c=e.tmpData.source["indicatorCQ"==o?"indicator":o],"globalData"!==o?[3,3]:(s=n.find((function(e){return e.key===c.id||e.key===c.key})),(u=v(c.id))&&!i?[2,u.data]:s?[4,$(s,r)]:[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=K(c,o,r),[4,Y(p,o)];case 4:return[2,(null==(h=a.sent())?void 0:h.data)?h.data:h]}}))}))},$=function(e,t){return o(void 0,void 0,void 0,(function(){var r,n,o,i,c;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=K(o,n,t),[4,Y(i,n)];case 1:return c=a.sent(),[4,ee(c.data,r,!0,t)];case 2:return[2,a.sent()]}}))}))},ee=function(e,r,n,i){return void 0===n&&(n=!0),o(void 0,void 0,void 0,(function(){var c,s,u;return a(this,(function(l){switch(l.label){case 0:return l.trys.push([0,5,,7]),c=r.tmpData.source,s=c.converse,c.mapFields,s&&s.use&&n?[4,new Promise((function(r,n){var c=function(e,r,n,i,c){return o(this,void 0,void 0,(function(){var n,o,c,s,u,l,d;return a(this,(function(f){switch(f.label){case 0:if(n=e,o=t.cloneDeep(r),c=o.use,s=o.data,!c)return[3,4];l=function(e){var r,o;return a(this,(function(a){switch(a.label){case 0:return s[e].use?(r=s[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,j(s[e].code,n,o,s[e].mode?s[e].mode:"worker")]):[3,2];case 1:u=a.sent(),n=u.data,a.label=2;case 2:return[2]}}))},d=0,f.label=1;case 1:return d<s.length?[5,l(d)]:[3,4];case 2:f.sent(),f.label=3;case 3:return d++,[3,1];case 4:return[2,n]}}))}))}(e,s,0,i);r(c)}))]:[3,2];case 1:case 3:case 6:return[2,l.sent()];case 2:return[4,new Promise((function(t,r){t(e)}))];case 4:return[3,7];case 5:return u=l.sent(),console.error("执行过滤器发生错误:"+u),[4,new Promise((function(t,r){t(e)}))];case 7:return[2]}}))}))},te=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},re=function(e,t,r,n,i,c){return void 0===r&&(r=[]),o(void 0,void 0,void 0,(function(){var o,s,u,l;return a(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),o=e.tmpData.source.type,[4,Z(e,o,r,n,c||!1)];case 1:return null!=(s=a.sent())&&s?[4,ee(s,e,t,r)]:(i&&i({error:!0}),[2,Promise.resolve({error:!0})]);case 2:return u=a.sent(),te(e,u),i&&i(u),[2,Promise.resolve(u)];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]}}))}))},ne=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},oe=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 oe(e,t)}));if("object"==typeof e&&null!==e){var r={};for(var n in e)r[n]=oe(e[n],t);return r}return e},ae=function(e,t){var r=e.agency,n=e,o=n.url,a=void 0===o?null:o,i=n.headers,c=n.params,s=n.requestType,u=a?oe(a,t):void 0,l=i&&i.use?oe(i.value,t):{};return{url:u,requestType:s,params:c?oe(c,t):{},headers:l,agency:r}},ie=function(e,t,r,n,i){return o(void 0,void 0,void 0,(function(){var o,c,s,u;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 b(t,o.value,r)?[4,re({tmpData:{source:{type:"globalData",globalData:{id:o.key}}}},!0,r,e,(function(e){console.log("数据更新成功-变量改变全局数据跟新")}),!0)]:[3,2];case 1:a.sent(),m(n,(function(t){var n,a,c;"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===(c=null==t?void 0:t.tmpData)||void 0===c?void 0:c.source.globalData).id===o.key&&re(t,!0,r,e,(function(e){i(t,e)}),!1))})),a.label=2;case 2:return[2]}}))},c=0,s=e,l.label=1;case 1:return c<s.length?(u=s[c],[5,o(u)]):[3,4];case 2:l.sent(),l.label=3;case 3:return c++,[3,1];case 4:return[2]}}))}))},ce=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,re({tmpData:{source:{type:"globalData",globalData:{id:e.key}}}},!0,t,r,(function(e){console.log("数据更新成功-数据源编辑")}),!0)]:[2];case 1:return o.sent(),m(n,(function(n){var o,a,c;"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===(c=null==n?void 0:n.tmpData)||void 0===c?void 0:c.source.globalData).id===e.key&&re(n,!0,t,r,(function(e){i(n,e)}),!1))})),[2]}}))}))},se=function(e,t){return e.id===t&&!(null==e?void 0:e.forkValue)},ue=function(e,t){return Array.isArray(t)?t.some((function(t){return e&&(void 0!==e[t]||e.hasOwnProperty(t))})):"string"==typeof t&&(e&&(void 0!==e[t]||e.hasOwnProperty(t)))},le=function(e,t,r,n){var o,a;if(ue(e,null==t?void 0:t.field)||ue(e,null==t?void 0:t.forkValue))a=e[null==t?void 0:t.field]||"";else if(ue(e.data,null==t?void 0:t.field)||ue(e.data,null==t?void 0:t.forkValue))a=e.data[null==t?void 0:t.field]||"";else for(var i=w(r,n),c=0,s=(null===(o=null==i?void 0:i.tmpData)||void 0===o?void 0:o.actions)||[];c<s.length;c++){var u=s[c].vars.find((function(e){return(null==e?void 0:e.mapField)===(null==t?void 0:t.mapField)}));if(u){a=u.value;break}}return a},de=function(e,t,r){e.value=t,e.converter&&e.converterCode?(e.originalValue=t,e.value=V(e.converterCode,t,r)):(e.originalValue=t,e.value=t)},fe=function(e,t,r,n,o,a,i,c,s){switch(e.type){case"link":window.open(e.link,e.target);break;case"page":s&&s(e);break;case"dynamic":!function(e,t,r,n,o){for(var a=0,i=e.dynamic||[];a<i.length;a++){var c=i[a];if(e.id===t.cid){var s=w(r,c.pid);s&&(s.activeDynamic=c.name,s.isShow=c.visible||!n||e.index===t.index-1,o({cid:s.cid,flag:c.visible}))}}}(e,t,r,n,o);break;case"toggle":!function(e,t,r,n,o){for(var a=0,i=e.children||[];a<i.length;a++){var c=i[a],s=c.visible&&(!n||e.index===t.index-1);o({cid:c.cid,flag:s})}}(e,t,0,n,o);break;case"update":!function(e,t,r,n,o){for(var a=function(e){var a=w(t,e.cid);a&&re(a,!0,r,n,(function(e){o({cid:a.cid,data:e})}))},i=0,c=e.children||[];i<c.length;i++)a(c[i])}(e,r,a,i,c)}},ve=function(e,r,n,o,a,i,c,s,u,l){var d=a.cid,f=a.actions,v=a.index,p=f.eventName,h=2===f.mode;!function(e,r,n,o,a,i,c,s){for(var u=[],l=0,d=e;l<d.length;l++){var f=d[l];if(se(f,a)&&f.type==r){var v=le(n,f,o,a),p=void 0!==v?v:f.value;de(f,p,e);for(var h=0,m=e;h<m.length;h++){var g=m[h];if(g.id!=a&&!(null==f?void 0:f.forkValue)&&g.mapField==f.mapField){var y=void 0!==v?v:g.value;de(g,y,e)}}u.push(f)}}for(var b=e.filter((function(e){return u&&(u.find((function(t){return t.mapField==e.mapField}))||u.find((function(t){return t.mapField==e.forkValue}))||u.find((function(t){return Array.isArray(e.forkValue)&&e.forkValue.includes(t.mapField)})))})),w=function(t){if(!i)return"break";var r=i[t.mapField]||[];if(t.fork)if(Array.isArray(t.forkValue))t.originalValue=t.forkValue.map((function(t){var r=e.find((function(e){return e.mapField==t}));if(r)return r.value}));else{var n=e.find((function(e){return e.mapField==t.forkValue}));n&&(t.originalValue=n.value)}t.converter&&t.converterCode?t.value=V(t.converterCode,t.originalValue,e):t.value=t.originalValue;var o=c.find((function(e){return e.mapField==t.mapField}));console.log(c,"gcItemgcItem"),o&&(t.converter&&t.converterCode?o.value=V(t.converterCode,t.originalValue,e):o.value=t.originalValue),s&&s(t,r)},k=0,E=b=t.uniqBy(b,"mapField");k<E.length&&"break"!==w(f=E[k]);k++);}(r,p,a,o,d,n,l,(function(e,t){if(ie(u,e.mapFile,r,o,(function(e,t){c({cid:e.cid,data:t})})),null==t?void 0:t.length)for(var n=function(t){e.eventSourceId=t;var n=w(o,t);!(null==e?void 0:e.delayUpdate)&&n&&re(n,!0,r,u,(function(e){c({cid:n.cid,data:e})}))},a=0,i=t;a<i.length;a++){n(i[a])}}));for(var m=function(e,t,r,n,o){return e.filter((function(e){return e.id===t&&e.eventType===r&&(!o||parseInt(e.index||"0")+1===parseInt(n||"0"))}))}(e,d,p,v,h),g=0,y=m;g<y.length;g++){var b=y[g];fe(b,a,o,h,i,r,u,c,s)}},pe=function(){function e(e,t){this.des=e.des,this.field=e.field,this.id=e.id,this.key=e.key,this.mapping=e.mapping,this.mapField=e.mapField,this.type=e.type,this.originalValue=e.originalValue,this.model=e.model,this.converter=e.converter,this.converterCode=e.converterCode,this.fork=e.fork,t&&(this.globalVariables=t),e.fork&&(this.forkValue=e.forkValue,this.originalValue=this.getForkedValue())}return Object.defineProperty(e.prototype,"value",{get:function(){return this.fork&&(this.originalValue=this.getForkedValue()),this.converter&&this.converterCode?E(this.converterCode,this.originalValue):this.originalValue},set:function(e){this.value=e},enumerable:!1,configurable:!0}),e.prototype.getForkedValue=function(){var e=this;if(this.forkValue&&Array.isArray(this.forkValue))return this.forkValue.map((function(t){var r=e.globalVariables.get(t);return r?r.value:null}));if(this.forkValue){var t=this.globalVariables.get(this.forkValue);return t?t.value:null}return null},e.prototype.renew=function(e){e&&e(this)},e.prototype.updateValue=function(e,t){var r,n,o,a,i,c,s,u,l;this.des=null!==(r=e.des)&&void 0!==r?r:this.des,this.field=null!==(n=e.field)&&void 0!==n?n:this.field,this.mapping=null!==(o=e.mapping)&&void 0!==o?o:this.mapping,this.type=null!==(a=e.type)&&void 0!==a?a:this.type,this.originalValue=null!==(i=e.originalValue)&&void 0!==i?i:this.originalValue,this.converter=null!==(c=e.converter)&&void 0!==c?c:this.converter,this.converterCode=null!==(s=e.converterCode)&&void 0!==s?s:this.converterCode,this.fork=null!==(u=e.fork)&&void 0!==u?u:this.fork,e.fork&&(this.forkValue=null!==(l=e.forkValue)&&void 0!==l?l:this.forkValue,this.originalValue=this.getForkedValue()),t&&t(this)},e.create=function(t,r){return new e(t,r)},e}(),he=function(){function e(){this.variables=new Map,this.globalObservers=[]}return e.getInstance=function(){return e.instance||(e.instance=new e),e.instance},e.prototype.addVariables=function(e){var t=this;return Array.isArray(e)?e.map((function(e){return t.addVariable(e)})):[this.addVariable(e)]},e.prototype.addVariable=function(e,t){if(this.isVariableNameExist(e.mapField))throw new Error("Variable with key '".concat(e.mapField,"' already exists."));var r=pe.create(e,this.variables);return this.variables.set(r.mapField,r),t&&t(r),this.notifyGlobalObservers(r),r},e.prototype.editVariable=function(e,t){var r=this,n=this.getVariable(e.mapField);n?n.updateValue(e,(function(e){r.notifyGlobalObservers(e);var n=r.isMapFieldInForkValues(e.mapField);if(null==n?void 0:n.length)for(var o=0,a=n;o<a.length;o++){a[o].renew((function(e){r.notifyGlobalObservers(e)}))}t&&t(e)})):this.addVariable(e,t)},e.prototype.isMapFieldInForkValues=function(e){var t=this.getAllVariables();return console.log(t,"999999"),t.filter((function(e){return e.fork&&e.forkValue})).filter((function(t){return t.forkValue==e||Array.from(t.forkValue).includes(e)}))},e.prototype.isVariableNameExist=function(e){return this.variables.has(e)},e.prototype.getVariable=function(e){return this.variables.get(e)},e.prototype.getAllVariables=function(){return t.cloneDeep(Array.from(this.variables.values()))},e.prototype.restoreVariables=function(e){var t=this;e.forEach((function(e){t.addVariable(e)}))},e.prototype.registerGlobalObserver=function(e){this.globalObservers.push(e)},e.prototype.notifyGlobalObservers=function(e){this.globalObservers.forEach((function(t){t.update(e)}))},e.instance=null,e}(),me=he.getInstance();export{he as GlobalVariables,U as Http,q as Log,M as agentData,te as editItem,ve as emitEvent,$ as fetchDataByGlobal,Z as fetchDataByType,ee as filterData,w as findItemDeep,k as findItemDeep2,J as getData,_ as getDataForApi,W as getDataForSource,H as getDataForStatic,X as getDataForZb,Q as getDataForZbCQ,v as getSessionData,l as getStandardData,g as getStringVars,me as globalVars,b as hasVar,d as isJSON,m as recursion,V as safeEval,E as safeEvalForCode,f as setSessionData,ie as updataGlobalDataSourceForVar,re as updateComData,ce as updateGlobalDataSource};
|
|
@@ -1 +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;
|
|
1
|
+
export declare const changeVar: (globalVars: any, eventName: string, element: any, list: any, cid: string, shareVariableTree: any, globalConstant: any, callback: (mapFild: string, ids: any[]) => void) => void;
|
|
@@ -15,4 +15,4 @@ import { GlobalDataSourceItem, GoComponent } from '../fetchUtils/type';
|
|
|
15
15
|
export declare const emitEvent: (globalEvents: GlobalEvent[], globalVars: GlobalVar[], shareVariableTree: any, list: any, element: GoComponent, changeShow: (props: {
|
|
16
16
|
cid: string;
|
|
17
17
|
flag: boolean;
|
|
18
|
-
}) => void, updataSourceForComponent: any, callback?: any, globalSource?: GlobalDataSourceItem[]) => void;
|
|
18
|
+
}) => void, updataSourceForComponent: any, callback?: any, globalSource?: GlobalDataSourceItem[], globalConstant?: any[]) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const ERR_OK = 200;
|
|
2
2
|
export declare const ERR_OK2 = 20000;
|
|
3
|
-
export declare const TIMEOUT =
|
|
4
|
-
export declare const TIMEOUT2 =
|
|
3
|
+
export declare const TIMEOUT = 5000;
|
|
4
|
+
export declare const TIMEOUT2 = 5000;
|
|
5
5
|
export declare const STATUS = "status";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
type GlobalVariables = any;
|
|
2
|
+
type CallbackFunction = (result?: any) => void;
|
|
3
|
+
declare class BasicVariable {
|
|
4
|
+
des: string;
|
|
5
|
+
field: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
key: string;
|
|
8
|
+
mapping?: string;
|
|
9
|
+
mapField: string;
|
|
10
|
+
type?: string;
|
|
11
|
+
originalValue: any;
|
|
12
|
+
model?: any;
|
|
13
|
+
converter?: boolean;
|
|
14
|
+
converterCode?: (data: any) => any;
|
|
15
|
+
fork?: boolean;
|
|
16
|
+
forkValue?: string | string[];
|
|
17
|
+
update?: boolean;
|
|
18
|
+
globalVariables: GlobalVariables;
|
|
19
|
+
constructor(params: BasicVariableParams, globalVariables: GlobalVariables);
|
|
20
|
+
get value(): any;
|
|
21
|
+
set value(val: any);
|
|
22
|
+
private getForkedValue;
|
|
23
|
+
renew(calback?: CallbackFunction): void;
|
|
24
|
+
updateValue(params: BasicVariableParams, callback?: (value: any) => void): void;
|
|
25
|
+
static create(params: BasicVariableParams, globalVariables: GlobalVariables): BasicVariable;
|
|
26
|
+
}
|
|
27
|
+
interface BasicVariableParams {
|
|
28
|
+
des: string;
|
|
29
|
+
field: string;
|
|
30
|
+
id?: string;
|
|
31
|
+
key: string;
|
|
32
|
+
mapping?: string;
|
|
33
|
+
mapField: string;
|
|
34
|
+
type?: string;
|
|
35
|
+
value: string;
|
|
36
|
+
originalValue: any;
|
|
37
|
+
model?: any;
|
|
38
|
+
converter?: boolean;
|
|
39
|
+
converterCode?: (data: any) => any | any;
|
|
40
|
+
fork?: boolean;
|
|
41
|
+
forkValue?: string | string[];
|
|
42
|
+
update?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export { BasicVariable, BasicVariableParams };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BasicVariable, BasicVariableParams } from './BasicVariable';
|
|
2
|
+
type CallbackFunction = (result?: any) => void;
|
|
3
|
+
interface GlobalObserver {
|
|
4
|
+
update(variable: BasicVariable): void;
|
|
5
|
+
}
|
|
6
|
+
declare class GlobalVariables {
|
|
7
|
+
private static instance;
|
|
8
|
+
private variables;
|
|
9
|
+
private globalObservers;
|
|
10
|
+
private constructor();
|
|
11
|
+
static getInstance(): GlobalVariables;
|
|
12
|
+
addVariables(variablesData: BasicVariableParams[] | BasicVariableParams): BasicVariable[];
|
|
13
|
+
addVariable(variableData: BasicVariableParams, callback?: CallbackFunction): BasicVariable;
|
|
14
|
+
editVariable(variableData: BasicVariableParams, callback?: CallbackFunction): void;
|
|
15
|
+
isMapFieldInForkValues(mapField: string): BasicVariable[];
|
|
16
|
+
private isVariableNameExist;
|
|
17
|
+
getVariable(key: string): BasicVariable | undefined;
|
|
18
|
+
getAllVariables(): BasicVariable[];
|
|
19
|
+
restoreVariables(variablesData: BasicVariableParams[]): void;
|
|
20
|
+
registerGlobalObserver(observer: GlobalObserver): void;
|
|
21
|
+
private notifyGlobalObservers;
|
|
22
|
+
}
|
|
23
|
+
declare const globalVars: GlobalVariables;
|
|
24
|
+
export { GlobalVariables, GlobalObserver, globalVars };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -64,4 +64,12 @@ export declare const findItemDeep2: (array: GoComponent[], cid: string, del?: bo
|
|
|
64
64
|
* @param {any} globalVars - 执行代码时的变量
|
|
65
65
|
* @returns {any} - 执行结果或默认参数值
|
|
66
66
|
*/
|
|
67
|
-
export declare function safeEval(code: string, params: any, globalVars
|
|
67
|
+
export declare function safeEval(code: string, params: any, globalVars?: any): any;
|
|
68
|
+
/**
|
|
69
|
+
* 安全执行 JavaScript 代码的函数
|
|
70
|
+
* @param {string} code - 待执行的 JavaScript 代码
|
|
71
|
+
* @param {any} params - 执行代码时的参数
|
|
72
|
+
* @param {any} globalVars - 执行代码时的变量
|
|
73
|
+
* @returns {any} - 执行结果或默认参数值
|
|
74
|
+
*/
|
|
75
|
+
export declare function safeEvalForCode(code: string, params: any): any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdslib/go-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "go-core utils",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/types/index.d.ts",
|
|
@@ -9,6 +9,13 @@
|
|
|
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 --tsconfig ./tsconfig.json src"
|
|
18
|
+
},
|
|
12
19
|
"keywords": [],
|
|
13
20
|
"author": "ws880321",
|
|
14
21
|
"license": "ISC",
|
|
@@ -43,12 +50,5 @@
|
|
|
43
50
|
"ts-indexdb": "^0.0.8",
|
|
44
51
|
"tslib": "^2.6.2",
|
|
45
52
|
"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"
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
}
|