Countdown_wev8.js
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
define(['mUtil', "Component"],function(mUtil, Component) {
var Countdown = function(options) {
Component.super(this, options);
this.type = "Countdown";
this.tpl = this.type + "_html";
this.css = this.type + "_css";
var vm = this.viewModel = {
countdowndate: new Date().getFullYear() + 1 + "-01-01 00:00:01" //默认值
};
this.beforeMount = function () {
vm.validate = true;//合法日期
if (!vm.countdowndate.match(/^[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{1,2}:[0-9]{2}:[0-9]{2}$/)) {
vm.countdowndate = "0";
vm.validate = false;
}
};
this.mounted = function(){
var $comp = $('.wev-comp-Countdown > div',this.$el);
var oriDate = vm.validate ? new Date(vm.countdowndate) : new Date();
require(["timeCircles"], function () {
$comp.TimeCircles({
time: {
Days: {
show: false,
text: "天",
color: "#FC6"
},
Hours: {
show: false,
text: "时",
color: "#9CF"
},
Minutes: {
show: false,
text: "分",
color: "#BFB"
},
Seconds: {
show: false,
text: "秒",
color: "#F99"
}
},
refresh_interval: 0.1,
count_past_zero: vm.validate && ((new Date()).getTime() - oriDate.getTime())/1000 >= 0 ? false : vm.validate,
circle_bg_color: "#ddd",
fg_width: 0.03,
bg_width: 0.2
}).addListener(function (unit, value, total) {
var diff = ((new Date()).getTime() - oriDate.getTime())/1000;
if ((total <= 1 && Math.abs(diff) <= 1) || diff > 1) {
if (diff <= 1) {
setTimeout(function () {
$comp.TimeCircles().stop();
}, 1000);
}
}
});
});
};
};
return Component.init(Countdown);
});