From 0511c973021de287d281634db8afc661d9d25877 Mon Sep 17 00:00:00 2001 From: Theluyuan <1162963624@qq.com> Date: Fri, 30 Dec 2022 16:14:33 +0800 Subject: [PATCH] update --- src/component/input/index.vue | 82 +++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/src/component/input/index.vue b/src/component/input/index.vue index 2068bc6..5870a26 100644 --- a/src/component/input/index.vue +++ b/src/component/input/index.vue @@ -40,7 +40,7 @@ const props = withDefaults(defineProps(), { password: false, modelValue: "", size: "md", - qfw: false + qfw: false, }); interface InputEmits { @@ -81,15 +81,14 @@ const formatMoney = function (s: string) { t += l[i] + ""; //加上空格 } } - let z:any = (noNegative ? "" : "-") + t.split("").reverse().join(""); + let z: any = (noNegative ? "" : "-") + t.split("").reverse().join(""); // z = isNaN(z) ? 0 : z; - if(r){ - return z+ "." + r; - - }else{ + if (r) { + return z + "." + r; + } else { return isNaN(parseInt(z)) ? 0 : z; } -} +}; watch( () => props.type, @@ -97,15 +96,15 @@ watch( type.value = props.type; } ); -const input:any = ref() +const input: any = ref(); watch( () => props.modelValue, () => { - console.log(input) - if(!(input.value == document.activeElement) && props.qfw){ + console.log(input); + if (!(input.value == document.activeElement) && props.qfw) { currentValue.value = formatMoney(props.modelValue.toString()); - return + return; } currentValue.value = String( props.modelValue == null ? "" : props.modelValue @@ -119,7 +118,7 @@ const onInput = function (event: Event) { emit("input", value); if (composing.value) return; if (props.qfw) { - value = value.replace(/,/g, "") + value = value.replace(/,/g, ""); } emit("update:modelValue", value); }; @@ -130,7 +129,7 @@ const onClear = () => { }; const onFocus = (event: Event) => { - currentValue.value = new String(props.modelValue).replace(/,/g, "") + currentValue.value = new String(props.modelValue).replace(/,/g, ""); emit("focus", event); }; @@ -138,7 +137,7 @@ const onChange = (event: Event) => { const inputElement = event.target as HTMLInputElement; let value = inputElement.value; if (props.qfw) { - value = value.replace(/,/g, "") + value = value.replace(/,/g, ""); } emit("change", value); }; @@ -148,18 +147,16 @@ const onBlur = (event: Event) => { onNumberBlur(event); } if (props.qfw) { - try { let reg = /\d{1,3}(?=(\d{3})+$)/g; // new String(props.modelValue).replace(reg, '$&,'); - console.log("添加,", formatMoney(props.modelValue.toString())) + console.log("添加,", formatMoney(props.modelValue.toString())); currentValue.value = formatMoney(props.modelValue.toString()); } catch { - currentValue.value = "输入错误" + currentValue.value = "输入错误"; } } - emit("blur", event); }; @@ -172,7 +169,7 @@ const onNumberBlur = (event: Event) => { if (props.min && props.min > Number(value)) value = props.min.toString(); } if (props.qfw) { - value = value.replace(/,/g, "") + value = value.replace(/,/g, ""); } emit("update:modelValue", value); }; @@ -210,22 +207,53 @@ const showPassword = () => {
- + - - + + - + - +