This commit is contained in:
2025-06-13 17:58:39 +08:00
parent facb9e5928
commit 9c346b6530
10 changed files with 229 additions and 118 deletions

View File

@@ -1,12 +1,10 @@
<template> <template>
<input <input
type="text" type="number"
:value="displayValue" :value="displayValue"
@input="handleInput" @input="handleInput"
@blur="handleBlur" @blur="handleBlur"
:placeholder="placeholder"
:class="inputClass" :class="inputClass"
:style="inputStyle"
/> />
</template> </template>
@@ -14,109 +12,124 @@
export default { export default {
name: "NumberInput", name: "NumberInput",
props: { props: {
value: { value: [Number, String],
type: [Number, String],
default: ''
},
min: {
type: Number,
default: 0.001
},
max: {
type: Number,
default: 100000
},
placeholder: {
type: String,
default: '请输入大于0的数字'
},
inputClass: { inputClass: {
type: String, type: String,
default: '' default: ''
}, },
inputStyle: { // 输入模式integer(纯整数), decimal(纯小数), mixed(混合)
mode: {
type: String, type: String,
default: '' default: "mixed",
} validator: (v) => ["integer", "decimal", "mixed"].includes(v),
},
// 小数位数限制
decimalLength: {
type: Number,
default: 2,
},
// 最小值
min: {
type: Number,
default: 0,
},
// 最大值
max: {
type: Number,
default: Infinity,
},
}, },
data() { data() {
return { return {
displayValue: this.value.toString() displayValue: this.value?.toString() || "",
}; };
}, },
watch: { watch: {
value(newVal) { value(newVal) {
// 当外部value变化时更新显示值 this.displayValue = newVal?.toString() || "";
this.displayValue = newVal.toString(); },
}
}, },
methods: { methods: {
handleInput(e) { handleInput(e) {
const rawValue = e.detail.value; let value = e.detail.value;
let filtered = rawValue
// 移除非数字和小数点的字符
.replace(/[^\d.]/g, '')
// 只保留第一个小数点
.replace(/(\.+)/g, '.')
.replace(/(\..*)\./g, '$1')
// 避免以0开头0后面没有小数点的情况
.replace(/^0+(\d)/, '$1');
// 处理开头是小数点的情况添加0前缀 // 1. 过滤非法字符
if (filtered.startsWith('.')) { let filtered = value.replace(/[^\d.]/g, "");
filtered = '0' + filtered;
// 2. 处理多余的小数点
if (this.mode === "integer") {
filtered = filtered.replace(/\./g, ""); // 整数模式删除所有小数点
} else {
const firstDotIndex = filtered.indexOf(".");
if (firstDotIndex !== -1) {
// 只保留第一个小数点
filtered =
filtered.substring(0, firstDotIndex + 1) +
filtered.substring(firstDotIndex + 1).replace(/\./g, "");
}
}
// 3. 处理前导0
if (filtered.startsWith("0") && filtered.length > 1 && !filtered.startsWith("0.")) {
filtered = filtered.replace(/^0+/, "0").replace(/^0([^.])/, "$1");
}
// 4. 处理开头的小数点
if (filtered.startsWith(".")) {
if (this.mode === "integer") {
filtered = "";
} else {
filtered = "0" + filtered;
}
} }
this.displayValue = filtered; this.displayValue = filtered;
this.$emit('input', filtered);
}, },
handleBlur() { handleBlur() {
let finalValue = this.displayValue; let value = this.displayValue;
// 空值处理 // 空值处理
if (!finalValue) { if (value === "" || value === ".") {
finalValue = this.min.toString(); this.$emit("input", "");
return;
} }
// 处理以小数点结尾的情况 // 处理结尾的小数点
if (finalValue.endsWith('.')) { if (value.endsWith(".")) {
finalValue = finalValue.slice(0, -1); value = value.slice(0, -1);
} }
// 转换为数字 // 转换为数字
let numValue = parseFloat(finalValue); const numValue = Number(value);
// 验证数字有效性 // 小数位数处理
if (isNaN(numValue)) { let processedValue = value;
numValue = this.min; if (this.mode !== "integer" && value.includes(".")) {
} const parts = value.split(".");
if (parts[1].length > this.decimalLength) {
// 边界校验 processedValue = `${parts[0]}.${parts[1].slice(0, this.decimalLength)}`;
if (numValue <= 0) {
numValue = this.min;
} else if (numValue > this.max) {
numValue = this.max;
} else if (numValue < this.min) {
numValue = this.min;
}
// 小数位处理最多3位
const numStr = numValue.toString();
const decimalIndex = numStr.indexOf('.');
if (decimalIndex !== -1) {
const decimalPart = numStr.slice(decimalIndex + 1);
if (decimalPart.length > 3) {
// 直接截断而非四舍五入
numValue = parseFloat(numStr.substring(0, decimalIndex + 4));
} }
} }
// 更新显示值并通知父组件 // 范围校验
this.displayValue = numValue.toString(); let finalNum = Number(processedValue);
this.$emit('input', numValue); if (finalNum < this.min) finalNum = this.min;
this.$emit('change', numValue); if (finalNum > this.max) finalNum = this.max;
}
} // 更新值
} this.displayValue = finalNum.toString();
this.$emit("input", finalNum);
},
},
};
</script> </script>
<style scoped>
.number-input {
border: 1px solid #ddd;
padding: 8px 12px;
border-radius: 4px;
font-size: 14px;
}
</style>

