| | |
| | | // 多线程里面需要保存的数据 |
| | | import Big from "big.js"; |
| | | import { parseInspectionValueAnnotation, formatInspectionValue } from "../utils/inspectionValueFormat"; |
| | | |
| | | let code = ""; |
| | | // 表格数据(渲染) |
| | |
| | | // 判断当前行是否为当前检验项所在行,如果为当前行,则给表格数据赋值 |
| | | for (var b in a) { |
| | | if (a[b].c == item.c) { |
| | | a[b].v.v = comResult; |
| | | // 计算值、最终值也按单元格批注的小数位数格式化,避免计算结果绕过前端输入校验。 |
| | | const annotation = a[b].v && a[b].v.ps && a[b].v.ps.value; |
| | | const formatConfig = parseInspectionValueAnnotation(annotation); |
| | | a[b].v.v = formatConfig && !formatConfig.error |
| | | ? formatInspectionValue(comResult, formatConfig) |
| | | : comResult; |
| | | hasComputedWrite = true; |
| | | break; |
| | | } |
| | |
| | | */ |
| | | function AVERAGE(...val) { |
| | | try { |
| | | let num = null; |
| | | let arr = []; |
| | | if ( |
| | | val != null && |
| | | val != undefined && |
| | | val != "undefined" && |
| | | val != "NaN" && |
| | | val.length > 0 |
| | | ) { |
| | | arr = val.filter( |
| | | (item) => item !== null && item !== "" && item != undefined |
| | | ); |
| | | arr.forEach((item) => { |
| | | num += item; |
| | | }); |
| | | if (arr.length > 0) { |
| | | return num / arr.length; |
| | | } else { |
| | | return null; |
| | | // 单元格值可能是字符串;统一转数字后再计算,兼容区间参数。 |
| | | const values = []; |
| | | const flatten = (items) => items.forEach((item) => { |
| | | if (Array.isArray(item)) return flatten(item); |
| | | if (item !== null && item !== undefined && item !== "" && item !== " ") { |
| | | const number = Number(item); |
| | | if (Number.isFinite(number)) values.push(number); |
| | | } |
| | | } else { |
| | | return null; |
| | | } |
| | | }); |
| | | flatten(val || []); |
| | | return values.length ? values.reduce((sum, item) => sum + item, 0) / values.length : null; |
| | | } catch (error) { |
| | | console.log("error---", error); |
| | | } |