@fecp/mobile
Version:
168 lines (167 loc) • 5.89 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
;/* empty css */
;/* empty css */
;/* empty css */
;/* empty css */
;/* empty css */
const vue = require("vue");
require("../../../../../../_virtual/index.js");
const formatterUtil = require("../../../utils/formatterUtil.js");
const useCursor = require("../../../utils/use-cursor.js");
;/* empty css */
const index = require("../../../../../../node_modules/.pnpm/vant@4.9.17_vue@3.5.13_typescript@5.7.3_/node_modules/vant/es/field/index.js");
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 = vue.ref("");
const fieldInputRef = vue.ref();
const [recordCursor, setCursor] = useCursor.useCursor();
const emit = __emit;
const textValue = vue.ref("");
const compValue = vue.computed({
get: () => {
if (!props.fieldType || props.fieldType == "text") {
unit.value = formatterUtil.getUnit(props.dataFormatter);
if (props.readonly) {
textValue.value = formatterUtil.textFormatter(props.modelValue, props.dataFormatter);
} else {
textValue.value = formatterUtil.textFormatter4Input(
props.modelValue,
props.dataFormatter
);
}
} else {
textValue.value = props.modelValue;
}
return props.modelValue;
},
set: (val) => {
emit("update:modelValue", val);
}
});
vue.watch(textValue, (val) => {
if (!val) {
emit("update:modelValue", val);
}
});
const compClickable = vue.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 = formatterUtil.textFormatter4Input(
inputElement.value,
props.dataFormatter
);
setCursor(inputElement);
const unformattedValue = formatterUtil.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 = formatterUtil.textFormatter4Input(
inputElement.value,
props.dataFormatter
);
setCursor(inputElement);
const unformattedValue = formatterUtil.reverseTextFormatter(
inputElement.value,
props.dataFormatter
);
compValue.value = unformattedValue;
};
return (_ctx, _cache) => {
const _component_van_field = index.Field;
return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
vue.createVNode(_component_van_field, vue.mergeProps(_ctx.$attrs, {
modelValue: vue.unref(textValue),
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => vue.isRef(textValue) ? textValue.value = $event : null),
disabled: __props.disabled,
readonly: __props.readonly,
clearable: "",
clickable: vue.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
}), vue.createSlots({ _: 2 }, [
vue.renderList(_ctx.$slots, (item, key) => {
return {
name: key,
fn: vue.withCtx(() => [
vue.renderSlot(_ctx.$slots, key)
])
};
}),
__props.showUnit && vue.unref(unit) ? {
name: "button",
fn: vue.withCtx(() => [
vue.createTextVNode(vue.toDisplayString(vue.unref(unit)), 1)
]),
key: "0"
} : void 0
]), 1040, ["modelValue", "disabled", "readonly", "clickable"]),
vue.withDirectives(vue.createElementVNode("input", {
type: "hidden",
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => vue.isRef(compValue) ? compValue.value = $event : null)
}, null, 512), [
[vue.vModelText, vue.unref(compValue)]
]),
vue.renderSlot(_ctx.$slots, "default")
], 64);
};
}
};
exports.default = _sfc_main;