1.新增套餐商品

This commit is contained in:
gyq
2024-12-06 14:41:58 +08:00
parent 96ab68f463
commit 7c27372c4d
15 changed files with 1320 additions and 15927 deletions

View File

@@ -57,3 +57,42 @@ export function formatDecimal(num, decimal = 2, isInt = false) {
return parseFloat(num).toFixed(decimal);
}
}
/**
* 过滤input只能输入整数
* @param {*} value
* @returns
*/
export function inputFilterInt(value) {
if (!value) return;
return value.replace(/[^\d]/g, "");
}
/**
* 过滤input只能输入数字并且最多输入两位小数
* @param {*} value
* @returns
*/
export function inputFilterFloat(value) {
if (!value) return;
// 去除首位小数点
if (value.startsWith(".")) {
value = value.slice(1);
}
// 清除非数字和小数点(除了第一个小数点)
value = value.replace(/[^\d.]/g, "");
// 确保最多只有一个小数点
if (value.split(".").length > 2) {
value = value.split(".").slice(0, 2).join(".");
}
// 限制小数位数为两位
if (value.split(".")[1] && value.split(".")[1].length > 2) {
value = value.split(".")[0] + "." + value.split(".")[1].slice(0, 2);
}
// 限制首位只能输入一个0
if (value.startsWith("0") && value.length > 1 && value[1] === "0") {
// 如果首位是0且第二位也是0将第二个0及之后的内容清空
value = "0";
}
return value;
}