Skip to content

Commit

Permalink
perf: dict-select增加onSelectedChange事件,可以获取option
Browse files Browse the repository at this point in the history
Closes #335
  • Loading branch information
greper committed Jan 25, 2024
1 parent c8b0ee1 commit 84298c1
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions packages/fast-crud/src/components/extends/fs-dict-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@ export default defineComponent({
default: undefined
}
},
emits: ["dict-change"],
emits: [
/**
* 字典项变化
*/
"dict-change",
/**
* 选中值变化事件,可以获取到当前选中的option对象
*/
"selected-change",
/**
* 值变化事件
*/
"change"
],
setup(props, ctx) {
const { t } = useI18n();
const computedPlaceholder = computed(() => {
Expand All @@ -51,10 +64,20 @@ export default defineComponent({
const { ui } = useUi();
const usedDict = useDict(props, ctx, ui.select.modelValue);
const computedOptions = usedDict.createComputedOptions();

const onSelectedChange = (value: any) => {
ctx.emit("change", value);
const dict = usedDict.getDict();
if (dict.dataMap && dict.dataMap[value]) {
const opt = dict.dataMap[value];
ctx.emit("selected-change", opt);
}
};
return {
computedPlaceholder,
...usedDict,
computedOptions
computedOptions,
onSelectedChange
};
},
render() {
Expand All @@ -64,7 +87,14 @@ export default defineComponent({
//naive ui
//以options参数作为options
const options = this.computedOptions || [];
return <selectComp placeholder={this.computedPlaceholder} options={options} renderLabel={this.renderLabel} />;
return (
<selectComp
placeholder={this.computedPlaceholder}
options={options}
renderLabel={this.renderLabel}
onChange={this.onSelectedChange}
/>
);
}
// options 为子组件
const options = [];
Expand All @@ -79,7 +109,7 @@ export default defineComponent({
options.push(option);
}
return (
<selectComp placeholder={this.computedPlaceholder} v-slots={this.slots}>
<selectComp placeholder={this.computedPlaceholder} v-slots={this.slots} onChange={this.onSelectedChange}>
{options}
</selectComp>
);
Expand Down

0 comments on commit 84298c1

Please sign in to comment.