1 |
- /*AGENT_VERSION=1.3.8*/"use strict";var i=wx;function m(){return+new Date}function a(t){var e;try{e=i.getStorageSync(t)}catch(t){}return e}function r(t,e){try{i.setStorageSync(t,e)}catch(t){}}function t(){return i.getSystemInfoSync()}function y(t){return t.statusCode}function e(){return["requestPayment","scanCode","previewImage"]}var n=[],v={context:null},o={networkType:"",system:t()};function s(t){n.push({timestamp:m(),route:t})}function u(){n=[]}function c(){return n.slice()}function d(e){return function(t){return"Array"===e&&Array.isArray?Array.isArray(t):Object.prototype.toString.call(t)==="[object "+e+"]"}}var h=d("String"),f=d("Array"),g=d("Function"),T=d("Object"),l=d("Boolean"),p=d("Number");function D(t,e){return function(){if(g(e))try{e.apply(this,arguments)}catch(t){}if(g(t))return t.apply(this,arguments)}}function q(e,n,a){return function(){var t;if(g(n))try{n.apply(this,arguments)}catch(t){}if(g(e)&&(t=e.apply(this,arguments)),g(a))try{a.apply(this,arguments)}catch(t){}return t}}function S(t,e){var n,a,r;T(t)&&g(t.handler)&&(n=t.name,a=t.handler,r=t.afterHandler,e[n]=q(e[n],a,r),e[n]._ty_hook=!0)}var x=function(){function t(t){return t<0?NaN:t<=30?0|Math.random()*(1<<t):t<=53?(0|Math.random()*(1<<30))+(0|Math.random()*(1<<t-30))*(1<<30):NaN}function e(t,e){for(var n=t.toString(16),a=e-n.length,r="0";0<a;a>>>=1,r+=r)1&a&&(n=r+n);return n}return function(){return e(t(32),8)+"-"+e(t(16),4)+"-"+e(16384|t(12),4)+"-"+e(32768|t(14),4)+"-"+e(t(48),12)}}();function I(t){return t&&h(t)?JSON.parse(t):t}function b(t){try{return I(t)}catch(t){}return null}function k(t,e){var n="",a=!1;try{n=JSON.stringify(t)}catch(t){a=!(n="")}return e?{error:a,value:n}:n}function E(t){return t+""}function A(t){return t?T(t)?k(t).length:h(t)?t.length:t instanceof ArrayBuffer?t.byteLength:t.length?t.length:0:0}function C(t,e){var n=T(t)?k(t):h(t)?t:"";return e&&(n=n.substring(0,e)),n}var O="recordTyTime",_="TINGYUN_UID",F="custom",L="TRIGGER_LIFECYCLE",M="2.6.4",R=20,P="event",N="request",w="api",j="timer",H=1500,z=!0,Y=!0,B=5,G="TY_CONFIG",K="TY_SAMPLING",U="TY_SETDATA_THRESHOLD",J="TY_SETDATA_TRACE",V="TY_SETDATA_TRACEHINT",X="TY_IGNORE_ERRCODES",Q="TY_SETDATA_TIME_INTERVAL",W=[500,1500],Z=256,$=256,tt="__ty_page_param",et={},nt=!1;function at(t){null==(et=t||{}).requestFailMessageSize&&(et.requestFailMessageSize=$),null==et.apiFailMessageSize&&(et.apiFailMessageSize=Z)}function rt(){return nt}function it(t){nt=t}function ot(){for(var t=0;t<arguments.length;t++)if(null!=arguments[t])return arguments[t]}function st(t){this.size=t||100,this.queue=[],this.running=!1}st.prototype.add=function(t){this.queue.length>=this.size||(this.queue.push(t),this.running||(this.running=!0,this.run()))},st.prototype.run=function(){var t=this;this.handler(this.queue.shift(),function(){0<t.queue.length?t.run():t.running=!1})},st.prototype.handler=function(t,e){var n={url:"".concat(et.beacon).concat(t.uri),method:t.method||"POST",_no_record:!0,success:function(){t.success&&t.success.apply(this,arguments)},fail:function(){t.fail&&t.fail.apply(this,arguments)},complete:function(){t.complete&&t.complete.apply(this,arguments),e()}};t.data&&(n.data=t.data),i.request(n)};var ut=new st,ct=6e5,dt=yt(K),ht=!1;function ft(t){return null!=t&&p(t)}function lt(t){return null!=t&&l(t)}function pt(t){return null!=t&&f(t)}function mt(t){return pt(t)&&2==t.length}function yt(t){var e=a(G);if(e&&T(e))return e[t]}function vt(t){var e=a(G);if(e&&T(e)||(e={}),t)for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);r(G,e)}function gt(t,r){var i=this,o={};t.forEach(function(t){var e=t.key,n=t.storeKey,a=t.validFunc;!!a&&a.call(i,r[e])&&(et[e]=r[e],o[n]=r[e])}),vt(o)}function Tt(t){et.key&&et.beacon&&ut.add({uri:"/mp-config/config/pullSampling?encodeMpId=".concat(et.key),success:function(t){var e,n=t.data||{},a=n.data;200===n.code&&a&&(ft(a.sampling)&&(dt=a.sampling,(e={})[K]=dt,vt(e)),gt([{key:"setdataThreshold",storeKey:U,validFunc:ft},{key:"setdataTrace",storeKey:J,validFunc:lt},{key:"setdataTraceHint",storeKey:V,validFunc:lt},{key:"ignoreErrorCodes",storeKey:X,validFunc:pt},{key:"setdataTimeInterval",storeKey:Q,validFunc:mt}],a))},complete:function(){t&&t(dt)}})}function Dt(){dt=dt||(+et.sampleRate||1);var t=Math.random();ht=t<=dt}function qt(){return{uniqueId:0,requestId:0,apiId:0,otherActions:[],eventActions:[],setData:{threshold:ot(et.setdataThreshold,yt(U),H),setDataTrace:ot(et.setdataTrace,yt(J),z),setDataTraceHint:ot(et.setdataTraceHint,yt(V),Y),setDataTimeInterval:ot(et.setdataTimeInterval,yt(Q),W),stuck:!1,max:0,currentSegmentTime:0,data:{},requestBridge:[]},reqStat:{currentSegmentTime:0,data:{}},lastSetDataInOnReady:0,stuck:!1,jsError:!1,netError:!1,recordFirstLoad:!1}}function St(){return{stuck:!1,firstLoad:0,jsError:!1,netError:!1}}setInterval(Tt,ct);var xt={},It=[],bt=0,kt={},Et=qt(),At=St(),Ct={canSend:!1,sent:!1,apiRemain:0,needClearDeferredData:!1};function Ot(){xt={},It=[],bt=0,Ct.apiRemain=0,Et=qt(),Ct.needClearDeferredData=!0}function _t(){At=St()}function Ft(t){var e;Et.eventActions||(Et.eventActions=[]),Et.otherActions||(Et.otherActions=[]),t&&(t.type===P?(e=et&&et.eventMaxSize||R,Et.eventActions&&Et.eventActions.length>=e&&Et.eventActions.shift(),Et.eventActions.push(t)):Et.otherActions.push(t))}function Lt(t,e){for(var n in e)e.hasOwnProperty(n)&&e[n]&&0<e[n].count&&t.push(Object.assign(e[n]||{},{timestamp:+n}))}function Mt(){var t=[],e=[];Lt(t,Et.setData.data),Lt(e,Et.reqStat.data);var n,a,r={metric:{jsError:It&&0<It.length,netError:Et.netError,stuck:Et.stuck}};return 0<t.length&&(r.setData={threshold:ot(Et.setData.threshold,H),setDataTrace:ot(Et.setData.setDataTrace,z),setDataTraceHint:ot(Et.setData.setDataTraceHint,Y),setDataTimeInterval:ot(Et.setData.setDataTimeInterval,W),max:Et.setData.max,requestBridge:Et.setData.requestBridge,data:t}),0<e.length&&(r.reqStat=e),!xt.onLoad||(a=(a=Et.lastSetDataInOnReady)||xt.onReady)&&(n=0<(n=a-xt.onLoad)?n:0,r.metric.firstLoad=n),At=r.metric,r}function Rt(){bt=m()}var Pt={uid:Nt(),sid:x(),v:"1.3.8",at:"wx"};function Nt(){var t=a(_);return t||(t=x(),r(_,t)),t}function wt(t){var e;ht&&((e=Object.assign({},Pt,o||{},{key:et.key},t||{})).launch=!t,e.launch&&(e.launchOptions=v.launchOptions),ut.add({uri:"/mp-app",data:e}))}function jt(t){var e,n;ht&&(L===t&&(Ct.canSend=!0),!Ct.sent&&Ct.canSend&&(e=Object.assign({},{path:kt.current,pageEvent:Object.assign({},xt),errs:It.slice(),fromPath:kt.prev||"",actions:(Et.eventActions||[]).concat(Et.otherActions||[])},Object.assign({},Pt,o||{},{key:et.key}),0<bt?{ct:bt}:{},Mt()),(n=c())&&(e.routeTrack=n),ut.add({uri:"/mp-page",data:e}),Ot(),Ct.sent=!0,Ct.canSend=!1))}function Ht(t){Dt();var e=t.path,n=t.query,a=t.scene;o.openPath=e,et.disableFetchQuery||(o.query=n),o.scene=a,v.launchOptions=t,i.getNetworkType({success:function(t){o.networkType=t.networkType},complete:function(){wt()}})}function zt(t){var e,n="",a="";h(t)?n=t:t&&(n=t.stack,a=t.message),n&&(e={time:m(),stack:n},a&&(e.msg=a),It.push(e))}function Yt(){var t=c();u();var e=kt.current;kt.prev="",kt.current="",wt({routeTrack:t,closePath:e,metric:At})}function Bt(t,e){t=t.split("."),e=e.split(".");for(var n=Math.max(t.length,e.length);t.length<n;)t.push("0");for(;e.length<n;)e.push("0");for(var a=0;a<n;a++){var r=parseInt(t[a]),i=parseInt(e[a]);if(i<r)return 1;if(r<i)return-1}return 0}function Gt(){return 0<=Kt(o,M)}function Kt(t,e){var n="";return t&&t.system&&(n=t.system.SDKVersion),n&&e?Bt(n,e):-1}var Ut=[{name:"onLaunch",handler:Ht},{name:"onError",handler:zt},{name:"onHide",handler:Yt}];function Jt(e){return Ut.forEach(function(t){S(t,e)}),e}function Vt(t){return Gt()||!rt()?t:Jt.apply(this,arguments)}function Xt(){var e=App;App=function(t){if(t=Jt(t),e)return e.call(this,t)}}function Qt(t){return et.ignoredPages&&f(et.ignoredPages)?et.ignoredPages.indexOf(t)<0:!et.pages||!f(et.pages)||-1<et.pages.indexOf(t)}function Wt(t,e){if(!T(e))return t;try{var n=Object.keys(e).map(function(t){return"".concat(t,"=").concat(e[t])}).join("&");n&&(t+="?".concat(n))}catch(t){}return t}function Zt(){var u=this.setData,c=Et.setData.threshold,d=Et.setData.setDataTrace,h=Et.setData.setDataTraceHint,f=Et.setData.setDataTimeInterval;this.setData=function(){var a=arguments[0],r=arguments[1],t=m(),i={start:t},o=v.context,s=o&&o.type===N&&o.data&&o.data.recordFirstLoad;(Et.recordFirstLoad||s)&&(i.calcFirstLoad=!0);try{var e=Et.setData.currentSegmentTime;1e3<t-e?(Et.setData.currentSegmentTime=t,Et.setData.data[t]={count:0,grade:{good:{count:0},normal:{count:0},bad:{count:0}},traces:[]},i.segmentTime=t):i.segmentTime=e}catch(t){}function n(){try{i.end=m(),i.calcFirstLoad&&i.end>Et.lastSetDataInOnReady&&(Et.lastSetDataInOnReady=i.end),i.duration=i.end-i.start;var t=Et.setData.data[i.segmentTime];if(t.count++,i.duration>Et.setData.max&&(Et.setData.max=i.duration),i.duration>f[1]?t.grade.bad.count++:i.duration>f[0]?t.grade.normal.count++:t.grade.good.count++,i.duration>c&&(Et.stuck||(Et.stuck=!0),t.traces.length<B&&d))try{var e=k(a,!0),n={timestamp:i.start,duration:i.duration,size:e.value.length};h&&(n.hint=e.value.substring(0,200)),e.error&&(n.error=e.error),t.traces.push(n)}catch(t){}s&&Et.setData.requestBridge.push({start:i.start,end:i.end,requestId:o.data.requestId,url:o.data.url})}catch(t){}return r&&r.apply(this,arguments)}return u.call(this,arguments[0],n)}}function $t(){Qt(this.route)&&(Ct.needClearDeferredData&&(_t(),Ct.needClearDeferredData=!1),Et.recordFirstLoad=!0,Zt.call(this),xt.onLoad=m(),this[tt]=Wt(this.route,arguments[0]))}function te(){var t;Qt(this.route)&&(Ct.needClearDeferredData&&(_t(),Ct.needClearDeferredData=!1),xt.onShow=m(),s(t=this[tt]||this.route),kt.prev=kt.current,kt.current=t,Ct.sent=!1)}function ee(){Qt(this.route)&&(xt.onReady=m())}function ne(){Qt(this.route)&&(Et.recordFirstLoad=!1)}function ae(){Qt(this.route)&&(xt.onHide=m(),jt(L))}function re(){Qt(this.route)&&(xt.onUnload=m(),jt(L))}var ie=[{name:"onLoad",handler:$t},{name:"onShow",handler:te},{name:"onReady",handler:ee,afterHandler:ne},{name:"onHide",handler:ae},{name:"onUnload",handler:re}];function oe(t,e){for(var n in t){var a;t.hasOwnProperty(n)&&g(t[n])&&!t[n]._ty_hook&&g(e)&&(a=t[n],t[n]=e.call(this,n,a),t[n]._ty_hook=!0)}}var se=[N,w,j];function ue(){var e={};return se.forEach(function(t){e[t]={current:0,children:0}}),e}function ce(t,e){for(var n=0;n<t.length;n++)if(t[n].cid===e.id){e.requests&&0<e.requests.length&&(t[n].requests=e.requests),e.apis&&0<e.apis.length&&(t[n].apis=e.apis);break}}function de(t){t=t||{},this.id=++Et.uniqueId,this.parent=t.parent||null,this.name=t.name||"<root>",this.type=t.type||P,this.subType=this.type===P?t.subType||"tap":t.subType,this.requests=[],this.apis=[],this.remain=ue(),this.s=m(),this.e=null,this.data=t.data,this.closed=!1,this.path=kt.current,this.prevPath=kt.prev,this.dataComposed=t.dataComposed||!1}de.prototype.end=function(t){var e;this.closed||(t&&((e=this.getItemsByType(t.type))&&0<e.length&&ce(e,t),this.updateRemain(-1,t.type)),this.isNoRemain()&&(this.e=m(),this.closed=!0,this.parent?this.parent.end(this):(Ft(this.composeActionData()),v.context=null)))},de.prototype.getItemsByType=function(t){var e;return t===N?e=this.requests:t===w&&(e=this.apis),e},de.prototype.isNoRemain=function(t){var e=!0;for(var n in this.remain){if(this.remain.hasOwnProperty(n))if(!(this.remain[n].current<=0&&(!!t||this.remain[n].children<=0))){e=!1;break}}return e},de.prototype.setData=function(t){this.data=t},de.prototype.hasPrevAssignedData=function(){return this.requests&&0<this.requests.length||this.apis&&0<this.apis.length},de.prototype.composeActionData=function(){var t={id:this.id,name:this.name,type:this.type,start:this.s,end:this.e,duration:0<this.e-this.s?this.e-this.s:0,path:this.path,prevPath:this.prevPath};return this.requests&&0<this.requests.length&&(t.requests=this.requests),this.apis&&0<this.apis.length&&(t.apis=this.apis),this.data&&(t.data=this.data),this.type!==N&&this.type!==w||(delete(t=Object.assign({},t,this.data)).data,this.type===N&&delete t.name),t},de.prototype.canEnd=function(){return this.isNoRemain(!0)},de.prototype.isEventChildContext=function(){for(var t=this.parent,e=!1;null!=t;){if(t.type===P){e=!0;break}t=t.parent}return e},de.prototype.updateRemain=function(t,e){e=e||N;var n=t||0;this.remain[e].current=this.remain[e].current+n;for(var a=this.parent;a;)a.remain[e].children=a.remain[e].children+n,a=a.parent},Object.defineProperty(de.prototype,"current",{get:function(){return v.context},enumerable:!0,configurable:!0});var he="tyname";function fe(t){return!t||"tap"!==t.type||!T(t.target)||!T(t.currentTarget)||null==t.timeStamp}function le(t,e){var n,a=t.target||{},r=a.offsetLeft,i=a.offsetTop,o=a.id,s=a.dataset,u=t.detail||{},c=u.x,d=u.y;t._relatedInfo&&(n=t._relatedInfo.anchorTargetText);var h={target:{offsetLeft:r,offsetTop:i,id:o,x:c,y:d},dataset:{name:s[he],targetName:n,methodName:e}},f=e||"";v.context=new de({name:f,type:P,subType:t.type,data:h,dataComposed:!0})}function pe(){v.context&&v.context.canEnd()&&v.context.end(),v.context=null}function me(a,r){return function(){var t,e=arguments[0]||{},n=fe(e);if(!n)try{le.call(this,e,a)}catch(t){}try{t=r.apply(this,arguments)}finally{if(!n)try{pe.call(this)}catch(t){}}return t}}function ye(e){var n=v.context;return function(){var t;v.context=n;try{t=e.apply(this,arguments)}finally{v.context=null}return t}}function ve(e){return ie.forEach(function(t){S(t,e)}),oe(e,me),e[O]=Rt,e}function ge(t){return Gt()||!rt()?t:ve.apply(this,arguments)}function Te(){var e=Page;Page=function(t){if(t=ve(t),e)return e.call(this,t)}}function De(t){v.context=t.context}function qe(){v.context&&v.context.canEnd()&&v.context.end()}var Se=i.request;function xe(t,e){if(!t)return null;var n=null,a=b(t["X-Tingyun-Tx-Data"]);return a&&a.r&&E(a.r)===E(e)&&(n=a),n}function Ie(t,e){et.id&&(t.header["X-Tingyun-Id"]="".concat(et.id,";r=").concat(e.r))}function be(t){if(!t)return 0;var e=t.header,n=t.data,a=0;return(a=+(e&&e["Content-Length"]))&&p(a)&&!Number.isNaN(a)||(a=A(n)||0),a}function ke(t,e){var n={},a=xe(t.header,e.r);return a&&(n.s_id=a.id,n.s_name=a.action,a.time&&(n.s_du=a.time.duration,n.s_qu=a.time.qu),n.t_id=a.trId),n}function Ee(t,e,n){return{requestId:t.requestId,type:N,url:t.url,method:t.method,start:t.start,end:t.end,cbTime:t.cbTime,duration:0<t.end-t.start?t.end-t.start:0,send:A(e.data),rec:be(n),statusCode:t.statusCode||0,failMessage:t.failMessage||"",cid:t.cid}}function Ae(t,e){var n;t.context||(n="".concat(t.url,"-").concat(t.requestId),t.context=new de({parent:e,name:n,type:N,data:t.data}))}var Ce=function(t){var e,n,a,f,r,i,l,p=t||{};return!p._no_record&&p.url&&rt()&&(1e3<(e=m())-(n=Et.reqStat.currentSegmentTime)&&(n=e,Et.reqStat.currentSegmentTime=e,Et.reqStat.data[e]={count:0}),Et.reqStat.data[n].count++,a=v.context,(f={requestId:++Et.requestId,url:p.url,method:p.method&&p.method.toUpperCase()||"GET",callbackContextCreated:!1,cbTime:0,recordFirstLoad:Et.recordFirstLoad,data:{}}).data={url:f.url,requestId:f.requestId,recordFirstLoad:f.recordFirstLoad},Ae(f,a),f.context&&(f.cid=f.context.id),f.r=m()%1e9,p.header=p.header||{},Ie(p,f),r=p.success,i=p.fail,l=p.complete,p.success=ye(function(){var t;if(f.end||(f.end=m()),De(f),r){var e=m();try{t=r.apply(this,arguments)}finally{var n=m()-e;0<n&&(f.cbTime+=n)}}return t}),p.fail=ye(function(){var t;if(f.end||(f.end=m()),De(f),i){var e=m();try{t=i.apply(this,arguments)}finally{var n=m()-e;0<n&&(f.cbTime+=n)}}return t}),p.complete=ye(function(t){var e,n;f.end||(f.end=m()),f.statusCode=y(t);var a=et[F];if(a&&g(a))try{var r=a.apply(this,arguments);T(r)&&(n={custom:r})}catch(t){}if(De(f),l){var i=m();try{e=l.apply(this,arguments)}finally{var o=m()-i;0<o&&(f.cbTime+=o)}}var s,u=t,c=!1;400<=(u=u||{}).statusCode&&(et.ignoreErrorCodes||[]).indexOf(u.statusCode)<0?(c=!0,s=u.data,f.failMessage=C(s,et.requestFailMessageSize)):u.errMsg&&!u.statusCode&&(c=!0,f.failMessage=u.errMsg.substring(0,et.requestFailMessageSize)),c&&!Et.netError&&(Et.netError=!0);var d=ke(u,f),h=Ee(f,p,u);return f.context&&(f.context.dataComposed=!0),Object.assign(f.data,h,d||{},n||{}),qe(),e}),f.start=e,a&&(a.updateRemain(1),a.requests.push(f.data))),Se.apply(this,arguments)};function Oe(){Object.defineProperty(i,"request",{configurable:!0,enumerable:!0,writable:!0,value:Ce})}function _e(e){return e.methods||(e.methods={}),ie.forEach(function(t){S(t,e.methods)}),oe(e.methods,me),e}function Fe(t){return Gt()||!rt()?t:_e.apply(this,arguments)}function Le(){var e=Component;Component=function(t){t=_e(t),e&&e.call(this,t)}}function Me(t,e){o.uid=t,r(_,t)}function Re(){return v.context}var Pe,Ne={version:"1.3.8",setUser:Me,hookApp:Vt,hookPage:ge,hookComponent:Fe,request:Ce,getContext:Re},we=["success","fail"],je=[],He={requestPayment:{fail:function(t){var e=arguments&&t,n="fail";return e&&T(e)&&"requestPayment:fail cancel"===e.errMsg&&(n="cancel"),n}}};function ze(){(Pe=et.hookApis||e()).forEach(function(t){-1<je.indexOf(t)||"request"===t||je.push(t)})}function Ye(t){return{apiId:t.apiId,type:w,name:t.name,success:t.success||0,fail:t.fail||0,cancel:t.cancel||0,start:t.start,end:t.end,duration:0<t.end-t.start?t.end-t.start:0,count:1,failMessage:t.failMessage||"",cid:t.cid}}function Be(t,e){var n;t.context||(n="".concat(t.name,"-").concat(t.apiId),t.context=new de({parent:e,name:n,type:w,data:t.data}))}function Ge(r){var n=i[r];return function(){var t=arguments[0]||{},e=v.context,a={apiId:++Et.apiId,name:r,data:{}};return Be(a,e),a.context&&(a.cid=a.context.id),we.forEach(function(n){t[n]=ye(D(t[n],function(){var t,e;a.end||(a.end=m()),De(a),(t=He[r]&&He[r][n]&&g(He[r][n])?He[r][n].apply(this,arguments):n)&&(a[t]=1),"fail"===t&&(e=arguments&&arguments[0],a.failMessage=C(e,et.apiFailMessageSize))}))}),t.complete=ye(q(t.complete,function(){a.end||(a.end=m()),De(a)},function(){Object.assign(a.data,Ye(a)),a.context&&(a.context.dataComposed=!0),qe()})),e&&(e.updateRemain(1,w),e.apis.push(a.data)),a.start=m(),n.apply(this,arguments)}}function Ke(t){t&&i[t]&&Object.defineProperty(i,t,{configurable:!0,enumerable:!0,writable:!0,value:Ge(t)})}function Ue(){Pe||ze();var e={};return je.forEach(function(t){e[t]=Ge(t)}),e}function Je(){Pe||ze(),je.forEach(function(t){Ke(t)})}function Ve(t){t&&!Gt()||(Xt(),Te(),Oe(),Le(),Je()),t&&Object.assign(Ne,Ue()||{})}function Xe(t){var e;rt()||(at(t||{}),it(!0),Tt(),e=!0,null!=et.plugin&&(e=et.plugin),Ve(e))}function Qe(){return Ne.config=Xe,Ne}i.onNetworkStatusChange(function(t){o.networkType=t.networkType});var We=Qe();module.exports=We;
|