diff --git a/src/views/RechargeAgency/index.vue b/src/views/RechargeAgency/index.vue index 217511e..e891b3d 100644 --- a/src/views/RechargeAgency/index.vue +++ b/src/views/RechargeAgency/index.vue @@ -200,8 +200,11 @@ v-model="rechargeAmount" type="number" min="1" + step="1" :placeholder="t('enter_recharge_amount')" class="amount-input" + @input="preventDecimalInput" + @keydown="onKeyDown" /> @@ -438,6 +441,27 @@ const Confirm = () => { closedPopup() } +// 防止输入小数点的函数 +const preventDecimalInput = (event) => { + // 移除小数点和其他非整数字符 + event.target.value = event.target.value.replace(/[^0-9]/g, '') + + // 确保最小值为1 + if (event.target.value === '' || parseInt(event.target.value) < 1) { + event.target.value = '' + } + + rechargeAmount.value = event.target.value +} + +// 键盘按下事件,阻止某些按键 +const onKeyDown = (event) => { + // 阻止小数点、e、+、- 等特殊字符 + if (['.', 'e', '+', '-'].includes(event.key)) { + event.preventDefault() + } +} + // 校验销售商权限 const checkDealerAccess = async () => { try {