-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathCustomZoom.vue
115 lines (109 loc) · 2.57 KB
/
CustomZoom.vue
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<template>
<div class="container">
<div class="timeShow">当前时间:{{ showTime }}</div>
<div class="timeLine" ref="timeLine">
<TimeLine
ref="Timeline"
:enableZoom="false"
:enableDrag="false"
:showDateAtZero="false"
:initZoomIndex="11"
:initTime="initTime"
:customShowTime="customShowTime"
:extendZOOM="extendZOOM"
:formatTime="formatTime"
:hoverTimeFormat="hoverTimeFormat"
@click_timeline="click_timeline"
></TimeLine>
</div>
</div>
</template>
<script>
import dayjs from 'dayjs'
export default {
data() {
return {
time: Date.now(),
initTime: dayjs().format('YYYY-MM-DD 12:00:00').valueOf(),
// 扩展时间分辨率
extendZOOM: [
{
zoom: 25,
zoomHourGrid: 0.5
}
]
}
},
computed: {
showTime() {
return dayjs(this.time).format('YYYY-MM-DD HH:mm:ss')
}
},
mounted () {
console.log(this.$refs.timeLine.getBoundingClientRect());
},
methods: {
click_timeline(time, date) {
this.time = time
},
// 格式化时间轴上显示的时间
formatTime(time) {
// 下一天的00:00显示24:00
if (time.isAfter(dayjs().format('YYYY-MM-DD 23:59:59'))) {
return '24:00'
}
if (
time.hour() === 0 &&
time.minute() === 0 &&
time.millisecond() === 0
) {
return time.format('HH:mm')
}
},
// 格式化鼠标滑过显示的时间
hoverTimeFormat(time) {
// 小于今天,大于今天的时间不显示
if (
dayjs(time).isBefore(dayjs().format('YYYY-MM-DD 00:00:00')) ||
dayjs(time).isAfter(dayjs().format('YYYY-MM-DD 23:59:59'))
) {
return ''
}
return dayjs(time).format('HH:mm:ss')
},
// 自定义判断时间轴上是否显示某个日期时间
customShowTime(date, zoomIndex) {
// 当zoomIndex等于11,也就是等于我们开展的zoom时才自己处理
if (zoomIndex === 11) {
// 时间是2的倍数时才会显示
return date.getHours() % 2 === 0 && date.getMinutes() === 0
}
}
}
}
</script>
<style lang="less" scoped>
.container {
width: 1200px;
height: 100%;
margin: 0 auto;
display: flex;
position: relative;
justify-content: center;
flex-direction: column;
.timeLine {
height: 50px;
}
}
.btns {
margin: 10px 0;
display: flex;
justify-content: center;
}
.timeShow {
margin: 10px 0;
display: flex;
justify-content: center;
user-select: none;
}
</style>