vue-navigation-progress-plugin
Version:
2 lines • 2.68 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.vueNavigationProgressPlugin=e()}(this,function(){"use strict";var t={render:function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",{staticClass:"router-progress",style:t.style})},staticRenderFns:[],name:"router-progress",computed:{style:function(){return{transform:"translate3d("+(this.percent-100)+"%, 0, 0)",backgroundColor:this.canSuccess?this.color:this.failedColor,opacity:this.show?1:0}}},created:function(){!this.$root.$progress&&(this.$root.$progress=this)},props:{duration:{type:Number,default:3e3},color:{type:String,default:"#77b6ff"},failedColor:{type:String,default:"red"}},data:function(){return{percent:0,show:!1,canSuccess:!0}},methods:{start:function(){var t=this;this.show=!0,this.canSuccess=!0,this._timer&&(clearInterval(this._timer),this.percent=0),this._cut=1e4/Math.floor(this.duration),this._timer=setInterval(function(){t.increase(t._cut*Math.random()),t.percent>90&&t.pause()},100)},set:function(t){this.show=!0,this.canSuccess=!0,this.percent=Math.floor(t)},get:function(){return Math.floor(this.percent)},increase:function(t){this.percent=this.percent+Math.floor(t)},decrease:function(t){this.percent=this.percent-Math.floor(t)},finish:function(){this.percent=100,this.hide()},pause:function(){clearInterval(this._timer)},hide:function(){var t=this;clearInterval(this._timer),this._timer=null,setTimeout(function(){t.show=!1,t.$nextTick(function(){setTimeout(function(){t.percent=0},200)})},500)},fail:function(){this.canSuccess=!1}}},e=function(t,e){return Array.prototype.concat.apply([],t.matched.map(function(t,n){return Object.keys(t.components).map(function(o){return e(t.components[o],t,o,n)})}))},n=function(t,n,o,i,r){var s=r.app&&r.app.$root.$progress,c=e(t,function(t,e,n){return"function"!=typeof t||t.options?t:new Promise(function(o,r){var s=function(t){t.options?(t._Ctor=t,t.extendOptions=t.options):(t=i.extend(t),t._Ctor=t),e.components[n]=t,o(t)};t().then(s).catch(r)})});n.fullPath.split("#")[0]!==t.fullPath.split("#")[0]&&s&&s.start(),Promise.all(c).then(function(){s&&s.finish(),o()},function(){s&&s.fail(),s&&s.finish(),o(!1)})};return{install:function(e,o){var i=document.createElement("style");i.type="text/css",i.textContent=".router-progress{position:fixed;top:0;left:0;right:0;height:2px;width:100%;transition:transform .3s ease-out,opacity .3s ease-out;box-shadow:rgba(119,182,255,.7);z-index:9999}",document.head.appendChild(i),e.component(t.name,t),o.beforeEach(function(t,i,r){return n(t,i,r,e,o)})}}});
//# sourceMappingURL=dist/vue-navigation-progress-plugin.min.js.map