优化预下单选择人数

This commit is contained in:
gyq
2025-12-04 09:39:53 +08:00
parent 00c5987ccc
commit ca829d7f00
6 changed files with 573 additions and 340 deletions

View File

@@ -207,6 +207,12 @@
"style": { "style": {
"navigationBarTitleText": "适用门店" "navigationBarTitleText": "适用门店"
} }
},
{
"path": "pages/mesaage/index",
"style": {
"navigationBarTitleText": "消息"
}
} }
], ],
"subPackages": [{ "subPackages": [{

7
pages/mesaage/index.vue Normal file
View File

@@ -0,0 +1,7 @@
<template>
<view class="container">消息</view>
</template>
<script setup></script>
<style scoped lang="scss"></style>

View File

@@ -1,30 +1,24 @@
<template> <template>
<view class="container"> <view class="container">
<image class="top_bg" src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/order/orderAMeal.png" <image class="top_bg" src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/order/orderAMeal.png" mode="aspectFill"></image>
mode="aspectFill"></image>
<view class="content_box"> <view class="content_box">
<view class="content"> <view class="content">
<view class="title"> <view class="title">
<view class="title_text">请选择就餐人数</view> <view class="title_text">请选择就餐人数</view>
<view class="title_tabNum">桌号{{shopTable.name}}</view> <view class="title_tabNum">桌号{{ shopTable.name }}</view>
</view> </view>
<view class="num" :class="{'active':numIndex==-1}"> <view class="num" :class="{ active: numIndex == -1 }">
<view class="item" @click="tabCut(index)" v-for="(item,index) in 9" :key="index"> <view class="item" @click="tabCut(index)" v-for="(item, index) in 9" :key="index">
<view class="num_item" :class="{'active':numIndex==index }">{{index+1}}</view> <view class="num_item" :class="{ active: numIndex == index }">{{ index + 1 }}</view>
</view> </view>
<view class="item" @click="tabCut(-1)"> <view class="item" @click="tabCut(-1)">
<view class="num_item" :style="numIndex==-1?'background-color: #E8AD7B;':'' "> <view class="num_item" :style="numIndex == -1 ? 'background-color: #E8AD7B;' : ''">
<up--input v-model="otherNum" @input="isOtherNum" @blur="blur()" border="none" type="nubmer" <up--input v-model="otherNum" @input="isOtherNum" @blur="blur()" border="none" type="nubmer" maxlength="3" placeholder="请输入.."></up--input>
maxlength="3" placeholder='请输入..'></up--input>
</view> </view>
</view> </view>
<!-- <view class="num_item" v-else :class="{'active':numIndex==-1 }"></view> --> <!-- <view class="num_item" v-else :class="{'active':numIndex==-1 }"></view> -->
</view> </view>
<view class="startBtn" @click="start"> <view class="startBtn" @click="start">开始点餐</view>
开始点餐
</view>
</view> </view>
</view> </view>
<Loading :isLoading="isLoading" /> <Loading :isLoading="isLoading" />
@@ -32,74 +26,61 @@
</template> </template>
<script setup> <script setup>
import { import { ref, onMounted, getCurrentInstance, nextTick } from 'vue';
ref,
onMounted,
getCurrentInstance,
nextTick
} from 'vue'
import { import { onLoad } from '@dcloudio/uni-app';
onLoad
} from '@dcloudio/uni-app'
import { import { Storelogin } from '@/stores/user.js';
Storelogin
} from '@/stores/user.js';
import Loading from '@/components/Loading.vue'; import Loading from '@/components/Loading.vue';
// 获取全局属性 // 获取全局属性
const { const { proxy } = getCurrentInstance();
proxy
} = getCurrentInstance();
import { import { productStore } from '@/stores/user.js';
productStore
} from '@/stores/user.js';
// 初始加载中 // 初始加载中
const isLoading = ref(true); const isLoading = ref(true);
const otherNum = ref('') const otherNum = ref('');
const numIndex = ref(0) const numIndex = ref(0);
const dinersNum = ref(1) const dinersNum = ref(1);
const isOtherNum = (e) => { const isOtherNum = (e) => {
otherNum.value = otherNum.value.replace(/\D/g, '') otherNum.value = otherNum.value.replace(/\D/g, '');
} };
const tableCode = uni.cache.get('tableCode') const tableCode = uni.cache.get('tableCode');
// 切换桌型 // 切换桌型
const tabCut = (index) => { const tabCut = (index) => {
console.log(index) console.log(index);
numIndex.value = index; numIndex.value = index;
if (index != -1) { if (index != -1) {
dinersNum.value = index + 1; dinersNum.value = index + 1;
} else { } else {
otherNum.value = otherNum.value == "其他" ? "" : otherNum.value otherNum.value = otherNum.value == '其他' ? '' : otherNum.value;
}
} }
};
const blur = (index) => { const blur = (index) => {
otherNum.value = otherNum.value == "" ? "其他" : otherNum.value otherNum.value = otherNum.value == '' ? '其他' : otherNum.value;
} };
const shopTable = uni.cache.get('shopTable') const shopTable = uni.cache.get('shopTable');
const start = async () => { const start = async () => {
if (numIndex.value == -1 && (otherNum.value == "其他" || otherNum.value <= 0)) { if (numIndex.value == -1 && (otherNum.value == '其他' || otherNum.value <= 0)) {
uni.showToast({ uni.showToast({
title: '请选择就餐人数', title: '请选择就餐人数',
icon: 'none', icon: 'none'
}) });
return; return;
} }
if (numIndex.value == -1 && otherNum.value != "其他") { if (numIndex.value == -1 && otherNum.value != '其他') {
dinersNum.value = otherNum.value dinersNum.value = otherNum.value;
} }
if (shopTable.useNum < dinersNum.value && shopTable.useNum > 0) { if (shopTable.useNum < dinersNum.value && shopTable.useNum > 0) {
uni.showToast({ uni.showToast({
@@ -108,11 +89,11 @@
}); });
return false; return false;
} }
uni.cache.set('dinersNum', dinersNum.value) uni.cache.set('dinersNum', dinersNum.value);
uni.pro.redirectTo('product/index') uni.pro.redirectTo('product/index');
} };
onMounted(async () => { onMounted(async () => {
await proxy.$onLaunched; await proxy.$onLaunched;
// 获取当前页面栈 // 获取当前页面栈
const pages = getCurrentPages(); const pages = getCurrentPages();
@@ -123,47 +104,47 @@
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
if (options.q) { if (options.q) {
const store = productStore(); const store = productStore();
await store.scanCodeactions(options.q) await store.scanCodeactions(options.q);
} }
// #endif // #endif
// #ifdef MP-ALIPAY // #ifdef MP-ALIPAY
if (getApp().globalData.tableCode) { if (getApp().globalData.tableCode) {
await store.scanCodeactions(getApp().globalData.tableCode) await store.scanCodeactions(getApp().globalData.tableCode);
} }
// #endif // #endif
await nextTick() await nextTick();
isLoading.value = uni.cache.get('shopInfo').isTableFee == 0 ? false : true isLoading.value = uni.cache.get('shopInfo').isTableFee == 0 ? false : true;
}) });
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
page { page {
// background: #f6f6f6; // background: #f6f6f6;
} }
.top_bg { .top_bg {
width: 100%; width: 100%;
height: 100%; height: 100%;
position: absolute; position: absolute;
z-index: 1; z-index: 1;
top: 0; top: 0;
} }
.content_box { .content_box {
width: 100%; width: 100%;
padding: 0 28rpx; padding: 0 28rpx;
position: absolute; position: absolute;
bottom: 148rpx; bottom: 148rpx;
} }
.content { .content {
width: 100%; width: 100%;
position: relative; position: relative;
z-index: 2; z-index: 2;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 48rpx 0 32rpx 32rpx; padding: 48rpx 0 32rpx 32rpx;
background: #FFFFFF; background: #ffffff;
border-radius: 44rpx 44rpx 44rpx 44rpx; border-radius: 44rpx 44rpx 44rpx 44rpx;
.title { .title {
@@ -202,7 +183,7 @@
text-align: center; text-align: center;
margin-right: 28rpx; margin-right: 28rpx;
margin-bottom: 32rpx; margin-bottom: 32rpx;
background-color: #FEF4EB; background-color: #fef4eb;
border-radius: 12rpx; border-radius: 12rpx;
font-weight: 400; font-weight: 400;
font-size: 28rpx; font-size: 28rpx;
@@ -219,9 +200,8 @@
line-height: 56rpx; line-height: 56rpx;
text-align: center; text-align: center;
margin-bottom: 32rpx; margin-bottom: 32rpx;
background-color: #FEF4EB; background-color: #fef4eb;
border-radius: 12rpx; border-radius: 12rpx;
} }
::v-deep input { ::v-deep input {
@@ -230,14 +210,13 @@
font-size: 28rpx !important; font-size: 28rpx !important;
color: #333333 !important; color: #333333 !important;
text-align: center !important; text-align: center !important;
background-color: #FEF4EB; background-color: #fef4eb;
} }
.active { .active {
color: #fff; color: #fff;
background-color: #E8AD7B; background-color: #e8ad7b;
} }
} }
::v-deep .num.active .u-input { ::v-deep .num.active .u-input {
@@ -246,27 +225,26 @@
line-height: 56rpx; line-height: 56rpx;
text-align: center; text-align: center;
margin-bottom: 32rpx; margin-bottom: 32rpx;
background-color: #E8AD7B !important; background-color: #e8ad7b !important;
border-radius: 12rpx; border-radius: 12rpx;
} }
::v-deep .num.active input { ::v-deep .num.active input {
color: #fff !important; color: #fff !important;
border-radius: 12rpx; border-radius: 12rpx;
background-color: #E8AD7B !important; background-color: #e8ad7b !important;
} }
}
} .startBtn {
.startBtn {
width: 100%; width: 100%;
height: 96rpx; height: 96rpx;
line-height: 96rpx; line-height: 96rpx;
text-align: center; text-align: center;
background-color: #E8AD7B; background-color: #e8ad7b;
border-radius: 48rpx; border-radius: 48rpx;
font-weight: bold; font-weight: bold;
font-size: 32rpx; font-size: 32rpx;
color: #FFFFFF; color: #ffffff;
} }
</style> </style>

View File

@@ -513,6 +513,42 @@
<recommendGoodsModal v-if="isDataLoaded" @onBuyClick="onBuyClick"></recommendGoodsModal> <recommendGoodsModal v-if="isDataLoaded" @onBuyClick="onBuyClick"></recommendGoodsModal>
<goodsModal></goodsModal> <goodsModal></goodsModal>
<xbSwiperPreview :visable="showPrveImg" :imgs="prveImgsList" @update:visable="showPrveImg = $event"></xbSwiperPreview> <xbSwiperPreview :visable="showPrveImg" :imgs="prveImgsList" @update:visable="showPrveImg = $event"></xbSwiperPreview>
<!-- 显示选择人数popup -->
<u-popup mode="bottom" :safe-area-inset-bottom="false" :show="showTableInfoPeopleNumPopup">
<view class="select_num_wrap">
<image class="top_bg" src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/order/orderAMeal.png" mode="aspectFill"></image>
<view class="sn-bnottom">
<view class="sn-header">
<text class="t1">请选择就餐人数</text>
<text class="t2">桌号{{ shopTable.name }}</text>
</view>
<view class="sn-num-wrap">
<view class="sn-num">
<view
class="item"
:class="{ active: tableInfoPeopleActive == index }"
v-for="(item, index) in 10"
:key="item"
@click="tableInfoPeopleNumHandle(item, index)"
>
<text class="t">{{ item }}</text>
</view>
</view>
<view class="input">
<u-input v-model="tableInfoPeopleNum" :maxlength="2" placeholder="请输入自定义人数" clearable @change="tableInfoPeopleNumInput"></u-input>
</view>
</view>
<view class="sn-footer-wrap">
<view class="btn">
<u-button plain shape="circle" @click="closeTableInfoPeopleNum">取消</u-button>
</view>
<view class="btn">
<u-button type="primary" shape="circle" @click="tableInfoPeopleNumConfirm">确认</u-button>
</view>
</view>
</view>
</view>
</u-popup>
</view> </view>
</template> </template>
@@ -541,6 +577,7 @@ import Loading from '@/components/Loading.vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import isBetween from 'dayjs/plugin/isBetween'; import isBetween from 'dayjs/plugin/isBetween';
dayjs.extend(isBetween); dayjs.extend(isBetween);
import { filterNumberInput } from '@/utils/util.js';
//点单智能推荐 //点单智能推荐
function onBuyClick(item) { function onBuyClick(item) {
@@ -1461,8 +1498,19 @@ async function onMessage(Message) {
// 转桌成功 // 转桌成功
if (Message.operate_type == 'rottable' && Message.status == 1) { if (Message.operate_type == 'rottable' && Message.status == 1) {
console.log('转桌成功了'); console.log('转桌成功了');
uni.showToast({
title: '扫码成功,请下单',
icon: 'none'
});
orderType.value = 'scan'; orderType.value = 'scan';
uni.cache.set('tableCode', Message.data.new_table_code); uni.cache.set('tableCode', Message.data.new_table_code);
if (showTableInfoPeopleNumPopup.value == true) {
showTableInfoPeopleNumPopup.value = false;
}
websocketsendMessage(options.initMessage); websocketsendMessage(options.initMessage);
} }
@@ -1860,12 +1908,46 @@ provide('shopInfo', shopInfo);
const orderType = ref('scan'); const orderType = ref('scan');
// 扫码下单 // 扫码下单
function beforehandHandle() {
uni.scanCode({ // 台桌信息
success(res) { const showTableInfoPeopleNumPopup = ref(false);
const tableInfo = ref('');
// 选择的人数
const tableInfoPeopleActive = ref(-1);
const tableInfoPeopleNum = ref('');
// 选择人数
function tableInfoPeopleNumHandle(num, index) {
tableInfoPeopleActive.value = index;
tableInfoPeopleNum.value = num;
}
// 人数输入框
function tableInfoPeopleNumInput(e) {
tableInfoPeopleActive.value = -1;
setTimeout(() => {
tableInfoPeopleNum.value = filterNumberInput(e, 1);
}, 50);
}
// 取消选择人数
function closeTableInfoPeopleNum() {
showTableInfoPeopleNumPopup.value = false;
tableInfoPeopleActive.value = -1;
tableInfoPeopleNum.value = '';
}
// 确认选择人数
function tableInfoPeopleNumConfirm() {
uni.cache.set('dinersNum', tableInfoPeopleNum.value);
startUseTable();
}
// 开始换桌
function startUseTable() {
const shopInfo = uni.cache.get('shopInfo'); const shopInfo = uni.cache.get('shopInfo');
const oldTableCode = uni.cache.get('tableCode'); const oldTableCode = uni.cache.get('tableCode');
const newTableCode = userStore.getQueryString(res.result, 'code');
const cartIds = cartStore.carts.map((item) => item.id); const cartIds = cartStore.carts.map((item) => item.id);
const data = { const data = {
@@ -1873,14 +1955,31 @@ function beforehandHandle() {
operate_type: 'rottable', operate_type: 'rottable',
account: shopInfo.phone, account: shopInfo.phone,
table_code: oldTableCode, table_code: oldTableCode,
new_table_code: newTableCode, new_table_code: tableInfo.value.tableCode,
cart_id: cartIds, cart_id: cartIds,
shop_id: shopInfo.id shop_id: shopInfo.id
}; };
console.log('scanCode.data===', data);
// return;
websocketsendMessage(data); websocketsendMessage(data);
}
// 预点单扫码下单
function beforehandHandle() {
uni.scanCode({
success: async (res) => {
try {
const newTableCode = userStore.getQueryString(res.result, 'code');
if (shopInfo.isTableFee) {
startUseTable();
} else {
await userStore.actionsproductqueryShop(newTableCode);
tableInfo.value = uni.cache.get('shopTable');
showTableInfoPeopleNumPopup.value = true;
}
} catch (error) {
console.log(error);
}
} }
}); });
} }
@@ -2961,4 +3060,81 @@ function toHistory() {
z-index: 9; z-index: 9;
color: #fff; color: #fff;
} }
.select_num_wrap {
width: 100vw;
height: 100vh;
position: relative;
.top_bg {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
.sn-bnottom {
width: 90vw;
border-radius: 20upx;
background-color: #fff;
position: absolute;
left: 5vw;
bottom: 20vw;
z-index: 2;
.sn-header {
height: 120upx;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #ececec;
padding: 0 28upx;
.t1 {
color: #333;
font-size: 32upx;
}
.t2 {
color: #999;
font-size: 28upx;
}
}
.sn-num-wrap {
padding: 38upx 28upx;
border-bottom: 1px solid #ececec;
.sn-num {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 14px;
.item {
height: 40px;
border-radius: 6px;
background-color: #fef4eb;
display: flex;
align-items: center;
justify-content: center;
&.active {
background-color: #e8ad7b;
.t {
color: #fff;
}
}
.t {
color: #333333;
font-size: 32upx;
}
}
}
.input {
display: flex;
padding-top: 28upx;
}
}
.sn-footer-wrap {
display: flex;
gap: 28upx;
padding: 28upx;
.btn {
flex: 1;
}
}
}
}
</style> </style>

View File

@@ -1,7 +1,7 @@
<template> <template>
<view class="container"> <view class="container">
<view class="header-wrap"> <view class="header-wrap">
<view class="u-flex" style="justify-content: flex-end;"> <view class="u-flex" style="justify-content: flex-end">
<view @click="toExchangeCode" class="color-333 font-12 u-m-b-26 font-700">优惠券兑换码</view> <view @click="toExchangeCode" class="color-333 font-12 u-m-b-26 font-700">优惠券兑换码</view>
</view> </view>
<view class="search-wrap"> <view class="search-wrap">
@@ -140,10 +140,10 @@ onReachBottom(() => {
getCouponList(); getCouponList();
} }
}); });
function toExchangeCode(){ function toExchangeCode() {
uni.navigateTo({ uni.navigateTo({
url: '/user/exchange/index' url: '/user/exchange/index'
}) });
} }
const showDetail = ref(false); const showDetail = ref(false);
const selectListItem = ref(''); const selectListItem = ref('');
@@ -223,7 +223,7 @@ async function getCouponList() {
userId: uni.cache.get('userInfo').id, userId: uni.cache.get('userInfo').id,
name: querForm.value.searchValue, name: querForm.value.searchValue,
status: statusList.value[querForm.value.statusActiveIndex].value, status: statusList.value[querForm.value.statusActiveIndex].value,
// shopId: querForm.value.shopId ? querForm.value.shopId : uni.cache.get('shopId'), shopId: querForm.value.shopId ? querForm.value.shopId : uni.cache.get('shopId'),
page: list.page, page: list.page,
size: list.size size: list.size
}); });
@@ -426,7 +426,7 @@ page {
} }
} }
.list-wrap { .list-wrap {
padding-top: 28upx; padding-top: 88upx;
.item { .item {
border-radius: 18upx; border-radius: 18upx;
background-color: #fff; background-color: #fff;

View File

@@ -15,9 +15,9 @@ export function desensitizePhone(phone) {
// 3. 脱敏前3位 + **** + 后4位 // 3. 脱敏前3位 + **** + 后4位
return purePhone.replace(/(\d{3})(\d{4})(\d{4})/, "$1****$3"); return purePhone.replace(/(\d{3})(\d{4})(\d{4})/, "$1****$3");
} }
/** /**
* 姓名合法性校验 * 姓名合法性校验
* @param {string} name - 待校验的姓名 * @param {string} name - 待校验的姓名
* @returns {Object} 校验结果:{ valid: boolean, msg: string } * @returns {Object} 校验结果:{ valid: boolean, msg: string }
@@ -25,13 +25,19 @@ export function desensitizePhone(phone) {
export function validateName(name) { export function validateName(name) {
// 1. 空值校验 // 1. 空值校验
if (!name || name.trim() === '') { if (!name || name.trim() === '') {
return { valid: false, msg: '姓名不能为空' }; return {
valid: false,
msg: '姓名不能为空'
};
} }
const pureName = name.trim(); const pureName = name.trim();
// 2. 长度校验2-6位含少数民族中间点 // 2. 长度校验2-6位含少数民族中间点
if (pureName.length < 2 || pureName.length > 6) { if (pureName.length < 2 || pureName.length > 6) {
return { valid: false, msg: '姓名长度应为2-6位' }; return {
valid: false,
msg: '姓名长度应为2-6位'
};
} }
// 3. 正则校验:仅允许中文、少数民族中间点(·),且中间点不能在开头/结尾 // 3. 正则校验:仅允许中文、少数民族中间点(·),且中间点不能在开头/结尾
@@ -46,11 +52,17 @@ export function validateName(name) {
// 4. 额外限制:中间点不能连续(如“李··四”) // 4. 额外限制:中间点不能连续(如“李··四”)
if (/[\u00b7]{2,}/.test(pureName)) { if (/[\u00b7]{2,}/.test(pureName)) {
return { valid: false, msg: '姓名中的中间点(·)不能连续' }; return {
valid: false,
msg: '姓名中的中间点(·)不能连续'
};
} }
// 校验通过 // 校验通过
return { valid: true, msg: '姓名格式合法' }; return {
valid: true,
msg: '姓名格式合法'
};
} }
/** /**
@@ -62,7 +74,10 @@ export function validateName(name) {
export function validateIdCard(idCard) { export function validateIdCard(idCard) {
// 1. 空值校验 // 1. 空值校验
if (!idCard || idCard.trim() === '') { if (!idCard || idCard.trim() === '') {
return { valid: false, msg: '身份证号码不能为空' }; return {
valid: false,
msg: '身份证号码不能为空'
};
} }
const pureIdCard = idCard.trim().toUpperCase(); // 统一转为大写处理X const pureIdCard = idCard.trim().toUpperCase(); // 统一转为大写处理X
@@ -95,11 +110,14 @@ export function validateIdCard(idCard) {
// 校验出生日期有效性如20230230 → 日期对象会是Invalid Date // 校验出生日期有效性如20230230 → 日期对象会是Invalid Date
if ( if (
isNaN(birthDate.getTime()) || isNaN(birthDate.getTime()) ||
birthDateStr.slice(0,4) !== birthDate.getFullYear().toString() || birthDateStr.slice(0, 4) !== birthDate.getFullYear().toString() ||
birthDateStr.slice(4,6) !== (birthDate.getMonth() + 1).toString().padStart(2, '0') || birthDateStr.slice(4, 6) !== (birthDate.getMonth() + 1).toString().padStart(2, '0') ||
birthDateStr.slice(6,8) !== birthDate.getDate().toString().padStart(2, '0') birthDateStr.slice(6, 8) !== birthDate.getDate().toString().padStart(2, '0')
) { ) {
return { valid: false, msg: '身份证中的出生日期无效' }; return {
valid: false,
msg: '身份证中的出生日期无效'
};
} }
// 4. 18位身份证额外校验校验码合法性加权算法 // 4. 18位身份证额外校验校验码合法性加权算法
@@ -117,7 +135,10 @@ export function validateIdCard(idCard) {
const expectedCheckCode = checkCodeMap[sum % 11]; const expectedCheckCode = checkCodeMap[sum % 11];
// 对比实际校验码(最后一位) // 对比实际校验码(最后一位)
if (pureIdCard[17] !== expectedCheckCode) { if (pureIdCard[17] !== expectedCheckCode) {
return { valid: false, msg: '身份证校验码错误,可能是无效身份证' }; return {
valid: false,
msg: '身份证校验码错误,可能是无效身份证'
};
} }
} }
@@ -141,3 +162,48 @@ export function validateIdCard(idCard) {
} }
}; };
} }
/**
* 过滤输入,只允许数字和最多两位小数
* @param {string} value - 输入框当前值
* @param {boolean} isIntegerOnly - 是否只允许正整数无小数点开启时最小值为1
* @returns {string} 过滤后的合法值
*/
export function filterNumberInput(value, isIntegerOnly = false) {
// 第一步就过滤所有非数字和非小数点的字符(包括字母)
let filtered = value.replace(/[^\d.]/g, "");
// 整数模式处理
if (isIntegerOnly !== false) {
// 移除所有小数点
filtered = filtered.replace(/\./g, "");
// 处理前导零
filtered = filtered.replace(/^0+(\d)/, "$1") || filtered;
// 空值处理(允许临时删除)
if (filtered === "") {
return "";
}
// 最小值限制
if (filtered === isIntegerOnly || parseInt(filtered, 10) < isIntegerOnly) {
return isIntegerOnly;
}
return filtered;
}
// 小数模式处理
const parts = filtered.split(".");
if (parts.length > 1) {
filtered = parts[0] + "." + (parts[1].substring(0, 2) || "");
}
// 处理前导零
if (filtered.startsWith("0") && filtered.length > 1 && !filtered.startsWith("0.")) {
filtered = filtered.replace(/^0+(\d)/, "$1");
}
return filtered;
}