gaoluyang
4 天以前 c2398150b44b54a1f08e7af4b6a64f0c170046f0
src/utils/inspectionValueFormat.js
@@ -1,9 +1,10 @@
/**
 * 解析原始记录模板中的检验值批注。
 * 兼容旧格式“检验值”,并支持:检验值,2、检验值,2,科学计数法。
 * 支持检验值、计算值、最终值的批注,例如:检验值,2、计算值,2,最终值,2,科学计数法。
 */
export function parseInspectionValueAnnotation(annotation) {
  if (typeof annotation !== 'string' || !annotation.includes('检验值')) return null;
  const targetNames = ['检验值', '计算值', '最终值'];
  if (typeof annotation !== 'string') return null;
  // 批注允许中文逗号、英文逗号以及“和”连接格式参数。
  const parts = annotation
    .replace(/,/g, ',')
@@ -12,6 +13,7 @@
    .split(',')
    .map(item => item.trim())
    .filter(Boolean);
  if (!targetNames.includes(parts[0])) return null;
  const decimalIndex = parts.findIndex((item, index) => index > 0 && /^\d+$/.test(item));
  const decimalPlaces = decimalIndex < 0 ? null : Number(parts[decimalIndex]);
  if (decimalPlaces != null && (!Number.isInteger(decimalPlaces) || decimalPlaces < 0 || decimalPlaces > 15)) {
@@ -31,9 +33,10 @@
    item && index + 1 !== decimalIndex && item !== '科学计数法' && !roundingNames[item]
  );
  if (unsupported.length || parts.length > 4) {
    return { error: '检验值批注格式应为:检验值,2,四舍五入 或 检验值,2,科学计数法,四舍五入' };
    return { error: '批注格式应为:检验值,2,四舍五入;计算值,2;最终值,2,科学计数法' };
  }
  return {
    target: parts[0],
    decimalPlaces,
    displayMode,
    // 参数顺序决定处理顺序:科学计数法在小数位前表示先转科学计数法。