Commit 46726afdf4c11218e254148358b26a39b23b1ed0

Authored by Sergio Crisostomo
1 parent bcf09be7

Fix panels reset on blur and

src/components/date-picker/panel/Date/date-range.vue
... ... @@ -198,12 +198,6 @@
198 198 this.leftPanelDate = leftPanelDate;
199 199 const rightPanelDate = new Date(leftPanelDate.getFullYear(), leftPanelDate.getMonth() + 1, leftPanelDate.getDate());
200 200 this.rightPanelDate = this.splitPanels ? new Date(Math.max(this.dates[1], rightPanelDate)) : rightPanelDate;
201   -
202   - // reset stuff
203   - this.currentView = this.selectionMode || 'range';
204   - this.leftPickerTable = `${this.currentView}-table`;
205   - this.rightPickerTable = `${this.currentView}-table`;
206   -
207 201 },
208 202 currentView(currentView){
209 203 const leftMonth = this.leftPanelDate.getMonth();
... ... @@ -225,6 +219,11 @@
225 219 }
226 220 },
227 221 methods: {
  222 + reset(){
  223 + this.currentView = this.selectionMode;
  224 + this.leftPickerTable = `${this.currentView}-table`;
  225 + this.rightPickerTable = `${this.currentView}-table`;
  226 + },
228 227 panelLabelConfig (direction) {
229 228 const locale = this.t('i.locale');
230 229 const datePanelLabel = this.t('i.datepicker.datePanelLabel');
... ...
src/components/date-picker/panel/Date/date.vue
... ... @@ -139,17 +139,21 @@
139 139 value (newVal) {
140 140 this.dates = newVal;
141 141 if (JSON.stringify(newVal) === '[null]') this.panelDate = this.startDate || new Date();
142   -
143   - // reset stuff
144   - this.currentView = this.selectionMode;
145   - this.pickerTable = this.getTableType(this.currentView);
146 142 },
147 143 currentView (currentView) {
148 144 this.$emit('on-selection-mode-change', currentView);
149 145 this.pickertable = this.getTableType(currentView);
  146 + },
  147 + selectionMode(type){
  148 + this.currentView = type;
  149 + this.pickerTable = this.getTableType(type);
150 150 }
151 151 },
152 152 methods: {
  153 + reset(){
  154 + this.currentView = this.selectionMode;
  155 + this.pickerTable = this.getTableType(this.currentView);
  156 + },
153 157 changeYear(dir){
154 158 if (this.selectionMode === 'year'){
155 159 this.panelDate = new Date(this.panelDate.getFullYear() + dir * 10, 0, 1);
... ...
src/components/date-picker/picker.vue
... ... @@ -35,6 +35,7 @@
35 35 <div>
36 36 <component
37 37 :is="panel"
  38 + ref="pickerPanel"
38 39 :visible="visible"
39 40 :showTime="type === 'datetime' || type === 'datetimerange'"
40 41 :confirm="isConfirm"
... ... @@ -212,10 +213,9 @@
212 213 },
213 214 methods: {
214 215 onSelectionModeChange(type){
215   -
216 216 if (type.match(/^date/)) type = 'date';
217   - this.selectionMode = type;
218   - return type;
  217 + this.selectionMode = oneOf(type, ['year', 'month', 'date', 'time']) && type;
  218 + return this.selectionMode;
219 219 },
220 220 // 开启 transfer 时,点击 Drop 即会关闭,这里不让其关闭
221 221 handleTransferClick () {
... ... @@ -237,7 +237,12 @@
237 237 },
238 238 handleBlur () {
239 239 this.visible = false;
  240 + this.onSelectionModeChange(this.type);
240 241 this.internalValue = this.internalValue.slice(); // trigger panel watchers to reset views
  242 + this.reset();
  243 + },
  244 + reset(){
  245 + this.$refs.pickerPanel.reset && this.$refs.pickerPanel.reset();
241 246 },
242 247 handleInputChange (event) {
243 248 const isArrayValue = this.type.includes('range') || this.multiple;
... ... @@ -280,6 +285,7 @@
280 285 this.$emit('on-clear');
281 286 this.dispatch('FormItem', 'on-form-change', '');
282 287 this.emitChange();
  288 + this.reset();
283 289  
284 290 setTimeout(
285 291 () => this.onSelectionModeChange(this.type),
... ... @@ -354,6 +360,7 @@
354 360 onPickSuccess(){
355 361 this.visible = false;
356 362 this.$emit('on-ok');
  363 + this.reset();
357 364 },
358 365 },
359 366 watch: {
... ...