17e1fcf1
梁灏
init DatePicker
|
1
|
<template>
|
e0cd7f90
梁灏
fixed #134
|
2
|
<div :class="classes">
|
3cf7cfd1
梁灏
update DatePicker
|
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
|
<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']">
<div :class="[datePrefixCls + '-header']" v-show="currentView !== 'time'">
<span
:class="iconBtnCls('prev', '-double')"
@click="prevYear"><Icon type="ios-arrow-left"></Icon></span>
<span
:class="iconBtnCls('prev')"
@click="prevMonth"
v-show="currentView === 'date'"><Icon type="ios-arrow-left"></Icon></span>
<span
:class="[datePrefixCls + '-header-label']"
@click="showYearPicker">{{ leftYear }} 年</span>
<span
:class="[datePrefixCls + '-header-label']"
@click="showMonthPicker"
v-show="currentView === 'date'">{{ leftMonth + 1 }} 月</span>
</div>
<date-table
v-show="currentView === 'date'"
:year="leftYear"
:month="leftMonth"
:date="date"
:min-date="minDate"
:max-date="maxDate"
:range-state="rangeState"
|
472b4ff1
梁灏
update DatePicker
|
35
|
selection-mode="range"
|
3cf7cfd1
梁灏
update DatePicker
|
36
|
:disabled-date="disabledDate"
|
472b4ff1
梁灏
update DatePicker
|
37
38
|
@on-changerange="handleChangeRange"
@on-pick="handleRangePick"></date-table>
|
3cf7cfd1
梁灏
update DatePicker
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
</div>
<div :class="[prefixCls + '-content', prefixCls + '-content-right']">
<div :class="[datePrefixCls + '-header']" v-show="currentView !== 'time'">
<span
:class="[datePrefixCls + '-header-label']"
@click="showYearPicker">{{ rightYear }} 年</span>
<span
:class="[datePrefixCls + '-header-label']"
@click="showMonthPicker"
v-show="currentView === 'date'">{{ rightMonth + 1 }} 月</span>
<span
:class="iconBtnCls('next', '-double')"
@click="nextYear"><Icon type="ios-arrow-right"></Icon></span>
<span
:class="iconBtnCls('next')"
@click="nextMonth"
v-show="currentView === 'date'"><Icon type="ios-arrow-right"></Icon></span>
</div>
<date-table
v-show="currentView === 'date'"
:year="rightYear"
:month="rightMonth"
:date="rightDate"
:min-date="minDate"
:max-date="maxDate"
:range-state="rangeState"
|
472b4ff1
梁灏
update DatePicker
|
65
|
selection-mode="range"
|
3cf7cfd1
梁灏
update DatePicker
|
66
|
:disabled-date="disabledDate"
|
472b4ff1
梁灏
update DatePicker
|
67
68
|
@on-changerange="handleChangeRange"
@on-pick="handleRangePick"></date-table>
|
3cf7cfd1
梁灏
update DatePicker
|
69
70
|
</div>
</div>
|
e0cd7f90
梁灏
fixed #134
|
71
|
</div>
|
17e1fcf1
梁灏
init DatePicker
|
72
73
|
</template>
<script>
|
3cf7cfd1
梁灏
update DatePicker
|
74
75
76
77
78
79
|
import Icon from '../../icon/icon.vue';
import DateTable from '../base/date-table.vue';
import { toDate } from '../util';
import Mixin from './mixin';
|
e0cd7f90
梁灏
fixed #134
|
80
81
82
|
const prefixCls = 'ivu-picker-panel';
const datePrefixCls = 'ivu-date-picker';
|
17e1fcf1
梁灏
init DatePicker
|
83
|
export default {
|
3cf7cfd1
梁灏
update DatePicker
|
84
85
|
mixins: [Mixin],
components: { Icon, DateTable },
|
17e1fcf1
梁灏
init DatePicker
|
86
|
data () {
|
3cf7cfd1
梁灏
update DatePicker
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
return {
prefixCls: prefixCls,
datePrefixCls: datePrefixCls,
shortcuts: [],
date: new Date(),
value: '',
minDate: '',
maxDate: '',
rangeState: {
endDate: null,
selecting: false
},
showTime: false,
disabledDate: '',
currentView: 'date',
selectionMode: 'range'
}
|
17e1fcf1
梁灏
init DatePicker
|
104
|
},
|
e0cd7f90
梁灏
fixed #134
|
105
106
107
108
|
computed: {
classes () {
return [
`${prefixCls}-body-wrapper`,
|
3cf7cfd1
梁灏
update DatePicker
|
109
|
`${datePrefixCls}-with-range`,
|
e0cd7f90
梁灏
fixed #134
|
110
111
112
113
|
{
[`${prefixCls}-with-sidebar`]: this.shortcuts.length
}
]
|
3cf7cfd1
梁灏
update DatePicker
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
},
leftYear() {
return this.date.getFullYear();
},
leftMonth() {
return this.date.getMonth();
},
rightYear() {
return this.rightDate.getFullYear();
},
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);
// this.handleConfirm(true); // todo 稍后测试
}
|
e0cd7f90
梁灏
fixed #134
|
152
153
|
}
},
|
3cf7cfd1
梁灏
update DatePicker
|
154
|
methods: {
|
472b4ff1
梁灏
update DatePicker
|
155
156
157
158
159
|
handleClear() {
this.minDate = null;
this.maxDate = null;
this.handleConfirm();
},
|
3cf7cfd1
梁灏
update DatePicker
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
prevYear () {
},
nextYear () {
},
prevMonth () {
},
nextMonth () {
},
showYearPicker () {
},
showMonthPicker () {
},
|
3cf7cfd1
梁灏
update DatePicker
|
178
179
|
handleConfirm(visible) {
this.$emit('on-pick', [this.minDate, this.maxDate], visible);
|
472b4ff1
梁灏
update DatePicker
|
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
},
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
|
196
197
|
}
}
|
17e1fcf1
梁灏
init DatePicker
|
198
199
|
}
</script>
|