UNPKG

@open-data-v/data

Version:

OpenDataV 数据处理基础组件包

3 lines (2 loc) 1.3 kB
"use strict";var r=Object.defineProperty;var c=(e,t,s)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var o=(e,t,s)=>c(e,typeof t!="symbol"?t+"":t,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("lodash-es"),u=require("../hooks/http.umd.cjs");class h{constructor(t,s){o(this,"options");o(this,"requestInstance");o(this,"timer",0);this.options=t,this.requestInstance=s||u.useRequest()}close(){clearInterval(this.timer)}async connect(t){const{otherConfig:s={isRepeat:!1,interval:3e3}}=this.options||{};if(s.isRepeat){const a=async()=>{const i=await this.getRespData();t(i)},n=s.interval|3e3;this.timer=setInterval(a,n)}else{const a=await this.getRespData();t(a)}}async getRespData(){const t={status:"FAILED",data:""};if(!this.options)return t;try{const s={url:this.options.url,method:this.options.method,headers:this.options.headers,params:this.options.params,data:this.options.data},a=await this.requestInstance.request(s);t.status="SUCCESS",t.data=a.data}catch(s){s.response||s.toJSON&&s.toJSON(),t.status="FAILED",t.data=s.stack||s.message}return t}async debug(t){this.connect(t)}toJSON(){return{options:p.cloneDeep(this.options),type:"REST"}}}exports.default=h; //# sourceMappingURL=handler.umd.cjs.map