Steps_wev8.js
2.18 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
define(['mUtil', "Component"],function(mUtil, Component) {
var Steps = function(options) {
Component.super(this, options);
this.type = "Steps";
this.tpl = this.type + "_html";
this.css = this.type + "_css";
var vm = this.viewModel = {
direction: 'horizontal',
steps: []
};
this.current = -1;
this.beforeMount = function(){
var that = this, getStatus = function(condition){
try{
var regex = new RegExp("(\\w+\\s*)=(\\s*\\w+)"), m;
while((m = regex.exec(condition)) != null) {
condition = condition.replace(m[0], m[1]+"=="+m[2]);
}
return eval(condition);
}catch(e){
return false;
}
};
vm.steps.forEach(function(step, i){
if(getStatus(step.condition) === true || step.status == 'current') that.current = i;
});
vm.steps.forEach(function(step, i) {
var status = step.status || "wait";
if(that.current != -1) status = (that.current == i ? "current" : (that.current > i ? "finish" : "wait"));
step.status = status;
});
that.current++;
};
this.mounted = function(){
};
this.setCurrent = function(current){
if(isNaN(current)) return;
this.current = current;
current--;
var $el = this.$el, prefix = "wev-steps-";
vm.steps.forEach(function(step, i) {
var status = (current == i ? "current" : (current > i ? "finish" : "wait"));
$el.find(".wev-steps-item").eq(i).removeClass(prefix + step.status).addClass(prefix + status);
step.status = status;
});
};
this.setNext = function(){
this.setCurrent(this.current + 1);
}
this.setPrev = function(){
this.setCurrent(this.current - 1);
}
};
return Component.init(Steps);
});