View File

@@ -23,13 +23,24 @@
<view class="filter_item"> <view class="filter_item">
<view class="filter_label">温度</view> <view class="filter_label">温度</view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="text" class="filter_input" v-model="val3"> <!-- <input type="text" class="filter_input" v-model="val3"> -->
<NumberInput
v-model="val3"
input-class="filter_input"
mode="mixed"
:decimalLength="3"
/>
</view> </view>
</view> </view>
<view class="filter_item"> <view class="filter_item">
<view class="filter_label">时间</view> <view class="filter_label">时间</view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="text" class="filter_input" v-model="val4"> <!-- <input type="text" class="filter_input" v-model="val4"> -->
<NumberInput
v-model="val4"
input-class="filter_input"
mode="integer"
/>
</view> </view>
</view> </view>
</view> </view>
@@ -46,11 +57,13 @@
<script> <script>
import NavBar from '@/components/NavBar.vue' import NavBar from '@/components/NavBar.vue'
import SearchBox from '@/components/SearchBox.vue' import SearchBox from '@/components/SearchBox.vue'
import NumberInput from '@/components/NumberInput.vue'
import {ovenInAndOut, inCoolIvt, bakingrelease, bakingquery} from '@/utils/getData1.js' import {ovenInAndOut, inCoolIvt, bakingrelease, bakingquery} from '@/utils/getData1.js'
export default { export default {
components: { components: {
NavBar, NavBar,
SearchBox SearchBox,
NumberInput
}, },
data() { data() {
return { return {

View File

@@ -49,7 +49,12 @@
<view class="filter_item"> <view class="filter_item">
<view class="filter_label">数量</view> <view class="filter_label">数量</view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="number" class="filter_input" v-model="qty"> <!-- <input type="number" class="filter_input" v-model="qty"> -->
<NumberInput
v-model="qty"
input-class="filter_input"
mode="integer"
/>
</view> </view>
</view> </view>
</view> </view>
@@ -65,12 +70,14 @@
<script> <script>
import NavBar from '@/components/NavBar.vue' import NavBar from '@/components/NavBar.vue'
import SearchBox from '@/components/SearchBox.vue' import SearchBox from '@/components/SearchBox.vue'
import NumberInput from '@/components/NumberInput.vue'
import {queryProductArea, queryDeviceByarea} from '@/utils/getData2.js' import {queryProductArea, queryDeviceByarea} from '@/utils/getData2.js'
import {paperQueryPaperMaterial, callPaperShaft, labourShaftBack} from '@/utils/getData3.js' import {paperQueryPaperMaterial, callPaperShaft, labourShaftBack} from '@/utils/getData3.js'
export default { export default {
components: { components: {
NavBar, NavBar,
SearchBox SearchBox,
NumberInput
}, },
data() { data() {
return { return {

View File

@@ -23,13 +23,24 @@
<view class="filter_item"> <view class="filter_item">
<view class="filter_label">温度</view> <view class="filter_label">温度</view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="text" class="filter_input" v-model="val3"> <!-- <input type="text" class="filter_input" v-model="val3"> -->
<NumberInput
v-model="val3"
input-class="filter_input"
mode="mixed"
:decimalLength="3"
/>
</view> </view>
</view> </view>
<view class="filter_item"> <view class="filter_item">
<view class="filter_label">时间</view> <view class="filter_label">时间</view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="text" class="filter_input" v-model="val4"> <!-- <input type="text" class="filter_input" v-model="val4"> -->
<NumberInput
v-model="val4"
input-class="filter_input"
mode="integer"
/>
</view> </view>
</view> </view>
<view class="filter_item"> <view class="filter_item">
@@ -53,11 +64,13 @@
<script> <script>
import NavBar from '@/components/NavBar.vue' import NavBar from '@/components/NavBar.vue'
import SearchBox from '@/components/SearchBox.vue' import SearchBox from '@/components/SearchBox.vue'
import NumberInput from '@/components/NumberInput.vue'
import {handleBakingovenInAndOut, handleBakingcheckConfirm, bakingquery} from '@/utils/getData1.js' import {handleBakingovenInAndOut, handleBakingcheckConfirm, bakingquery} from '@/utils/getData1.js'
export default { export default {
components: { components: {
NavBar, NavBar,
SearchBox SearchBox,
NumberInput
}, },
data() { data() {
return { return {

View File

@@ -40,7 +40,13 @@
</view> </view>
<view class="relative filter_input_wraper"> <view class="relative filter_input_wraper">
<view class="absolute filter_tip">B2车间需要输入温度</view> <view class="absolute filter_tip">B2车间需要输入温度</view>
<input type="number" class="filter_input" v-model="val3"> <!-- <input type="number" class="filter_input" v-model="val3"> -->
<NumberInput
v-model="val3"
input-class="filter_input"
mode="mixed"
:decimalLength="3"
/>
</view> </view>
<view class="filter_unit"></view> <view class="filter_unit"></view>
</view> </view>
@@ -50,7 +56,12 @@
</view> </view>
<view class="relative filter_input_wraper"> <view class="relative filter_input_wraper">
<view class="absolute filter_tip">B2车间需要输入时间</view> <view class="absolute filter_tip">B2车间需要输入时间</view>
<input type="number" class="filter_input" v-model="val4"> <!-- <input type="number" class="filter_input" v-model="val4"> -->
<NumberInput
v-model="val4"
input-class="filter_input"
mode="integer"
/>
</view> </view>
<view class="filter_unit">小时</view> <view class="filter_unit">小时</view>
</view> </view>
@@ -109,11 +120,13 @@
<script> <script>
import NavBar from '@/components/NavBar.vue' import NavBar from '@/components/NavBar.vue'
import SearchBox from '@/components/SearchBox.vue' import SearchBox from '@/components/SearchBox.vue'
import NumberInput from '@/components/NumberInput.vue'
import {queryRawFoilList, needEmptyAxis, needEmptyVehicle, confirmBlanking, finishBlanking, finish} from '@/utils/getData1.js' import {queryRawFoilList, needEmptyAxis, needEmptyVehicle, confirmBlanking, finishBlanking, finish} from '@/utils/getData1.js'
export default { export default {
components: { components: {
NavBar, NavBar,
SearchBox SearchBox,
NumberInput
}, },
data() { data() {
return { return {

View File

@@ -23,13 +23,24 @@
<view class="filter_item"> <view class="filter_item">
<view class="filter_label">温度</view> <view class="filter_label">温度</view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="text" class="filter_input" v-model="val3"> <!-- <input type="text" class="filter_input" v-model="val3"> -->
<NumberInput
v-model="val3"
input-class="filter_input"
mode="mixed"
:decimalLength="3"
/>
</view> </view>
</view> </view>
<view class="filter_item"> <view class="filter_item">
<view class="filter_label">时间</view> <view class="filter_label">时间</view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="text" class="filter_input" v-model="val4"> <!-- <input type="text" class="filter_input" v-model="val4"> -->
<NumberInput
v-model="val4"
input-class="filter_input"
mode="integer"
/>
</view> </view>
</view> </view>
</view> </view>
@@ -46,11 +57,13 @@
<script> <script>
import NavBar from '@/components/NavBar.vue' import NavBar from '@/components/NavBar.vue'
import SearchBox from '@/components/SearchBox.vue' import SearchBox from '@/components/SearchBox.vue'
import NumberInput from '@/components/NumberInput.vue'
import {ovenInAndOut, inCoolIvt, bakingrelease, bakingquery} from '@/utils/getData1.js' import {ovenInAndOut, inCoolIvt, bakingrelease, bakingquery} from '@/utils/getData1.js'
export default { export default {
components: { components: {
NavBar, NavBar,
SearchBox SearchBox,
NumberInput
}, },
data() { data() {
return { return {

View File

@@ -23,13 +23,24 @@
<view class="filter_item"> <view class="filter_item">
<view class="filter_label">温度</view> <view class="filter_label">温度</view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="text" class="filter_input" v-model="val3"> <!-- <input type="text" class="filter_input" v-model="val3"> -->
<NumberInput
v-model="val3"
input-class="filter_input"
mode="mixed"
:decimalLength="3"
/>
</view> </view>
</view> </view>
<view class="filter_item"> <view class="filter_item">
<view class="filter_label">时间</view> <view class="filter_label">时间</view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="text" class="filter_input" v-model="val4"> <!-- <input type="text" class="filter_input" v-model="val4"> -->
<NumberInput
v-model="val4"
input-class="filter_input"
mode="integer"
/>
</view> </view>
</view> </view>
<view class="filter_item"> <view class="filter_item">
@@ -53,11 +64,13 @@
<script> <script>
import NavBar from '@/components/NavBar.vue' import NavBar from '@/components/NavBar.vue'
import SearchBox from '@/components/SearchBox.vue' import SearchBox from '@/components/SearchBox.vue'
import NumberInput from '@/components/NumberInput.vue'
import {handleBakingovenInAndOut, handleBakingcheckConfirm, bakingquery} from '@/utils/getData1.js' import {handleBakingovenInAndOut, handleBakingcheckConfirm, bakingquery} from '@/utils/getData1.js'
export default { export default {
components: { components: {
NavBar, NavBar,
SearchBox SearchBox,
NumberInput
}, },
data() { data() {
return { return {

View File

@@ -31,7 +31,7 @@
<span class="filter_label">数量</span> <span class="filter_label">数量</span>
</view> </view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="number" class="filter_input" v-model="val2"> <uni-data-select v-model="index2" :localdata="options2" @change="selectChange2"></uni-data-select>
</view> </view>
</view> </view>
<view class="filter_item"> <view class="filter_item">
@@ -44,8 +44,8 @@
</view> </view>
<view class="zd-row submitbar"> <view class="zd-row submitbar">
<button class="zd-col-5 btn-submit btn-default" @tap="clearUp">清空</button> <button class="zd-col-5 btn-submit btn-default" @tap="clearUp">清空</button>
<button class="zd-col-8 btn-submit btn-success" :class="{'btn-info': !val1 || !val2 || !index || !index1 || !val3}" :disabled="disabled" @tap="_operateIvt('1')">绑定</button> <button class="zd-col-8 btn-submit btn-success" :class="{'btn-info': !val1 || !index2 || !index || !index1 || !val3}" :disabled="disabled" @tap="_operateIvt('1')">绑定</button>
<button class="zd-col-8 btn-submit btn-success" :class="{'btn-info': !val1 || !val2 || !index || !index1 || !val3}" :disabled="disabled" @tap="_operateIvt('2')">清除</button> <button class="zd-col-8 btn-submit btn-success" :class="{'btn-info': !val1 || !index2 || !index || !index1 || !val3}" :disabled="disabled" @tap="_operateIvt('2')">清除</button>
</view> </view>
</view> </view>
</template> </template>
@@ -66,8 +66,9 @@
val1: '', val1: '',
val3: '', val3: '',
options1: [{value: '1', text: '1'}, {value: '2', text: '2'}, {value: '3', text: '3'}, {value: '4', text: '4'}, {value: '5', text: '5'}], options1: [{value: '1', text: '1'}, {value: '2', text: '2'}, {value: '3', text: '3'}, {value: '4', text: '4'}, {value: '5', text: '5'}],
options2: [{value: '1', text: '1'}, {value: '2', text: '2'}, {value: '3', text: '3'}, {value: '4', text: '4'}, {value: '5', text: '5'}],
index1: '', index1: '',
val2: '', index2: '',
options: [], options: [],
index: '', index: '',
newoptions: [], newoptions: [],
@@ -91,6 +92,9 @@
selectChange1 (e) { selectChange1 (e) {
this.index1 = e this.index1 = e
}, },
selectChange2 (e) {
this.index2 = e
},
selectChange (e) { selectChange (e) {
this.index = e this.index = e
}, },
@@ -117,12 +121,12 @@
}, },
async _operateIvt (type) { async _operateIvt (type) {
this.disabled = true this.disabled = true
if (!this.val1 || !this.val2 || !this.index || !this.index1 || !this.val3) { if (!this.val1 || !this.index2 || !this.index || !this.index1 || !this.val3) {
this.disabled = false this.disabled = false
return return
} }
try { try {
let res = await operateIvt(type, this.val1, this.index1, this.val2, this.index, this.val3) let res = await operateIvt(type, this.val1, this.index1, this.index2, this.index, this.val3)
uni.showToast({ uni.showToast({
title: res.message, title: res.message,
icon: 'none' icon: 'none'
@@ -136,7 +140,7 @@
clearUp () { clearUp () {
this.val1 = '' this.val1 = ''
this.val3 = '' this.val3 = ''
this.val2 = '' this.index2 = ''
this.index = '' this.index = ''
this.index1 = '' this.index1 = ''
} }

View File

@@ -17,7 +17,13 @@
<span class="filter_label">管芯重量</span> <span class="filter_label">管芯重量</span>
</view> </view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="number" class="filter_input" v-model="val2"> <!-- <input type="number" class="filter_input" v-model="val2"> -->
<NumberInput
v-model="val2"
input-class="filter_input"
mode="decimal"
:decimalLength="3"
/>
</view> </view>
</view> </view>
<view class="filter_item"> <view class="filter_item">
@@ -25,7 +31,13 @@
<span class="filter_label">子卷重量</span> <span class="filter_label">子卷重量</span>
</view> </view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="number" class="filter_input" v-model="val3"> <!-- <input type="number" class="filter_input" v-model="val3"> -->
<NumberInput
v-model="val3"
input-class="filter_input"
mode="decimal"
:decimalLength="3"
/>
</view> </view>
</view> </view>
<view class="msg_item">提示{{obj.tip}}</view> <view class="msg_item">提示{{obj.tip}}</view>
@@ -41,11 +53,13 @@
<script> <script>
import NavBar from '@/components/NavBar.vue' import NavBar from '@/components/NavBar.vue'
import SearchBox from '@/components/SearchBox.vue' import SearchBox from '@/components/SearchBox.vue'
import NumberInput from '@/components/NumberInput.vue'
import {doSubRollWeightBindingTip, doSubRollWeightBinding} from '@/utils/getData3.js' import {doSubRollWeightBindingTip, doSubRollWeightBinding} from '@/utils/getData3.js'
export default { export default {
components: { components: {
NavBar, NavBar,
SearchBox SearchBox,
NumberInput
}, },
data() { data() {
return { return {

View File

@@ -27,7 +27,13 @@
<view class="filter_item"> <view class="filter_item">
<view class="filter_label">重量</view> <view class="filter_label">重量</view>
<view class="filter_input_wraper"> <view class="filter_input_wraper">
<input type="number" class="filter_input" v-model="val3"> <!-- <input type="number" class="filter_input" v-model="val3"> -->
<NumberInput
v-model="val3"
input-class="filter_input"
mode="decimal"
:decimalLength="3"
/>
</view> </view>
</view> </view>
</view> </view>
@@ -42,11 +48,13 @@
<script> <script>
import NavBar from '@/components/NavBar.vue' import NavBar from '@/components/NavBar.vue'
import SearchBox from '@/components/SearchBox.vue' import SearchBox from '@/components/SearchBox.vue'
import NumberInput from '@/components/NumberInput.vue'
import {mendCode, stBale} from '@/utils/getData2.js' import {mendCode, stBale} from '@/utils/getData2.js'
export default { export default {
components: { components: {
NavBar, NavBar,
SearchBox SearchBox,
NumberInput
}, },
data() { data() {
return { return {