@fmdevui/fm-dev
Version:
Page level components developed based on Element Plus.
109 lines (104 loc) • 3.17 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
...{ name: "FmInput" },
__name: "index",
props: /* @__PURE__ */ vue.mergeModels({
placeholder: {
type: String,
default: "\u8BF7\u8F93\u5165\u91D1\u989D"
},
defaultValue: {
type: Number,
default: -1
},
bType: {
type: String,
default: "money"
}
}, {
"modelValue": { required: true, default: 0 },
"modelModifiers": {}
}),
emits: ["update:modelValue"],
setup(__props) {
const modelValue = vue.useModel(__props, "modelValue");
const props = __props;
const handleInput = (val) => {
if (val == "" && props.defaultValue != -1) {
modelValue.value = props.defaultValue;
return;
}
if (props.bType == "number") {
modelValue.value = parseInt(val);
return;
}
let cleaned = String(val).replace(/[^\d.]/g, "");
const dotIndex = cleaned.indexOf(".");
if (dotIndex !== -1) {
const before = cleaned.substring(0, dotIndex + 1);
const after = cleaned.substring(dotIndex + 1).replace(/\./g, "");
cleaned = before + after;
}
if (cleaned.startsWith(".")) {
cleaned = "0" + cleaned;
}
const parts = cleaned.split(".");
parts[0] = parts[0].replace(/^0+/, "") || "0";
cleaned = parts.join(".");
if (cleaned.includes(".")) {
const [intPart, decPart] = cleaned.split(".");
cleaned = `${intPart}.${decPart.substring(0, 2)}`;
}
modelValue.value = cleaned;
};
vue.watch(() => modelValue.value, (newvalue, oldValue) => {
if (newvalue == "") {
modelValue.value = props.defaultValue == -1 ? 0 : props.defaultValue;
}
});
return (_ctx, _cache) => {
const _component_el_input = vue.resolveComponent("el-input");
return vue.openBlock(), vue.createBlock(_component_el_input, {
modelValue: modelValue.value,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => modelValue.value = $event),
placeholder: __props.placeholder,
onInput: handleInput
}, vue.createSlots({
_: 2
/* DYNAMIC */
}, [
_ctx.$slots.prepend ? {
name: "prepend",
fn: vue.withCtx(() => [
vue.renderSlot(_ctx.$slots, "prepend")
]),
key: "0"
} : void 0,
_ctx.$slots.append ? {
name: "append",
fn: vue.withCtx(() => [
vue.renderSlot(_ctx.$slots, "append")
]),
key: "1"
} : void 0,
_ctx.$slots.prefix ? {
name: "prefix",
fn: vue.withCtx(() => [
vue.renderSlot(_ctx.$slots, "prefix")
]),
key: "2"
} : void 0,
_ctx.$slots.suffix ? {
name: "suffix",
fn: vue.withCtx(() => [
vue.renderSlot(_ctx.$slots, "suffix")
]),
key: "3"
} : void 0
]), 1032, ["modelValue", "placeholder"]);
};
}
});
exports.default = _sfc_main;