@ued2345/octopus-util
Advanced tools
Comparing version 1.1.6-8 to 1.1.6-9
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.OcUtil=t():e.OcUtil=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";t.__esModule=!0,t.default=function(){var e=navigator.userAgent;return{trident:e.indexOf("Trident")>-1,presto:e.indexOf("Presto")>-1,webKit:e.indexOf("AppleWebKit")>-1,gecko:e.indexOf("Gecko")>-1&&-1===e.indexOf("KHTML"),mobile:!!e.match(/AppleWebKit.*Mobile.*/)||e.indexOf("Mobile")>-1,ios:!!e.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),android:e.indexOf("Android")>-1||e.indexOf("Linux")>-1,iPhone:e.indexOf("iPhone")>-1,iPad:e.indexOf("iPad")>-1,webApp:-1===e.indexOf("Safari"),weixin:e.indexOf("MicroMessenger")>-1,qq:null!==e.match(/\sQQ/i)}}},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e,t,n){var r=new Date;r.setTime(r.getTime()+24*n*60*60*1e3);var i="expires="+r.toUTCString();document.cookie=e+"="+t+";path=/;;"+i}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var i=r(n(0)),o=r(n(3)),a=r(n(4)),s=r(n(6)),u=r(n(1)),c=r(n(7)),f=r(n(8)),d=r(n(11)),l=r(n(12));e.exports.default=e.exports={getBrowser:i.default,getInApp:o.default,JsBridge:a.default,getCookie:s.default,setCookie:u.default,delCookie:c.default,VuePlugin:f.default,CatchError:d.default,CatchPerformance:l.default}},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){return!!(navigator.userAgent.indexOf(e)>-1)}},function(e,t,n){"use strict";var r,i=(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var a=new(function(e){function t(){return e.call(this)||this}return i(t,e),t.prototype.callHandler=function(t,n){e.prototype.init.call(this,(function(e){e.callHandler("jsCallJavaAllInOne",t,n)}))},t.prototype.registerHandler=function(t,n){e.prototype.init.call(this,(function(e){e.registerHandler(t,n)}))},t}(o(n(5)).default));a.first(),t.default={callHandler:a.callHandler,registerHandler:a.registerHandler}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var i=r(n(0)).default(),o=function(){function e(){this.isIOS=i.ios}return e.prototype.init=function(e){if(this.isIOS){if(window.WebViewJavascriptBridge)return e(window.WebViewJavascriptBridge);if(window.WVJBCallbacks)return window.WVJBCallbacks.push(e);window.WVJBCallbacks=[e];var t=document.createElement("iframe");t.style.display="none",t.src="wvjbscheme://__BRIDGE_LOADED__",document.documentElement.appendChild(t),setTimeout((function(){document.documentElement.removeChild(t)}),0)}else window.WebViewJavascriptBridge?e(window.WebViewJavascriptBridge):document.addEventListener("WebViewJavascriptBridgeReady",(function(){e(window.WebViewJavascriptBridge)}),!1)},e.prototype.first=function(){this.isIOS||this.init((function(e){e.init((function(e,t){t()}))}))},e}();t.default=o},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){for(var t=document.cookie.replace(/\s/g,"").split(";"),n=0;n<t.length;n++){var r=t[n].split("=");if(r[0]==e)return decodeURIComponent(r[1])}return""}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var i=r(n(1));t.default=function(e){i.default(e,"",-1)}},function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var i=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var o=i(n(9));t.default={install:function(e,t){Object.keys(o.default).forEach((function(n){"object"===r(o.default[n])?e.directive(n,o.default[n]):"function"==typeof o.default[n]&&e.directive(n,new o.default[n](t[n]))}))}}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var i=r(n(10));t.default={bang:i.default}},function(e,t,n){"use strict";var r,i=function(){return(i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};t.__esModule=!0,function(e){e.Exposure="exposure",e.Click="click",e.Mounted="mounted"}(r||(r={}));var o=function(e){var t=this;this.inserted=function(e,n,i,o){var a,s,u;switch(n.arg){case r.Exposure:new Promise((function(n,r){"IMG"===e.tagName?(e.onload=function(){var r=e.getAttribute("data-src"),i=e.getAttribute("src");((r?r===i:i)||t.config.imgErrExposure)&&n(!0)},e.onerror=function(e){t.config.imgErrExposure?n(!0):r(e)}):n(!0)})).then((function(r){r&&IntersectionObserver&&(e.observer=new IntersectionObserver((function(r){r[0].intersectionRatio>=.95&&(t.callback(e,n,i,o),t.config.exposureMulti||e.observer.unobserve(e))}),{root:null,threshold:[.95]}),e.observer.observe(e))})).catch((function(e){console.error(e)}));break;case r.Click:var c=(a=t.callback,s=(s=t.config.clickThrottleInterval)||2e3,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=this,r=+new Date;u&&r-u>0&&r-u<s||(u=r,a.apply(n,e))});e.bangClickCb=function(){c(e,n,i,o)},e.addEventListener("click",e.bangClickCb);break;case r.Mounted:t.callback(e,n,i,o);break;default:t.callback(e,n,i,o)}},this.unbind=function(e,n){switch(n.arg){case r.Exposure:t.config.exposureMulti&&e.observer&&e.observer.unobserve(e);case r.Click:setTimeout((function(){e.removeEventListener("click",e.bangClickCb)}),0)}},this.config=i(i({},this.DefaultConfig),e),this.callback=this.config.cb};t.default=o},function(e,t,n){"use strict";var r,i,o=function(){return(o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};t.__esModule=!0,function(e){e[e.ERROR=1]="ERROR",e[e.WARNING=2]="WARNING",e[e.INFO=3]="INFO"}(r||(r={})),function(e){e.SCRIP="ERROR_LOAD_SCRIPT",e.LINK="ERROR_LOAD_STYLE",e.IMG="ERROR_LOAD_IMAGE",e.AUDIO="ERROR_LOAD_AUDIO",e.VIDEO="ERROR_LOAD_VIDEO"}(i||(i={}));var a=function(){function e(e,t){this.DefaultConfig={isReportNow:!1,delay:3e3,random:1,repeatNum:3,reportUnhandledRejection:!0,reportFun:function(){}},this.config=o(o({},this.DefaultConfig),t),this.reportFun=this.config.reportFun,this.errorList=[],this.Vue=e,this.errorMap={}}return e.getInstance=function(e,t){return this.instance instanceof this||(this.instance=new this(e,t),this.instance.registerError()),this.instance},e.prototype.registerError=function(){var e=this;try{var t=window.onerror;window.onerror=function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var o=n[0],a=n[1],s=n[2],u=n[3],c=n[4],f=o;c&&c.stack&&(f=e.runStackMsgFun(c)),e.errorList.push({type:"ERROR_RUNTIME",level:r.ERROR,message:f,url:a,col:u,row:s}),e.reportErrorFun(),t&&t.apply(window,n)}}catch(e){console.log(e)}try{window.addEventListener("error",(function(t){var n=t.target||t.srcElement;n!==window&&n.nodeName&&i[n.nodeName.toUpperCase()]&&(e.errorList.push({type:i[n.nodeName.toUpperCase()],level:r.ERROR,message:n.baseURI+"@"+(n.src||n.href),url:n.src||n.href}),e.reportErrorFun())}),!0)}catch(e){console.log(e)}e.Vue&&(e.Vue.config.errorHandler=function(t,n,i){var o,a=t&&t.msg?t.msg:t;t&&t.stack&&(o=e.runStackVueFun(t)),e.errorList.push({type:"ERROR_VUE",level:r.ERROR,message:i+"@"+a,col:Number(o.col),row:Number(o.row),url:o.url||location.href}),e.reportErrorFun()}),e.config.reportUnhandledRejection&&window.addEventListener("unhandledrejection",(function(t){var n=e.runStackMsgFun(t.reason);e.errorList.push({type:"ERROR_REJECT",level:r.WARNING,message:n,url:location.href}),e.reportErrorFun()}))},e.prototype.runStackMsgFun=function(e){var t=e.stack.replace(/\n/gi,"").split(/\bat\b/).slice(0,9).join("@").replace(/\?[^:]+/gi,""),n=e.toString();return t.indexOf(n)<0&&(t=n+"@"+t),t},e.prototype.runStackVueFun=function(e){var t="",n=1,r=1,i=e.stack.match(/https?:\/\/[^\n]+/),o=i?i[0]:"",a=/https?:\/\/(\S)*\.js/;a.test(o)&&(t=o.match(a)[0]);var s=o.match(/:(\d+):(\d+)/);return s&&s.length>=3&&(n=s[1],r=s[2]),{url:t,col:Number(n),row:Number(r)}},e.prototype.isRepeatFun=function(e){var t=e.message;return(this.errorMap[t]=(parseInt(this.errorMap[t],10)||0)+1)>this.config.repeatNum},e.prototype.reportErrorFun=function(){var e=this;Math.random()>=this.config.random||setTimeout((function(){for(var t=function(){var t=e.errorList.pop();if(t.message=(t.message+""||"").substr(0,500),e.isRepeatFun(t))return"continue";e.config.isReportNow?e.reportFun(t):setTimeout((function(){e.reportFun(t)}),e.config.delay*e.errorList.length)};e.errorList.length;)t()}),this.config.delay)},e}();t.default=a},function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}t.__esModule=!0;var i=function(){function e(e){var t=this;void 0===e&&(e={}),this.config={paintTiming:!0,navigationTiming:!0,networkInformation:!0,resourceTiming:!0,random:1,dataConsumption:!0},this.d=document,this.w=window,this.wp=window.performance,this.wn=window.navigator,this.perfObservers={},this.logList=[],this.isHidden=!1,this.perfResourceTiming={beacon:0,link:0,fetch:0,img:0,other:0,script:0,total:0,xmlhttprequest:0},this.didVisibilityChange=function(){t.d.hidden&&(t.isHidden=t.d.hidden)},this.config=Object.assign({},this.config,e),this.isPerformanceSupported()&&this.onVisibilityChange()}return e.getInstance=function(e){return this.instance instanceof this||(this.instance=new this(e),this.instance.registerOnLoad()),this.instance},e.prototype.registerOnLoad=function(){var e=this;window.addEventListener("load",(function(){setTimeout((function(){if(e.isPerformanceObserverSupported())try{e.config.paintTiming&&e.initFirstPaint(),(e.config.resourceTiming||e.config.dataConsumption)&&e.initResourceTiming()}catch(e){console.log("error:",e)}e.config.navigationTiming&&e.logData("navigationTiming",e.getNavigationTiming()),e.config.networkInformation&&e.logData("networkInformation",e.getNetworkInformation())}))}))},e.prototype.initFirstPaint=function(){var e=this;this.perfObservers.paint=this.performanceObserver("paint",(function(t){e.logData("paintTiming",e.performanceObserverCb(t))}))},e.prototype.initResourceTiming=function(){var e=this;this.performanceObserver("resource",(function(t){e.logData("resourceTiming",e.performanceObserverResourceCb(t))}))},e.prototype.performanceObserverCb=function(e){var t=[];return e.forEach((function(e){t.push({name:e.name,value:e.startTime})})),t},e.prototype.performanceObserverResourceCb=function(e){var t=this,n=[];return e.forEach((function(e){if(n.push({type:e.initiatorType,name:e.name,value:e.duration}),t.config.dataConsumption&&e.decodedBodySize&&e.initiatorType){var r=e.decodedBodySize/1e3;t.perfResourceTiming[e.initiatorType]+=r,t.perfResourceTiming.total+=r}})),{resourceTiming:n,dataConsumption:this.config.dataConsumption?this.perfResourceTiming:null}},e.prototype.getNavigationTiming=function(){if(!this.isPerformanceSupported())return{};var e="function"==typeof this.w.PerformanceNavigationTiming?performance.getEntriesByType("navigation")[0]:this.wp.timing;return e?{redirectTime:e.redirectEnd-e.redirectStart,dnsCatchTime:e.domainLookupStart-e.fetchStart,dnsTime:e.domainLookupEnd-e.domainLookupStart,ttfbTime:e.responseStart-e.domainLookupStart,unloadTime:e.unloadEventEnd-e.unloadEventStart,tcpTime:e.connectEnd-e.connectStart,reqTime:e.responseEnd-e.requestStart,domTreeTime:e.domInteractive-e.responseEnd,domAnalyzeTime:e.domComplete-e.domInteractive,blankTime:e.domInteractive-e.fetchStart,domReadyTime:e.domContentLoadedEventEnd-e.fetchStart,loadTime:e.loadEventEnd-e.fetchStart}:{}},e.prototype.getNetworkInformation=function(){if("connection"in this.wn){var e=this.wn.connection;return"object"!==r(e)?{}:{downlink:e.downlink,effectiveType:e.effectiveType,rtt:e.rtt,saveData:!!e.saveData}}return{}},e.prototype.performanceObserver=function(e,t){return this.perfObserver=new PerformanceObserver((function(e){var n=e.getEntries();t(n)})),this.perfObserver.observe({type:e,buffered:!0}),this.perfObserver},e.prototype.logData=function(e,t){this.logList=[],this.logList.push({name:e,data:t}),this.reportFun(),this.perfObservers.paint&&this.perfObservers.paint.disconnect()},e.prototype.reportFun=function(){this.isHidden||Math.random()>=this.config.random||this.config.reportFun(this.logList)},e.prototype.onVisibilityChange=function(){void 0!==this.d.hidden&&this.d.addEventListener("visibilitychange",this.didVisibilityChange)},e.prototype.isPerformanceSupported=function(){return this.wp&&!!this.wp.getEntriesByType&&!!this.wp.now},e.prototype.isPerformanceObserverSupported=function(){return this.w.chrome&&"PerformanceObserver"in this.w},e}();t.default=i}])})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.OcUtil=t():e.OcUtil=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";t.__esModule=!0,t.default=function(){var e=navigator.userAgent;return{trident:e.indexOf("Trident")>-1,presto:e.indexOf("Presto")>-1,webKit:e.indexOf("AppleWebKit")>-1,gecko:e.indexOf("Gecko")>-1&&-1===e.indexOf("KHTML"),mobile:!!e.match(/AppleWebKit.*Mobile.*/)||e.indexOf("Mobile")>-1,ios:!!e.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),android:e.indexOf("Android")>-1||e.indexOf("Linux")>-1,iPhone:e.indexOf("iPhone")>-1,iPad:e.indexOf("iPad")>-1,webApp:-1===e.indexOf("Safari"),weixin:e.indexOf("MicroMessenger")>-1,qq:null!==e.match(/\sQQ/i)}}},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e,t,n){var r=new Date;r.setTime(r.getTime()+24*n*60*60*1e3);var o="expires="+r.toUTCString();document.cookie=e+"="+t+";path=/;;"+o}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var o=r(n(0)),i=r(n(3)),a=r(n(4)),s=r(n(6)),u=r(n(1)),c=r(n(7)),f=r(n(8)),l=r(n(11)),d=r(n(12));e.exports.default=e.exports={getBrowser:o.default,getInApp:i.default,JsBridge:a.default,getCookie:s.default,setCookie:u.default,delCookie:c.default,VuePlugin:f.default,CatchError:l.default,CatchPerformance:d.default}},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){return!!(navigator.userAgent.indexOf(e)>-1)}},function(e,t,n){"use strict";var r,o=(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var a=new(function(e){function t(){return e.call(this)||this}return o(t,e),t.prototype.callHandler=function(t,n){e.prototype.init.call(this,(function(e){e.callHandler("jsCallJavaAllInOne",t,n)}))},t.prototype.registerHandler=function(t,n){e.prototype.init.call(this,(function(e){e.registerHandler(t,n)}))},t}(i(n(5)).default));a.first(),t.default={callHandler:a.callHandler,registerHandler:a.registerHandler}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var o=r(n(0)).default(),i=function(){function e(){this.isIOS=o.ios}return e.prototype.init=function(e){if(this.isIOS){if(window.WebViewJavascriptBridge)return e(window.WebViewJavascriptBridge);if(window.WVJBCallbacks)return window.WVJBCallbacks.push(e);window.WVJBCallbacks=[e];var t=document.createElement("iframe");t.style.display="none",t.src="wvjbscheme://__BRIDGE_LOADED__",document.documentElement.appendChild(t),setTimeout((function(){document.documentElement.removeChild(t)}),0)}else window.WebViewJavascriptBridge?e(window.WebViewJavascriptBridge):document.addEventListener("WebViewJavascriptBridgeReady",(function(){e(window.WebViewJavascriptBridge)}),!1)},e.prototype.first=function(){this.isIOS||this.init((function(e){e.init((function(e,t){t()}))}))},e}();t.default=i},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){for(var t=document.cookie.replace(/\s/g,"").split(";"),n=0;n<t.length;n++){var r=t[n].split("=");if(r[0]==e)return decodeURIComponent(r[1])}return""}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var o=r(n(1));t.default=function(e){o.default(e,"",-1)}},function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var o=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var i=o(n(9));t.default={install:function(e,t){Object.keys(i.default).forEach((function(n){"object"===r(i.default[n])?e.directive(n,i.default[n]):"function"==typeof i.default[n]&&e.directive(n,new i.default[n](t[n]))}))}}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var o=r(n(10));t.default={bang:o.default}},function(e,t,n){"use strict";var r,o=function(){return(o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},i=function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r};t.__esModule=!0,function(e){e.Exposure="exposure",e.Click="click",e.Mounted="mounted"}(r||(r={}));var a={clickThrottleInterval:2e3,exposureMulti:!1,imgErrExposure:!1,exposureRatio:.95,cbDataType:"default"},s=function(){function e(e){var t,n,s,u,c,f,l=this;this.inserted=function(e,t,n,o){switch(t.arg){case r.Exposure:l._addExposureEvent(e,t,n,o);break;case r.Click:l._addClickEvent(e,t,n,o);break;case r.Mounted:l._formatCb(e,t,n,o,l.cb);break;default:l._formatCb(e,t,n,o,l.cb)}},this.unbind=function(e,t){switch(t.arg){case r.Exposure:l.config.exposureMulti&&e.observer&&e.observer.unobserve(e),l.config.exposureUseCache&&l.exposureCallback();case r.Click:setTimeout((function(){l._removeClickEvent(e)}),0)}},this.update=function(e,t,n,o){n.data.directives.forEach((function(t){if(t.oldValue!==t.value)switch(t.arg){case r.Click:setTimeout((function(){l._removeClickEvent(e),l._addClickEvent(e,t,n,o)}),0);break;case r.Exposure:setTimeout((function(){l._removeExposureEvent(e),l._addExposureEvent(e,t,n,o,!0)}),0)}}))},this.config=o(o({},a),e),this.cb=this.config.cb,this.exposureCallback=this.config.exposureUseCache?(t=this.config.cb,n=this.config.exposureUseCache,s=n.cacheLen,u=n.cacheTime,c=null,f=[],function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];c&&clearTimeout(c);var r=this;if(0!==e.length)if(e.length>1?f.push({el:e[0],binding:e[1],vnode:e[2],oldVnode:e[3]}):f.push(e[0]),f.length>=s)for(o=i(f),t.call(r,o);f.length>0;)f.pop();else{if(0===f.length)return;c=setTimeout((function(){var e=i(f);for(t.call(r,e);f.length>0;)f.pop()}),u)}else if(f.length>0){var o=i(f);for(t.apply(r,e);f.length>0;)f.pop()}}):this.cb}return e.prototype._addExposureEvent=function(e,t,n,r,o){var i=this;void 0===o&&(o=!1),new Promise((function(t,n){"IMG"===e.tagName?(e.onload=function(){var n=e.getAttribute("data-src"),r=e.getAttribute("src");((n?n===r:r)||i.config.imgErrExposure)&&t(!0)},e.onerror=function(e){i.config.imgErrExposure?t(!0):n(e)}):t(!0)})).then((function(o){o&&IntersectionObserver&&(e.observer=new IntersectionObserver((function(o){o[0].intersectionRatio>=i.config.exposureRatio&&("array"===i.config.cbDataType?i.exposureCallback({el:e,binding:t,vnode:n,oldVnode:r}):i.exposureCallback(e,t,n,r),i.config.exposureMulti||e.observer.unobserve(e))}),{root:null,threshold:[i.config.exposureRatio]}),e.observer.observe(e))})).catch((function(e){console.error(e)}))},e.prototype._removeExposureEvent=function(e){e.observer&&e.observer.unobserve(e)},e.prototype._addClickEvent=function(e,t,n,r){var o,i,a,s=this,u=(o=this.cb,i=(i=this.config.clickThrottleInterval)||2e3,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=this,r=+new Date;a&&r-a>0&&r-a<i||(a=r,o.apply(n,e))});e.bangClickCb=function(){s._formatCb(e,t,n,r,u)},e.addEventListener("click",e.bangClickCb)},e.prototype._removeClickEvent=function(e){e.removeEventListener("click",e.bangClickCb)},e.prototype._formatCb=function(e,t,n,r,o){"array"===this.config.cbDataType?o([{el:e,binding:t,vnode:n,oldVnode:r}]):o(e,t,n,r)},e}();t.default=s},function(e,t,n){"use strict";var r,o,i=function(){return(i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};t.__esModule=!0,function(e){e[e.ERROR=1]="ERROR",e[e.WARNING=2]="WARNING",e[e.INFO=3]="INFO"}(r||(r={})),function(e){e.SCRIP="ERROR_LOAD_SCRIPT",e.LINK="ERROR_LOAD_STYLE",e.IMG="ERROR_LOAD_IMAGE",e.AUDIO="ERROR_LOAD_AUDIO",e.VIDEO="ERROR_LOAD_VIDEO"}(o||(o={}));var a=function(){function e(e,t){this.DefaultConfig={isReportNow:!1,delay:3e3,random:1,repeatNum:3,reportUnhandledRejection:!0,reportFun:function(){}},this.config=i(i({},this.DefaultConfig),t),this.reportFun=this.config.reportFun,this.errorList=[],this.Vue=e,this.errorMap={}}return e.getInstance=function(e,t){return this.instance instanceof this||(this.instance=new this(e,t),this.instance.registerError()),this.instance},e.prototype.registerError=function(){var e=this;try{var t=window.onerror;window.onerror=function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];var i=n[0],a=n[1],s=n[2],u=n[3],c=n[4],f=i;c&&c.stack&&(f=e.runStackMsgFun(c)),e.errorList.push({type:"ERROR_RUNTIME",level:r.ERROR,message:f,url:a,col:u,row:s}),e.reportErrorFun(),t&&t.apply(window,n)}}catch(e){console.log(e)}try{window.addEventListener("error",(function(t){var n=t.target||t.srcElement;n!==window&&n.nodeName&&o[n.nodeName.toUpperCase()]&&(e.errorList.push({type:o[n.nodeName.toUpperCase()],level:r.ERROR,message:n.baseURI+"@"+(n.src||n.href),url:n.src||n.href}),e.reportErrorFun())}),!0)}catch(e){console.log(e)}e.Vue&&(e.Vue.config.errorHandler=function(t,n,o){var i,a=t&&t.msg?t.msg:t;t&&t.stack&&(i=e.runStackVueFun(t)),e.errorList.push({type:"ERROR_VUE",level:r.ERROR,message:o+"@"+a,col:Number(i.col),row:Number(i.row),url:i.url||location.href}),e.reportErrorFun()}),e.config.reportUnhandledRejection&&window.addEventListener("unhandledrejection",(function(t){var n=e.runStackMsgFun(t.reason);e.errorList.push({type:"ERROR_REJECT",level:r.WARNING,message:n,url:location.href}),e.reportErrorFun()}))},e.prototype.runStackMsgFun=function(e){var t=e.stack.replace(/\n/gi,"").split(/\bat\b/).slice(0,9).join("@").replace(/\?[^:]+/gi,""),n=e.toString();return t.indexOf(n)<0&&(t=n+"@"+t),t},e.prototype.runStackVueFun=function(e){var t="",n=1,r=1,o=e.stack.match(/https?:\/\/[^\n]+/),i=o?o[0]:"",a=/https?:\/\/(\S)*\.js/;a.test(i)&&(t=i.match(a)[0]);var s=i.match(/:(\d+):(\d+)/);return s&&s.length>=3&&(n=s[1],r=s[2]),{url:t,col:Number(n),row:Number(r)}},e.prototype.isRepeatFun=function(e){var t=e.message;return(this.errorMap[t]=(parseInt(this.errorMap[t],10)||0)+1)>this.config.repeatNum},e.prototype.reportErrorFun=function(){var e=this;Math.random()>=this.config.random||setTimeout((function(){for(var t=function(){var t=e.errorList.pop();if(t.message=(t.message+""||"").substr(0,500),e.isRepeatFun(t))return"continue";e.config.isReportNow?e.reportFun(t):setTimeout((function(){e.reportFun(t)}),e.config.delay*e.errorList.length)};e.errorList.length;)t()}),this.config.delay)},e}();t.default=a},function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}t.__esModule=!0;var o=function(){function e(e){var t=this;void 0===e&&(e={}),this.config={paintTiming:!0,navigationTiming:!0,networkInformation:!0,resourceTiming:!0,random:1,dataConsumption:!0},this.d=document,this.w=window,this.wp=window.performance,this.wn=window.navigator,this.perfObservers={},this.logList=[],this.isHidden=!1,this.perfResourceTiming={beacon:0,link:0,fetch:0,img:0,other:0,script:0,total:0,xmlhttprequest:0},this.didVisibilityChange=function(){t.d.hidden&&(t.isHidden=t.d.hidden)},this.config=Object.assign({},this.config,e),this.isPerformanceSupported()&&this.onVisibilityChange()}return e.getInstance=function(e){return this.instance instanceof this||(this.instance=new this(e),this.instance.registerOnLoad()),this.instance},e.prototype.registerOnLoad=function(){var e=this;window.addEventListener("load",(function(){setTimeout((function(){if(e.isPerformanceObserverSupported())try{e.config.paintTiming&&e.initFirstPaint(),(e.config.resourceTiming||e.config.dataConsumption)&&e.initResourceTiming()}catch(e){console.log("error:",e)}e.config.navigationTiming&&e.logData("navigationTiming",e.getNavigationTiming()),e.config.networkInformation&&e.logData("networkInformation",e.getNetworkInformation())}))}))},e.prototype.initFirstPaint=function(){var e=this;this.perfObservers.paint=this.performanceObserver("paint",(function(t){e.logData("paintTiming",e.performanceObserverCb(t))}))},e.prototype.initResourceTiming=function(){var e=this;this.performanceObserver("resource",(function(t){e.logData("resourceTiming",e.performanceObserverResourceCb(t))}))},e.prototype.performanceObserverCb=function(e){var t=[];return e.forEach((function(e){t.push({name:e.name,value:e.startTime})})),t},e.prototype.performanceObserverResourceCb=function(e){var t=this,n=[];return e.forEach((function(e){if(n.push({type:e.initiatorType,name:e.name,value:e.duration}),t.config.dataConsumption&&e.decodedBodySize&&e.initiatorType){var r=e.decodedBodySize/1e3;t.perfResourceTiming[e.initiatorType]+=r,t.perfResourceTiming.total+=r}})),{resourceTiming:n,dataConsumption:this.config.dataConsumption?this.perfResourceTiming:null}},e.prototype.getNavigationTiming=function(){if(!this.isPerformanceSupported())return{};var e="function"==typeof this.w.PerformanceNavigationTiming?performance.getEntriesByType("navigation")[0]:this.wp.timing;return e?{redirectTime:e.redirectEnd-e.redirectStart,dnsCatchTime:e.domainLookupStart-e.fetchStart,dnsTime:e.domainLookupEnd-e.domainLookupStart,ttfbTime:e.responseStart-e.domainLookupStart,unloadTime:e.unloadEventEnd-e.unloadEventStart,tcpTime:e.connectEnd-e.connectStart,reqTime:e.responseEnd-e.requestStart,domTreeTime:e.domInteractive-e.responseEnd,domAnalyzeTime:e.domComplete-e.domInteractive,blankTime:e.domInteractive-e.fetchStart,domReadyTime:e.domContentLoadedEventEnd-e.fetchStart,loadTime:e.loadEventEnd-e.fetchStart}:{}},e.prototype.getNetworkInformation=function(){if("connection"in this.wn){var e=this.wn.connection;return"object"!==r(e)?{}:{downlink:e.downlink,effectiveType:e.effectiveType,rtt:e.rtt,saveData:!!e.saveData}}return{}},e.prototype.performanceObserver=function(e,t){return this.perfObserver=new PerformanceObserver((function(e){var n=e.getEntries();t(n)})),this.perfObserver.observe({type:e,buffered:!0}),this.perfObserver},e.prototype.logData=function(e,t){this.logList=[],this.logList.push({name:e,data:t}),this.reportFun(),this.perfObservers.paint&&this.perfObservers.paint.disconnect()},e.prototype.reportFun=function(){this.isHidden||Math.random()>=this.config.random||this.config.reportFun(this.logList)},e.prototype.onVisibilityChange=function(){void 0!==this.d.hidden&&this.d.addEventListener("visibilitychange",this.didVisibilityChange)},e.prototype.isPerformanceSupported=function(){return this.wp&&!!this.wp.getEntriesByType&&!!this.wp.now},e.prototype.isPerformanceObserverSupported=function(){return this.w.chrome&&"PerformanceObserver"in this.w},e}();t.default=o}])})); |
{ | ||
"name": "@ued2345/octopus-util", | ||
"version": "1.1.6-8", | ||
"version": "1.1.6-9", | ||
"description": "ued2345 utils", | ||
@@ -5,0 +5,0 @@ "main": "dist/octopus-util.min.js", |
@@ -208,26 +208,26 @@ ### 技术选型 | ||
return { | ||
// 重定向时间: | ||
redirectTime: t.redirectEnd - t.redirectStart, | ||
// dns缓存时间 | ||
dnsCatchTime: t.domainLookupStart - t.fetchStart, | ||
// dns查询耗时 | ||
dnsTime: t.domainLookupEnd - t.domainLookupStart, | ||
// ttfb 读取第一个字节的时间 | ||
ttfbTime: t.responseStart - t.domainLookupStart, | ||
// 卸载页面耗时 | ||
unloadTime: t.unloadEventEnd - t.unloadEventStart, | ||
// tcp链接耗时 | ||
tcpTime: t.connectEnd - t.connectStart, | ||
// request请求耗时 | ||
reqTime: t.responseEnd - t.requestStart, | ||
// 创建dom树 | ||
domTreeTime: t.domInteractive - t.responseEnd, | ||
//解析dom树耗时 | ||
domAnalyzeTime: t.domComplete - t.domInteractive, | ||
// 白屏时间 | ||
blankTime: t.domInteractive - t.fetchStart, | ||
// domReadyTime | ||
domReadyTime: t.domContentLoadedEventEnd - t.fetchStart, | ||
// onload耗时 | ||
loadTime: t.loadEventEnd - t.fetchStart | ||
// 重定向时间: | ||
redirectTime: t.redirectEnd - t.redirectStart, | ||
// DNS缓存时间 | ||
dnsCatchTime: t.domainLookupStart - t.fetchStart, | ||
// DNS解析时间 | ||
dnsTime: t.domainLookupEnd - t.domainLookupStart, | ||
// ttfb 读取第一个字节的时间 | ||
ttfbTime: t.responseStart - t.domainLookupStart, | ||
// 卸载页面耗时 | ||
unloadTime: t.unloadEventEnd - t.unloadEventStart, | ||
// tcp链接耗时 | ||
tcpTime: t.connectEnd - t.connectStart, | ||
// request请求耗时,页面下载耗时 | ||
reqTime: t.responseEnd - t.requestStart, | ||
// dom渲染完成时间 | ||
domTreeTime: t.domInteractive - t.responseEnd, | ||
//解析dom树耗时 | ||
domAnalyzeTime: t.domComplete - t.domInteractive, | ||
// 白屏时间 | ||
blankTime: t.domInteractive - t.fetchStart, | ||
// domReadyTime | ||
domReadyTime: t.domContentLoadedEventEnd - t.fetchStart, | ||
// onload耗时、首屏时间 | ||
loadTime: t.loadEventEnd - t.fetchStart | ||
}; | ||
@@ -304,4 +304,11 @@ } | ||
import {VuePlugin} from '@ued2345/octopus-util' | ||
// 模拟上报函数(参数同vue自定义指令) | ||
// 模拟上报函数 | ||
// 1。若cbDataType为默认的情况下,参数同vue自定义指令 | ||
const bang = (el, binding) => {console.log(`触发上报,类型:${binding.arg},值: ${binding.value}`)} | ||
// 2、若cbDataType为'array'的情况下, 参数为 [{el, binding, vnode, oldVnode}] | ||
// const bang = (dataArr) => { | ||
// dataArr.forEach(item => { | ||
// console.log(`触发上报,类型:${item.binding.arg},值: ${item.binding.value}`) | ||
// }) | ||
// } | ||
Vue.use(VuePlugin, { | ||
@@ -333,7 +340,9 @@ bang: { | ||
| ------ | ------ |------ | ------ |------ | | ||
| cb | 触发上报后的回调函数 | 同vue自定义指令钩子函数,(el: HTMLElement, binding: DirectiveBinding, vnode: vnode, oldVnode: vnode) => void 详见[官网](https://cn.vuejs.org/v2/guide/custom-directive.html#%E9%92%A9%E5%AD%90%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0)| 是 | 无 | | ||
| cb | 触发上报后的回调函数:当cbData为default时默认返回数据类型为:(el: HTMLElement, binding: DirectiveBinding, vnode: vnode, oldVnode: vnode) => void 详见[官网](https://cn.vuejs.org/v2/guide/custom-directive.html#%E9%92%A9%E5%AD%90%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0)。当cbDataType为'array'时会返回[{el, binding, vnode, oldVnode}]| 是 | 无 | | ||
| clickThrottleInterval | 点击事件上报节流的间隙时间 | number | 否 | 2000 | | ||
| exposureMulti | 元素未销毁时是否可以多次发送曝光统计事件 | boolean | false | | ||
| imgErrExposure | 图片加载出错的时候是否算曝光成功(曝光事件绑定在img元素上时) | boolean | false | | ||
| exposureMulti | 元素未销毁时是否可以多次发送曝光统计事件 | boolean| 否 | false | | ||
| imgErrExposure | 图片加载出错的时候是否算曝光成功(曝光事件绑定在img元素上时) | boolean | 否 | false | | ||
cbDataType | 回调函数收到的参数类型 | 'default'/'array' | 否 | 'default' | ||
exposureUseCache | 是否对曝光事件使用缓存, cacheLen:缓存的消息条数, cacheTime: 缓存的时间(ms) | {cacheLen: number, cacheTime: number} | 否 | false | ||
exposureRatio | 元素在可视区中展示超过多少比例时触发曝光 | number | 否 | 0.95 | ||
- 注意事项 | ||
@@ -340,0 +349,0 @@ + 在给**不定高**图片绑定曝光事件时,由于网络原因可能出现后面的图片先加载完曝光的情况,造成未在可视区内但是却曝光的假象。 |
@@ -243,5 +243,5 @@ interface PerformanceOptions { | ||
redirectTime: t.redirectEnd - t.redirectStart, | ||
// dns缓存时间 | ||
// DNS缓存时间 | ||
dnsCatchTime: t.domainLookupStart - t.fetchStart, | ||
// dns查询耗时 | ||
// DNS解析时间 | ||
dnsTime: t.domainLookupEnd - t.domainLookupStart, | ||
@@ -254,5 +254,5 @@ // ttfb 读取第一个字节的时间 | ||
tcpTime: t.connectEnd - t.connectStart, | ||
// request请求耗时 | ||
// request请求耗时,页面下载耗时 | ||
reqTime: t.responseEnd - t.requestStart, | ||
// 创建dom树 | ||
// dom渲染完成时间 | ||
domTreeTime: t.domInteractive - t.responseEnd, | ||
@@ -265,3 +265,3 @@ //解析dom树耗时 | ||
domReadyTime: t.domContentLoadedEventEnd - t.fetchStart, | ||
// onload耗时 | ||
// onload耗时、首屏时间 | ||
loadTime: t.loadEventEnd - t.fetchStart | ||
@@ -268,0 +268,0 @@ }; |
@@ -9,3 +9,13 @@ type Config = { | ||
// 上报事件(事件触发后的回调) | ||
cb: callBack; | ||
cb: CallBack; | ||
// 缓存相关: cacheLen: // 缓存数据条数 | ||
exposureUseCache: { | ||
cacheLen: number, | ||
cacheTime: number | ||
}, | ||
// 曝光比例为多少时触发曝光事件 | ||
exposureRatio: number, | ||
// 默认返回的数据与自定义指令返回参数一样,若开启了exposureUseCache则会返回数组类型, | ||
// 如设置了cbDataType则其他数据类型会切换成设置的类型,但是曝光事件还是返回数组 | ||
cbDataType: 'default' | 'array' | ||
}; | ||
@@ -37,3 +47,3 @@ | ||
// 回调函数 | ||
type callBack = ( | ||
type CallBackObj = { | ||
el: HTMLElement, | ||
@@ -43,15 +53,27 @@ binding: DirectiveBinding, | ||
oldVnode: any | ||
) => void; | ||
} | ||
interface CallBack { | ||
(el: HTMLElement, binding: DirectiveBinding, vnode: any, oldVnode: any ): void, | ||
(args: CallBackObj[]): void | ||
}; | ||
const DefaultConfig = { | ||
clickThrottleInterval: 2000, | ||
exposureMulti: false, | ||
imgErrExposure: false, | ||
exposureRatio: 0.95, | ||
// exposureUseCache: { | ||
// cacheLen: 3, | ||
// cacheTime: 10000 | ||
// }, | ||
cbDataType: 'default' | ||
} | ||
class BurriedDirective { | ||
private DefaultConfig: { | ||
clickThrottleInterval: 2000; | ||
exposureMulti: false; | ||
imgErrExposure: false; | ||
}; | ||
private config: Config; | ||
private callback: callBack; | ||
private cb: CallBack; | ||
private exposureCallback; | ||
constructor(cusConfig: Config) { | ||
this.config = { ...this.DefaultConfig, ...cusConfig }; | ||
this.callback = this.config.cb; | ||
this.config = { ...DefaultConfig, ...cusConfig }; | ||
this.cb = this.config.cb; | ||
this.exposureCallback = this.config.exposureUseCache ? _addCache(this.config.cb, this.config.exposureUseCache) : this.cb | ||
} | ||
@@ -62,62 +84,12 @@ public inserted = (el, binding, vnode, oldVnode) => { | ||
case BuriedTypes.Exposure: | ||
// 对图片做单独处理,需要等图片加载完毕再上报曝光事件 | ||
new Promise((resolve, reject) => { | ||
if (el.tagName === "IMG") { | ||
el.onload = () => { | ||
// 使用了懒加载的情况 | ||
const dataSrc = el.getAttribute("data-src"); | ||
const src = el.getAttribute("src"); | ||
if ( | ||
(dataSrc ? dataSrc === src : src) || | ||
this.config.imgErrExposure | ||
) { | ||
resolve(true); | ||
} | ||
}; | ||
el.onerror = err => { | ||
this.config.imgErrExposure ? resolve(true) : reject(err); | ||
}; | ||
} else { | ||
resolve(true); | ||
} | ||
}) | ||
.then(res => { | ||
if (!res || !IntersectionObserver) return; | ||
el.observer = new IntersectionObserver( | ||
entries => { | ||
if (entries[0].intersectionRatio >= 0.95) { | ||
// 触发回调 | ||
this.callback(el, binding, vnode, oldVnode); | ||
if (!this.config.exposureMulti) { | ||
// 解除监听 | ||
el.observer.unobserve(el); | ||
} | ||
} | ||
}, | ||
{ | ||
root: null, | ||
threshold: [0.95] | ||
} | ||
); | ||
el.observer.observe(el); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
this._addExposureEvent(el, binding, vnode, oldVnode) | ||
break; | ||
case BuriedTypes.Click: | ||
const throttleCb = _usThrottle( | ||
this.callback, | ||
this.config.clickThrottleInterval | ||
); | ||
el.bangClickCb = () => { | ||
throttleCb(el, binding, vnode, oldVnode); | ||
}; | ||
el.addEventListener("click", el.bangClickCb); | ||
this._addClickEvent(el, binding, vnode, oldVnode) | ||
break; | ||
case BuriedTypes.Mounted: | ||
this.callback(el, binding, vnode, oldVnode); | ||
break; | ||
this._formatCb(el, binding, vnode, oldVnode, this.cb) | ||
break; | ||
default: | ||
this.callback(el, binding, vnode, oldVnode); | ||
this._formatCb(el, binding, vnode, oldVnode, this.cb) | ||
} | ||
@@ -133,9 +105,111 @@ }; | ||
} | ||
// 缓存的曝光数据上报 | ||
if(!!this.config.exposureUseCache) { | ||
this.exposureCallback() | ||
} | ||
} | ||
case BuriedTypes.Click: { | ||
// 可能存在点击后移除自身的情况,这是不应解绑事件,故将解绑事件放入下一个事件循环 | ||
setTimeout(() => {el.removeEventListener("click", el.bangClickCb)}, 0) | ||
setTimeout(() => { | ||
this._removeClickEvent(el) | ||
}, 0) | ||
} | ||
} | ||
}; | ||
} | ||
public update = (el, binding, vnode, oldVnode) => { | ||
vnode.data.directives.forEach(directive => { | ||
if(directive.oldValue === directive.value) return | ||
switch(directive.arg) { | ||
case BuriedTypes.Click: | ||
setTimeout(() => { | ||
this._removeClickEvent(el); | ||
this._addClickEvent(el, directive, vnode, oldVnode) | ||
}, 0) | ||
break; | ||
case BuriedTypes.Exposure: | ||
setTimeout(() => { | ||
this._removeExposureEvent(el); | ||
this._addExposureEvent(el, directive, vnode, oldVnode, true) | ||
}, 0) | ||
break; | ||
default: | ||
break | ||
} | ||
}); | ||
// console.log(binding.value, vnode, oldVnode) | ||
} | ||
private _addExposureEvent (el, binding, vnode, oldVnode, isUpdate=false) { | ||
// 对图片做单独处理,需要等图片加载完毕再上报曝光事件 | ||
new Promise((resolve, reject) => { | ||
if (el.tagName === "IMG") { | ||
el.onload = () => { | ||
// 使用了懒加载的情况 | ||
const dataSrc = el.getAttribute("data-src"); | ||
const src = el.getAttribute("src"); | ||
if ( | ||
(dataSrc ? dataSrc === src : src) || | ||
this.config.imgErrExposure | ||
) { | ||
resolve(true); | ||
} | ||
}; | ||
el.onerror = err => { | ||
this.config.imgErrExposure ? resolve(true) : reject(err); | ||
}; | ||
} else { | ||
resolve(true); | ||
} | ||
}) | ||
.then(res => { | ||
if (!res || !IntersectionObserver) return; | ||
el.observer = new IntersectionObserver( | ||
entries => { | ||
if (entries[0].intersectionRatio >= this.config.exposureRatio) { | ||
// 触发回调 | ||
this.config.cbDataType === 'array' ? this.exposureCallback({el, binding, vnode, oldVnode}) : this.exposureCallback(el, binding, vnode, oldVnode) | ||
if (!this.config.exposureMulti) { | ||
// 解除监听 | ||
el.observer.unobserve(el); | ||
} | ||
} | ||
}, | ||
{ | ||
root: null, | ||
threshold: [this.config.exposureRatio] | ||
} | ||
); | ||
el.observer.observe(el); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
} | ||
private _removeExposureEvent(el) { | ||
el.observer && el.observer.unobserve(el); | ||
} | ||
// | ||
private _addClickEvent (el, binding, vnode, oldVnode) { | ||
const throttleCb = _usThrottle( | ||
this.cb, | ||
this.config.clickThrottleInterval | ||
); | ||
el.bangClickCb = () => { | ||
this._formatCb(el, binding, vnode, oldVnode, throttleCb); | ||
}; | ||
el.addEventListener("click", el.bangClickCb); | ||
} | ||
private _removeClickEvent(el) { | ||
el.removeEventListener("click", el.bangClickCb) | ||
} | ||
// 根据不同的cbDataType配置给callback传递不同的参数 | ||
private _formatCb(el, binding, vnode, oldVnode, fn) { | ||
this.config.cbDataType === 'array' ? fn([{el, binding, vnode, oldVnode}]) : fn(el, binding, vnode, oldVnode); | ||
} | ||
} | ||
@@ -158,2 +232,38 @@ | ||
} | ||
function _addCache(fn, options) { | ||
const {cacheLen, cacheTime} = options | ||
let timer = null | ||
const cacheList = [] | ||
return function (...args) { | ||
timer && clearTimeout(timer) | ||
const th = this | ||
if(args.length === 0) { | ||
if(cacheList.length > 0) { | ||
const nowList = [...cacheList] | ||
fn.apply(th, args) | ||
while(cacheList.length> 0){cacheList.pop()} | ||
} | ||
return | ||
} else { | ||
if(args.length > 1) { | ||
cacheList.push({el: args[0], binding: args[1], vnode: args[2], oldVnode: args[3]}) | ||
} else { | ||
cacheList.push(args[0]) | ||
} | ||
} | ||
if(cacheList.length >= cacheLen) { | ||
const nowList = [...cacheList] | ||
fn.call(th, nowList) | ||
while(cacheList.length> 0){cacheList.pop()} | ||
} else { | ||
if(cacheList.length === 0) return | ||
timer = setTimeout(() => { | ||
const nowList = [...cacheList] | ||
fn.call(th, nowList) | ||
while(cacheList.length> 0){cacheList.pop()} | ||
}, cacheTime) | ||
} | ||
} | ||
} | ||
export default BurriedDirective; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62877
1158
356