|
11 | 11 | .c-datepicker__icon(:clas="className") |
12 | 12 | c-icon(name="calendar") |
13 | 13 | c-input( |
14 | | - v-if="type == 'daterange'" |
| 14 | + v-if="type == 'daterange' || type == 'monthrange'" |
15 | 15 | v-model="daterange" |
16 | 16 | :placeholder="placeholder" |
17 | 17 | :disabled="disabled" |
|
31 | 31 | @change="dateChange" |
32 | 32 | @focusin.native="open" |
33 | 33 | @focusout.native="onBlur" |
| 34 | + @keydown.native="onKeyDown" |
34 | 35 | ) |
35 | 36 |
|
36 | 37 | .c-datepicker__panel |
37 | 38 | c-calendar( |
38 | 39 | ref="calendar" |
39 | | - v-if="type !== 'daterange'" |
| 40 | + v-if="type == 'date' || type == 'month'" |
40 | 41 | :type="type" |
41 | 42 | :pattern="datePattern" |
42 | 43 | :value="date" |
|
55 | 56 | :show="isOpen" |
56 | 57 | @change="setDateRange" |
57 | 58 | ) |
| 59 | + .c-datepicker__body( |
| 60 | + v-if="type == 'monthrange'" |
| 61 | + ) |
| 62 | + c-daterange( |
| 63 | + :value="date" |
| 64 | + :size="size" |
| 65 | + :show="isOpen" |
| 66 | + type="month" |
| 67 | + @change="setDateRange" |
| 68 | + ) |
58 | 69 | </template> |
59 | 70 |
|
60 | 71 | <script> |
@@ -95,7 +106,7 @@ export default { |
95 | 106 | return this.size ? `is-size-${this.size}` : '' |
96 | 107 | }, |
97 | 108 | daterange () { |
98 | | - if (this.type === 'date') return [] |
| 109 | + if (this.type.indexOf('range') === -1) return [] |
99 | 110 | const [start, end] = this.date |
100 | 111 | return !start && !end ? '' : `${start} 至 ${end}` |
101 | 112 | }, |
@@ -124,11 +135,9 @@ export default { |
124 | 135 | this.resize() |
125 | 136 | window.addEventListener('mousedown', this.onMouseDown, true) |
126 | 137 | window.addEventListener('mouseup', this.onMouseUp, true) |
127 | | - window.addEventListener('keydown', this.onKeyDown, false) |
128 | 138 | } else { |
129 | 139 | window.removeEventListener('mousedown', this.onMouseDown, true) |
130 | 140 | window.removeEventListener('mouseup', this.onMouseUp, true) |
131 | | - window.removeEventListener('keydown', this.onKeyDown, false) |
132 | 141 | } |
133 | 142 | }, |
134 | 143 | value (newVal) { |
@@ -187,19 +196,23 @@ export default { |
187 | 196 | } |
188 | 197 | const { keyCode } = e |
189 | 198 | if (keyCode === keys.ESC) this.close() |
| 199 | + const { calendar } = this.$refs |
| 200 | + const date = new Date(calendar.year, calendar.month, calendar.day).format(this.datePattern) |
190 | 201 | if (keyCode === keys.ENTER && this.type === 'date') { |
191 | | - const { calendar } = this.$refs |
192 | | - const date = new Date(calendar.year, calendar.month, calendar.day).format(this.datePattern) |
193 | 202 | this.setDate(date) |
194 | 203 | } |
195 | 204 | if (keyCode === keys.UP) { |
196 | | - this.$refs.calendar.updateDay(7, 'sub') |
| 205 | + this.type === 'date' && this.$refs.calendar.updateDay(7, 'sub') |
| 206 | + this.type === 'month' && this.$refs.calendar.updateMonthBykeydown(3, 'sub') |
197 | 207 | } else if (keyCode === keys.DOWN) { |
198 | | - this.$refs.calendar.updateDay(7, 'plus') |
| 208 | + this.type === 'date' && this.$refs.calendar.updateDay(7, 'plus') |
| 209 | + this.type === 'month' && this.$refs.calendar.updateMonthBykeydown(3, 'plus') |
199 | 210 | } else if (keyCode === keys.LEFT) { |
200 | | - this.$refs.calendar.updateDay(1, 'sub') |
| 211 | + this.type === 'date' && this.$refs.calendar.updateDay(1, 'sub') |
| 212 | + this.type === 'month' && this.$refs.calendar.updateMonthBykeydown(1, 'sub') |
201 | 213 | } else if (keyCode === keys.RIGHT) { |
202 | | - this.$refs.calendar.updateDay(1, 'plus') |
| 214 | + this.type === 'date' && this.$refs.calendar.updateDay(1, 'plus') |
| 215 | + this.type === 'month' && this.$refs.calendar.updateMonthBykeydown(1, 'plus') |
203 | 216 | } |
204 | 217 | }, |
205 | 218 | resetDate (e) { |
|
0 commit comments