Commit eefa3fec authored by cinwell.li's avatar cinwell.li Committed by FuryBean

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

parent bdd0604b
...@@ -408,30 +408,34 @@ export default { ...@@ -408,30 +408,34 @@ export default {
this.picker.format = this.format; this.picker.format = this.format;
} }
const options = this.pickerOptions; const updateOptions = () => {
const options = this.pickerOptions;
if (options && options.selectableRange) { if (options && options.selectableRange) {
let ranges = options.selectableRange; let ranges = options.selectableRange;
const parser = TYPE_VALUE_RESOLVER_MAP.datetimerange.parser; const parser = TYPE_VALUE_RESOLVER_MAP.datetimerange.parser;
const format = DEFAULT_FORMATS.timerange; const format = DEFAULT_FORMATS.timerange;
ranges = Array.isArray(ranges) ? ranges : [ranges]; ranges = Array.isArray(ranges) ? ranges : [ranges];
this.picker.selectableRange = ranges.map(range => parser(range, format)); this.picker.selectableRange = ranges.map(range => parser(range, format));
} }
if (this.type === 'time-select' && options) { if (this.type === 'time-select' && options) {
this.$watch('pickerOptions.minTime', val => { this.$watch('pickerOptions.minTime', val => {
this.picker.minTime = val; this.picker.minTime = val;
}); });
} }
for (const option in options) { for (const option in options) {
if (options.hasOwnProperty(option) && if (options.hasOwnProperty(option) &&
// 忽略 time-picker 的该配置项 // 忽略 time-picker 的该配置项
option !== 'selectableRange') { option !== 'selectableRange') {
this.picker[option] = options[option]; this.picker[option] = options[option];
}
} }
} };
updateOptions();
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.pickerVisible = this.picker.visible = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment