UNPKG

plus-pro-components

Version:

Page level components developed based on Element Plus.

184 lines (181 loc) 7.08 kB
import { defineComponent, ref, reactive, watch, useAttrs, openBlock, createBlock, unref, mergeProps, createSlots, withCtx, createElementBlock, Fragment, renderList, resolveDynamicComponent, createTextVNode, toDisplayString, createCommentVNode, normalizeProps, guardReactiveProps } from 'vue'; import { ElRadioGroup, ElRadio } from 'element-plus'; import { versionIsLessThan260 } from '../../utils/index.mjs'; import { isFunction } from '../../utils/is.mjs'; var _sfc_main = /* @__PURE__ */ defineComponent({ ...{ name: "PlusRadio" }, __name: "index", props: { modelValue: { type: [String, Number, Boolean], default: "" }, options: { default: () => [] }, isCancel: { type: Boolean, default: true }, fieldSlots: { default: void 0 }, fieldChildrenSlot: { default: void 0 } }, emits: ["change", "update:modelValue"], setup(__props, { expose: __expose, emit: __emit }) { const props = __props; const emit = __emit; const radioInstance = ref(); const radioGroupInstance = ref(); const state = reactive({ radio: "" }); watch( () => props.modelValue, (val) => { state.radio = val; }, { immediate: true } ); const attrs = useAttrs(); const radioClick = (e, val, fieldItemProps) => { if (Reflect.has(attrs, "disabled") || (fieldItemProps == null ? void 0 : fieldItemProps.disabled)) { return; } if (!props.isCancel) { return; } else { e.preventDefault(); } state.radio = state.radio === val ? "" : val; emit("update:modelValue", state.radio); emit("change", state.radio); }; const change = (val) => { if (props.isCancel) return; emit("update:modelValue", val); emit("change", val); }; __expose({ radioInstance, radioGroupInstance }); return (_ctx, _cache) => { return openBlock(), createBlock(unref(ElRadioGroup), mergeProps({ ref_key: "radioGroupInstance", ref: radioGroupInstance, modelValue: state.radio, "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => state.radio = $event), class: "plus-radio" }, _ctx.$attrs), createSlots({ default: withCtx(() => [ unref(versionIsLessThan260) ? (openBlock(true), createElementBlock( Fragment, { key: 0 }, renderList(_ctx.options, (item) => { return openBlock(), createBlock(unref(ElRadio), mergeProps({ key: `${item.label}${item.value}`, ref_for: true, ref_key: "radioInstance", ref: radioInstance, label: item.value }, item.fieldItemProps, { onClick: ($event) => radioClick($event, item.value, item.fieldItemProps), onChange: ($event) => change(item.value) }), { default: withCtx(() => [ unref(isFunction)(item.fieldSlot) ? (openBlock(), createBlock(resolveDynamicComponent(item.fieldSlot), mergeProps({ key: 0, "model-value": state.radio, column: props }, item), null, 16, ["model-value"])) : unref(isFunction)(_ctx.fieldChildrenSlot) ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.fieldChildrenSlot), mergeProps({ key: 1, "model-value": state.radio, column: props }, item), null, 16, ["model-value"])) : (openBlock(), createElementBlock( Fragment, { key: 2 }, [ createTextVNode( toDisplayString(item == null ? void 0 : item.label), 1 /* TEXT */ ) ], 64 /* STABLE_FRAGMENT */ )) ]), _: 2 /* DYNAMIC */ }, 1040, ["label", "onClick", "onChange"]); }), 128 /* KEYED_FRAGMENT */ )) : (openBlock(), createElementBlock( Fragment, { key: 1 }, [ createCommentVNode(" element-plus \u7248\u672C\u53F7\u5927\u4E8E\u7B49\u4E8E2.6.0 "), (openBlock(true), createElementBlock( Fragment, null, renderList(_ctx.options, (item) => { return openBlock(), createBlock(unref(ElRadio), mergeProps({ key: `${item.label}${item.value}`, ref_for: true, ref_key: "radioInstance", ref: radioInstance, value: item.value }, item.fieldItemProps, { onClick: ($event) => radioClick($event, item.value, item.fieldItemProps), onChange: ($event) => change(item.value) }), { default: withCtx(() => [ unref(isFunction)(item.fieldSlot) ? (openBlock(), createBlock(resolveDynamicComponent(item.fieldSlot), mergeProps({ key: 0, "model-value": state.radio, column: props }, item), null, 16, ["model-value"])) : unref(isFunction)(_ctx.fieldChildrenSlot) ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.fieldChildrenSlot), mergeProps({ key: 1, "model-value": state.radio, column: props }, item), null, 16, ["model-value"])) : (openBlock(), createElementBlock( Fragment, { key: 2 }, [ createTextVNode( toDisplayString(item == null ? void 0 : item.label), 1 /* TEXT */ ) ], 64 /* STABLE_FRAGMENT */ )) ]), _: 2 /* DYNAMIC */ }, 1040, ["value", "onClick", "onChange"]); }), 128 /* KEYED_FRAGMENT */ )) ], 64 /* STABLE_FRAGMENT */ )) ]), _: 2 /* DYNAMIC */ }, [ renderList(_ctx.fieldSlots, (fieldSlot, key) => { return { name: key, fn: withCtx((data) => [ (openBlock(), createBlock( resolveDynamicComponent(fieldSlot), normalizeProps(guardReactiveProps(data)), null, 16 /* FULL_PROPS */ )) ]) }; }) ]), 1040, ["modelValue"]); }; } }); export { _sfc_main as default };