countdown-f
Version:
一个用vue封装的倒计时组件
2 lines • 3.93 kB
JavaScript
(function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports["count-down"]=e():t["count-down"]=e()})("undefined"!==typeof self?self:this,(function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t["default"]}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s="fb15")}({"2cb3":function(t,e,n){},e280:function(t,e,n){"use strict";n("2cb3")},fb15:function(t,e,n){"use strict";if(n.r(e),"undefined"!==typeof window){var o=window.document.currentScript,r=o&&o.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);r&&(n.p=r[1])}var i=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"countDown_container"},[n("div",{staticClass:"content"},[t._t("default",null,null,{d:t.days,h:t.hours,m:t.mins,s:t.seconds,dd:("00"+t.days).slice(-2),hh:("00"+t.hours).slice(-2),mm:("00"+t.mins).slice(-2),ss:("00"+t.seconds).slice(-2)})],2)])},s=[],u={name:"CountDown",props:{time:{type:[Number,String],default:0},isMilliSecond:{type:Boolean,default:!1},end:{type:[Number,String],default:0}},data(){return{timer:null,curTime:0,days:0,hours:0,mins:0,seconds:0}},computed:{durationTime(){if(this.end>0){let t=String(this.end).length>=13?+this.end:1e3*+this.end;return t-=Date.now(),t}const t=this.isMilliSecond?Math.round(+this.time/1e3):Math.round(+this.time);return t}},methods:{countDown(){this.curTime=Date.now(),this.getTime(this.durationTime)},getTime(t){if(this.timer&&clearTimeout(this.timer),t<=0)return!1;const{daysVal:e,hoursVal:n,minsVal:o,secondsVal:r}=this.durationFormatter(t);this.days=e||0,this.hours=n||0,this.mins=o||0,this.seconds=r||0,this.timer=setTimeout(()=>{const e=Date.now(),n=Math.floor((e-this.curTime)/1e3);this.curTime=Date.now(),this.getTime(t-n)},1e3)},durationFormatter(t){if(!t)return{secondsVal:0};let e=t;const n=e%60;if(e=(e-n)/60,e<1)return{secondsVal:n};const o=e%60;if(e=(e-o)/60,e<1)return{minsVal:o,secondsVal:n};const r=e%24;if(e=(e-r)/24,e<1)return{hoursVal:r,minsVal:o,secondsVal:n};const i=e;return{daysVal:i,hoursVal:r,minsVal:o,secondsVal:n}}},mounted(){this.countDown()},watch:{durationTime(){this.countDown()}}},c=u;n("e280");function a(t,e,n,o,r,i,s,u){var c,a="function"===typeof t?t.options:t;if(e&&(a.render=e,a.staticRenderFns=n,a._compiled=!0),o&&(a.functional=!0),i&&(a._scopeId="data-v-"+i),s?(c=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"===typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),r&&r.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},a._ssrRegister=c):r&&(c=u?function(){r.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:r),c)if(a.functional){a._injectStyles=c;var d=a.render;a.render=function(t,e){return c.call(e),d(t,e)}}else{var l=a.beforeCreate;a.beforeCreate=l?[].concat(l,c):[c]}return{exports:t,options:a}}var d=a(c,i,s,!1,null,"1c5ae9a9",null),l=d.exports;const f=[l],m=function(t){f.forEach(e=>{t.component(e.name,e)})};var h=m;e["default"]=h}})}));
//# sourceMappingURL=count-down.umd.min.js.map