This commit is contained in:
2025-06-13 17:46:05 +08:00
parent 6aa55bb786
commit 4b427a7ad7
3 changed files with 116 additions and 118 deletions

View File

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

View File

@@ -18,20 +18,6 @@
<uni-data-select v-model="index2" :localdata="options2" @change="selectChange2"></uni-data-select>
</view>
</view>
<view class="filter_item">
<view class="filter_label_wraper">
<span class="filter_label">子卷重量</span>
</view>
<view class="filter_input_wraper">
<!-- <input type="number" class="filter_input" v-model="val3"> -->
<number-input
v-model="numberValue"
:min="0"
:max="999.999"
input-class="filter_input"
/>
</view>
</view>
</view>
<view class="zd_wrapper grid-wraper">
<view class="slide_new">
@@ -86,7 +72,6 @@
},
data() {
return {
numberValue: 1,
// val3: '',
title: '',
top: 0,
@@ -111,7 +96,7 @@
/** 区域下拉框查询 */
async _queryProductArea () {
let res = await queryProductArea()
this.options1 = [...res.data]
this.options1 = [...res.rows]
},
selectChange1(e) {
this.index1 = e
@@ -124,7 +109,7 @@
/** 管芯规格下拉框 */
async _queryPaperMaterial (e) {
let res = await queryPaperMaterial(e)
this.options2 = [...res.data]
this.options2 = [...res.rows]
},
selectChange2(e) {
this.index2 = e

View File

@@ -30,30 +30,30 @@ export const allAuthority = () => {
]},
{menu_id: '5', path: 'RF03', title: '分切管理', sonTree: [
{menu_id: '1', title: '分切上料', path: '/pages/SecondPhase/slitting/SlittingFeeding'},
{menu_id: '6', title: '分切下料', path: '/pages/SecondPhase/slitting/SlittingCutting'},
// {menu_id: '6', title: '分切下料', path: '/pages/SecondPhase/slitting/SlittingCutting'},
{menu_id: '6', title: '分切下料2', path: '/pages/SecondPhase/slitting/SlittingCutting2'},
{menu_id: '2', title: '空轴套管', path: '/pages/SecondPhase/slitting/ZjCasing'},
{menu_id: '3', title: '空轴配送', path: '/pages/SecondPhase/slitting/ZjDelivery'},
{menu_id: '4', title: '空轴进站', path: '/pages/SecondPhase/slitting/ZjInStore'},
{menu_id: '5', title: '子卷出站', path: '/pages/SecondPhase/slitting/ZjOutStore'},
// {menu_id: '2', title: '空轴套管', path: '/pages/SecondPhase/slitting/ZjCasing'},
// {menu_id: '3', title: '空轴配送', path: '/pages/SecondPhase/slitting/ZjDelivery'},
// {menu_id: '4', title: '空轴进站', path: '/pages/SecondPhase/slitting/ZjInStore'},
// {menu_id: '5', title: '子卷出站', path: '/pages/SecondPhase/slitting/ZjOutStore'},
{menu_id: '7', title: '穿拔轴初始化', path: '/pages/SecondPhase/slitting/DoInitShaft'},
{menu_id: '8', title: '纸管绑定', path: '/pages/SecondPhase/slitting/PaperBind'},
{menu_id: '8', title: '分切暂存下料', path: '/pages/SecondPhase/slitting/CacheCut'},
{menu_id: '8', title: '分切暂存清除', path: '/pages/SecondPhase/slitting/CacheClean'},
{menu_id: '8', title: '分切暂存管理', path: '/pages/SecondPhase/slitting/CacheClean'},
{menu_id: '8', title: '气胀轴库维护', path: '/pages/SecondPhase/slitting/ShaftSave'},
{menu_id: '8', title: '分切子卷维护', path: '/pages/SecondPhase/slitting/ZjSave'},
{menu_id: '8', title: '备货区管理', path: '/pages/SecondPhase/slitting/StockingArea'},
{menu_id: '8', title: 'AGV放行', path: '/pages/SecondPhase/slitting/AGVPass'},
{menu_id: '8', title: '子卷重维护', path: '/pages/SecondPhase/slitting/SubRollWeight'},
{menu_id: '8', title: '子卷重维护', path: '/pages/SecondPhase/slitting/SubRollWeight'},
{menu_id: '8', title: '分切上轴', path: '/pages/SecondPhase/slitting/UpperShaftCut'},
{menu_id: '8', title: '分切上轴2', path: '/pages/SecondPhase/slitting/UpperShaftCut2'},
// {menu_id: '8', title: '分切上轴2', path: '/pages/SecondPhase/slitting/UpperShaftCut2'},
{menu_id: '8', title: '分切呼叫送轴', path: '/pages/SecondPhase/slitting/CallShaft'},
{menu_id: '8', title: '人工呼叫套轴顺序', path: '/pages/SecondPhase/slitting/CallAxisSeq'},
{menu_id: '8', title: '母卷暂存管理', path: '/pages/SecondPhase/slitting/RollCacheManage'},
// {menu_id: '8', title: '人工呼叫套轴顺序', path: '/pages/SecondPhase/slitting/CallAxisSeq'},
{menu_id: '8', title: '分切上料架管理', path: '/pages/SecondPhase/slitting/RollCacheManage'},
{menu_id: '8', title: '饵料下卷', path: '/pages/SecondPhase/slitting/BaitRoll'},
{menu_id: '8', title: '空轴绑定', path: '/pages/SecondPhase/slitting/EmptyAxisBind'},
// {menu_id: '8', title: '空轴绑定', path: '/pages/SecondPhase/slitting/EmptyAxisBind'},
{menu_id: '8', title: '空轴退回', path: '/pages/SecondPhase/slitting/EmptyAxisReturn'},
{menu_id: '8', title: '分切暂存维护', path: '/pages/SecondPhase/slitting/CacheSave'},
// {menu_id: '8', title: '分切暂存维护', path: '/pages/SecondPhase/slitting/CacheSave'},
{menu_id: '8', title: '管芯备货', path: '/pages/SecondPhase/slitting/TubeStock'}
]},
{menu_id: '10', path: 'RF15', title: '打包间管理', sonTree: [