mirror of https://github.com/ElemeFE/element
DatePicker: make type responsive(#4417)
parent
5013415426
commit
4243920a17
|
@ -220,7 +220,8 @@ export default {
|
||||||
return {
|
return {
|
||||||
pickerVisible: false,
|
pickerVisible: false,
|
||||||
showClose: false,
|
showClose: false,
|
||||||
currentValue: ''
|
currentValue: '',
|
||||||
|
unwatchPickerOptions: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -411,7 +412,26 @@ export default {
|
||||||
showPicker() {
|
showPicker() {
|
||||||
if (this.$isServer) return;
|
if (this.$isServer) return;
|
||||||
if (!this.picker) {
|
if (!this.picker) {
|
||||||
this.panel.defaultValue = this.defaultValue || this.currentValue;
|
this.mountPicker();
|
||||||
|
}
|
||||||
|
this.pickerVisible = this.picker.visible = true;
|
||||||
|
|
||||||
|
this.updatePopper();
|
||||||
|
|
||||||
|
if (this.currentValue instanceof Date) {
|
||||||
|
this.picker.date = new Date(this.currentValue.getTime());
|
||||||
|
} else {
|
||||||
|
this.picker.value = this.currentValue;
|
||||||
|
}
|
||||||
|
this.picker.resetView && this.picker.resetView();
|
||||||
|
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.picker.ajustScrollTop && this.picker.ajustScrollTop();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
mountPicker() {
|
||||||
|
this.panel.defaultValue = this.currentValue;
|
||||||
this.picker = new Vue(this.panel).$mount();
|
this.picker = new Vue(this.panel).$mount();
|
||||||
this.picker.popperClass = this.popperClass;
|
this.picker.popperClass = this.popperClass;
|
||||||
this.popperElm = this.picker.$el;
|
this.popperElm = this.picker.$el;
|
||||||
|
@ -443,10 +463,9 @@ export default {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
updateOptions();
|
updateOptions();
|
||||||
this.$watch('pickerOptions', () => updateOptions(), { deep: true });
|
this.unwatchPickerOptions = this.$watch('pickerOptions', () => updateOptions(), { deep: true });
|
||||||
|
|
||||||
this.$el.appendChild(this.picker.$el);
|
this.$el.appendChild(this.picker.$el);
|
||||||
this.pickerVisible = this.picker.visible = true;
|
|
||||||
this.picker.resetView && this.picker.resetView();
|
this.picker.resetView && this.picker.resetView();
|
||||||
|
|
||||||
this.picker.$on('dodestroy', this.doDestroy);
|
this.picker.$on('dodestroy', this.doDestroy);
|
||||||
|
@ -460,22 +479,17 @@ export default {
|
||||||
this.refInput.setSelectionRange(start, end);
|
this.refInput.setSelectionRange(start, end);
|
||||||
this.refInput.focus();
|
this.refInput.focus();
|
||||||
});
|
});
|
||||||
} else {
|
},
|
||||||
this.pickerVisible = this.picker.visible = true;
|
|
||||||
|
unmountPicker() {
|
||||||
|
if (this.picker) {
|
||||||
|
this.picker.$destroy();
|
||||||
|
this.picker.$off();
|
||||||
|
if (typeof this.unwatchPickerOptions === 'function') {
|
||||||
|
this.unwatchPickerOptions();
|
||||||
}
|
}
|
||||||
|
this.picker.$el.parentNode.removeChild(this.picker.$el);
|
||||||
this.updatePopper();
|
|
||||||
|
|
||||||
if (this.currentValue instanceof Date) {
|
|
||||||
this.picker.date = new Date(this.currentValue.getTime());
|
|
||||||
} else {
|
|
||||||
this.picker.value = this.currentValue;
|
|
||||||
}
|
}
|
||||||
this.picker.resetView && this.picker.resetView();
|
|
||||||
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.picker.ajustScrollTop && this.picker.ajustScrollTop();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,18 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
type(type) {
|
||||||
|
if (this.picker) {
|
||||||
|
this.unmountPicker();
|
||||||
|
this.panel = getPanel(type);
|
||||||
|
this.mountPicker();
|
||||||
|
} else {
|
||||||
|
this.panel = getPanel(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.panel = getPanel(this.type);
|
this.panel = getPanel(this.type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,20 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
isRange(isRange) {
|
||||||
|
if (this.picker) {
|
||||||
|
this.unmountPicker();
|
||||||
|
this.type = isRange ? 'timerange' : 'time';
|
||||||
|
this.panel = isRange ? TimeRangePanel : TimePanel;
|
||||||
|
this.mountPicker();
|
||||||
|
} else {
|
||||||
|
this.type = isRange ? 'timerange' : 'time';
|
||||||
|
this.panel = isRange ? TimeRangePanel : TimePanel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.type = this.isRange ? 'timerange' : 'time';
|
this.type = this.isRange ? 'timerange' : 'time';
|
||||||
this.panel = this.isRange ? TimeRangePanel : TimePanel;
|
this.panel = this.isRange ? TimeRangePanel : TimePanel;
|
||||||
|
|
Loading…
Reference in New Issue