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
| <template>
| <div class="time-shortcut">
| <ul>
| <li :class="{act:actPicker=='today'}" @click="checkToday">今日</li>
| <li :class="{act:actPicker=='week'}" @click="checkWeek">本周</li>
| <li :class="{act:actPicker=='month'}" @click="checkMonth">本月</li>
| <li :class="{act:actPicker=='year'}" @click="checkYear">全年</li>
| </ul>
| </div>
| </template>
|
| <script>
| export default {
| data () {
| return {
| //actPicker: 'today',
| }
| },
| props: {
| actPicker:{
| type: String,
| default: 'today' //现提供可选参数为:today week month year
| }
| },
| watch: {
| actPicker (n, o) {
| let tempArr = [];
| if (n == 'today') {
| tempArr = this.checkToday()
| } else if (n == 'week') {
| tempArr = this.checkWeek();
| } else if (n == 'month') {
| tempArr = this.checkMonth();
| } else if (n == 'year') {
| tempArr = this.checkYear();
| }
| this.$emit('actPickerChange', tempArr)
| }
| },
| methods: {
| checkToday () {
| this.actPicker = 'today';
| const start = new Date();
| const end = new Date();
| start.setHours(0, 0, 0);
| return [start, end];
| },
| checkWeek () {
| this.actPicker = 'week';
| const start = new Date();
| const end = new Date();
| start.setDate(start.getDate() - start.getDay() + 1);
| start.setHours(0, 0, 0);
| return [start, end];
| },
| checkMonth () {
| this.actPicker = 'month';
| const start = new Date();
| const end = new Date();
| start.setDate(1);
| start.setHours(0, 0, 0);
| return [start, end];
| },
| checkYear () {
| this.actPicker = 'year';
| const start = new Date(new Date().getFullYear(), 0);
| const end = new Date();
| start.setHours(0, 0, 0);
| return [start, end];
| }
| }
| }
| </script>
|
| <style lang="scss">
| .time-shortcut {
| margin-right: 62px;
| ul {
| display: flex;
| li {
| padding: 10px 14px;
| font-size: 14px;
| cursor: pointer;
| &.act {
| color: #409eff;
| }
| }
| }
| }
| </style>
|
|