UNPKG

@fecp/mobile

Version:

168 lines (167 loc) 5.81 kB
/* empty css */ /* empty css */ /* empty css */ /* empty css */ /* empty css */ import { ref, computed, watch, createElementBlock, openBlock, Fragment, createVNode, withDirectives, renderSlot, mergeProps, unref, isRef, createSlots, renderList, withCtx, createTextVNode, toDisplayString, createElementVNode, vModelText } from "vue"; import "../../../../../../_virtual/index.mjs"; import { getUnit, textFormatter, textFormatter4Input, reverseTextFormatter } from "../../../utils/formatterUtil.mjs"; import { useCursor } from "../../../utils/use-cursor.mjs"; /* empty css */ import { Field } from "../../../../../../node_modules/.pnpm/vant@4.9.17_vue@3.5.13_typescript@5.7.3_/node_modules/vant/es/field/index.mjs"; const _sfc_main = { __name: "Field", props: { modelValue: { type: String, default: "" }, fieldType: { type: String }, disabled: { type: Boolean, default: false }, readonly: { type: Boolean, default: false }, clickable: { type: Boolean, default: false }, dataFormatter: { type: String, default: "" }, showUnit: { type: Boolean, default: true } }, emits: ["openPicker", "update:modelValue"], setup(__props, { emit: __emit }) { const props = __props; const unit = ref(""); const fieldInputRef = ref(); const [recordCursor, setCursor] = useCursor(); const emit = __emit; const textValue = ref(""); const compValue = computed({ get: () => { if (!props.fieldType || props.fieldType == "text") { unit.value = getUnit(props.dataFormatter); if (props.readonly) { textValue.value = textFormatter(props.modelValue, props.dataFormatter); } else { textValue.value = textFormatter4Input( props.modelValue, props.dataFormatter ); } } else { textValue.value = props.modelValue; } return props.modelValue; }, set: (val) => { emit("update:modelValue", val); } }); watch(textValue, (val) => { if (!val) { emit("update:modelValue", val); } }); const compClickable = computed(() => { if (props.disabled || props.readonly) { return false; } return true; }); var isComposing = false; const handleInput = (e) => { if (isComposing) return; const inputElement = e.target; recordCursor(inputElement); inputElement.value = textFormatter4Input( inputElement.value, props.dataFormatter ); setCursor(inputElement); const unformattedValue = reverseTextFormatter( inputElement.value, props.dataFormatter ); compValue.value = unformattedValue; }; const handleCompositionStart = () => { isComposing = true; }; const handleCompositionEnd = (e) => { isComposing = false; doSomethingFunction(e); }; const doSomethingFunction = (e) => { const inputElement = e.target; recordCursor(inputElement); inputElement.value = textFormatter4Input( inputElement.value, props.dataFormatter ); setCursor(inputElement); const unformattedValue = reverseTextFormatter( inputElement.value, props.dataFormatter ); compValue.value = unformattedValue; }; return (_ctx, _cache) => { const _component_van_field = Field; return openBlock(), createElementBlock(Fragment, null, [ createVNode(_component_van_field, mergeProps(_ctx.$attrs, { modelValue: unref(textValue), "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(textValue) ? textValue.value = $event : null), disabled: __props.disabled, readonly: __props.readonly, clearable: "", clickable: unref(compClickable), "clear-trigger": "focus", onClick: _cache[1] || (_cache[1] = ($event) => !__props.disabled && emit("openPicker")), ref_key: "fieldInputRef", ref: fieldInputRef, onInput: handleInput, onCompositionstart: handleCompositionStart, onCompositionend: handleCompositionEnd }), createSlots({ _: 2 }, [ renderList(_ctx.$slots, (item, key) => { return { name: key, fn: withCtx(() => [ renderSlot(_ctx.$slots, key) ]) }; }), __props.showUnit && unref(unit) ? { name: "button", fn: withCtx(() => [ createTextVNode(toDisplayString(unref(unit)), 1) ]), key: "0" } : void 0 ]), 1040, ["modelValue", "disabled", "readonly", "clickable"]), withDirectives(createElementVNode("input", { type: "hidden", "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(compValue) ? compValue.value = $event : null) }, null, 512), [ [vModelText, unref(compValue)] ]), renderSlot(_ctx.$slots, "default") ], 64); }; } }; export { _sfc_main as default };