Browse Source

修复parseSpecification函数,支持净重X+格式的规格解析

pull/18/head
徐飞洋 1 month ago
parent
commit
f5473038c8
  1. 38
      pages/evaluate2/index.js

38
pages/evaluate2/index.js

@ -211,11 +211,12 @@ Page({
// 解析规格,提取类型(净重/毛重)和数值范围
parseSpecification(spec) {
const weightMatch = spec.match(/(净重|毛重)(\d+)-(\d+)/);
if (weightMatch) {
const type = weightMatch[1]; // 净重或毛重
const min = parseFloat(weightMatch[2]);
const max = parseFloat(weightMatch[3]);
// 匹配 "净重X-Y" 或 "毛重X-Y" 格式
const rangeMatch = spec.match(/(净重|毛重)(\d+)-(\d+)/);
if (rangeMatch) {
const type = rangeMatch[1]; // 净重或毛重
const min = parseFloat(rangeMatch[2]);
const max = parseFloat(rangeMatch[3]);
const avg = (min + max) / 2;
return {
type: type,
@ -224,6 +225,33 @@ Page({
avg: avg
};
}
// 匹配 "净重X+" 或 "毛重X+" 格式
const plusMatch = spec.match(/(净重|毛重)(\d+)\+/);
if (plusMatch) {
const type = plusMatch[1]; // 净重或毛重
const value = parseFloat(plusMatch[2]);
return {
type: type,
min: value,
max: value,
avg: value
};
}
// 匹配 "净重X" 或 "毛重X" 格式
const singleMatch = spec.match(/(净重|毛重)(\d+)/);
if (singleMatch) {
const type = singleMatch[1]; // 净重或毛重
const value = parseFloat(singleMatch[2]);
return {
type: type,
min: value,
max: value,
avg: value
};
}
return null;
},

Loading…
Cancel
Save