diff --git a/src/components/Template/HandleFormItem.vue b/src/components/Template/HandleFormItem.vue
index 5f25537..6137993 100644
--- a/src/components/Template/HandleFormItem.vue
+++ b/src/components/Template/HandleFormItem.vue
@@ -1238,7 +1238,7 @@ export default {
},
//处理更新记录
- handleUpdateRecord(data, recordData) {
+ handleUpdateRecord(data, recordData, isUpdateInputValue = true) {
const baseInfo = this.getCommonRecordInfo();
//有recordData表示从组件外部调用的更新操作,
if (!this.oldValue && !this.inputValue && !recordData) {
@@ -1246,8 +1246,10 @@ export default {
}
let finallyKey = this.fieldKey;
if (recordData) {
- this.oldValue = recordData.oldValue;
- this.inputValue = recordData.inputValue;
+ if(isUpdateInputValue){
+ this.oldValue = recordData.oldValue;
+ this.inputValue = recordData.inputValue;
+ }
}
let recordOldVlaue = this.oldValue, recordValue = this.inputValue, isModify = !!this.oldValue,oldUrl = "",url="";
if (this.type === "checkboxTag") {
@@ -1291,10 +1293,12 @@ export default {
oldUrl = oldAttList.map(item => item.url).join("|");
url = attList.map(item => item.url).join("|");
}
- // if (recordData) {
- // recordOldVlaue = recordData.oldValue;
- // recordValue = recordData.inputValue;
- // }
+ if (recordData) {
+ if(!isUpdateInputValue){//单纯更新记录,不更新表单的值
+ recordOldVlaue = recordData.oldValue;
+ recordValue = recordData.inputValue;
+ }
+ }
const record = {
...baseInfo,
oldValue: recordOldVlaue,
diff --git a/src/components/Template/StepComponents/ry/tpjydd.vue b/src/components/Template/StepComponents/ry/tpjydd.vue
index 7a1bd80..eab566c 100644
--- a/src/components/Template/StepComponents/ry/tpjydd.vue
+++ b/src/components/Template/StepComponents/ry/tpjydd.vue
@@ -11,7 +11,7 @@
diff --git a/src/components/Template/StepFormPackage.vue b/src/components/Template/StepFormPackage.vue
index 9bdd619..bdb487b 100644
--- a/src/components/Template/StepFormPackage.vue
+++ b/src/components/Template/StepFormPackage.vue
@@ -7,13 +7,13 @@
:item="sItem" v-model="formFields[key]" :field-key="prefixKey+'_' + key"
:ref="key"
@copy="onCopy(sItem, key)" :error="errors[key]" @update:error="errors[key] = false"
- :orange-bg="orangeBgFields[key]" />
+ :orange-bg="getOrangeBg(key,sItem)" />
+ :error="errors[key]" @update:error="errors[key] = false" :orange-bg="getOrangeBg(key,sItem)" />
{
- this.$refs[key][0].handleUpdateRecord(signData, re)
+ this.$refs[key][0].handleUpdateRecord(signData, re, isUpdateInputValue)
}, 10)
}
},
diff --git a/src/components/Template/mixins/stepMixins.js b/src/components/Template/mixins/stepMixins.js
index feefa7b..4836f6e 100644
--- a/src/components/Template/mixins/stepMixins.js
+++ b/src/components/Template/mixins/stepMixins.js
@@ -233,7 +233,7 @@ export default {
const value = dw?result.value:`${result.value}${result.unit}`
if(fillDwField){//需要回填的单位字段
this.$refs.stepFormPackageRef.updateFormData(fillField, value)
- this.$refs.stepFormPackageRef.updateFormData(fillDwField, result.unit,{isUpdateRecord:true,signData,record:{
+ this.$refs.stepFormPackageRef.updateFormData(fillDwField, result.unit,{isUpdateRecord:true,signData,isUpdateInputValue:false,record:{
oldValue,
inputValue:result.value+result.unit
}})
diff --git a/src/utils/massTool.js b/src/utils/massTool.js
index 6c803b1..1c72ee1 100644
--- a/src/utils/massTool.js
+++ b/src/utils/massTool.js
@@ -33,4 +33,46 @@ export function compareMass(value1, unit1, value2, unit2) {
if (grams1 > grams2) return 1;
if (Math.abs(grams1 - grams2) < 1e-12) return 0;
return -1;
+}
+
+/**
+ * 质量单位转换
+ * @param {string} massStr - 质量字符串,如 "3kg"
+ * @param {string} targetUnit - 目标单位,如 "g"
+ * @returns {number} 转换后的数值
+ * @example
+ * convertMass('3kg', 'g') // 返回 3000
+ * convertMass('500mg', 'g') // 返回 0.5
+ */
+export function convertMass(massStr, targetUnit) {
+ if (typeof massStr !== 'string' || massStr.length === 0) {
+ throw new Error('质量字符串不能为空');
+ }
+ if (typeof targetUnit !== 'string' || targetUnit.length === 0) {
+ throw new Error('目标单位不能为空');
+ }
+
+ // 解析质量字符串,提取数值和单位
+ const match = massStr.trim().match(/^([\d.]+)\s*([a-zA-Z]+)$/);
+ if (!match) {
+ throw new Error(`无效的质量字符串格式: ${massStr}`);
+ }
+
+ const value = parseFloat(match[1]);
+ const sourceUnit = match[2].toLowerCase();
+ const lowerTargetUnit = targetUnit.toLowerCase();
+
+ if (isNaN(value)) {
+ throw new Error('无法解析数值');
+ }
+ if (!isMassUnit(sourceUnit)) {
+ throw new Error(`无效的源单位: ${sourceUnit}`);
+ }
+ if (!isMassUnit(lowerTargetUnit)) {
+ throw new Error(`无效的目标单位: ${targetUnit}`);
+ }
+
+ // 先转换为克,再转换为目标单位
+ const grams = value * toGramFactor[sourceUnit];
+ return grams / toGramFactor[lowerTargetUnit];
}
\ No newline at end of file