UNPKG

vue-admin-core

Version:
86 lines (83 loc) 2.83 kB
import { defineComponent, ref, reactive, toRefs, createVNode } from 'vue'; import { h, connect, mapProps, mapReadPretty } from '@formily/vue'; import '../../preview-text/index.mjs'; import { ElSelect, UPDATE_MODEL_EVENT, CHANGE_EVENT, ElOption, ElIcon } from 'element-plus'; import '../../../components/config-provider/index.mjs'; import { Loading } from '@element-plus/icons-vue'; import { useArrToStr } from '../../__builtins__/hooks/useArrToStr.mjs'; import { isFunction, omit } from 'lodash-es'; import { useGlobalConfig } from '../../../components/config-provider/src/hooks/use-global-config.mjs'; import { PreviewText } from '../../preview-text/src/index.mjs'; const SelectOption = defineComponent({ name: "FSelect", props: { ...ElSelect.props, options: Array, props: { type: Object, default: () => ({ children: "children", label: "label", value: "value", disabled: "disabled" }) } }, emits: [UPDATE_MODEL_EVENT, CHANGE_EVENT], setup(props, ctx) { const config = useGlobalConfig(); const select = ref(); const _props = useArrToStr(props, ctx, { vm: select }); return () => { const options = props.options || []; const slots = { ...ctx.slots }; if (options.length !== 0 && !ctx.slots.default) { slots.default = () => options.map((option) => { if (typeof option === "string") { return h(ElOption, { key: option, value: option, label: option }, {}); } else { return h(ElOption, { key: option[props.props.value] || option[config.value.dictValueKey], label: option[props.props.label] || option[config.value.dictLabelKey], value: option[props.props.value] || option[config.value.dictValueKey], disabled: isFunction(props.props.disabled) ? props.props.disabled(option) : option[props.props.disabled] }, {}); } }); } return h(ElSelect, reactive({ ...omit(toRefs(props), ["options", "props"]), ..._props, ref: (ref2) => select.value = ref2 }), slots); }; } }); const Select = connect(SelectOption, mapProps({ dataSource: "options", loading: true, value: "modelValue", readOnly: "readonly" }, (props, field) => { return { ...props, suffixIcon: ( // @ts-ignore (field == null ? void 0 : field["loading"]) || (field == null ? void 0 : field["validating"]) ? createVNode(ElIcon, { "class": "is-loading" }, { default: () => [createVNode(Loading, null, null)] }) : props.suffixIcon ) }; }), mapReadPretty(PreviewText.Select)); export { Select, Select as default }; //# sourceMappingURL=index.mjs.map