UNPKG

vue-admin-core

Version:
207 lines (202 loc) 6.89 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var vue$1 = require('@formily/vue'); require('../../__builtins__/shared/index.js'); var elementPlus = require('element-plus'); require('../../preview-text/index.js'); require('../../../components/config-provider/index.js'); var lodashEs = require('lodash-es'); var reactive = require('@formily/reactive'); var useArrToStr = require('../../__builtins__/hooks/useArrToStr.js'); var resolveComponent = require('../../__builtins__/shared/resolve-component.js'); var transformComponent = require('../../__builtins__/shared/transform-component.js'); var useGlobalConfig = require('../../../components/config-provider/src/hooks/use-global-config.js'); var index = require('../../preview-text/src/index.js'); var utils = require('../../__builtins__/shared/utils.js'); const CheckboxOption = vue.defineComponent({ name: "FCheckbox", inheritAttrs: false, props: { option: { type: Object, default: null } }, setup(curtomProps, { attrs, slots }) { return () => { const props = attrs; const option = curtomProps == null ? void 0 : curtomProps.option; if (option) { const children = { default: () => { var _a; return [resolveComponent.resolveComponent((_a = slots.default) != null ? _a : option.label, { option })]; } }; const newProps = { ...props }; Object.assign(newProps, option); newProps.label = option.value; delete newProps.value; return vue.h( attrs.optionType === "button" ? elementPlus.ElCheckboxButton : elementPlus.ElCheckbox, { ...newProps }, children ); } return vue.h( elementPlus.ElCheckbox, { ...props }, slots ); }; } }); const TransformElCheckboxGroup = transformComponent.transformComponent(elementPlus.ElCheckboxGroup, { change: "update:modelValue" }); const CheckboxGroupOption = vue.defineComponent({ name: "FCheckboxGroup", props: { ...elementPlus.ElCheckboxGroup.props, modelValue: { type: [Array, String], default: () => [] }, options: { type: Array, default: () => [] }, optionType: { type: String, default: "default" }, mutualExclusion: { type: Array, default: () => [] }, props: { type: Object, default: () => ({ children: "children", label: "label", value: "value", disabled: "disabled" }) } }, emits: [elementPlus.UPDATE_MODEL_EVENT, elementPlus.CHANGE_EVENT], setup(customProps, { attrs, slots, emit }) { const config = useGlobalConfig.useGlobalConfig(); const checkbox = vue.ref(); const label = vue.computed(() => customProps.props.label || "label"); const value = vue.computed(() => customProps.props.value || "value"); const _props = useArrToStr.useArrToStr(customProps, { attrs, slots }, { vm: checkbox, always: true }); const mutualExclusionFn = (checked, value2) => { const _modelValue = reactive.toJS(attrs.modelValue); if (!checked) return; const mutualExclusion = customProps.mutualExclusion; if (mutualExclusion.indexOf("*") !== -1) { if (mutualExclusion.indexOf(value2) !== -1) { emit("change", [value2]); return; } else { lodashEs.remove(_modelValue, (val) => mutualExclusion.indexOf(val) !== -1); emit("change", _modelValue); return; } } if (lodashEs.flattenDeep(mutualExclusion).indexOf(value2) === -1) return; if (checked && Array.isArray(mutualExclusion[0])) { mutualExclusion.forEach((item) => { if (item.indexOf(value2) === -1) { lodashEs.remove(_modelValue, (val) => item.indexOf(val) !== -1 && item.indexOf(value2) === -1); } }); } else { lodashEs.remove(_modelValue, (val) => mutualExclusion.indexOf(val) !== -1 && val !== value2); } emit("change", _modelValue); }; return () => { const options = customProps.options || []; const children = options.length !== 0 ? { default: () => options.map((option) => { var _a, _b, _c, _d; if (typeof option === "string") { return vue.h( Checkbox, { option: { label: option, value: option }, optionType: customProps.optionType }, (slots == null ? void 0 : slots.option) ? { default: () => { var _a2; return (_a2 = slots == null ? void 0 : slots.option) == null ? void 0 : _a2.call(slots, { option }); } } : {} ); } else { const { [label.value]: __label, [value.value]: __value, [config.value.dictLabelKey]: _label, [config.value.dictValueKey]: _value, ...other } = option; return vue.h( Checkbox, { ...other, option: { label: __label || _label, value: __value || _value }, optionType: customProps.optionType, disabled: lodashEs.isFunction((_a = customProps.props) == null ? void 0 : _a.disabled) ? (_b = customProps.props) == null ? void 0 : _b.disabled(option) : ((_c = customProps.props) == null ? void 0 : _c.disabled) ? option[(_d = customProps.props) == null ? void 0 : _d.disabled] : false, onChange: customProps.mutualExclusion.length > 0 ? (checked) => mutualExclusionFn(checked, __value || _value) : null }, (slots == null ? void 0 : slots.option) ? { default: () => { var _a2; return (_a2 = slots == null ? void 0 : slots.option) == null ? void 0 : _a2.call(slots, { option }); } } : {} ); } }) } : slots; return vue.h( TransformElCheckboxGroup, vue.reactive({ ...lodashEs.omit(vue.toRefs(customProps), ["options", "props"]), ..._props, ref: (ref2) => checkbox.value = ref2 }), children ); }; } }); const CheckboxGroup = vue$1.connect( CheckboxGroupOption, vue$1.mapProps({ dataSource: "options", value: "modelValue" }), vue$1.mapReadPretty(index.PreviewText.Select, { multiple: true }) ); const Checkbox = utils.composeExport(vue$1.connect(CheckboxOption), { Group: CheckboxGroup }); exports.Checkbox = Checkbox; exports.default = Checkbox; //# sourceMappingURL=index.js.map