@fecp/mobile
Version:
93 lines (92 loc) • 2.89 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const index = require("../field/index.js");
const optionUtil = require("../../../utils/optionUtil.js");
const index$1 = require("../radioGroup/index.js");
const _hoisted_1 = { key: 1 };
const _sfc_main = {
__name: "FieldRadio",
props: {
modelValue: {
type: [String, Number],
default: ""
},
options: {
type: Array,
default: []
},
fieldNames: {
type: Object,
default: {
text: "text",
value: "value",
disabled: "disabled"
}
},
readonly: {
type: Boolean,
default: false
}
},
emits: ["update:modelValue"],
setup(__props, { emit: __emit }) {
const props = __props;
const attrs = vue.useAttrs();
const finalOptions = vue.ref([]);
optionUtil.getOptions({
...attrs,
staticOptions: props.options,
optionsFieldNames: props.fieldNames
}).then((data) => {
finalOptions.value = data;
});
vue.watch(
() => props.options,
() => {
optionUtil.getOptions({
...attrs,
staticOptions: props.options,
optionsFieldNames: props.fieldNames
}).then((data) => {
finalOptions.value = data;
});
},
{
deep: true
}
);
const emit = __emit;
const compValue = vue.computed({
get: () => {
return props.modelValue;
},
set: (val) => {
emit("update:modelValue", val);
}
});
const fieldTextValue = vue.computed(() => {
const selectedOption = finalOptions.value.find(
(option) => option.value === compValue.value
);
return selectedOption ? selectedOption.text : "";
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createBlock(vue.unref(index.MobileField), vue.mergeProps(_ctx.$attrs, {
readonly: __props.readonly,
modelValue: vue.unref(fieldTextValue),
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => vue.isRef(fieldTextValue) ? fieldTextValue.value = $event : null)
}), {
input: vue.withCtx(() => [
!__props.readonly ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.MobileRadioGroup), vue.mergeProps({ key: 0 }, _ctx.$attrs, {
options: vue.unref(finalOptions),
modelValue: vue.unref(compValue),
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => vue.isRef(compValue) ? compValue.value = $event : null)
}), null, 16, ["options", "modelValue"])) : (vue.openBlock(), vue.createElementBlock("span", _hoisted_1, vue.toDisplayString(vue.unref(fieldTextValue)), 1))
]),
_: 1
}, 16, ["readonly", "modelValue"]);
};
}
};
exports.default = _sfc_main;