@wdslib/go-utils 0.1.6 → 0.1.7
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{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
|
+
import e from"axios";import t from"lodash";import r from"crypto-js";function i(e,t,r,i){return new(r||(r=Promise))((function(o,a){function n(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,s)}l((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const o=5e3,a=5e3,n=(t="",r)=>{let i=e.create({baseURL:t,timeout:o,headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"}});return i.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)})),i.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)})),i};function s(e,t=!1){return t?l(e)?e:JSON.stringify(e):l(e)?JSON.parse(e):e}const l=e=>{if("string"==typeof e)try{const t=JSON.parse(e);return"object"==typeof t&&null!==t}catch(e){return!1}return!1},d=(e,t)=>{try{const r=JSON.stringify(t);sessionStorage.setItem(e,r)}catch(t){console.error(`Error setting session data for key ${e}:`,t)}},c=e=>{const t=sessionStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(t){console.error(`Error parsing session data for key ${e}:`,t)}return null},u=e=>{for(const t of e)t.code&&(t.code=t.code.replace(/>/g,">").replace(/</g,"<"))},h=(e,t)=>{e instanceof Map?e.forEach((e=>{t([e])})):Array.isArray(e)&&e.forEach((e=>{t(e.children)}))},f=(e,t)=>{const r=e=>{var i,o,a;if(e)for(const n of e){const e=null===(a=null===(o=null===(i=null==n?void 0:n.tmpData)||void 0===i?void 0:i.source)||void 0===o?void 0:o.converse)||void 0===a?void 0:a.data;(null==e?void 0:e.length)&&u(e),t(n),n.children?r(n.children):n.dynamicChildren?h(n.dynamicChildren,r):n.stateChildren&&r(n.stateChildren)}};r(e)},p=(e,t,r,i)=>{const o=e.match(/({{[\w]*}})|((@)[\w]*)/gm);if(o){const e=o.map((e=>e.replace(/{{|}}|@/gm,"")));for(const o of e)if(o&&t&&!(t.findIndex((e=>e.mapField===o))<0))return r&&i&&v(i,o,r.cid),!0}return!1},v=(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)},m=(e,t,r)=>{var i;let o=!1;const a=null==t?void 0:t.converse;if(a&&a.use&&a.data.length)for(const t of a.data)if((null==t?void 0:t.dependVars)&&t.dependVars.includes(e))return!0;const n=null==t?void 0:t[null==t?void 0:t.type];return((null==n?void 0:n.inputSql)||(null==n?void 0:n.url)||(null==n?void 0:n.headers)||(null==n?void 0:n.params))&&(o=p(n.inputSql||n.url||(null===(i=n.headers)||void 0===i?void 0:i.value)||n.params,r)),o},g=(e,r,i=!1)=>{let o=null;const a=e=>{for(const n of e){if(n.cid===r){o=n,i&&t.remove(e,(e=>e.cid===r));break}if(n.children&&a(n.children),n.dynamicChildren&&Array.isArray(n.dynamicChildren))for(const[,e]of Array.from(n.dynamicChildren))a(e);n.stateChildren&&a(n.stateChildren)}};return a(e),o},y=(e,r,i)=>{let o=!1;const a=e=>{for(let n=0;n<e.length;n++){if(e[n].cid==r){o=e[n],i&&t.remove(e,(e=>e.cid==r));break}if(e[n].children)a(e[n].children);else if(e[n].dynamicChildren){if(e[n].dynamicChildren instanceof Map){let t=Array.from(e[n].dynamicChildren);for(let e=0;e<t.length;e++)if(t[e]instanceof Array){let r=t[e][1];a(r)}}else if(e[n].dynamicChildren instanceof Array){let t=e[n].dynamicChildren;for(let e=0;e<t.length;e++)if(t[e]instanceof Array){let r=t[e][1];a(r)}}}else e[n].stateChildren&&a(e[n].stateChildren)}};return a(e),o||!1};function b(e,t,r){const i={};r&&r.forEach((e=>{(null==e?void 0:e.name)&&(i[e.name]=e.value||e.originvalue)}));try{return new Function("data","vars",e)(t,i)}catch(e){return console.error(e),t}}function w(e,r){let i=t.cloneDeep(r);try{return new Function("data",e)(i)}catch(e){return console.error(e),i}}const V="anov@2019:helloX",k="anov@2020:helloX";function E(e){let t=r.enc.Utf8.parse(V),i=r.enc.Utf8.parse(k);return r.AES.encrypt(e,t,{iv:i,mode:r.mode.CBC,padding:r.pad.Pkcs7}).toString()}const F=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"]),N=URL.createObjectURL(F);function O(e,t,r={},o="worker"){return i(this,void 0,void 0,(function*(){try{if("window"==o){let[i,o]=[["data"],[t]];"object"==typeof r&&Object.keys(r).forEach((e=>{i.push(e),o.push(r[e])}));const a=new Function(...i,e);return{success:!0,data:a(...o)}}{let[o,a,n]=[t,r,""];"object"==typeof o&&(o=JSON.stringify(t)),"object"==typeof r&&(a=JSON.stringify(r)),Object.keys(r).forEach((e=>n+=`${e},`));let s=`let data=eval(${o}); \n let app=${JSON.stringify({})};`;s+=n?`let {${n}} = eval(${a}); `:"",s+=`${e}`;let l=yield function(e,t=5e3){return i(this,void 0,void 0,(function*(){let r=new Worker(N);return new Promise(((i,o)=>{const a=()=>{clearTimeout(s),r.removeEventListener("message",n),r.terminate(),r=null},n=e=>{let{code:t,result:r,err:n}=e.data;a(),1===t?i(r):o(n)};r.postMessage({code:e}),r.addEventListener("message",n);let s=setTimeout((()=>{a(),o("timeout")}),t)}))}))}(s);return{success:!0,data:l}}}catch(e){return{success:!1,error:e,data:t}}}))}var A,D,C,S;!function(e){e.StaticFile="staticFile",e.DataSource="datasource"}(A||(A={})),function(e){e.json="application/json;charset=UTF-8",e.form="application/x-www-form-urlencoded; charset=UTF-8"}(D||(D={})),function(e){e.get="GET",e.post="POST",e.put="PUT",e.patch="PATCH",e.delete="DELETE"}(C||(C={}));class I{constructor(e){this.db=null,this.dbName=e.databaseName,this.tableName=e.tableName,this.keyPath=e.keyPath}static getInstance(e){return I.instance||(I.instance=new I(e)),I.instance}init(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const r=indexedDB.open(this.dbName,1);r.onerror=e=>{t(e.target.error)},r.onupgradeneeded=e=>{this.db=e.target.result,this.db.objectStoreNames.contains(this.tableName)||this.db.createObjectStore(this.tableName,{keyPath:this.keyPath})},r.onsuccess=t=>{this.db=t.target.result,e()}}))}))}addRecord(e){return i(this,void 0,void 0,(function*(){if(!this.db)throw new Error("数据库未初始化。");return new Promise(((t,r)=>{const i=this.db.transaction([this.tableName],"readwrite").objectStore(this.tableName).add(e);i.onsuccess=()=>{t()},i.onerror=e=>{r(e.target.error)}}))}))}deleteRecord(e){return i(this,void 0,void 0,(function*(){if(!this.db)throw new Error("数据库未初始化。");return new Promise(((t,r)=>{const i=this.db.transaction([this.tableName],"readwrite").objectStore(this.tableName).delete(e);i.onsuccess=()=>{t()},i.onerror=e=>{r(e.target.error)}}))}))}updateRecord(e){return i(this,void 0,void 0,(function*(){if(!this.db)throw new Error("数据库未初始化。");return new Promise(((t,r)=>{const i=this.db.transaction([this.tableName],"readwrite").objectStore(this.tableName).put(e);i.onsuccess=()=>{t()},i.onerror=e=>{r(e.target.error)}}))}))}getRecord(e){return i(this,void 0,void 0,(function*(){if(!this.db)throw new Error("数据库未初始化。");return new Promise(((t,r)=>{const i=this.db.transaction([this.tableName],"readonly").objectStore(this.tableName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=e=>{r(e.target.error)}}))}))}getAllRecords(){return i(this,void 0,void 0,(function*(){if(!this.db)throw new Error("数据库未初始化。");return new Promise(((e,t)=>{const r=this.db.transaction([this.tableName],"readonly").objectStore(this.tableName).getAll();r.onsuccess=()=>{e(r.result)},r.onerror=e=>{t(e.target.error)}}))}))}}I.instance=null,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"}(S||(S={}));const T={databaseName:"GODB",tableName:"go-log",keyPath:"time"};class U{constructor(){this.logLevel=S.INFO,this.indexedDBInstance=I.getInstance(T);try{this.indexedDBInstance.init(),console.log("IndexedDB 初始化成功。")}catch(e){console.error("初始化 IndexedDB 时出错:",e)}}static getInstance(){return U.instance||(U.instance=new U),U.instance}setLogLevel(e){this.logLevel=e}getColor(e){switch(e){case S.FATAL:return"[31;1m";case S.ERROR:return"[31m";case S.WARN:return"[33m";case S.INFO:return"[32m";case S.DEBUG:return"[36m";case S.TRACE:return"[34m";default:return"[0m"}}log(e,t){if(t<=this.logLevel){const r=(new Date).toISOString(),i=`[${r}] [${S[t]}]`,o=this.getColor(t);if(null===window||void 0===window?void 0:window.goDev)console.log(`${o}${i} ${e}[0m`);else{let t=c("anov-go-userInfo"),a=c("anov-go-proid"),n=` [操作人:${null==t?void 0:t.userName} 项目ID:${a}] `;const s={time:r,value:`${e}`};try{this.indexedDBInstance.addRecord(s)}catch(e){console.error("添加记录时出错:",e)}console.log(`${o}${i} ${n} ${e}[0m`)}}}fatal(e){this.log(e,S.FATAL)}error(e){this.log(e,S.ERROR)}warn(e){this.log(e,S.WARN)}info(e){this.log(e,S.INFO)}debug(e){this.log(e,S.DEBUG)}trace(e){this.log(e,S.TRACE)}}const P=U.getInstance(),j=(e,t)=>"string"!=typeof e?Promise.reject(new Error("URL should be a string")):n(e,t),$=n();let x=n();function R(e,r="get",o={},n={}){return i(this,void 0,void 0,(function*(){try{const s={method:C[r],url:e,headers:n,timeout:a};["post","put"].includes(r.toLowerCase())?s.data=t.cloneDeep(o):s.params=t.cloneDeep(o);return/.json$/.test(e)?function(e){return i(this,void 0,void 0,(function*(){try{return(yield $({method:"get",url:e})).data}catch(e){throw console.error("JSON 数据请求:",e),e}}))}(e):function(e){return i(this,void 0,void 0,(function*(){try{return{code:2e4,data:(yield $(e)).data}}catch(e){throw console.error("请求数据发生错误-Error:",e),e}}))}(s)}catch(e){throw console.error("获取数据:Error:",e),e}}))}function q(e,t,r,o){return i(this,void 0,void 0,(function*(){try{const i=window.anUrl||"",a=i+(window.agentPath||"/ds/v1/api-proxy/v1/query"),n=s(r,!0);return yield $({url:a,method:"post",headers:{"Content-Type":"application/json;charset=UTF-8"},data:{body:"post"===e?n:void 0,headers:l(o)?JSON.parse(o):o,method:e,url:t}})}catch(e){throw console.error("代理请求数据:Error:",e),e}}))}function L(e,t,r,o,a){return i(this,void 0,void 0,(function*(){return a?q(t,e,r,o):R(e,t,r,o)}))}function B(e,t="",r){var i,a,n;const s=`${null!==(a=null===(i=null===window||void 0===window?void 0:window.BaseUrl)||void 0===i?void 0:i.replace("/management",""))&&void 0!==a?a:""}/ds/data-engine/v1/${e}/zb-query?${`token=${Y("YZH_EXCHANGE_TOKEN")||(null===(n=null===window||void 0===window?void 0:window.yzhAuth)||void 0===n?void 0:n.getToken())}&passid=${null===window||void 0===window?void 0:window.gdPassid}`}${(null===window||void 0===window?void 0:window.BASE_RELEASE)?"&preview=1":""}`;let l={};try{l=t?JSON.parse(t):{}}catch(e){l=t||{}}return $({method:"POST",url:s,data:{headers:r,param:l},timeout:o})}const G=(e,t)=>i(void 0,void 0,void 0,(function*(){const r=window.BaseUrl,{dateType:i="",endPeriod:a="",metricsName:n=e,startPeriod:s=""}=t;return x({method:"GET",url:`${r}ds/v1/metrics/v1/data-alarm?dateType=${i}&endPeriod=${a}&metricsName=${n}&startPeriod=${s}`,timeout:o})})),z=(e,t,r)=>i(void 0,void 0,void 0,(function*(){var i;const a=(null===(i=window.BaseUrl)||void 0===i?void 0:i.replace("/management",""))||"";t.newEncryption=!0;const n={staticFile:{method:"get",params:t,url:`${a}/ds/v1/file/v1/${e}/query`},datasource:{method:"post",url:`${a}/ds/v1/database/v1/${e}/query`,data:Object.assign({},t)}}[r];if(!n)throw new Error("Invalid data type provided");return $(Object.assign({timeout:o},n))})),J=e=>new Promise(((t,r)=>{let i;i=e.originData&&Object.keys(e.originData).length?e.originData:e.data,void 0!==i?t({data:i}):r("Failed to retrieve cdata")})),M=(e,t,r)=>{try{switch(t){case"api":{let t=ee(e,r);return{requestType:t.requestType,url:t.url,params:t.params,headers:t.headers,agency:t.agency}}case"static":return{data:e};case"datasource":{const t=Z(e.inputSql,r);return{dsName:e.dsName,dsType:"1",sql:E(t),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)}},W=(e,t)=>i(void 0,void 0,void 0,(function*(){try{switch(t){case"api":return yield L(e.url,e.requestType,e.params,e.headers,e.agency);case"static":return yield J(e.data);case"datasource":return yield z(e.dsName,{dsType:e.dsType,sql:e.sql,filter:e.filter},"datasource");case"staticFile":return yield z(e.dsName,{dsType:e.dsType,sql:e.sql},"staticFile");case"indicator":return yield B(e.zbId,e.params,e.headers);case"indicatorCQ":return yield G(e.zbName,e.params);case"packData":return{};default:throw new Error("Invalid type")}}catch(e){return console.warn(e,"执行请求并获取数据发生错误"),yield new Promise(((e,t)=>{e({error:!0})}))}})),_=(e,t,r,o=[],a=!1)=>i(void 0,void 0,void 0,(function*(){const i=t||e.tmpData.source.dataType,n=e.tmpData.source["indicatorCQ"==i?"indicator":i];if("globalData"===i){const e=o.find((e=>e.key===n.id||e.key===n.key)),t=c(n.id);if(t&&!a)return t.data;if(e){let t=yield X(e,r),i={key:n.id,data:t};return d(n.id,i),t}return}const s=M(n,i,r),l=yield W(s,i);return(null==l?void 0:l.data)?l.data:l})),X=(e,t)=>i(void 0,void 0,void 0,(function*(){let r=Object.assign({},{tmpData:{source:e.value}});const i=r.tmpData.source.type,o=r.tmpData.source[i],a=M(o,i,t),n=yield W(a,i);return yield Q(n.data,r,!0,t)})),Q=(e,r,o=!0,a)=>i(void 0,void 0,void 0,(function*(){try{const{converse:n,mapFields:s}=r.tmpData.source;return n&&n.use&&o?yield new Promise(((r,o)=>{const s=function(e,r,o,a,n){return i(this,void 0,void 0,(function*(){let i,o=e,{use:n,data:s}=t.cloneDeep(r);if(n)for(let e=0;e<s.length;e++)if(s[e].use){let r=s[e].dependVars,n={};a&&n&&r&&r.length&&r.map((e=>{let r=t.cloneDeep(a).filter((t=>{let r=t.mapField==e;return r&&(n[e]=t.value),r}));r&&0!=r.length||(n[e]="")})),i=yield O(s[e].code,o,n,s[e].mode?s[e].mode:"worker"),o=i.data}return o}))}(e,n,0,a);r(s)})):yield new Promise(((t,r)=>{t(e)}))}catch(t){return console.error("执行过滤器发生错误:"+t),yield new Promise(((t,r)=>{t(e)}))}})),H=(e,t,r)=>{const{source:i}=e.tmpData,o=i.type;r?("static"===o&&i[o]&&(i[o].originData=r),"indicatorCQ"===o?i.indicator.data=t:i[o].data=t):"indicatorCQ"===o?i.indicator.data=t:i[o].data=t,e.source=t},K=(e,t,r=[],o,a,n)=>i(void 0,void 0,void 0,(function*(){try{let i=e.tmpData.source.type,s=yield _(e,i,r,o,n||!1);if(null==s||!s)return a&&a({error:!0}),Promise.resolve({error:!0});let l=yield Q(s,e,t,r);return H(e,l),a&&a(l),Promise.resolve(l)}catch(e){return a&&a(e),P.error("Error in updateComData"),console.error("Error in updateComData:",e),Promise.reject(e)}})),Y=e=>{const t={};if(e&&e.includes("?")){const r=e.split("?")[1].split("&");for(let e of r){const[r,i]=e.split("=").map(decodeURIComponent);t[r]=i}}return t},Z=(e,t)=>{if(!t)return e;if("string"==typeof e)return""===e.trim()?"":e.replace(/@(\w+)|{{(\w+)}}/g,((e,r,i)=>{const o=r||i,a=t.find((e=>e.mapField===o));return a?a.value||a.originalValue||"":e}));if(Array.isArray(e))return e.map((e=>Z(e,t)));if("object"==typeof e&&null!==e){const r={};for(let i in e)r[i]=Z(e[i],t);return r}return e},ee=(e,t)=>{const r=e.agency,i=e,{url:o=null,headers:a,params:n,requestType:s}=i,l=o?Z(o,t):void 0,d=a&&a.use?Z(a.value,t):{};return{url:l,requestType:s,params:n?Z(n,t):{},headers:d,agency:r}},te=(e,t,r,o,a)=>i(void 0,void 0,void 0,(function*(){if(e&&e.length)for(const i of e){m(t,i.value,r)&&(yield K({tmpData:{source:{type:"globalData",globalData:{id:i.key}}}},!0,r,e,(e=>{console.log("数据更新成功-变量改变全局数据跟新")}),!0),f(o,(t=>{var o,n,s;if("globalData"===(null===(n=null===(o=null==t?void 0:t.tmpData)||void 0===o?void 0:o.source)||void 0===n?void 0:n.type)){(null===(s=null==t?void 0:t.tmpData)||void 0===s?void 0:s.source.globalData).id===i.key&&K(t,!0,r,e,(e=>{a(t,e)}),!1)}})))}})),re=(e,t,r,o,a)=>i(void 0,void 0,void 0,(function*(){e&&(yield K({tmpData:{source:{type:"globalData",globalData:{id:e.key}}}},!0,t,r,(e=>{console.log("数据更新成功-数据源编辑")}),!0),f(o,(i=>{var o,n,s;if("globalData"===(null===(n=null===(o=null==i?void 0:i.tmpData)||void 0===o?void 0:o.source)||void 0===n?void 0:n.type)){(null===(s=null==i?void 0:i.tmpData)||void 0===s?void 0:s.source.globalData).id===e.key&&K(i,!0,t,r,(e=>{a(i,e)}),!1)}})))}));class ie{constructor(e,t){this.isUpdating=!1,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=(null==e?void 0:e.model)?null==e?void 0:e.model:1,this.converter=e.converter,this.converterCode=e.converterCode,this.fork=e.fork,this.delayUpdate=!!(null==e?void 0:e.delayUpdate),t&&(this.globalVariables=t),e.fork&&(this.model=5,this.forkValue=e.forkValue,this.originalValue=this.getForkedValue())}get value(){return this.fork&&(this.originalValue=this.getForkedValue()),this.converter&&this.converterCode?w(this.converterCode,this.originalValue):this.originalValue}getForkedValue(){if(this.forkValue&&Array.isArray(this.forkValue))return this.forkValue.map((e=>{const t=this.globalVariables.get(e);return t?t.value:null}));if(this.forkValue){const e=this.globalVariables.get(this.forkValue);return e?e.value:null}return null}updateValue(e,t){var r;const i=Object.assign({},this,e);this.des=i.des,this.field=i.field,this.mapping=i.mapping,this.type=i.type,this.originalValue=i.originalValue,this.converter=i.converter,this.converterCode=i.converterCode,this.fork=i.fork,this.delayUpdate=null==i?void 0:i.delayUpdate,this.model=null==i?void 0:i.model,e.id&&(this.id?"string"==typeof this.id?this.id=[this.id,e.id]:this.id instanceof Array&&!this.id.includes(e.id)&&this.id.push(e.id):this.id=e.id),e.fork&&(this.model=5,this.forkValue=null!==(r=e.forkValue)&&void 0!==r?r:this.forkValue,this.originalValue=this.getForkedValue()),t&&t(this),this.isUpdating=!1}updateWidthOriginalValue(e,t){var r;this.originalValue=e,this.fork&&(this.forkValue=null!==(r=this.forkValue)&&void 0!==r?r:this.forkValue,this.originalValue=this.getForkedValue()),t&&t(this)}renew(e){e&&e(this)}static create(e,t){return new ie(e,t)}}class oe{constructor(){this.variables=new Map,this.globalObservers=[],this.url=window.location.search}static getInstance(){return oe.instance||(oe.instance=new oe),oe.instance}getFullUrl(){this.url=window.location.search}getAllUrlParams(){const e=new URLSearchParams(window.location.search),t={};for(const[r,i]of e.entries())t[r]=i;return t}addUrlParamsToGlobalVars(){this.getFullUrl();let e=this.getAllUrlParams(),t=Object.keys(e),r=[];for(const i of t)r.push({mapField:i,originalValue:e[i],model:4});if(r.length)for(const e of r)this.addVariable(e)}addVariables(e){Array.isArray(e)?e.map((e=>this.addVariable(e))):this.addVariable(e),this.addUrlParamsToGlobalVars()}addVariable(e,t){if(this.isVariableNameExist(e.mapField)){let r=this.getVariable(e.mapField);if(this.sameValue(r,e))return r;this.editVariable(e,t)}const r=ie.create(e,this.variables);return this.variables.set(r.mapField,r),t&&t(r),this.notifyGlobalObservers(r),r}sameValue(e,t){if(e.fork&&e.forkValue===t.forkValue)return!0;if(e.converter&&e.converterCode===t.converterCode&&e.originalValue===t.originalValue)return!0;let r=!!e.delayUpdate==!!t.delayUpdate,i=e.originalValue==t.originalValue;return!(!r||!i)}editVariable(e,t){const r=this.getVariable(e.mapField);if(r&&this.isVariableNameExist(e.mapField)){if(this.sameValue(r,e))return}const i=e=>{if(!e.isUpdating){e.isUpdating=!0,this.notifyGlobalObservers(e);this.isMapFieldInForkValues(e.mapField).forEach((e=>{e.renew((e=>{this.notifyGlobalObservers(e)}))})),t&&t(e),e.isUpdating=!1}};r?r.updateValue(e,i):this.addVariable(e,i)}editVariableForValue(e,t,r){const i=this.getVariable(e),o=e=>{if(!e.isUpdating){e.isUpdating=!0,this.notifyGlobalObservers(e);this.isMapFieldInForkValues(e.mapField).forEach((e=>{e.renew((e=>{this.notifyGlobalObservers(e)}))})),r&&r(e),e.isUpdating=!1}};i&&i.updateWidthOriginalValue(t,o)}isMapFieldInForkValues(e){return this.getAllVariables().filter((e=>e.fork&&e.forkValue)).filter((t=>t.forkValue==e||Array.from(t.forkValue).includes(e)))}isVariableNameExist(e){return this.variables.has(e)}checkExist(e){if("string"==typeof e)return[{key:e}];if(Array.isArray(e)){const t=e.filter((e=>this.isVariableNameExist(e))).map((e=>({key:e})));return!!t.length&&t}return!1}getVariable(e){return this.variables.get(e)}getVariableForId(e){var t;let r=[];for(const[,i]of this.variables)(i.id===e||(null===(t=i.id)||void 0===t?void 0:t.includes(e)))&&r.push(i);return r}getAllVariables(){return Array.from(this.variables.values())}restoreVariables(e){e.forEach((e=>{this.addVariable(e)}))}registerGlobalObserver(e){this.globalObservers.push(e)}notifyGlobalObservers(e){this.globalObservers.forEach((t=>{t.update(e)}))}}oe.instance=null;const ae=oe.getInstance(),ne=(e,t)=>Array.isArray(t)?t.some((t=>e&&(void 0!==e[t]||e.hasOwnProperty(t)))):"string"==typeof t&&(e&&(void 0!==e[t]||e.hasOwnProperty(t))),se=(e,t,r,i)=>{const o=((e,t,r,i)=>{var o;let a;if(ne(e,null==t?void 0:t.field)||ne(e,null==t?void 0:t.forkValue))a=e[null==t?void 0:t.field]||"";else if(ne(e.data,null==t?void 0:t.field)||ne(e.data,null==t?void 0:t.forkValue))a=e.data[null==t?void 0:t.field]||"";else{const e=g(r,i),n=(null===(o=null==e?void 0:e.tmpData)||void 0===o?void 0:o.actions)||[];for(const e of n){const r=e.vars.find((e=>(null==e?void 0:e.mapField)===(null==t?void 0:t.mapField)));if(r){a=r.value;break}}}return a})(e,t,r,i);return void 0!==o?o:t.value},le=(e,t,r,i,o,a,n,s,l)=>{switch(e.type){case"link":window.open(e.link,e.target);break;case"page":l&&l(e);break;case"dynamic":((e,t,r,i,o)=>{const a=e.dynamic||[];for(const n of a){if(e.id!==t.cid)continue;const a=g(r,n.pid);a&&(a.activeDynamic=n.name,a.isShow=n.visible||!i||e.index===t.index-1,o({cid:a.cid,flag:n.visible}))}})(e,t,r,i,o);break;case"toggle":((e,t,r,i,o)=>{const a=e.children||[];for(const r of a){const a=r.visible&&(!i||e.index===t.index-1);o({cid:r.cid,flag:a})}})(e,t,0,i,o);break;case"update":((e,t,r,i,o)=>{const a=e.children||[];for(const e of a){const a=g(t,e.cid);a&&K(a,!0,r,i,(e=>{o({cid:a.cid,data:e})}))}})(e,r,a,n,s)}},de=(e,t,r,i,o,a,n,s,l,d)=>{const{cid:c,actions:u,index:h}=o,{eventName:f,mode:p}=u,v=2===p;((e,t,r,i,o,a)=>{let n=ae.getVariableForId(t.cid);if(null==n?void 0:n.length)for(const s of n)if(s.type==e){let e=se(t,s,r,i);ae.editVariableForValue(s.mapField,e,(()=>{const e=o[s.mapField]||[];a&&a(s,e)}))}})(f,o,i,c,r,((e,t)=>{if(te(l,e.mapFile,ae.getAllVariables(),i,((e,t)=>{n({cid:e.cid,data:t})})),null==t?void 0:t.length)for(const r of t){e.eventSourceId=r;const t=g(i,r);!(null==e?void 0:e.delayUpdate)&&t&&K(t,!0,ae.getAllVariables(),l,(e=>{n({cid:t.cid,data:e})}))}}));const m=((e,t,r,i,o)=>e.filter((e=>e.id===t&&e.eventType===r&&(!o||parseInt(e.index||"0")+1===parseInt(i||"0")))))(e,c,f,h,v);for(const e of m)le(e,o,i,v,a,ae.getAllVariables(),l,n,s)};export{oe as GlobalVariables,j as Http,P as Log,q as agentData,H as editItem,de as emitEvent,X as fetchDataByGlobal,_ as fetchDataByType,Q as filterData,g as findItemDeep,y as findItemDeep2,R as getData,L as getDataForApi,z as getDataForSource,J as getDataForStatic,B as getDataForZb,G as getDataForZbCQ,c as getSessionData,s as getStandardData,p as getStringVars,se as getVarDefaultVal,ae as globalVars,m as hasVar,l as isJSON,f as recursion,b as safeEval,w as safeEvalForCode,d as setSessionData,te as updataGlobalDataSourceForVar,K as updateComData,re as updateGlobalDataSource};
|
|
@@ -1 +1,3 @@
|
|
|
1
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;
|
|
2
|
+
export declare const getVarDefaultVal: (element: any, varItem: any, list: any, cid: any) => any;
|
|
3
|
+
export declare const changeVarNew: (eventName: string, element: any, list: any, cid: string, shareVariableTree: any, callback: (item: any, ids: any[]) => void) => void;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { GlobalEvent, GlobalVar } from './type';
|
|
2
2
|
import { GlobalDataSourceItem, GoComponent } from '../fetchUtils/type';
|
|
3
|
+
import { getVarDefaultVal } from './changeVar';
|
|
4
|
+
export { getVarDefaultVal };
|
|
3
5
|
/**
|
|
4
6
|
* 触发并处理组件事件
|
|
5
7
|
* @param {GlobalEvent[]} globalEvents - 全局事件列表
|
|
@@ -3,7 +3,7 @@ type CallbackFunction = (result?: any) => void;
|
|
|
3
3
|
declare class BasicVariable {
|
|
4
4
|
des: string;
|
|
5
5
|
field: string;
|
|
6
|
-
id?: string;
|
|
6
|
+
id?: string | string[];
|
|
7
7
|
key: string;
|
|
8
8
|
mapping?: string;
|
|
9
9
|
mapField: string;
|
|
@@ -16,23 +16,25 @@ declare class BasicVariable {
|
|
|
16
16
|
forkValue?: string | string[];
|
|
17
17
|
update?: boolean;
|
|
18
18
|
globalVariables: GlobalVariables;
|
|
19
|
-
|
|
19
|
+
[props: string]: any;
|
|
20
|
+
isUpdating: boolean;
|
|
21
|
+
constructor(params: Partial<BasicVariableParams>, globalVariables: GlobalVariables);
|
|
20
22
|
get value(): any;
|
|
21
|
-
set value(val: any);
|
|
22
23
|
private getForkedValue;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
updateValue(params: Partial<BasicVariableParams>, callback?: (value: any) => void): void;
|
|
25
|
+
updateWidthOriginalValue(value: any, callback?: (value: any) => void): void;
|
|
26
|
+
renew(callback?: CallbackFunction): void;
|
|
27
|
+
static create(params: Partial<BasicVariableParams>, globalVariables: GlobalVariables): BasicVariable;
|
|
26
28
|
}
|
|
27
29
|
interface BasicVariableParams {
|
|
28
|
-
des
|
|
29
|
-
field
|
|
30
|
+
des?: string;
|
|
31
|
+
field?: string;
|
|
30
32
|
id?: string;
|
|
31
|
-
key
|
|
33
|
+
key?: string;
|
|
32
34
|
mapping?: string;
|
|
33
35
|
mapField: string;
|
|
34
36
|
type?: string;
|
|
35
|
-
value
|
|
37
|
+
value?: string;
|
|
36
38
|
originalValue: any;
|
|
37
39
|
model?: any;
|
|
38
40
|
converter?: boolean;
|
|
@@ -40,5 +42,7 @@ interface BasicVariableParams {
|
|
|
40
42
|
fork?: boolean;
|
|
41
43
|
forkValue?: string | string[];
|
|
42
44
|
update?: boolean;
|
|
45
|
+
delayUpdate?: boolean;
|
|
46
|
+
[props: string]: any;
|
|
43
47
|
}
|
|
44
48
|
export { BasicVariable, BasicVariableParams };
|
|
@@ -7,14 +7,26 @@ declare class GlobalVariables {
|
|
|
7
7
|
private static instance;
|
|
8
8
|
private variables;
|
|
9
9
|
private globalObservers;
|
|
10
|
+
url: string;
|
|
10
11
|
private constructor();
|
|
11
12
|
static getInstance(): GlobalVariables;
|
|
12
|
-
|
|
13
|
+
getFullUrl(): void;
|
|
14
|
+
getAllUrlParams(): {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
};
|
|
17
|
+
addUrlParamsToGlobalVars(): void;
|
|
18
|
+
addVariables(variablesData: BasicVariableParams[] | BasicVariableParams): void;
|
|
13
19
|
addVariable(variableData: BasicVariableParams, callback?: CallbackFunction): BasicVariable;
|
|
20
|
+
sameValue(variable: BasicVariable, variableData: BasicVariableParams): boolean;
|
|
14
21
|
editVariable(variableData: BasicVariableParams, callback?: CallbackFunction): void;
|
|
22
|
+
editVariableForValue(mapfield: string, value: any, callback?: CallbackFunction): void;
|
|
15
23
|
isMapFieldInForkValues(mapField: string): BasicVariable[];
|
|
16
24
|
private isVariableNameExist;
|
|
25
|
+
checkExist(parameter: string | string[]): false | {
|
|
26
|
+
key: string;
|
|
27
|
+
}[];
|
|
17
28
|
getVariable(key: string): BasicVariable | undefined;
|
|
29
|
+
getVariableForId(id: string): BasicVariable[];
|
|
18
30
|
getAllVariables(): BasicVariable[];
|
|
19
31
|
restoreVariables(variablesData: BasicVariableParams[]): void;
|
|
20
32
|
registerGlobalObserver(observer: GlobalObserver): void;
|
|
@@ -68,8 +68,8 @@ export declare function safeEval(code: string, params: any, globalVars?: any): a
|
|
|
68
68
|
/**
|
|
69
69
|
* 安全执行 JavaScript 代码的函数
|
|
70
70
|
* @param {string} code - 待执行的 JavaScript 代码
|
|
71
|
-
* @param {any}
|
|
71
|
+
* @param {any} _params - 执行代码时的参数
|
|
72
72
|
* @param {any} globalVars - 执行代码时的变量
|
|
73
73
|
* @returns {any} - 执行结果或默认参数值
|
|
74
74
|
*/
|
|
75
|
-
export declare function safeEvalForCode(code: string,
|
|
75
|
+
export declare function safeEvalForCode(code: string, _params: any): any;
|