date.vue
5.83 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
<div style="margin: 50px">
<i-button @click="setDate">change date</i-button>
<br>
<row>
<i-col span="8">
<!--<i-button @click="setDate">set date</i-button>-->
<date-picker
style="width:200px"
placeholder="请选择日期"
:value.sync="value"
:options="options"
@on-change="change"
:format="format"
@on-open-change="change2"></date-picker>
</i-col>
<i-col span="8">
<date-picker
type="daterange"
style="width:300px"
placeholder="请选择日期"
:value.sync="value2"
align="right"
:editable="true"
:format="format"
@on-change="change"
:clearable="false"
:options="options2"></date-picker>
</i-col>
</row>
</div>
</template>
<script>
export default {
data () {
return {
// value: new Date(),
value: '2016-12-25',
value2: ['2016-12-17', '2017-01-05'],
options2: {
// disabledDate(time) {
//// console.log(time)
//// return time.getFullYear() < 2016;
//// return time.getTime() < Date.now() - 8.64e7;
//// return time && time.valueOf() < Date.now();
// if (time.getDate() === 22 || time.getDate() === 23) {
// return true;
// } else {
// return false;
// }
// },
shortcuts: [
{
text: '最近一周',
value () {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
return [start, end];
},
onClick (picker) {
console.log('点击了最近一周');
}
},
{
text: '最近一个月',
value () {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
return [start, end];
},
onClick () {
console.log('点击了最近一个月');
}
},
{
text: '最近三个月',
value () {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
return [start, end];
},
onClick () {
console.log('点击了最近三个月');
}
}
]
},
options: {
disabledDate(time) {
// console.log(time)
// return time.getFullYear() < 2016;
return time.getTime() < Date.now() - 8.64e7;
// return time && time.valueOf() < Date.now();
},
shortcuts: [
{
text: '今天',
value () {
// return new Date();
return '1/2/19'
},
onClick (picker) {
console.log('点击了今天');
}
},
{
text: '昨天',
value () {
const date = new Date();
date.setTime(date.getTime() - 3600 * 1000 * 24);
return date;
},
onClick () {
console.log('点击了昨天');
}
},
{
text: '最近三个月',
value () {
const date = new Date();
date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
return date;
},
onClick () {
console.log('点击了一周前');
}
}
]
},
format: 'yyyy-MM-dd'
}
},
computed: {},
methods: {
change (date) {
console.log(date)
},
change2 (s) {
// console.log(s)
},
setDate () {
// this.value = '2016-12-24'
this.value2 = ['2016-9-1', '2016-9-20']
}
}
}
</script>