This commit is contained in:
2022-12-30 16:14:41 +08:00
parent c5d893ba35
commit 7ab98231e8
14 changed files with 454 additions and 187 deletions

View File

@@ -102,11 +102,37 @@ const _sfc_main = defineComponent({
});
const isPassword = computed(() => type.value == "password");
const composing = ref(false);
const formatMoney = function(s) {
var noNegative = true;
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")) + "";
if (parseFloat(s) < 0) {
s = Math.abs(s) + "";
noNegative = false;
}
var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];
var t = "";
for (let i = 0; i < l.length; i++) {
if (i % 3 == 2 && i != l.length - 1) {
t += l[i] + ",";
} else {
t += l[i] + "";
}
}
let z = (noNegative ? "" : "-") + t.split("").reverse().join("");
if (r) {
return z + "." + r;
} else {
return isNaN(parseInt(z)) ? 0 : z;
}
};
watch(() => props.type, () => {
type.value = props.type;
});
const input = ref();
watch(() => props.modelValue, () => {
if (props.qfw && currentValue.value.indexOf(",") != -1) {
console.log(input);
if (!(input.value == document.activeElement) && props.qfw) {
currentValue.value = formatMoney(props.modelValue.toString());
return;
}
currentValue.value = String(props.modelValue == null ? "" : props.modelValue);
@@ -142,6 +168,15 @@ const _sfc_main = defineComponent({
if (props.type === "number") {
onNumberBlur(event);
}
if (props.qfw) {
try {
let reg = /\d{1,3}(?=(\d{3})+$)/g;
console.log("\u6DFB\u52A0\uFF0C", formatMoney(props.modelValue.toString()));
currentValue.value = formatMoney(props.modelValue.toString());
} catch {
currentValue.value = "\u8F93\u5165\u9519\u8BEF";
}
}
emit("blur", event);
};
const onNumberBlur = (event) => {
@@ -157,7 +192,6 @@ const _sfc_main = defineComponent({
if (props.qfw) {
value = value.replace(/,/g, "");
}
currentValue.value = new String(props.modelValue).toLocaleString();
emit("update:modelValue", value);
};
const onCompositionstart = () => {
@@ -213,7 +247,9 @@ const _sfc_main = defineComponent({
onFocus,
onBlur,
onCompositionstart,
onCompositionend
onCompositionend,
ref_key: "input",
ref: input
}, null, 40, _hoisted_5),
__props.password && unref(hasContent) ? (openBlock(), createElementBlock("span", {
key: 1,