Commit 5cc9b892b8e08fb8eb27589e9047292d58fafb01
1 parent
d596b9e4
update DateTimePicker
update DateTimePicker
Showing
8 changed files
with
98 additions
and
21 deletions
Show diff stats
src/components/date-picker/base/confirm.vue
1 | <template> | 1 | <template> |
2 | <div :class="[prefixCls + '-confirm']"> | 2 | <div :class="[prefixCls + '-confirm']"> |
3 | + <span v-if="showTime" @click="handleToggleTime"> | ||
4 | + <template v-if="isTime">选择日期</template> | ||
5 | + <template v-else>选择时间</template> | ||
6 | + </span> | ||
3 | <i-button size="small" type="text" @click="handleClear">清空</i-button> | 7 | <i-button size="small" type="text" @click="handleClear">清空</i-button> |
4 | <i-button size="small" type="primary" @click="handleSuccess">确定</i-button> | 8 | <i-button size="small" type="primary" @click="handleSuccess">确定</i-button> |
5 | </div> | 9 | </div> |
@@ -11,6 +15,10 @@ | @@ -11,6 +15,10 @@ | ||
11 | 15 | ||
12 | export default { | 16 | export default { |
13 | components: { iButton }, | 17 | components: { iButton }, |
18 | + props: { | ||
19 | + showTime: false, | ||
20 | + isTime: false | ||
21 | + }, | ||
14 | data () { | 22 | data () { |
15 | return { | 23 | return { |
16 | prefixCls: prefixCls | 24 | prefixCls: prefixCls |
@@ -22,6 +30,9 @@ | @@ -22,6 +30,9 @@ | ||
22 | }, | 30 | }, |
23 | handleSuccess () { | 31 | handleSuccess () { |
24 | this.$emit('on-pick-success'); | 32 | this.$emit('on-pick-success'); |
33 | + }, | ||
34 | + handleToggleTime () { | ||
35 | + this.$emit('on-pick-toggle-time'); | ||
25 | } | 36 | } |
26 | } | 37 | } |
27 | }; | 38 | }; |
src/components/date-picker/base/date-table.vue
@@ -168,6 +168,11 @@ | @@ -168,6 +168,11 @@ | ||
168 | let month = this.month; | 168 | let month = this.month; |
169 | let day = cell.text; | 169 | let day = cell.text; |
170 | 170 | ||
171 | + const date = this.date; | ||
172 | + const hours = date.getHours(); | ||
173 | + const minutes = date.getMinutes(); | ||
174 | + const seconds = date.getSeconds(); | ||
175 | + | ||
171 | if (cell.type === 'prev-month') { | 176 | if (cell.type === 'prev-month') { |
172 | if (month === 0) { | 177 | if (month === 0) { |
173 | month = 11; | 178 | month = 11; |
@@ -184,7 +189,7 @@ | @@ -184,7 +189,7 @@ | ||
184 | } | 189 | } |
185 | } | 190 | } |
186 | 191 | ||
187 | - return new Date(year, month, day); | 192 | + return new Date(year, month, day, hours, minutes, seconds); |
188 | }, | 193 | }, |
189 | handleClick (event) { | 194 | handleClick (event) { |
190 | const target = event.target; | 195 | const target = event.target; |
src/components/date-picker/panel/date-range.vue
@@ -126,7 +126,7 @@ | @@ -126,7 +126,7 @@ | ||
126 | import YearTable from '../base/year-table.vue'; | 126 | import YearTable from '../base/year-table.vue'; |
127 | import MonthTable from '../base/month-table.vue'; | 127 | import MonthTable from '../base/month-table.vue'; |
128 | import Confirm from '../base/confirm.vue'; | 128 | import Confirm from '../base/confirm.vue'; |
129 | - import { toDate, prevMonth, nextMonth } from '../util'; | 129 | + import { toDate, prevMonth, nextMonth, initTimeDate } from '../util'; |
130 | 130 | ||
131 | import Mixin from './mixin'; | 131 | import Mixin from './mixin'; |
132 | 132 | ||
@@ -141,7 +141,7 @@ | @@ -141,7 +141,7 @@ | ||
141 | prefixCls: prefixCls, | 141 | prefixCls: prefixCls, |
142 | datePrefixCls: datePrefixCls, | 142 | datePrefixCls: datePrefixCls, |
143 | shortcuts: [], | 143 | shortcuts: [], |
144 | - date: new Date(), | 144 | + date: initTimeDate(), |
145 | value: '', | 145 | value: '', |
146 | minDate: '', | 146 | minDate: '', |
147 | maxDate: '', | 147 | maxDate: '', |
src/components/date-picker/panel/date.vue
@@ -59,9 +59,18 @@ | @@ -59,9 +59,18 @@ | ||
59 | :disabled-date="disabledDate" | 59 | :disabled-date="disabledDate" |
60 | @on-pick="handleMonthPick" | 60 | @on-pick="handleMonthPick" |
61 | @on-pick-click="handlePickClick"></month-table> | 61 | @on-pick-click="handlePickClick"></month-table> |
62 | + <time-picker | ||
63 | + v-show="currentView === 'time'" | ||
64 | + v-ref:time-picker | ||
65 | + :date="date" | ||
66 | + :value="value" | ||
67 | + @on-pick="handleTimePick"></time-picker> | ||
62 | </div> | 68 | </div> |
63 | <Confirm | 69 | <Confirm |
64 | v-if="confirm" | 70 | v-if="confirm" |
71 | + :show-time="showTime" | ||
72 | + :is-time="isTime" | ||
73 | + @on-pick-toggle-time="handleToggleTime" | ||
65 | @on-pick-clear="handlePickClear" | 74 | @on-pick-clear="handlePickClear" |
66 | @on-pick-success="handlePickSuccess"></Confirm> | 75 | @on-pick-success="handlePickSuccess"></Confirm> |
67 | </div> | 76 | </div> |
@@ -72,30 +81,34 @@ | @@ -72,30 +81,34 @@ | ||
72 | import DateTable from '../base/date-table.vue'; | 81 | import DateTable from '../base/date-table.vue'; |
73 | import YearTable from '../base/year-table.vue'; | 82 | import YearTable from '../base/year-table.vue'; |
74 | import MonthTable from '../base/month-table.vue'; | 83 | import MonthTable from '../base/month-table.vue'; |
84 | + import TimePicker from './time.vue'; | ||
75 | import Confirm from '../base/confirm.vue'; | 85 | import Confirm from '../base/confirm.vue'; |
76 | 86 | ||
77 | import Mixin from './mixin'; | 87 | import Mixin from './mixin'; |
78 | 88 | ||
89 | + import { initTimeDate } from '../util'; | ||
90 | + | ||
79 | const prefixCls = 'ivu-picker-panel'; | 91 | const prefixCls = 'ivu-picker-panel'; |
80 | const datePrefixCls = 'ivu-date-picker'; | 92 | const datePrefixCls = 'ivu-date-picker'; |
81 | 93 | ||
82 | export default { | 94 | export default { |
83 | mixins: [Mixin], | 95 | mixins: [Mixin], |
84 | - components: { Icon, DateTable, YearTable, MonthTable, Confirm }, | 96 | + components: { Icon, DateTable, YearTable, MonthTable, TimePicker, Confirm }, |
85 | data () { | 97 | data () { |
86 | return { | 98 | return { |
87 | prefixCls: prefixCls, | 99 | prefixCls: prefixCls, |
88 | datePrefixCls: datePrefixCls, | 100 | datePrefixCls: datePrefixCls, |
89 | shortcuts: [], | 101 | shortcuts: [], |
90 | currentView: 'date', | 102 | currentView: 'date', |
91 | - date: new Date(), | 103 | + date: initTimeDate(), |
92 | value: '', | 104 | value: '', |
93 | showTime: false, | 105 | showTime: false, |
94 | selectionMode: 'day', | 106 | selectionMode: 'day', |
95 | disabledDate: '', | 107 | disabledDate: '', |
96 | year: null, | 108 | year: null, |
97 | month: null, | 109 | month: null, |
98 | - confirm: false | 110 | + confirm: false, |
111 | + isTime: false | ||
99 | }; | 112 | }; |
100 | }, | 113 | }, |
101 | computed: { | 114 | computed: { |
@@ -126,23 +139,29 @@ | @@ -126,23 +139,29 @@ | ||
126 | this.year = newVal.getFullYear(); | 139 | this.year = newVal.getFullYear(); |
127 | this.month = newVal.getMonth(); | 140 | this.month = newVal.getMonth(); |
128 | } | 141 | } |
142 | + }, | ||
143 | + currentView (val) { | ||
144 | + if (val === 'time') this.$refs.timePicker.updateScroll(); | ||
129 | } | 145 | } |
130 | }, | 146 | }, |
131 | methods: { | 147 | methods: { |
132 | resetDate () { | 148 | resetDate () { |
133 | this.date = new Date(this.date); | 149 | this.date = new Date(this.date); |
134 | }, | 150 | }, |
135 | - handleClear() { | 151 | + handleClear () { |
136 | this.date = new Date(); | 152 | this.date = new Date(); |
137 | this.$emit('on-pick', ''); | 153 | this.$emit('on-pick', ''); |
154 | + if (this.showTime) this.$refs.timePicker.handleClear(); | ||
138 | }, | 155 | }, |
139 | - resetView() { | ||
140 | - if (this.selectionMode === 'month') { | ||
141 | - this.currentView = 'month'; | ||
142 | - } else if (this.selectionMode === 'year') { | ||
143 | - this.currentView = 'year'; | ||
144 | - } else { | ||
145 | - this.currentView = 'date'; | 156 | + resetView (reset = false) { |
157 | + if (this.currentView !== 'time' || reset) { | ||
158 | + if (this.selectionMode === 'month') { | ||
159 | + this.currentView = 'month'; | ||
160 | + } else if (this.selectionMode === 'year') { | ||
161 | + this.currentView = 'year'; | ||
162 | + } else { | ||
163 | + this.currentView = 'date'; | ||
164 | + } | ||
146 | } | 165 | } |
147 | 166 | ||
148 | this.year = this.date.getFullYear(); | 167 | this.year = this.date.getFullYear(); |
@@ -186,6 +205,15 @@ | @@ -186,6 +205,15 @@ | ||
186 | showMonthPicker () { | 205 | showMonthPicker () { |
187 | this.currentView = 'month'; | 206 | this.currentView = 'month'; |
188 | }, | 207 | }, |
208 | + handleToggleTime () { | ||
209 | + if (this.currentView === 'date') { | ||
210 | + this.currentView = 'time'; | ||
211 | + this.isTime = true; | ||
212 | + } else if (this.currentView === 'time') { | ||
213 | + this.currentView = 'date'; | ||
214 | + this.isTime = false; | ||
215 | + } | ||
216 | + }, | ||
189 | handleYearPick(year, close = true) { | 217 | handleYearPick(year, close = true) { |
190 | this.year = year; | 218 | this.year = year; |
191 | if (!close) return; | 219 | if (!close) return; |
@@ -216,15 +244,16 @@ | @@ -216,15 +244,16 @@ | ||
216 | }, | 244 | }, |
217 | handleDatePick (value) { | 245 | handleDatePick (value) { |
218 | if (this.selectionMode === 'day') { | 246 | if (this.selectionMode === 'day') { |
219 | - if (!this.showTime) { | ||
220 | - this.$emit('on-pick', new Date(value.getTime())); | ||
221 | - } | 247 | + this.$emit('on-pick', new Date(value.getTime())); |
222 | this.date.setFullYear(value.getFullYear()); | 248 | this.date.setFullYear(value.getFullYear()); |
223 | this.date.setMonth(value.getMonth()); | 249 | this.date.setMonth(value.getMonth()); |
224 | this.date.setDate(value.getDate()); | 250 | this.date.setDate(value.getDate()); |
225 | } | 251 | } |
226 | 252 | ||
227 | this.resetDate(); | 253 | this.resetDate(); |
254 | + }, | ||
255 | + handleTimePick (date) { | ||
256 | + this.handleDatePick(date); | ||
228 | } | 257 | } |
229 | }, | 258 | }, |
230 | compiled () { | 259 | compiled () { |
src/components/date-picker/panel/time.vue
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | <div :class="[prefixCls + '-body']"> | 3 | <div :class="[prefixCls + '-body']"> |
4 | <div :class="[prefixCls + '-content']"> | 4 | <div :class="[prefixCls + '-content']"> |
5 | <time-spinner | 5 | <time-spinner |
6 | + v-ref:time-spinner | ||
6 | :show-seconds="showSeconds" | 7 | :show-seconds="showSeconds" |
7 | :hours="hours" | 8 | :hours="hours" |
8 | :minutes="minutes" | 9 | :minutes="minutes" |
@@ -35,13 +36,21 @@ | @@ -35,13 +36,21 @@ | ||
35 | export default { | 36 | export default { |
36 | mixins: [Mixin], | 37 | mixins: [Mixin], |
37 | components: { TimeSpinner, Confirm }, | 38 | components: { TimeSpinner, Confirm }, |
39 | + props: { | ||
40 | + date: { | ||
41 | + default () { | ||
42 | + return initTimeDate() | ||
43 | + } | ||
44 | + }, | ||
45 | + value: { | ||
46 | + default: '' | ||
47 | + } | ||
48 | + }, | ||
38 | data () { | 49 | data () { |
39 | return { | 50 | return { |
40 | prefixCls: prefixCls, | 51 | prefixCls: prefixCls, |
41 | timePrefixCls: timePrefixCls, | 52 | timePrefixCls: timePrefixCls, |
42 | format: 'HH:mm:ss', | 53 | format: 'HH:mm:ss', |
43 | - date: initTimeDate(), | ||
44 | - value: '', | ||
45 | hours: '', | 54 | hours: '', |
46 | minutes: '', | 55 | minutes: '', |
47 | seconds: '', | 56 | seconds: '', |
@@ -92,6 +101,9 @@ | @@ -92,6 +101,9 @@ | ||
92 | this.seconds = this.date.getSeconds(); | 101 | this.seconds = this.date.getSeconds(); |
93 | } | 102 | } |
94 | if (emit) this.$emit('on-pick', this.date, true); | 103 | if (emit) this.$emit('on-pick', this.date, true); |
104 | + }, | ||
105 | + updateScroll () { | ||
106 | + this.$refs.timeSpinner.updateScroll(); | ||
95 | } | 107 | } |
96 | } | 108 | } |
97 | }; | 109 | }; |
src/components/date-picker/picker.vue
@@ -362,7 +362,13 @@ | @@ -362,7 +362,13 @@ | ||
362 | }, | 362 | }, |
363 | showPicker () { | 363 | showPicker () { |
364 | if (!this.picker) { | 364 | if (!this.picker) { |
365 | + const type = this.type; | ||
366 | + | ||
365 | this.picker = new Vue(this.panel).$mount(this.$els.picker); | 367 | this.picker = new Vue(this.panel).$mount(this.$els.picker); |
368 | + if (type === 'datetime' || type === 'datetimerange') { | ||
369 | + this.confirm = true; | ||
370 | + this.picker.showTime = true; | ||
371 | + } | ||
366 | this.picker.value = this.internalValue; | 372 | this.picker.value = this.internalValue; |
367 | this.picker.confirm = this.confirm; | 373 | this.picker.confirm = this.confirm; |
368 | this.picker.selectionMode = this.selectionMode; | 374 | this.picker.selectionMode = this.selectionMode; |
@@ -430,7 +436,7 @@ | @@ -430,7 +436,7 @@ | ||
430 | this.$refs.drop.update(); | 436 | this.$refs.drop.update(); |
431 | if (this.open === null) this.$emit('on-open-change', true); | 437 | if (this.open === null) this.$emit('on-open-change', true); |
432 | } else { | 438 | } else { |
433 | - if (this.picker) this.picker.resetView && this.picker.resetView(); | 439 | + if (this.picker) this.picker.resetView && this.picker.resetView(true); |
434 | this.$refs.drop.destroy(); | 440 | this.$refs.drop.destroy(); |
435 | if (this.open === null) this.$emit('on-open-change', false); | 441 | if (this.open === null) this.$emit('on-open-change', false); |
436 | } | 442 | } |
src/styles/components/date-picker.less
@@ -244,5 +244,19 @@ | @@ -244,5 +244,19 @@ | ||
244 | text-align: right; | 244 | text-align: right; |
245 | padding: 8px; | 245 | padding: 8px; |
246 | clear: both; | 246 | clear: both; |
247 | + & > span{ | ||
248 | + color: @link-color; | ||
249 | + cursor: pointer; | ||
250 | + user-select: none; | ||
251 | + float: left; | ||
252 | + padding: 2px 0; | ||
253 | + transition: all @transition-time @ease-in-out; | ||
254 | + &:hover{ | ||
255 | + color: @link-hover-color; | ||
256 | + } | ||
257 | + &:active{ | ||
258 | + color: @link-active-color; | ||
259 | + } | ||
260 | + } | ||
247 | } | 261 | } |
248 | } | 262 | } |
249 | \ No newline at end of file | 263 | \ No newline at end of file |
test/routers/date.vue
@@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
24 | <!--style="width: 168px"></time-picker>--> | 24 | <!--style="width: 168px"></time-picker>--> |
25 | <!--</i-col>--> | 25 | <!--</i-col>--> |
26 | <i-col span="12"> | 26 | <i-col span="12"> |
27 | - <Time-picker type="timerange" confirm placeholder="选择时间" style="width: 168px"></Time-picker> | 27 | + <Date-picker type="datetime" placeholder="选择日期时间" style="width: 200px" @on-change="c"></Date-picker> |
28 | <!--<time-picker--> | 28 | <!--<time-picker--> |
29 | <!--:value="value2"--> | 29 | <!--:value="value2"--> |
30 | <!--type="timerange"--> | 30 | <!--type="timerange"--> |