17e1fcf1
梁灏
init DatePicker
|
1
|
<template>
|
2533a192
梁灏
update DatePicker
|
2
|
<div :class="classes">
|
3cf7cfd1
梁灏
update DatePicker
|
3
|
<div :class="[prefixCls + '-sidebar']" v-if="shortcuts.length">
|
0f677893
梁灏
update DatePicker
|
4
5
6
7
8
9
10
11
12
|
<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')"
|
c46f385a
梁灏
update DatePicker
|
13
|
@click="prevYear"><Icon type="ios-arrow-left"></Icon></span>
|
0f677893
梁灏
update DatePicker
|
14
15
16
|
<span
:class="iconBtnCls('prev')"
@click="prevMonth"
|
c46f385a
梁灏
update DatePicker
|
17
|
v-show="currentView === 'date'"><Icon type="ios-arrow-left"></Icon></span>
|
0f677893
梁灏
update DatePicker
|
18
19
|
<span
:class="[datePrefixCls + '-header-label']"
|
c46f385a
梁灏
update DatePicker
|
20
|
@click="showYearPicker">{{ yearLabel }}</span>
|
0f677893
梁灏
update DatePicker
|
21
22
23
|
<span
:class="[datePrefixCls + '-header-label']"
@click="showMonthPicker"
|
c46f385a
梁灏
update DatePicker
|
24
25
26
27
|
v-show="currentView === 'date'">{{ month + 1 + '月' }}</span>
<span
:class="iconBtnCls('next', '-double')"
@click="nextYear"><Icon type="ios-arrow-right"></Icon></span>
|
0f677893
梁灏
update DatePicker
|
28
29
30
|
<span
:class="iconBtnCls('next')"
@click="nextMonth"
|
c46f385a
梁灏
update DatePicker
|
31
|
v-show="currentView === 'date'"><Icon type="ios-arrow-right"></Icon></span>
|
0f677893
梁灏
update DatePicker
|
32
33
34
|
</div>
<div :class="[prefixCls + '-content']">
<date-table
|
50637863
梁灏
update DatePicker
|
35
36
37
38
39
|
v-show="currentView === 'date'"
:year="year"
:month="month"
:date="date"
:value="value"
|
50637863
梁灏
update DatePicker
|
40
|
:selection-mode="selectionMode"
|
c46f385a
梁灏
update DatePicker
|
41
42
|
:disabled-date="disabledDate"
@on-pick="handleDatePick"></date-table>
|
0f677893
梁灏
update DatePicker
|
43
|
<year-table
|
c46f385a
梁灏
update DatePicker
|
44
45
46
47
|
v-ref:year-table
v-show="currentView === 'year'"
:year="year"
:date="date"
|
13be4434
梁灏
update DatePicker
|
48
|
:selection-mode="selectionMode"
|
c46f385a
梁灏
update DatePicker
|
49
50
|
:disabled-date="disabledDate"
@on-pick="handleYearPick"></year-table>
|
0f677893
梁灏
update DatePicker
|
51
|
<month-table
|
c46f385a
梁灏
update DatePicker
|
52
53
54
55
|
v-ref:month-table
v-show="currentView === 'month'"
:month="month"
:date="date"
|
13be4434
梁灏
update DatePicker
|
56
|
:selection-mode="selectionMode"
|
c46f385a
梁灏
update DatePicker
|
57
58
|
:disabled-date="disabledDate"
@on-pick="handleMonthPick"></month-table>
|
0f677893
梁灏
update DatePicker
|
59
|
</div>
|
b9041a0d
梁灏
DatePicker add co...
|
60
61
62
63
|
<Confirm
v-if="confirm"
@on-pick-clear="handlePickClear"
@on-pick-success="handlePickSuccess"></Confirm>
|
0f677893
梁灏
update DatePicker
|
64
65
|
</div>
</div>
|
17e1fcf1
梁灏
init DatePicker
|
66
67
|
</template>
<script>
|
c46f385a
梁灏
update DatePicker
|
68
|
import Icon from '../../icon/icon.vue';
|
0f677893
梁灏
update DatePicker
|
69
70
71
|
import DateTable from '../base/date-table.vue';
import YearTable from '../base/year-table.vue';
import MonthTable from '../base/month-table.vue';
|
b9041a0d
梁灏
DatePicker add co...
|
72
|
import Confirm from '../base/confirm.vue';
|
c46f385a
梁灏
update DatePicker
|
73
|
import { formatDate, parseDate } from '../util';
|
0f677893
梁灏
update DatePicker
|
74
|
|
3cf7cfd1
梁灏
update DatePicker
|
75
76
|
import Mixin from './mixin';
|
0f677893
梁灏
update DatePicker
|
77
78
79
|
const prefixCls = 'ivu-picker-panel';
const datePrefixCls = 'ivu-date-picker';
|
17e1fcf1
梁灏
init DatePicker
|
80
|
export default {
|
3cf7cfd1
梁灏
update DatePicker
|
81
|
mixins: [Mixin],
|
b9041a0d
梁灏
DatePicker add co...
|
82
|
components: { Icon, DateTable, YearTable, MonthTable, Confirm },
|
17e1fcf1
梁灏
init DatePicker
|
83
|
data () {
|
0f677893
梁灏
update DatePicker
|
84
85
86
87
|
return {
prefixCls: prefixCls,
datePrefixCls: datePrefixCls,
shortcuts: [],
|
50637863
梁灏
update DatePicker
|
88
89
90
91
92
|
currentView: 'date',
date: new Date(),
value: '',
showTime: false,
selectionMode: 'day',
|
50637863
梁灏
update DatePicker
|
93
94
95
|
disabledDate: '',
year: null,
month: null,
|
b9041a0d
梁灏
DatePicker add co...
|
96
|
confirm: false
|
50637863
梁灏
update DatePicker
|
97
98
99
|
}
},
computed: {
|
2533a192
梁灏
update DatePicker
|
100
101
102
103
104
105
106
107
|
classes () {
return [
`${prefixCls}-body-wrapper`,
{
[`${prefixCls}-with-sidebar`]: this.shortcuts.length
}
]
},
|
c46f385a
梁灏
update DatePicker
|
108
109
110
111
112
113
114
|
yearLabel () {
const year = this.year;
if (!year) return '';
if (this.currentView === 'year') {
const startYear = Math.floor(year / 10) * 10;
return `${startYear}年 - ${startYear + 9}年`;
}
|
0a5c5f41
梁灏
update DatePicker
|
115
|
return `${year}年`;
|
c46f385a
梁灏
update DatePicker
|
116
|
}
|
50637863
梁灏
update DatePicker
|
117
118
119
|
},
watch: {
value (newVal) {
|
c46f385a
梁灏
update DatePicker
|
120
|
if (!newVal) return;
|
50637863
梁灏
update DatePicker
|
121
122
|
newVal = new Date(newVal);
if (!isNaN(newVal)) {
|
50637863
梁灏
update DatePicker
|
123
124
125
|
this.date = newVal;
this.year = newVal.getFullYear();
this.month = newVal.getMonth();
|
50637863
梁灏
update DatePicker
|
126
|
}
|
0f677893
梁灏
update DatePicker
|
127
|
}
|
17e1fcf1
梁灏
init DatePicker
|
128
|
},
|
0f677893
梁灏
update DatePicker
|
129
|
methods: {
|
f92ef70f
梁灏
update DatePicker
|
130
131
132
|
resetDate () {
this.date = new Date(this.date);
},
|
c46f385a
梁灏
update DatePicker
|
133
134
135
136
|
handleClear() {
this.date = new Date();
this.$emit('on-pick', '');
},
|
0a5c5f41
梁灏
update DatePicker
|
137
138
139
140
141
142
143
144
145
146
147
|
resetView() {
if (this.selectionMode === 'month') {
this.currentView = 'month';
} else if (this.selectionMode === 'year') {
this.currentView = 'year';
} else {
this.currentView = 'date';
}
this.year = this.date.getFullYear();
this.month = this.date.getMonth();
|
c46f385a
梁灏
update DatePicker
|
148
|
},
|
0f677893
梁灏
update DatePicker
|
149
|
prevYear () {
|
c46f385a
梁灏
update DatePicker
|
150
151
152
153
154
155
156
|
if (this.currentView === 'year') {
this.$refs.yearTable.prevTenYear();
} else {
this.year--;
this.date.setFullYear(this.year);
this.resetDate();
}
|
0f677893
梁灏
update DatePicker
|
157
158
|
},
nextYear () {
|
c46f385a
梁灏
update DatePicker
|
159
160
161
162
163
164
165
|
if (this.currentView === 'year') {
this.$refs.yearTable.nextTenYear();
} else {
this.year++;
this.date.setFullYear(this.year);
this.resetDate();
}
|
0f677893
梁灏
update DatePicker
|
166
167
|
},
prevMonth () {
|
c46f385a
梁灏
update DatePicker
|
168
169
170
171
172
|
this.month--;
if (this.month < 0) {
this.month = 11;
this.year--;
}
|
0f677893
梁灏
update DatePicker
|
173
174
|
},
nextMonth () {
|
c46f385a
梁灏
update DatePicker
|
175
176
177
178
179
|
this.month++;
if (this.month > 11) {
this.month = 0;
this.year++;
}
|
0f677893
梁灏
update DatePicker
|
180
181
|
},
showYearPicker () {
|
c46f385a
梁灏
update DatePicker
|
182
|
this.currentView = 'year';
|
0f677893
梁灏
update DatePicker
|
183
184
|
},
showMonthPicker () {
|
c46f385a
梁灏
update DatePicker
|
185
186
187
188
189
|
this.currentView = 'month';
},
handleYearPick(year, close = true) {
this.year = year;
if (!close) return;
|
0f677893
梁灏
update DatePicker
|
190
|
|
c46f385a
梁灏
update DatePicker
|
191
192
|
this.date.setFullYear(year);
if (this.selectionMode === 'year') {
|
344131a7
梁灏
update DatePicker
|
193
|
this.$emit('on-pick', new Date(year, 0, 1));
|
c46f385a
梁灏
update DatePicker
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
} else {
this.currentView = 'month';
}
this.resetDate();
},
handleMonthPick (month) {
this.month = month;
const selectionMode = this.selectionMode;
if (selectionMode !== 'month') {
this.date.setMonth(month);
this.currentView = 'date';
this.resetDate();
} else {
this.date.setMonth(month);
this.year && this.date.setFullYear(this.year);
this.resetDate();
const value = new Date(this.date.getFullYear(), month, 1);
this.$emit('on-pick', value);
}
},
handleDatePick (value) {
if (this.selectionMode === 'day') {
if (!this.showTime) {
this.$emit('on-pick', new Date(value.getTime()));
}
this.date.setFullYear(value.getFullYear());
this.date.setMonth(value.getMonth());
this.date.setDate(value.getDate());
}
this.resetDate();
|
0f677893
梁灏
update DatePicker
|
226
227
|
}
},
|
50637863
梁灏
update DatePicker
|
228
229
230
231
232
233
234
235
236
|
compiled () {
if (this.selectionMode === 'month') {
this.currentView = 'month';
}
if (this.date && !this.year) {
this.year = this.date.getFullYear();
this.month = this.date.getMonth();
}
|
0f677893
梁灏
update DatePicker
|
237
|
}
|
17e1fcf1
梁灏
init DatePicker
|
238
239
|
}
</script>
|