From 0f571eabc8e9cbbac143c8acaafa62d50fbc0a51 Mon Sep 17 00:00:00 2001 From: bb_pan Date: Fri, 19 Dec 2025 11:26:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/bonus.js | 30 +++++++++++++++++++ .../equipmentInput/add.vue | 10 ++++--- .../equipmentInput/index.vue | 13 ++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/utils/bonus.js b/src/utils/bonus.js index 65d3883c..cf7b87d1 100644 --- a/src/utils/bonus.js +++ b/src/utils/bonus.js @@ -315,3 +315,33 @@ export async function downloadPDF(options) { modal?.closeLoading?.() } } + +/** + * 正数输入处理 + * @param {string | number} value 输入值 + * @param {number} decimal 最多保留的小数位,默认不限制 + */ +export function handlePositiveNumberInput(value, decimal = Infinity) { + let val = String(value ?? '') + + // 1️⃣ 只保留数字和 . + val = val.replace(/[^\d.]/g, '') + + // 2️⃣ 只保留第一个小数点 + const dotIndex = val.indexOf('.') + if (dotIndex !== -1) { + val = val.slice(0, dotIndex + 1) + val.slice(dotIndex + 1).replace(/\./g, '') + } + + // 3️⃣ 限制小数位数(可配置) + if (dotIndex !== -1 && Number.isFinite(decimal)) { + val = val.slice(0, dotIndex + decimal + 1) + } + + // 4️⃣ ".5" → "0.5" + if (val.startsWith('.')) { + val = '0' + val + } + + return val +} diff --git a/src/views/EquipmentEntryApply/equipmentInput/add.vue b/src/views/EquipmentEntryApply/equipmentInput/add.vue index 28942a14..af02b331 100644 --- a/src/views/EquipmentEntryApply/equipmentInput/add.vue +++ b/src/views/EquipmentEntryApply/equipmentInput/add.vue @@ -344,6 +344,7 @@ import { import { getManufacturerSelectApi } from '@/api/EquipmentLedger/index.js' import ImageUpload from '@/components/ImageUpload' import FileUpload from '@/components/FileImageUpload' +import { handlePositiveNumberInput } from '@/utils/bonus.js' export default { name: 'EquipmentEntryEditDialog', // 明确组件名称 @@ -536,10 +537,11 @@ export default { }, // 价格输入处理 handlePriceInput(v) { - this.form.originalValue = this.form.originalValue - .replace(/[^\d.]/g, '') // 删除所有非数字和点 - .replace(/\.{2,}/g, '.') // 多个点 -> 单点 - .replace(/^(\d+)\.(.*)\./, '$1.$2'); // 只允许一个点 + this.form.originalValue = handlePositiveNumberInput(this.form.originalValue) + // this.form.originalValue = this.form.originalValue + // .replace(/[^\d.]/g, '') // 删除所有非数字和点 + // .replace(/\.{2,}/g, '.') // 多个点 -> 单点 + // .replace(/^(\d+)\.(.*)\./, '$1.$2'); // 只允许一个点 }, // 处理图片上传变化 handleImageChange(files) { diff --git a/src/views/EquipmentEntryApproval/equipmentInput/index.vue b/src/views/EquipmentEntryApproval/equipmentInput/index.vue index 9433eb14..98ed1c9d 100644 --- a/src/views/EquipmentEntryApproval/equipmentInput/index.vue +++ b/src/views/EquipmentEntryApproval/equipmentInput/index.vue @@ -116,6 +116,7 @@ style="width: 105px" placeholder="请输入" v-model.trim="queryParams.minBuyPrice" + @input="handleNumber('min')" /> @@ -125,6 +126,7 @@ style="width: 105px" placeholder="请输入" v-model.trim="queryParams.maxBuyPrice" + @change="handleNumber('max')" /> @@ -304,6 +306,7 @@ import { equipmentPassAndRejectApiNew } from '@/api/EquipmentEntryApply/index' import { getManufacturerSelectApi } from '@/api/EquipmentLedger/index.js' +import { handlePositiveNumberInput } from '@/utils/bonus' export default { name: 'EquipmentDetailList', @@ -384,6 +387,16 @@ export default { } }) }, + handleNumber(key) { + if (key === 'min') { + this.queryParams.minBuyPrice = handlePositiveNumberInput(this.queryParams.minBuyPrice) + } else if (key === 'max') { + this.queryParams.maxBuyPrice = handlePositiveNumberInput(this.queryParams.maxBuyPrice) + } + if (Number(this.queryParams.minBuyPrice) > Number(this.queryParams.maxBuyPrice) && this.queryParams.maxBuyPrice) { + this.queryParams.minBuyPrice = this.queryParams.maxBuyPrice + } + }, /** * 获取装备申请列表 */