feat:分析值保留两位有效数字计算

This commit is contained in:
houjunxiang
2026-02-05 11:10:44 +08:00
parent e10c70e819
commit da01e1efcd
8 changed files with 123 additions and 80 deletions

View File

@@ -674,7 +674,7 @@ const saveDetail = async () => {
if (item.calcMethod === 'calculateAverageValue') {
item.value = calcAverageValue(sourceKey, currentAssayType.value.tableData)
} else {
item.value = handleRoundFiveNumber(row[sourceKey].value, row.decimalPosition)
item.value = handleRoundFiveNumber(row[sourceKey].value, row.decimalPosition, row.type === 'project')
}
// 如果处理后的值不为空,重新赋值该字段到其他样品类型下的样品上,并触发每一个样品的计算
for (const col of currentAssayType.value.columns) {
@@ -707,9 +707,10 @@ const saveDetail = async () => {
function calcAverageValue(fieldIndex, tableData) {
const rows = tableData.map(row => row[fieldIndex])
const decimalPosition = rows[0].decimalPosition
const isProject = rows[0].type === 'project'
const values = rows.map(row => Number(row.value))
if (values.some(item => item == null)) return null
return handleRoundFiveNumber(math.mean(values), decimalPosition)
return handleRoundFiveNumber(math.mean(values), decimalPosition, isProject)
}
// 表格数据更新后重新计算
@@ -1109,12 +1110,13 @@ const listenNumKeyboard = () => {
}
//自动补全小数位数
const decimalPosition = selectedField.value.decimalPosition
const isProject = selectedField.value.type === 'project'
let val = res.val
const symbol = res.symbol
if (decimalPosition == null) {
selectedField.value.value = val
} else {
selectedField.value.value = handleRoundFiveNumber(val, decimalPosition)
selectedField.value.value = handleRoundFiveNumber(val, decimalPosition, isProject)
}
if (symbol) {
selectedField.value.symbol = symbol