17e1fcf1
梁灏
init DatePicker
|
1
|
<template>
|
030a522d
Sergio Crisostomo
make picker close...
|
2
|
<div :class="classes" @mousedown.prevent>
|
3cf7cfd1
梁灏
update DatePicker
|
3
4
5
6
7
8
9
|
<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']">
|
2dc27713
梁灏
update DateTimePi...
|
10
|
<div :class="[prefixCls + '-content', prefixCls + '-content-left']" v-show="!isTime">
|
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>
|
b27858dd
Sergio Crisostomo
add date panel la...
|
19
20
21
22
|
<date-panel-label
:date-panel-label="leftDatePanelLabel"
:current-view="leftCurrentView"
:date-prefix-cls="datePrefixCls"/>
|
0a5c5f41
梁灏
update DatePicker
|
23
24
25
26
|
<span
:class="iconBtnCls('next', '-double')"
@click="nextYear('left')"
v-show="leftCurrentView === 'year' || leftCurrentView === 'month'"><Icon type="ios-arrow-right"></Icon></span>
|
3cf7cfd1
梁灏
update DatePicker
|
27
28
|
</div>
<date-table
|
0a5c5f41
梁灏
update DatePicker
|
29
|
v-show="leftCurrentView === 'date'"
|
3cf7cfd1
梁灏
update DatePicker
|
30
31
32
33
34
35
|
:year="leftYear"
:month="leftMonth"
:date="date"
:min-date="minDate"
:max-date="maxDate"
:range-state="rangeState"
|
472b4ff1
梁灏
update DatePicker
|
36
|
selection-mode="range"
|
3cf7cfd1
梁灏
update DatePicker
|
37
|
:disabled-date="disabledDate"
|
472b4ff1
梁灏
update DatePicker
|
38
|
@on-changerange="handleChangeRange"
|
68e9b100
梁灏
update DatePicker
|
39
40
|
@on-pick="handleRangePick"
@on-pick-click="handlePickClick"></date-table>
|
0a5c5f41
梁灏
update DatePicker
|
41
|
<year-table
|
531cd165
梁灏
support DatePicke...
|
42
|
ref="leftYearTable"
|
0a5c5f41
梁灏
update DatePicker
|
43
|
v-show="leftCurrentView === 'year'"
|
3732707e
梁灏
update DatePicker
|
44
45
|
:year="leftTableYear"
:date="leftTableDate"
|
0a5c5f41
梁灏
update DatePicker
|
46
47
|
selection-mode="range"
:disabled-date="disabledDate"
|
68e9b100
梁灏
update DatePicker
|
48
49
|
@on-pick="handleLeftYearPick"
@on-pick-click="handlePickClick"></year-table>
|
0a5c5f41
梁灏
update DatePicker
|
50
|
<month-table
|
531cd165
梁灏
support DatePicke...
|
51
|
ref="leftMonthTable"
|
0a5c5f41
梁灏
update DatePicker
|
52
53
|
v-show="leftCurrentView === 'month'"
:month="leftMonth"
|
3732707e
梁灏
update DatePicker
|
54
|
:date="leftTableDate"
|
0a5c5f41
梁灏
update DatePicker
|
55
56
|
selection-mode="range"
:disabled-date="disabledDate"
|
68e9b100
梁灏
update DatePicker
|
57
58
|
@on-pick="handleLeftMonthPick"
@on-pick-click="handlePickClick"></month-table>
|
3cf7cfd1
梁灏
update DatePicker
|
59
|
</div>
|
2dc27713
梁灏
update DateTimePi...
|
60
|
<div :class="[prefixCls + '-content', prefixCls + '-content-right']" v-show="!isTime">
|
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>
|
b27858dd
Sergio Crisostomo
add date panel la...
|
66
67
68
69
|
<date-panel-label
:date-panel-label="rightDatePanelLabel"
:current-view="rightCurrentView"
:date-prefix-cls="datePrefixCls"/>
|
3cf7cfd1
梁灏
update DatePicker
|
70
71
|
<span
:class="iconBtnCls('next', '-double')"
|
0a5c5f41
梁灏
update DatePicker
|
72
|
@click="nextYear('right')"><Icon type="ios-arrow-right"></Icon></span>
|
3cf7cfd1
梁灏
update DatePicker
|
73
74
75
|
<span
:class="iconBtnCls('next')"
@click="nextMonth"
|
0a5c5f41
梁灏
update DatePicker
|
76
|
v-show="rightCurrentView === 'date'"><Icon type="ios-arrow-right"></Icon></span>
|
3cf7cfd1
梁灏
update DatePicker
|
77
78
|
</div>
<date-table
|
0a5c5f41
梁灏
update DatePicker
|
79
|
v-show="rightCurrentView === 'date'"
|
3cf7cfd1
梁灏
update DatePicker
|
80
81
82
83
84
85
|
:year="rightYear"
:month="rightMonth"
:date="rightDate"
:min-date="minDate"
:max-date="maxDate"
:range-state="rangeState"
|
472b4ff1
梁灏
update DatePicker
|
86
|
selection-mode="range"
|
3cf7cfd1
梁灏
update DatePicker
|
87
|
:disabled-date="disabledDate"
|
472b4ff1
梁灏
update DatePicker
|
88
|
@on-changerange="handleChangeRange"
|
68e9b100
梁灏
update DatePicker
|
89
90
|
@on-pick="handleRangePick"
@on-pick-click="handlePickClick"></date-table>
|
0a5c5f41
梁灏
update DatePicker
|
91
|
<year-table
|
531cd165
梁灏
support DatePicke...
|
92
|
ref="rightYearTable"
|
0a5c5f41
梁灏
update DatePicker
|
93
|
v-show="rightCurrentView === 'year'"
|
3732707e
梁灏
update DatePicker
|
94
95
|
:year="rightTableYear"
:date="rightTableDate"
|
0a5c5f41
梁灏
update DatePicker
|
96
97
|
selection-mode="range"
:disabled-date="disabledDate"
|
68e9b100
梁灏
update DatePicker
|
98
99
|
@on-pick="handleRightYearPick"
@on-pick-click="handlePickClick"></year-table>
|
0a5c5f41
梁灏
update DatePicker
|
100
|
<month-table
|
531cd165
梁灏
support DatePicke...
|
101
|
ref="rightMonthTable"
|
0a5c5f41
梁灏
update DatePicker
|
102
103
|
v-show="rightCurrentView === 'month'"
:month="rightMonth"
|
3732707e
梁灏
update DatePicker
|
104
|
:date="rightTableDate"
|
0a5c5f41
梁灏
update DatePicker
|
105
106
|
selection-mode="range"
:disabled-date="disabledDate"
|
68e9b100
梁灏
update DatePicker
|
107
108
|
@on-pick="handleRightMonthPick"
@on-pick-click="handlePickClick"></month-table>
|
3cf7cfd1
梁灏
update DatePicker
|
109
|
</div>
|
2dc27713
梁灏
update DateTimePi...
|
110
111
|
<div :class="[prefixCls + '-content']" v-show="isTime">
<time-picker
|
531cd165
梁灏
support DatePicke...
|
112
|
ref="timePicker"
|
2dc27713
梁灏
update DateTimePi...
|
113
|
v-show="isTime"
|
a2a78c38
梁灏
update DateTimePi...
|
114
115
|
@on-pick="handleTimePick"
@on-pick-click="handlePickClick"></time-picker>
|
2dc27713
梁灏
update DateTimePi...
|
116
|
</div>
|
b9041a0d
梁灏
DatePicker add co...
|
117
118
|
<Confirm
v-if="confirm"
|
2dc27713
梁灏
update DateTimePi...
|
119
120
121
122
|
:show-time="showTime"
:is-time="isTime"
:time-disabled="timeDisabled"
@on-pick-toggle-time="handleToggleTime"
|
b9041a0d
梁灏
DatePicker add co...
|
123
124
|
@on-pick-clear="handlePickClear"
@on-pick-success="handlePickSuccess"></Confirm>
|
3cf7cfd1
梁灏
update DatePicker
|
125
|
</div>
|
e0cd7f90
梁灏
fixed #134
|
126
|
</div>
|
17e1fcf1
梁灏
init DatePicker
|
127
128
|
</template>
<script>
|
3cf7cfd1
梁灏
update DatePicker
|
129
130
|
import Icon from '../../icon/icon.vue';
import DateTable from '../base/date-table.vue';
|
0a5c5f41
梁灏
update DatePicker
|
131
132
|
import YearTable from '../base/year-table.vue';
import MonthTable from '../base/month-table.vue';
|
2dc27713
梁灏
update DateTimePi...
|
133
|
import TimePicker from './time-range.vue';
|
b9041a0d
梁灏
DatePicker add co...
|
134
|
import Confirm from '../base/confirm.vue';
|
b27858dd
Sergio Crisostomo
add date panel la...
|
135
136
|
import { toDate, prevMonth, nextMonth, initTimeDate, formatDateLabels } from '../util';
import datePanelLabel from './date-panel-label.vue';
|
3cf7cfd1
梁灏
update DatePicker
|
137
138
|
import Mixin from './mixin';
|
4ab11811
梁灏
some component su...
|
139
|
import Locale from '../../../mixins/locale';
|
3cf7cfd1
梁灏
update DatePicker
|
140
|
|
e0cd7f90
梁灏
fixed #134
|
141
142
143
|
const prefixCls = 'ivu-picker-panel';
const datePrefixCls = 'ivu-date-picker';
|
17e1fcf1
梁灏
init DatePicker
|
144
|
export default {
|
a2a78c38
梁灏
update DateTimePi...
|
145
|
name: 'DatePicker',
|
4ab11811
梁灏
some component su...
|
146
|
mixins: [ Mixin, Locale ],
|
b27858dd
Sergio Crisostomo
add date panel la...
|
147
|
components: { Icon, DateTable, YearTable, MonthTable, TimePicker, Confirm, datePanelLabel },
|
17e1fcf1
梁灏
init DatePicker
|
148
|
data () {
|
3cf7cfd1
梁灏
update DatePicker
|
149
150
151
152
|
return {
prefixCls: prefixCls,
datePrefixCls: datePrefixCls,
shortcuts: [],
|
5cc9b892
梁灏
update DateTimePi...
|
153
|
date: initTimeDate(),
|
3cf7cfd1
梁灏
update DatePicker
|
154
155
156
|
value: '',
minDate: '',
maxDate: '',
|
b9041a0d
梁灏
DatePicker add co...
|
157
|
confirm: false,
|
3cf7cfd1
梁灏
update DatePicker
|
158
159
160
161
162
163
|
rangeState: {
endDate: null,
selecting: false
},
showTime: false,
disabledDate: '',
|
0a5c5f41
梁灏
update DatePicker
|
164
165
|
leftCurrentView: 'date',
rightCurrentView: 'date',
|
3732707e
梁灏
update DatePicker
|
166
167
|
selectionMode: 'range',
leftTableYear: null,
|
2dc27713
梁灏
update DateTimePi...
|
168
169
170
|
rightTableYear: null,
isTime: false,
format: 'yyyy-MM-dd'
|
b0893113
jingsam
add eslint
|
171
|
};
|
17e1fcf1
梁灏
init DatePicker
|
172
|
},
|
e0cd7f90
梁灏
fixed #134
|
173
174
175
176
|
computed: {
classes () {
return [
`${prefixCls}-body-wrapper`,
|
3cf7cfd1
梁灏
update DatePicker
|
177
|
`${datePrefixCls}-with-range`,
|
e0cd7f90
梁灏
fixed #134
|
178
179
180
|
{
[`${prefixCls}-with-sidebar`]: this.shortcuts.length
}
|
b0893113
jingsam
add eslint
|
181
|
];
|
3cf7cfd1
梁灏
update DatePicker
|
182
|
},
|
3732707e
梁灏
update DatePicker
|
183
|
leftYear () {
|
3cf7cfd1
梁灏
update DatePicker
|
184
185
|
return this.date.getFullYear();
},
|
3732707e
梁灏
update DatePicker
|
186
187
188
189
190
191
192
|
leftTableDate () {
if (this.leftCurrentView === 'year' || this.leftCurrentView === 'month') {
return new Date(this.leftTableYear);
} else {
return this.date;
}
},
|
3732707e
梁灏
update DatePicker
|
193
|
leftMonth () {
|
3cf7cfd1
梁灏
update DatePicker
|
194
195
|
return this.date.getMonth();
},
|
3732707e
梁灏
update DatePicker
|
196
|
rightYear () {
|
3cf7cfd1
梁灏
update DatePicker
|
197
198
|
return this.rightDate.getFullYear();
},
|
3732707e
梁灏
update DatePicker
|
199
200
201
202
203
204
205
|
rightTableDate () {
if (this.rightCurrentView === 'year' || this.rightCurrentView === 'month') {
return new Date(this.rightTableYear);
} else {
return this.date;
}
},
|
3732707e
梁灏
update DatePicker
|
206
|
rightMonth () {
|
3cf7cfd1
梁灏
update DatePicker
|
207
208
|
return this.rightDate.getMonth();
},
|
3732707e
梁灏
update DatePicker
|
209
|
rightDate () {
|
3cf7cfd1
梁灏
update DatePicker
|
210
211
212
213
214
215
216
217
218
219
220
|
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;
|
2dc27713
梁灏
update DateTimePi...
|
221
|
},
|
b27858dd
Sergio Crisostomo
add date panel la...
|
222
223
224
225
226
227
228
229
|
leftDatePanelLabel () {
if (!this.leftYear) return null; // not ready yet
return this.panelLabelConfig('left');
},
rightDatePanelLabel () {
if (!this.leftYear) return null; // not ready yet
return this.panelLabelConfig('right');
},
|
2dc27713
梁灏
update DateTimePi...
|
230
231
|
timeDisabled () {
return !(this.minDate && this.maxDate);
|
3cf7cfd1
梁灏
update DatePicker
|
232
233
234
235
236
237
238
239
240
241
242
|
}
},
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
|
243
|
}
|
2dc27713
梁灏
update DateTimePi...
|
244
245
246
247
248
249
250
251
252
253
254
255
256
|
if (this.showTime) this.$refs.timePicker.value = newVal;
},
minDate (val) {
if (this.showTime) this.$refs.timePicker.date = val;
},
maxDate (val) {
if (this.showTime) this.$refs.timePicker.dateEnd = val;
},
format (val) {
if (this.showTime) this.$refs.timePicker.format = val;
},
isTime (val) {
if (val) this.$refs.timePicker.updateScroll();
|
e0cd7f90
梁灏
fixed #134
|
257
258
|
}
},
|
3cf7cfd1
梁灏
update DatePicker
|
259
|
methods: {
|
b27858dd
Sergio Crisostomo
add date panel la...
|
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
panelLabelConfig (direction) {
const locale = this.t('i.locale');
const datePanelLabel = this.t('i.datepicker.datePanelLabel');
const handler = type => {
const fn = type == 'month' ? this.showMonthPicker : this.showYearPicker;
return () => fn(direction);
};
const date = new Date(this[`${direction}Year`], this[`${direction}Month`]);
const { labels, separator } = formatDateLabels(locale, datePanelLabel, date);
return {
separator: separator,
labels: labels.map(obj => ((obj.handler = handler(obj.type)), obj))
};
},
|
f92ef70f
梁灏
update DatePicker
|
276
277
278
279
280
|
resetDate () {
this.date = new Date(this.date);
this.leftTableYear = this.date.getFullYear();
this.rightTableYear = this.rightDate.getFullYear();
},
|
472b4ff1
梁灏
update DatePicker
|
281
282
283
|
handleClear() {
this.minDate = null;
this.maxDate = null;
|
f92ef70f
梁灏
update DatePicker
|
284
|
this.date = new Date();
|
472b4ff1
梁灏
update DatePicker
|
285
|
this.handleConfirm();
|
2dc27713
梁灏
update DateTimePi...
|
286
|
if (this.showTime) this.$refs.timePicker.handleClear();
|
472b4ff1
梁灏
update DatePicker
|
287
|
},
|
a2a78c38
梁灏
update DateTimePi...
|
288
|
resetView(reset = false) {
|
f92ef70f
梁灏
update DatePicker
|
289
290
291
292
293
|
this.leftCurrentView = 'date';
this.rightCurrentView = 'date';
this.leftTableYear = this.leftYear;
this.rightTableYear = this.rightYear;
|
a2a78c38
梁灏
update DateTimePi...
|
294
295
|
if (reset) this.isTime = false;
|
f92ef70f
梁灏
update DatePicker
|
296
|
},
|
0a5c5f41
梁灏
update DatePicker
|
297
298
299
|
prevYear (direction) {
if (this[`${direction}CurrentView`] === 'year') {
this.$refs[`${direction}YearTable`].prevTenYear();
|
f92ef70f
梁灏
update DatePicker
|
300
301
|
} else if (this[`${direction}CurrentView`] === 'month') {
this[`${direction}TableYear`]--;
|
0a5c5f41
梁灏
update DatePicker
|
302
303
304
305
306
|
} else {
const date = this.date;
date.setFullYear(date.getFullYear() - 1);
this.resetDate();
}
|
3cf7cfd1
梁灏
update DatePicker
|
307
|
},
|
0a5c5f41
梁灏
update DatePicker
|
308
309
310
|
nextYear (direction) {
if (this[`${direction}CurrentView`] === 'year') {
this.$refs[`${direction}YearTable`].nextTenYear();
|
f92ef70f
梁灏
update DatePicker
|
311
|
} else if (this[`${direction}CurrentView`] === 'month') {
|
b9a4026f
梁灏
fixed #845
|
312
|
this[`${direction}TableYear`]++;
|
0a5c5f41
梁灏
update DatePicker
|
313
314
315
316
317
|
} else {
const date = this.date;
date.setFullYear(date.getFullYear() + 1);
this.resetDate();
}
|
3cf7cfd1
梁灏
update DatePicker
|
318
319
|
},
prevMonth () {
|
0a5c5f41
梁灏
update DatePicker
|
320
|
this.date = prevMonth(this.date);
|
3cf7cfd1
梁灏
update DatePicker
|
321
322
|
},
nextMonth () {
|
0a5c5f41
梁灏
update DatePicker
|
323
|
this.date = nextMonth(this.date);
|
3cf7cfd1
梁灏
update DatePicker
|
324
|
},
|
0a5c5f41
梁灏
update DatePicker
|
325
326
327
328
329
|
handleLeftYearPick (year, close = true) {
this.handleYearPick(year, close, 'left');
},
handleRightYearPick (year, close = true) {
this.handleYearPick(year, close, 'right');
|
3cf7cfd1
梁灏
update DatePicker
|
330
|
},
|
0a5c5f41
梁灏
update DatePicker
|
331
|
handleYearPick (year, close, direction) {
|
3732707e
梁灏
update DatePicker
|
332
|
this[`${direction}TableYear`] = year;
|
0a5c5f41
梁灏
update DatePicker
|
333
|
if (!close) return;
|
3cf7cfd1
梁灏
update DatePicker
|
334
|
|
0a5c5f41
梁灏
update DatePicker
|
335
336
337
338
339
340
341
342
343
|
this[`${direction}CurrentView`] = 'month';
},
handleLeftMonthPick (month) {
this.handleMonthPick(month, 'left');
},
handleRightMonthPick (month) {
this.handleMonthPick(month, 'right');
},
handleMonthPick (month, direction) {
|
3732707e
梁灏
update DatePicker
|
344
345
346
347
348
349
350
351
352
353
354
|
let year = this[`${direction}TableYear`];
if (direction === 'right') {
if (month === 0) {
month = 11;
year--;
} else {
month--;
}
}
this.date.setYear(year);
|
0a5c5f41
梁灏
update DatePicker
|
355
356
357
358
359
360
|
this.date.setMonth(month);
this[`${direction}CurrentView`] = 'date';
this.resetDate();
},
showYearPicker (direction) {
this[`${direction}CurrentView`] = 'year';
|
3732707e
梁灏
update DatePicker
|
361
|
this[`${direction}TableYear`] = this[`${direction}Year`];
|
0a5c5f41
梁灏
update DatePicker
|
362
363
364
|
},
showMonthPicker (direction) {
this[`${direction}CurrentView`] = 'month';
|
3cf7cfd1
梁灏
update DatePicker
|
365
|
},
|
3cf7cfd1
梁灏
update DatePicker
|
366
367
|
handleConfirm(visible) {
this.$emit('on-pick', [this.minDate, this.maxDate], visible);
|
472b4ff1
梁灏
update DatePicker
|
368
369
370
371
372
373
374
|
},
handleRangePick (val, close = true) {
if (this.maxDate === val.maxDate && this.minDate === val.minDate) return;
this.minDate = val.minDate;
this.maxDate = val.maxDate;
|
40aa9355
Sergio Crisostomo
patch chromium bug
|
375
376
377
378
379
380
381
382
|
// Remove when Chromium has fixed bug
// https://github.com/iview/iview/issues/2122
this.$nextTick(() => {
this.minDate = val.minDate;
this.maxDate = val.maxDate;
});
/* end of #2122 patch */
|
472b4ff1
梁灏
update DatePicker
|
383
|
if (!close) return;
|
2dc27713
梁灏
update DateTimePi...
|
384
385
386
387
|
// if (!this.showTime) {
// this.handleConfirm(false);
// }
this.handleConfirm(false);
|
472b4ff1
梁灏
update DatePicker
|
388
389
390
391
392
|
},
handleChangeRange (val) {
this.minDate = val.minDate;
this.maxDate = val.maxDate;
this.rangeState = val.rangeState;
|
2dc27713
梁灏
update DateTimePi...
|
393
394
395
396
397
398
399
400
401
402
|
},
handleToggleTime () {
this.isTime = !this.isTime;
},
handleTimePick (date) {
this.minDate = date[0];
this.maxDate = date[1];
this.handleConfirm(false);
}
},
|
531cd165
梁灏
support DatePicke...
|
403
|
mounted () {
|
2dc27713
梁灏
update DateTimePi...
|
404
|
if (this.showTime) {
|
a2a78c38
梁灏
update DateTimePi...
|
405
|
// todo 这里也到不了
|
2dc27713
梁灏
update DateTimePi...
|
406
407
408
409
410
|
this.$refs.timePicker.date = this.minDate;
this.$refs.timePicker.dateEnd = this.maxDate;
this.$refs.timePicker.value = this.value;
this.$refs.timePicker.format = this.format;
this.$refs.timePicker.showDate = true;
|
3cf7cfd1
梁灏
update DatePicker
|
411
412
|
}
}
|
b0893113
jingsam
add eslint
|
413
414
|
};
</script>
|