DatePicker: dynamic picker-options, close #2013 (#2051)

pull/2058/head
cinwell.li 2016-12-29 10:43:51 +08:00 committed by FuryBean
parent bdd0604bd0
commit eefa3fec78
1 changed files with 25 additions and 21 deletions

View File

@ -408,30 +408,34 @@ export default {
this.picker.format = this.format;
}
const options = this.pickerOptions;
const updateOptions = () => {
const options = this.pickerOptions;
if (options && options.selectableRange) {
let ranges = options.selectableRange;
const parser = TYPE_VALUE_RESOLVER_MAP.datetimerange.parser;
const format = DEFAULT_FORMATS.timerange;
if (options && options.selectableRange) {
let ranges = options.selectableRange;
const parser = TYPE_VALUE_RESOLVER_MAP.datetimerange.parser;
const format = DEFAULT_FORMATS.timerange;
ranges = Array.isArray(ranges) ? ranges : [ranges];
this.picker.selectableRange = ranges.map(range => parser(range, format));
}
if (this.type === 'time-select' && options) {
this.$watch('pickerOptions.minTime', val => {
this.picker.minTime = val;
});
}
for (const option in options) {
if (options.hasOwnProperty(option) &&
// time-picker
option !== 'selectableRange') {
this.picker[option] = options[option];
ranges = Array.isArray(ranges) ? ranges : [ranges];
this.picker.selectableRange = ranges.map(range => parser(range, format));
}
}
if (this.type === 'time-select' && options) {
this.$watch('pickerOptions.minTime', val => {
this.picker.minTime = val;
});
}
for (const option in options) {
if (options.hasOwnProperty(option) &&
// time-picker
option !== 'selectableRange') {
this.picker[option] = options[option];
}
}
};
updateOptions();
this.$watch('pickerOptions', () => updateOptions(), { deep: true });
this.$el.appendChild(this.picker.$el);
this.pickerVisible = this.picker.visible = true;