e32b86e9
Sergio Crisostomo
move date.vue to ...
|
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
|
<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')"
@click="changeYear(-1)"><Icon type="ios-arrow-left"></Icon></span>
<span
:class="iconBtnCls('prev')"
@click="changeMonth(-1)"
v-show="currentView === 'date'"><Icon type="ios-arrow-left"></Icon></span>
<date-panel-label
:date-panel-label="datePanelLabel"
:current-view="currentView"
:date-prefix-cls="datePrefixCls"></date-panel-label>
<span
:class="iconBtnCls('next', '-double')"
@click="changeYear(+1)"><Icon type="ios-arrow-right"></Icon></span>
<span
:class="iconBtnCls('next')"
@click="changeMonth(+1)"
v-show="currentView === 'date'"><Icon type="ios-arrow-right"></Icon></span>
</div>
<div :class="[prefixCls + '-content']">
<component
:is="pickerTable"
ref="pickerTable"
v-if="currentView !== 'time'"
:table-date="panelDate"
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
36
|
:show-week-numbers="showWeekNumbers"
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
37
38
39
|
:value="dates"
:selection-mode="selectionMode"
:disabled-date="disabledDate"
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
40
|
@on-pick="panelPickerHandlers"
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
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
|
@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"
@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: {
// in the mixin
},
data () {
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
95
96
97
|
const {selectionMode, value} = this;
const dates = value.slice().sort();
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
98
99
100
|
return {
prefixCls: prefixCls,
datePrefixCls: datePrefixCls,
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
101
102
|
currentView: selectionMode || 'date',
pickerTable: this.getTableType(selectionMode),
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
103
|
dates: dates,
|
63bd0f7d
Sergio Crisostomo
Add start-date pr...
|
104
|
panelDate: this.startDate || dates[0] || new Date()
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
105
106
107
108
109
110
111
112
113
114
115
|
};
},
computed: {
classes () {
return [
`${prefixCls}-body-wrapper`,
{
[`${prefixCls}-with-sidebar`]: this.shortcuts.length
}
];
},
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
116
117
|
panelPickerHandlers(){
return this.pickerTable === `${this.currentView}-table` ? this.handlePick : this.handlePreSelection
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
118
119
120
121
122
123
124
125
|
},
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...
|
126
|
return () => this.pickerTable = this.getTableType(type);
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
};
return {
separator: separator,
labels: labels.map(obj => ((obj.handler = handler(obj.type)), obj))
};
},
timeDisabled(){
return !this.dates[0];
}
},
watch: {
value (newVal) {
this.dates = newVal;
|
15457562
Sergio Crisostomo
Reset panel date ...
|
141
|
if (JSON.stringify(newVal) === '[null]') this.panelDate = this.startDate || new Date();
|
c2b7fed0
Sergio Crisostomo
Reset panel selec...
|
142
143
|
// reset stuff
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
144
|
this.currentView = this.selectionMode;
|
c2b7fed0
Sergio Crisostomo
Reset panel selec...
|
145
|
this.pickerTable = this.getTableType(this.currentView);
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
146
|
},
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
147
148
149
|
currentView (currentView) {
this.$emit('on-selection-mode-change', currentView);
this.pickertable = this.getTableType(currentView);
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
150
151
152
153
|
}
},
methods: {
changeYear(dir){
|
77e43f2b
Sergio Crisostomo
Correct year date...
|
154
155
156
157
158
|
if (this.selectionMode === 'year'){
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 ...
|
159
|
},
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
160
161
162
|
getTableType(currentView){
return currentView.match(/^time/) ? 'time-picker' : `${currentView}-table`;
},
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
163
164
165
|
changeMonth(dir){
this.panelDate = siblingMonth(this.panelDate, dir);
},
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
166
167
168
169
|
handlePreSelection(value){
this.panelDate = value;
this.pickerTable = this.getTableType(this.currentView);
},
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
170
|
handlePick (value) {
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
171
|
const {selectionMode, panelDate, pickerType} = this;
|
4ec8bc8a
Sergio Crisostomo
Fix month picker ...
|
172
173
|
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 ...
|
174
175
|
else value = new Date(value);
|
b52e02e4
Sergio Crisostomo
Fix month|year pr...
|
176
177
178
179
180
181
182
|
if (pickerType === selectionMode){
this.$emit('on-pick', value);
} else {
this.selectionMode
}
|
e32b86e9
Sergio Crisostomo
move date.vue to ...
|
183
184
185
186
|
},
},
};
</script>
|