From 505c41b4fc4a391d1f5f1904e31764f9d8156099 Mon Sep 17 00:00:00 2001
From: luojie <125330818@qq.com>
Date: Mon, 5 Jan 2026 19:42:41 +0800
Subject: [PATCH] =?UTF-8?q?feat:[=E6=A8=A1=E6=9D=BF=E7=AE=A1=E7=90=86][?=
=?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=8A=BD=E7=A6=BBing]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/Template/BaseInfoFormPcakge.vue | 4 -
src/components/Template/CustomTable.vue | 8 +-
src/components/Template/DecimalInput.vue | 89 ++++++++++------------
.../comps/template/comps/sp/SWYPBQGZYZBB.vue | 2 +-
.../comps/template/comps/sp/SWYPFXCBYPZB.vue | 2 +-
.../comps/template/comps/sp/SWYPFXRYPZB.vue | 2 +-
.../comps/template/mixins/templateMixin.js | 14 ++--
7 files changed, 55 insertions(+), 66 deletions(-)
diff --git a/src/components/Template/BaseInfoFormPcakge.vue b/src/components/Template/BaseInfoFormPcakge.vue
index dcabe6c..c67a8fa 100644
--- a/src/components/Template/BaseInfoFormPcakge.vue
+++ b/src/components/Template/BaseInfoFormPcakge.vue
@@ -182,10 +182,6 @@ export default {
return typeObj[type] || ""
},
onInputNumberChange(key, val){
- if(val === 0){
- this.formFields[key] = null;
- return;
- }
this.formFields[key] = val;
},
updateFormData(key, value){
diff --git a/src/components/Template/CustomTable.vue b/src/components/Template/CustomTable.vue
index ee5de5a..4465a80 100644
--- a/src/components/Template/CustomTable.vue
+++ b/src/components/Template/CustomTable.vue
@@ -44,7 +44,7 @@
-
@@ -262,7 +262,8 @@ export default {
options: col.bodySubOptions,
maxlength: col.bodySubMaxlength || 10,
label: "",
- placeholder:col.bodySubPlaceholder||"请输入"
+ placeholder:col.bodySubPlaceholder||"请输入",
+ precision: col.subPrecision || 0,
}
if(col.bodySubDisabled){
item.disabled = col.bodySubDisabled;
@@ -285,6 +286,9 @@ export default {
console.log(this.localDataSource,"this.localDataSource")
this.localDataSource = [...this.localDataSource];
},
+ onSubBlur(rowIndex, colKey, value) {
+ this.$emit("blur", {rowIndex, colKey, value,item:this.localDataSource[rowIndex]});
+ },
onBlur(rowIndex, colKey) {
const value = this.localDataSource[rowIndex][colKey];
this.$emit("blur", {rowIndex, colKey, value,item:this.localDataSource[rowIndex]});
diff --git a/src/components/Template/DecimalInput.vue b/src/components/Template/DecimalInput.vue
index f060d92..f989be1 100644
--- a/src/components/Template/DecimalInput.vue
+++ b/src/components/Template/DecimalInput.vue
@@ -1,5 +1,6 @@
-
+
{{ prepend }}
@@ -40,6 +41,7 @@ export default {
watch: {
value(newVal) {
// 外部值变化时同步到内部(但不做格式化,避免干扰用户输入)
+ console.log(newVal,"newVal")
if (newVal === '' || newVal == null) {
this.internalValue = '';
} else {
@@ -49,85 +51,72 @@ export default {
},
methods: {
handleInput(val) {
+ console.log(val,"val")
if (val === '') {
this.internalValue = '';
this.$emit('input', '');
return;
}
- // 1. 清除非合法字符(只保留数字、小数点、开头的负号)
+ // 1. 只保留数字、小数点、开头的负号
let cleaned = val
.replace(/[^\d.-]/g, '')
- .replace(/^(-)\1+/, '$1'); // 只允许一个开头的负号
+ .replace(/^(-)\1+/, '$1'); // 合并多个负号
- // 2. 处理多个小数点:只保留第一个
- const dotIndex = cleaned.indexOf('.');
- if (dotIndex !== -1) {
- const beforeDot = cleaned.slice(0, dotIndex);
- const afterDot = cleaned.slice(dotIndex + 1).replace(/\./g, ''); // 移除后面所有小数点
- cleaned = beforeDot + '.' + afterDot;
+ // 2. 只保留第一个小数点
+ const firstDotIndex = cleaned.indexOf('.');
+ if (firstDotIndex !== -1) {
+ const before = cleaned.slice(0, firstDotIndex);
+ const after = cleaned.slice(firstDotIndex + 1).replace(/\./g, '');
+ cleaned = before + '.' + after;
}
- // 3. 限制小数位数(仅当有小数点时)
+ // 3. 限制小数位数(仅当允许小数时)
if (this.decimalDigits > 0 && cleaned.includes('.')) {
- const parts = cleaned.split('.');
- let integerPart = parts[0];
- let decimalPart = parts[1] || '';
-
- // 限制小数位长度
- if (decimalPart.length > this.decimalDigits) {
- decimalPart = decimalPart.slice(0, this.decimalDigits);
- }
-
- // 关键修复:即使 decimalPart 为空(如 "1."),也要保留小数点!
- cleaned = integerPart + '.' + decimalPart;
+ const [intPart, decPart = ''] = cleaned.split('.');
+ cleaned = intPart + '.' + decPart.slice(0, this.decimalDigits);
} else if (this.decimalDigits === 0) {
- // 不允许小数,移除小数点及之后内容
- cleaned = cleaned.split('.')[0];
+ cleaned = cleaned.split('.')[0]; // 移除小数部分
}
- // 4. 处理以 . 或 -. 开头的情况
- if (cleaned === '.') {
- cleaned = '0.';
- } else if (cleaned === '-.') {
- cleaned = '-0.';
- } else if (cleaned.startsWith('.')) {
- cleaned = '0' + cleaned;
- } else if (cleaned.startsWith('-.')) {
- cleaned = '-0.' + cleaned.slice(2);
- }
+ // 4. 处理以 . 或 -. 开头
+ if (cleaned === '.') cleaned = '0.';
+ else if (cleaned === '-.') cleaned = '-0.';
+ else if (cleaned.startsWith('.')) cleaned = '0' + cleaned;
+ else if (cleaned.startsWith('-.')) cleaned = '-0.' + cleaned.slice(2);
- // 5. 去掉整数部分的前导零(但保留单个 0 或负数中的 -0)
+ // 5. 【关键】安全去除前导零,但保留单个 0
if (cleaned.includes('.')) {
- // 有小数点时,整数部分可以是 0 或 -0
- const parts = cleaned.split('.');
- let intPart = parts[0];
- if (intPart === '' || intPart === '-') {
- intPart = intPart + '0';
- } else if (/^-?0+\d/.test(intPart)) {
- // 如 -0012 → -12,0012 → 12
- intPart = intPart.replace(/^-?0+(\d)/, '$1');
+ // 有小数点:处理整数部分
+ const [int, dec] = cleaned.split('.');
+ // 整数部分:-0012 → -12,00 → 0,0 → 0,-0 → 0(或保留 -0)
+ let newInt = int;
+ if (/^-?0+\d/.test(int)) {
+ newInt = int.replace(/^-?0+(\d)/, '$1');
+ } else if (int === '' || int === '-') {
+ newInt = int + '0';
+ } else if (int === '00' || /^-00+$/.test(int)) {
+ newInt = int.startsWith('-') ? '-0' : '0';
}
- cleaned = intPart + '.' + parts[1];
+ cleaned = newInt + '.' + dec;
} else {
// 无小数点
if (/^-?0+\d/.test(cleaned)) {
cleaned = cleaned.replace(/^-?0+(\d)/, '$1');
+ } else if (cleaned === '00' || /^-00+$/.test(cleaned)) {
+ cleaned = cleaned.startsWith('-') ? '-0' : '0';
}
+ // 注意:不要把单独的 '0' 变成 ''
}
-
this.internalValue = cleaned;
- // emit 值(可能是数字、空字符串、或 '-')
+ // emit
if (cleaned === '' || cleaned === '-') {
this.$emit('input', cleaned === '-' ? '-' : '');
} else {
const num = parseFloat(cleaned);
- if (!isNaN(num)) {
- this.$emit('input', num);
- } else {
- this.$emit('input', '');
- }
+ console.log(num,isNaN(num),"num")
+ this.$emit('input', isNaN(num) ? '' : num);
}
},
diff --git a/src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue b/src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue
index 5bbbb3b..3084b42 100644
--- a/src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue
+++ b/src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue
@@ -479,7 +479,7 @@ export default {
const stepFormData = await this.$refs.stepFormPackageRef.getFormData();
const stepDataFormData = await this.$refs.stepTableRef.getFormData();
const stepData = await this.$refs.stepRef.getFormData();
- if (!stepData.length) {
+ if (!stepData.stepData.length) {
this.$message.error("请添加步骤");
return;
}
diff --git a/src/views/business/comps/template/comps/sp/SWYPFXCBYPZB.vue b/src/views/business/comps/template/comps/sp/SWYPFXCBYPZB.vue
index ed77f88..d4480d6 100644
--- a/src/views/business/comps/template/comps/sp/SWYPFXCBYPZB.vue
+++ b/src/views/business/comps/template/comps/sp/SWYPFXCBYPZB.vue
@@ -261,7 +261,7 @@ export default {
const conditionData = await this.$refs.storageConditionRef.getFormData();
const stepFormData = await this.$refs.stepFormPackageRef.getFormData();
const stepData = await this.$refs.stepRef.getFormData();
- if (!stepData.length) {
+ if (!stepData.stepData.length) {
this.$message.error("请添加步骤");
return;
}
diff --git a/src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue b/src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue
index 48efd8d..dfee8c1 100644
--- a/src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue
+++ b/src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue
@@ -275,7 +275,7 @@ export default {
const conditionData = await this.$refs.storageConditionRef.getFormData();
const stepFormData = await this.$refs.stepFormPackageRef.getFormData();
const stepData = await this.$refs.stepRef.getFormData();
- if (!stepData.length) {
+ if (!stepData.stepData.length) {
this.$message.error(this.$t('template.common.addStepError'));
return;
}
diff --git a/src/views/business/comps/template/mixins/templateMixin.js b/src/views/business/comps/template/mixins/templateMixin.js
index 5d40a31..32a383f 100644
--- a/src/views/business/comps/template/mixins/templateMixin.js
+++ b/src/views/business/comps/template/mixins/templateMixin.js
@@ -84,21 +84,21 @@ export default {
},
onHandleTableBlur(params){
const {rowIndex, colKey, value,item} = params;
- if(colKey === "targetSolutionVolume" || colKey === "targetSolutionConcentration"){//预设起始溶液体积:(目标溶液预计浓度 乘以 目标溶液预计体积)除以 起始溶液浓度
+ console.log(rowIndex, colKey, value,item, "params")
+ if(colKey === "targetSolutionVolume" || colKey === "targetSolutionConcentration" || colKey === "targetStartSolutionVolumePrecision" || colKey === "targetDiluentVolumePrecision"){//预设起始溶液体积:(目标溶液预计浓度 乘以 目标溶液预计体积)除以 起始溶液浓度
const volume = this.$refs.stepFormPackageRef.getFormDataByKey("targetStartSolution") || 0;
const precision = item.targetStartSolutionVolumePrecision || 0;
if(volume){
const concentration = item.targetSolutionConcentration || 0;
const targetVolume = item.targetSolutionVolume || 0;
const result = ((concentration * targetVolume) / volume).toFixed(precision);
- console.log(result,"reee")
this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex,{targetStartSolutionVolume:result});
+ if(targetVolume){//预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
+ const precision1 = item.targetDiluentVolumePrecision || 0;
+ const result1 = (targetVolume - result).toFixed(precision1);
+ this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex,{targetDiluentVolume:result1});
+ }
}
- }else if(colKey ==="targetSolutionVolume" || colKey === "targetDiluentVolume"){//预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
- // const targetVolume = item.targetSolutionVolume || 0;
- // const targetDiluentVolume = item.targetDiluentVolume || 0;
- // const result = (targetVolume - targetDiluentVolume).toFixed(precision);
- // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex,{targetDiluentVolume:result});
}
}