UNPKG

@fecp/mobile

Version:

101 lines (100 loc) 3.13 kB
"use strict"; 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("../checkboxGroup/index.js"); const _hoisted_1 = { key: 1 }; const _sfc_main = { __name: "FieldCheckbox", props: { modelValue: { type: String, 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: () => { if (props.modelValue) { if (Array.isArray(props.modelValue)) { return props.modelValue; } else { return props.modelValue.split("|"); } } else { return []; } }, set: (val) => { emit("update:modelValue", val.join("|")); } }); const fieldTextValue = vue.computed(() => { return compValue.value.map((value) => { const option = finalOptions.value.find((opt) => opt.value === value); return option ? option.text : value; }).join(", "); }); 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.MobileCheckboxGroup), 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;