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