e32b86e9
Sergio Crisostomo
move date.vue to ...
|
1
2
3
4
5
6
7
8
9
10
11
12
|
<template>
<div :class="classes" @mousedown.prevent>
<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="[datePrefixCls + '-header']" v-show="currentView !== 'time'">
<span
:class="iconBtnCls('prev', '-double')"
|
0f512d6a
梁灏
update Date Icons
|
13
|
@click="changeYear(-1)"><Icon type="ios-arrow-back"></Icon></span>
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
14
|
<span
|
73a34dfa
Sergio Crisostomo
Fix year/month pr...
|
15
|
v-if="pickerTable === 'date-table'"
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
16
17
|
:class="iconBtnCls('prev')"
@click="changeMonth(-1)"
|
0f512d6a
梁灏
update Date Icons
|
18
|
v-show="currentView === 'date'"><Icon type="ios-arrow-back"></Icon></span>
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
19
20
|
<date-panel-label
:date-panel-label="datePanelLabel"
|
73a34dfa
Sergio Crisostomo
Fix year/month pr...
|
21
|
:current-view="pickerTable.split('-').shift()"
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
22
23
24
|
:date-prefix-cls="datePrefixCls"></date-panel-label>
<span
:class="iconBtnCls('next', '-double')"
|
0f512d6a
梁灏
update Date Icons
|
25
|
@click="changeYear(+1)"><Icon type="ios-arrow-forward"></Icon></span>
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
26
|
<span
|
73a34dfa
Sergio Crisostomo
Fix year/month pr...
|
27
|
v-if="pickerTable === 'date-table'"
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
28
29
|
:class="iconBtnCls('next')"
@click="changeMonth(+1)"
|
0f512d6a
梁灏
update Date Icons
|
30
|
v-show="currentView === 'date'"><Icon type="ios-arrow-forward"></Icon></span>
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
31
32
33
34
35
36
37
|
</div>
<div :class="[prefixCls + '-content']">
<component
:is="pickerTable"
ref="pickerTable"
v-if="currentView !== 'time'"
:table-date="panelDate"
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
38
|
:show-week-numbers="showWeekNumbers"
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
39
40
41
|
:value="dates"
:selection-mode="selectionMode"
:disabled-date="disabledDate"
|
75cb2998
Sergio Crisostomo
Add keyboard navi...
|
42
43
|
:focused-date="focusedDate"
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
44
|
@on-pick="panelPickerHandlers"
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
45
46
47
48
49
50
51
52
53
54
|
@on-pick-click="handlePickClick"
></component>
</div>
<div :class="[prefixCls + '-content']" v-show="isTime">
<time-picker
ref="timePicker"
v-if="currentView === 'time'"
:value="dates"
:format="format"
:time-disabled="timeDisabled"
|
3cd62242
Sergio Crisostomo
Allow disableDate...
|
55
|
:disabled-date="disabledDate"
|
75cb2998
Sergio Crisostomo
Add keyboard navi...
|
56
57
|
:focused-date="focusedDate"
|
79ac2457
Sergio Crisostomo
Allow DatePicker ...
|
58
|
v-bind="timePickerOptions"
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
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
|
@on-pick="handlePick"
@on-pick-click="handlePickClick"
@on-pick-clear="handlePickClear"
@on-pick-success="handlePickSuccess"
@on-pick-toggle-time="handleToggleTime"
></time-picker>
</div>
<Confirm
v-if="confirm"
:show-time="showTime"
:is-time="isTime"
@on-pick-toggle-time="handleToggleTime"
@on-pick-clear="handlePickClear"
@on-pick-success="handlePickSuccess"
></Confirm>
</div>
</div>
</template>
<script>
import Icon from '../../../icon/icon.vue';
import DateTable from '../../base/date-table.vue';
import YearTable from '../../base/year-table.vue';
import MonthTable from '../../base/month-table.vue';
import TimePicker from '../Time/time.vue';
import Confirm from '../../base/confirm.vue';
import datePanelLabel from './date-panel-label.vue';
import Mixin from '../panel-mixin';
import DateMixin from './date-panel-mixin';
import Locale from '../../../../mixins/locale';
import { siblingMonth, formatDateLabels } from '../../util';
const prefixCls = 'ivu-picker-panel';
const datePrefixCls = 'ivu-date-picker';
export default {
name: 'DatePickerPanel',
mixins: [ Mixin, Locale, DateMixin ],
components: { Icon, DateTable, YearTable, MonthTable, TimePicker, Confirm, datePanelLabel },
props: {
|
02859de9
Sergio Crisostomo
Use the last pic...
|
100
101
102
103
104
|
// more props in the mixin
multiple: {
type: Boolean,
default: false
}
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
105
106
|
},
data () {
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
107
108
109
|
const {selectionMode, value} = this;
const dates = value.slice().sort();
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
110
111
112
|
return {
prefixCls: prefixCls,
datePrefixCls: datePrefixCls,
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
113
114
|
currentView: selectionMode || 'date',
pickerTable: this.getTableType(selectionMode),
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
115
|
dates: dates,
|
63bd0f7d
Sergio Crisostomo
Add start-date pr...
|
116
|
panelDate: this.startDate || dates[0] || new Date()
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
117
118
119
120
121
122
123
124
125
126
127
|
};
},
computed: {
classes () {
return [
`${prefixCls}-body-wrapper`,
{
[`${prefixCls}-with-sidebar`]: this.shortcuts.length
}
];
},
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
128
|
panelPickerHandlers(){
|
8d532306
Sergio Crisostomo
update panel date...
|
129
|
return this.pickerTable === `${this.currentView}-table` ? this.handlePick : this.handlePreSelection;
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
130
131
132
133
134
135
136
137
|
},
datePanelLabel () {
const locale = this.t('i.locale');
const datePanelLabel = this.t('i.datepicker.datePanelLabel');
const date = this.panelDate;
const { labels, separator } = formatDateLabels(locale, datePanelLabel, date);
const handler = type => {
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
138
|
return () => this.pickerTable = this.getTableType(type);
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
};
return {
separator: separator,
labels: labels.map(obj => ((obj.handler = handler(obj.type)), obj))
};
},
timeDisabled(){
return !this.dates[0];
}
},
watch: {
value (newVal) {
this.dates = newVal;
|
ba3ad889
SergioCrisostomo
Use last selected...
|
153
154
|
const panelDate = this.multiple ? this.dates[this.dates.length - 1] : (this.startDate || this.dates[0]);
this.panelDate = panelDate || new Date();
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
155
|
},
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
156
157
|
currentView (currentView) {
this.$emit('on-selection-mode-change', currentView);
|
3cd62242
Sergio Crisostomo
Allow disableDate...
|
158
159
160
161
162
163
164
|
if (this.currentView === 'time') {
this.$nextTick(() => {
const spinner = this.$refs.timePicker.$refs.timeSpinner;
spinner.updateScroll();
});
}
|
46726afd
Sergio Crisostomo
Fix panels reset ...
|
165
166
167
168
|
},
selectionMode(type){
this.currentView = type;
this.pickerTable = this.getTableType(type);
|
75cb2998
Sergio Crisostomo
Add keyboard navi...
|
169
170
171
172
173
|
},
focusedDate(date){
const isDifferentYear = date.getFullYear() !== this.panelDate.getFullYear();
const isDifferentMonth = isDifferentYear || date.getMonth() !== this.panelDate.getMonth();
if (isDifferentYear || isDifferentMonth){
|
ba3ad889
SergioCrisostomo
Use last selected...
|
174
|
if (!this.multiple) this.panelDate = date;
|
75cb2998
Sergio Crisostomo
Add keyboard navi...
|
175
|
}
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
176
177
178
|
}
},
methods: {
|
46726afd
Sergio Crisostomo
Fix panels reset ...
|
179
180
181
182
|
reset(){
this.currentView = this.selectionMode;
this.pickerTable = this.getTableType(this.currentView);
},
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
183
|
changeYear(dir){
|
73a34dfa
Sergio Crisostomo
Fix year/month pr...
|
184
|
if (this.selectionMode === 'year' || this.pickerTable === 'year-table'){
|
77e43f2b
Sergio Crisostomo
Correct year date...
|
185
186
187
188
|
this.panelDate = new Date(this.panelDate.getFullYear() + dir * 10, 0, 1);
} else {
this.panelDate = siblingMonth(this.panelDate, dir * 12);
}
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
189
|
},
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
190
191
192
|
getTableType(currentView){
return currentView.match(/^time/) ? 'time-picker' : `${currentView}-table`;
},
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
193
194
195
|
changeMonth(dir){
this.panelDate = siblingMonth(this.panelDate, dir);
},
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
196
197
|
handlePreSelection(value){
this.panelDate = value;
|
73a34dfa
Sergio Crisostomo
Fix year/month pr...
|
198
199
200
|
if (this.pickerTable === 'year-table') this.pickerTable = 'month-table';
else this.pickerTable = this.getTableType(this.currentView);
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
201
|
},
|
90ebd5a7
Sergio Crisostomo
Expose changed da...
|
202
|
handlePick (value, type) {
|
bcf09be7
Sergio Crisostomo
fix handlePick an...
|
203
|
const {selectionMode, panelDate} = this;
|
4ec8bc8a
Sergio Crisostomo
Fix month picker ...
|
204
205
|
if (selectionMode === 'year') value = new Date(value.getFullYear(), 0, 1);
else if (selectionMode === 'month') value = new Date(panelDate.getFullYear(), value.getMonth(), 1);
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
206
207
|
else value = new Date(value);
|
3cd62242
Sergio Crisostomo
Allow disableDate...
|
208
|
this.dates = [value];
|
90ebd5a7
Sergio Crisostomo
Expose changed da...
|
209
|
this.$emit('on-pick', value, false, type || selectionMode);
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
210
211
212
213
|
},
},
};
</script>
|