@icreate/ics-mui
Version:
京东风格的轻量级移动端 Vue2、Vue3 组件库(支持小程序开发)
149 lines (148 loc) • 5.38 kB
JavaScript
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
import { defineComponent, ref, toRef, watch, computed, openBlock, createElementBlock, createVNode, unref, withCtx, Fragment, renderList, createBlock, withModifiers, createTextVNode, toDisplayString } from "vue";
import "../input/Input.js";
import { u as useFormDisabled } from "../common-DXugw-he.js";
import { _ as _sfc_main$2 } from "../radio-group.vue_vue_type_script_setup_true_lang-lgndDtb3.js";
import { _ as _sfc_main$3 } from "../radio.vue_vue_type_script_setup_true_lang-vAuCptzn.js";
import { _ as _sfc_main$1 } from "../input.vue_vue_type_script_setup_true_lang-CUVjcKoZ.js";
import { w as withInstall } from "../with-install-DWwOiZS3.js";
const _hoisted_1 = { class: "ics-input-picker" };
const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, {
name: "IcsInputRadio"
}), {
__name: "index",
props: {
modelValue: {
type: String,
default: ""
},
suffix: {
type: String,
default: ""
},
options: {
type: Array,
default: []
},
disabled: {
type: Boolean,
default: false
}
},
emits: ["update:modelValue", "change"],
setup(__props, { emit: __emit }) {
const props = __props;
const radioVal = ref("");
const disabled = useFormDisabled(toRef(props, "disabled"));
const placeholder = ref("");
const selectVal = ref("");
const emits = __emit;
watch(() => props.modelValue, (val) => {
selectVal.value = val;
}, {
immediate: true
});
const _value = computed({
get() {
return props.modelValue;
},
set(value) {
emits("update:modelValue", value);
}
});
const input = (val) => {
placeholder.value = "";
const option = props.options.find((item) => item.label === val.target.value);
const value = option ? option.value : val.target.value;
radioVal.value = value;
emits("update:modelValue", value);
emits("change", value);
};
const blur = (val) => {
selectVal.value = val.target.value || placeholder.value;
if (selectVal.value === _value.value)
return;
emits("update:modelValue", val.target.value || placeholder.value);
emits("change", val.target.value || placeholder.value);
};
const focus = () => {
placeholder.value = selectVal.value;
selectVal.value = "";
};
const radioClick = (val) => {
if (disabled.value)
return;
placeholder.value = "";
if (_value.value === val) {
emits("update:modelValue", "");
emits("change", "");
return;
}
const option = props.options.find((item) => item.value === val);
const label = (option == null ? void 0 : option.label) || "";
emits("update:modelValue", _value.value === label ? "" : label);
emits("change", _value.value === label ? "" : label);
};
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", _hoisted_1, [
createVNode(unref(_sfc_main$1), {
modelValue: selectVal.value,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => selectVal.value = $event),
border: false,
suffix: __props.suffix,
disabled: unref(disabled),
placeholder: placeholder.value || "请输入",
onInput: input,
onBlur: blur,
onFocus: focus
}, null, 8, ["modelValue", "suffix", "disabled", "placeholder"]),
createVNode(_sfc_main$2, {
modelValue: radioVal.value,
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => radioVal.value = $event),
direction: "horizontal"
}, {
default: withCtx(() => [
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.options, (item) => {
return openBlock(), createBlock(_sfc_main$3, {
key: item.value,
disabled: unref(disabled),
label: item.value,
cancel: true,
onClick: withModifiers(($event) => radioClick(item.value), ["stop"])
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(item.label), 1)
]),
_: 2
}, 1032, ["disabled", "label", "onClick"]);
}), 128))
]),
_: 1
}, 8, ["modelValue"])
]);
};
}
}));
withInstall(_sfc_main);
export {
_sfc_main as InputRadio,
_sfc_main as default
};