TimeLine.js
2.02 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*可视化地呈现时间流信息*/
Component({
properties: {
// 时间轴节点数据
nodes: {
type: Array,
value: [],
observer: function(newVal, oldVal) {
this.processNodes(newVal);
}
}
},
data: {
timeLineNodes: []
},
/**
* 组件内部方法
*/
methods: {
/**
* 预处理节点数据,添加样式类
* @param {Array} nodes - 节点数组
*/
processNodes(nodes) {
if (!nodes || !Array.isArray(nodes)) return;
const timeLineNodes = nodes.map(node => {
return {
...node,
dotClass: this.getNodeDotClass(node),
contentClass: this.getNodeContentClass(node)
};
});
this.setData({
timeLineNodes
});
},
/**
* 获取节点点的样式类
* @param {Object} item - 时间轴节点项
* @returns {String} 样式类名
*/
getNodeDotClass(item) {
// 直接根据节点属性返回对应的样式类
if (item.active) {
return 'timeline-node__dot timeline-node__dot--active';
} else if (item.type === 'special') {
return 'timeline-node__dot timeline-node__dot--spacial';
} else if (item.small) {
return 'timeline-node__dot timeline-node__dot--small';
} else {
return 'timeline-node__dot';
}
},
/**
* 获取节点内容的样式类
* @param {Object} item - 时间轴节点项
* @returns {String} 样式类名
*/
getNodeContentClass(item) {
// 非激活状态的内容使用灰色
if (item.type === 'special') {
return 'timeline-node__content--special';
}else if(item.active){
return 'active';
}
},
/**
* 判断是否显示节点点
* @param {Object} item - 时间轴节点项
* @returns {Boolean} 是否显示节点点
*/
shouldShowNodeDot(item) {
// 修复逻辑:所有节点默认都应该显示点
// 只有特定情况下才不显示
return true;
}
}
});