Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Select & TimePicker 小优化 #344

Merged
merged 2 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default mixins(getConfigReceiverMixins<Vue, SelectConfig>('select')).exte
hoverIndex: -1,
popupOpenTime: 250, // popup打开弹出层的延迟时间
checkScroll: true, // 弹出层执行加宽事件(仅执行一次,且在有滚动条时执行)
isInited: false,
};
},
components: {
Expand Down Expand Up @@ -681,6 +682,37 @@ export default mixins(getConfigReceiverMixins<Vue, SelectConfig>('select')).exte
},
},

updated() {
if (this.realOptions.length || this.isInited) return;

// Parse options from slots before popup, execute only once
const children = renderTNodeJSX(this, 'default');
if (children) {
this.realOptions = parseOptions(children);
this.isInited = true;
}

function parseOptions(vnodes: VNode[]): TdOptionProps[] {
if (!vnodes) return [];
return vnodes.reduce((options, vnode) => {
if (vnode.componentOptions.tag === 't-option') {
const propsData = vnode.componentOptions.propsData as any;
return options.concat({
label: propsData.label,
value: propsData.value,
disabled: propsData.disabled,
content: propsData.content,
default: propsData.default,
});
}
if (vnode.componentOptions.tag === 't-option-group') {
return options.concat(parseOptions(vnode.componentOptions.children));
}
return options;
}, []);
}
},

render(): VNode {
const {
classes,
Expand Down
17 changes: 9 additions & 8 deletions src/time-picker/panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,20 @@ export default mixins(getConfigReceiverMixins<TimePickerPanelInstance, TimePicke
},
},
watch: {
isShowPanel(val: boolean) {
if (val) {
this.panelColUpdate();
}
isShowPanel: {
handler(val: boolean) {
if (val) {
this.panelColUpdate();
}
},
immediate: true,
},
},
methods: {
panelColUpdate() {
const panelCol0 = this.$refs.panelCol_0 as TimePickerPanelColInstance;
const panelCol1 = this.$refs.panelCol_1 as TimePickerPanelColInstance;
this.$nextTick(() => {
panelCol0 && panelCol0.updateTimeScrollPos();
panelCol1 && panelCol1.updateTimeScrollPos();
(this.$refs.panelCol_0 as TimePickerPanelColInstance)?.updateTimeScrollPos();
(this.$refs.panelCol_1 as TimePickerPanelColInstance)?.updateTimeScrollPos();
});
},
scrollToTime(colIndex: number, col: EPickerCols, time: number | string, behavior: ScrollBehavior) {
Expand Down