17e1fcf1
梁灏
init DatePicker
|
1
|
<template>
|
e0cd7f90
梁灏
fixed #134
|
2
|
<div :class="classes">
|
3cf7cfd1
梁灏
update DatePicker
|
3
4
5
6
7
8
9
10
|
<div :class="[prefixCls + '-sidebar']" v-if="shortcuts.length">
<div
:class="[prefixCls + '-shortcut']"
v-for="shortcut in shortcuts"
@click="handleShortcutClick(shortcut)">{{ shortcut.text }}</div>
</div>
<div :class="[prefixCls + '-body']">
<div :class="[prefixCls + '-content', prefixCls + '-content-left']">
|
0a5c5f41
梁灏
update DatePicker
|
11
|
<div :class="[datePrefixCls + '-header']" v-show="leftCurrentView !== 'time'">
|
3cf7cfd1
梁灏
update DatePicker
|
12
13
|
<span
:class="iconBtnCls('prev', '-double')"
|
0a5c5f41
梁灏
update DatePicker
|
14
|
@click="prevYear('left')"><Icon type="ios-arrow-left"></Icon></span>
|
3cf7cfd1
梁灏
update DatePicker
|
15
16
17
|
<span
:class="iconBtnCls('prev')"
@click="prevMonth"
|
0a5c5f41
梁灏
update DatePicker
|
18
|
v-show="leftCurrentView === 'date'"><Icon type="ios-arrow-left"></Icon></span>
|
3cf7cfd1
梁灏
update DatePicker
|
19
20
|
<span
:class="[datePrefixCls + '-header-label']"
|
0a5c5f41
梁灏
update DatePicker
|
21
|
@click="showYearPicker('left')">{{ leftYearLabel }}</span>
|
3cf7cfd1
梁灏
update DatePicker
|
22
23
|
<span
:class="[datePrefixCls + '-header-label']"
|
0a5c5f41
梁灏
update DatePicker
|
24
25
26
27
28
29
|
@click="showMonthPicker('left')"
v-show="leftCurrentView === 'date'">{{ leftMonth + 1 }} 月</span>
<span
:class="iconBtnCls('next', '-double')"
@click="nextYear('left')"
v-show="leftCurrentView === 'year' || leftCurrentView === 'month'"><Icon type="ios-arrow-right"></Icon></span>
|
3cf7cfd1
梁灏
update DatePicker
|
30
31
|
</div>
<date-table
|
0a5c5f41
梁灏
update DatePicker
|
32
|
v-show="leftCurrentView === 'date'"
|
3cf7cfd1
梁灏
update DatePicker
|
33
34
35
36
37
38
|
:year="leftYear"
:month="leftMonth"
:date="date"
:min-date="minDate"
:max-date="maxDate"
:range-state="rangeState"
|
472b4ff1
梁灏
update DatePicker
|
39
|
selection-mode="range"
|
3cf7cfd1
梁灏
update DatePicker
|
40
|
:disabled-date="disabledDate"
|
472b4ff1
梁灏
update DatePicker
|
41
42
|
@on-changerange="handleChangeRange"
@on-pick="handleRangePick"></date-table>
|
0a5c5f41
梁灏
update DatePicker
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
<year-table
v-ref:left-year-table
v-show="leftCurrentView === 'year'"
:year="leftYear"
:date="date"
selection-mode="range"
:disabled-date="disabledDate"
@on-pick="handleLeftYearPick"></year-table>
<month-table
v-ref:left-month-table
v-show="leftCurrentView === 'month'"
:month="leftMonth"
:date="date"
selection-mode="range"
:disabled-date="disabledDate"
@on-pick="handleLeftMonthPick"></month-table>
|
3cf7cfd1
梁灏
update DatePicker
|
59
60
|
</div>
<div :class="[prefixCls + '-content', prefixCls + '-content-right']">
|
0a5c5f41
梁灏
update DatePicker
|
61
62
63
64
65
|
<div :class="[datePrefixCls + '-header']" v-show="rightCurrentView !== 'time'">
<span
:class="iconBtnCls('prev', '-double')"
@click="prevYear('right')"
v-show="rightCurrentView === 'year' || rightCurrentView === 'month'"><Icon type="ios-arrow-left"></Icon></span>
|
3cf7cfd1
梁灏
update DatePicker
|
66
67
|
<span
:class="[datePrefixCls + '-header-label']"
|
0a5c5f41
梁灏
update DatePicker
|
68
|
@click="showYearPicker('right')">{{ rightYearLabel }}</span>
|
3cf7cfd1
梁灏
update DatePicker
|
69
70
|
<span
:class="[datePrefixCls + '-header-label']"
|
0a5c5f41
梁灏
update DatePicker
|
71
72
|
@click="showMonthPicker('right')"
v-show="rightCurrentView === 'date'">{{ rightMonth + 1 }} 月</span>
|
3cf7cfd1
梁灏
update DatePicker
|
73
74
|
<span
:class="iconBtnCls('next', '-double')"
|
0a5c5f41
梁灏
update DatePicker
|
75
|
@click="nextYear('right')"><Icon type="ios-arrow-right"></Icon></span>
|
3cf7cfd1
梁灏
update DatePicker
|
76
77
78
|
<span
:class="iconBtnCls('next')"
@click="nextMonth"
|
0a5c5f41
梁灏
update DatePicker
|
79
|
v-show="rightCurrentView === 'date'"><Icon type="ios-arrow-right"></Icon></span>
|
3cf7cfd1
梁灏
update DatePicker
|
80
81
|
</div>
<date-table
|
0a5c5f41
梁灏
update DatePicker
|
82
|
v-show="rightCurrentView === 'date'"
|
3cf7cfd1
梁灏
update DatePicker
|
83
84
85
86
87
88
|
:year="rightYear"
:month="rightMonth"
:date="rightDate"
:min-date="minDate"
:max-date="maxDate"
:range-state="rangeState"
|
472b4ff1
梁灏
update DatePicker
|
89
|
selection-mode="range"
|
3cf7cfd1
梁灏
update DatePicker
|
90
|
:disabled-date="disabledDate"
|
472b4ff1
梁灏
update DatePicker
|
91
92
|
@on-changerange="handleChangeRange"
@on-pick="handleRangePick"></date-table>
|
0a5c5f41
梁灏
update DatePicker
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
<year-table
v-ref:right-year-table
v-show="rightCurrentView === 'year'"
:year="rightYear"
:date="rightDate"
selection-mode="range"
:disabled-date="disabledDate"
@on-pick="handleRightYearPick"></year-table>
<month-table
v-ref:right-month-table
v-show="rightCurrentView === 'month'"
:month="rightMonth"
:date="rightDate"
selection-mode="range"
:disabled-date="disabledDate"
@on-pick="handleRightMonthPick"></month-table>
|
3cf7cfd1
梁灏
update DatePicker
|
109
110
|
</div>
</div>
|
e0cd7f90
梁灏
fixed #134
|
111
|
</div>
|
17e1fcf1
梁灏
init DatePicker
|
112
113
|
</template>
<script>
|
3cf7cfd1
梁灏
update DatePicker
|
114
115
|
import Icon from '../../icon/icon.vue';
import DateTable from '../base/date-table.vue';
|
0a5c5f41
梁灏
update DatePicker
|
116
117
118
|
import YearTable from '../base/year-table.vue';
import MonthTable from '../base/month-table.vue';
import { toDate, prevMonth, nextMonth } from '../util';
|
3cf7cfd1
梁灏
update DatePicker
|
119
120
121
|
import Mixin from './mixin';
|
e0cd7f90
梁灏
fixed #134
|
122
123
124
|
const prefixCls = 'ivu-picker-panel';
const datePrefixCls = 'ivu-date-picker';
|
17e1fcf1
梁灏
init DatePicker
|
125
|
export default {
|
3cf7cfd1
梁灏
update DatePicker
|
126
|
mixins: [Mixin],
|
0a5c5f41
梁灏
update DatePicker
|
127
|
components: { Icon, DateTable, YearTable, MonthTable },
|
17e1fcf1
梁灏
init DatePicker
|
128
|
data () {
|
3cf7cfd1
梁灏
update DatePicker
|
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
return {
prefixCls: prefixCls,
datePrefixCls: datePrefixCls,
shortcuts: [],
date: new Date(),
value: '',
minDate: '',
maxDate: '',
rangeState: {
endDate: null,
selecting: false
},
showTime: false,
disabledDate: '',
|
0a5c5f41
梁灏
update DatePicker
|
143
144
|
leftCurrentView: 'date',
rightCurrentView: 'date',
|
3cf7cfd1
梁灏
update DatePicker
|
145
146
|
selectionMode: 'range'
}
|
17e1fcf1
梁灏
init DatePicker
|
147
|
},
|
e0cd7f90
梁灏
fixed #134
|
148
149
150
151
|
computed: {
classes () {
return [
`${prefixCls}-body-wrapper`,
|
3cf7cfd1
梁灏
update DatePicker
|
152
|
`${datePrefixCls}-with-range`,
|
e0cd7f90
梁灏
fixed #134
|
153
154
155
156
|
{
[`${prefixCls}-with-sidebar`]: this.shortcuts.length
}
]
|
3cf7cfd1
梁灏
update DatePicker
|
157
158
159
160
|
},
leftYear() {
return this.date.getFullYear();
},
|
0a5c5f41
梁灏
update DatePicker
|
161
162
163
164
165
166
167
168
169
|
leftYearLabel () {
const year = this.leftYear;
if (!year) return '';
if (this.leftCurrentView === 'year') {
const startYear = Math.floor(year / 10) * 10;
return `${startYear}年 - ${startYear + 9}年`;
}
return `${year}年`;
},
|
3cf7cfd1
梁灏
update DatePicker
|
170
171
172
173
174
175
|
leftMonth() {
return this.date.getMonth();
},
rightYear() {
return this.rightDate.getFullYear();
},
|
0a5c5f41
梁灏
update DatePicker
|
176
177
178
179
180
181
182
183
184
|
rightYearLabel () {
const year = this.rightYear;
if (!year) return '';
if (this.rightCurrentView === 'year') {
const startYear = Math.floor(year / 10) * 10;
return `${startYear}年 - ${startYear + 9}年`;
}
return `${year}年`;
},
|
3cf7cfd1
梁灏
update DatePicker
|
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
rightMonth() {
return this.rightDate.getMonth();
},
rightDate() {
const newDate = new Date(this.date);
const month = newDate.getMonth();
newDate.setDate(1);
if (month === 11) {
newDate.setFullYear(newDate.getFullYear() + 1);
newDate.setMonth(0);
} else {
newDate.setMonth(month + 1);
}
return newDate;
}
},
watch: {
value(newVal) {
if (!newVal) {
this.minDate = null;
this.maxDate = null;
} else if (Array.isArray(newVal)) {
this.minDate = newVal[0] ? toDate(newVal[0]) : null;
this.maxDate = newVal[1] ? toDate(newVal[1]) : null;
if (this.minDate) this.date = new Date(this.minDate);
|
3cf7cfd1
梁灏
update DatePicker
|
211
|
}
|
e0cd7f90
梁灏
fixed #134
|
212
213
|
}
},
|
3cf7cfd1
梁灏
update DatePicker
|
214
|
methods: {
|
472b4ff1
梁灏
update DatePicker
|
215
216
217
218
219
|
handleClear() {
this.minDate = null;
this.maxDate = null;
this.handleConfirm();
},
|
0a5c5f41
梁灏
update DatePicker
|
220
221
222
223
224
225
226
227
|
prevYear (direction) {
if (this[`${direction}CurrentView`] === 'year') {
this.$refs[`${direction}YearTable`].prevTenYear();
} else {
const date = this.date;
date.setFullYear(date.getFullYear() - 1);
this.resetDate();
}
|
3cf7cfd1
梁灏
update DatePicker
|
228
|
},
|
0a5c5f41
梁灏
update DatePicker
|
229
230
231
232
233
234
235
236
|
nextYear (direction) {
if (this[`${direction}CurrentView`] === 'year') {
this.$refs[`${direction}YearTable`].nextTenYear();
} else {
const date = this.date;
date.setFullYear(date.getFullYear() + 1);
this.resetDate();
}
|
3cf7cfd1
梁灏
update DatePicker
|
237
238
|
},
prevMonth () {
|
0a5c5f41
梁灏
update DatePicker
|
239
|
this.date = prevMonth(this.date);
|
3cf7cfd1
梁灏
update DatePicker
|
240
241
|
},
nextMonth () {
|
0a5c5f41
梁灏
update DatePicker
|
242
|
this.date = nextMonth(this.date);
|
3cf7cfd1
梁灏
update DatePicker
|
243
|
},
|
0a5c5f41
梁灏
update DatePicker
|
244
245
246
247
248
|
handleLeftYearPick (year, close = true) {
this.handleYearPick(year, close, 'left');
},
handleRightYearPick (year, close = true) {
this.handleYearPick(year, close, 'right');
|
3cf7cfd1
梁灏
update DatePicker
|
249
|
},
|
0a5c5f41
梁灏
update DatePicker
|
250
251
252
253
|
handleYearPick (year, close, direction) {
this.date.setFullYear(year);
this.resetDate();
if (!close) return;
|
3cf7cfd1
梁灏
update DatePicker
|
254
|
|
0a5c5f41
梁灏
update DatePicker
|
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
this[`${direction}CurrentView`] = 'month';
},
handleLeftMonthPick (month) {
this.handleMonthPick(month, 'left');
},
handleRightMonthPick (month) {
this.handleMonthPick(month, 'right');
},
handleMonthPick (month, direction) {
this.date.setMonth(month);
this[`${direction}CurrentView`] = 'date';
this.resetDate();
},
showYearPicker (direction) {
this[`${direction}CurrentView`] = 'year';
},
showMonthPicker (direction) {
this[`${direction}CurrentView`] = 'month';
|
3cf7cfd1
梁灏
update DatePicker
|
273
|
},
|
3cf7cfd1
梁灏
update DatePicker
|
274
275
|
handleConfirm(visible) {
this.$emit('on-pick', [this.minDate, this.maxDate], visible);
|
472b4ff1
梁灏
update DatePicker
|
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
},
handleRangePick (val, close = true) {
if (this.maxDate === val.maxDate && this.minDate === val.minDate) return;
this.minDate = val.minDate;
this.maxDate = val.maxDate;
if (!close) return;
if (!this.showTime) {
this.handleConfirm(false);
}
},
handleChangeRange (val) {
this.minDate = val.minDate;
this.maxDate = val.maxDate;
this.rangeState = val.rangeState;
|
3cf7cfd1
梁灏
update DatePicker
|
292
293
|
}
}
|
17e1fcf1
梁灏
init DatePicker
|
294
295
|
}
</script>
|