gaoluyang
2024-07-12 6eac588d18ef1e98dd0c6979aec9741a91044d80
static/js/worker.js
@@ -37,9 +37,10 @@
  }
  let isToExponential = ''
  let list2 = []
  let isPoint = ''
  excelMethodList.forEach(item => {
    if (item.valueList.find(m => m.r == r && m.c == c)) {
    if (item.valueList&&item.valueList.length>0&&item.valueList.find(m => m.r == r && m.c == c)) {
      var comValue = {}
      item.valueList.forEach(a => {
        list.forEach(b => {
@@ -92,6 +93,7 @@
            // console.log(ask,res,item.v.f)
            if(ask){
              comp = ask.map((m, i) => {
                console.log('m----', m)
                if (m.includes('RTS')) {
                  m = m.replace('RTS*', '')
                }
@@ -101,7 +103,8 @@
                    if(res.includes('/')){
                      return handleMoreParam(res,m.split('=')[1],'=')
                    }else{
                      return  res.trim() == str.trim()
                      // console.log(res.trim().replace(/[.,。、;:'";??“,]/g, ''),' == ',str.trim().replace(/[.,。、;:'";??“,]/g, ''))
                      return  res.trim().replace(/[.,。、;:'";??“,]/g, '') == str.trim().replace(/[.,。、;:'";??“,]/g, '')
                    }
                  }else{
                    return  eval(res) == eval(str)
@@ -186,7 +189,6 @@
                }
              })
            } else {
              console.log(333333)
              item.v.v = 0
              list.forEach(a => {
                if (a[0].r == item.r) {
@@ -199,6 +201,7 @@
                }
              })
            }
            // console.log(tableList)
          }
          result = {
            method:'saveInsContext',
@@ -210,26 +213,22 @@
          self.postMessage(JSON.stringify(result))
        }
        } catch (error) {
          console.log('error---', error)
        }
      } else {
        let comResult = ''
        try {
          if(getInspectionValueType(item.i)==1){
            // let ask = currentSample.insProduct.find(m => m.id == item.i).ask?currentSample.insProduct.find(m => m.id == item.i).ask.split('&'):null;
            // let tell = currentSample.insProduct.find(m => m.id == item.i).tell?currentSample.insProduct.find(m => m.id == item.i).tell.split('&'):null;
            comResult = compute(item.v.f.replace(/=/g, ' '),comValue)
            let list3 = []
            list2.forEach(val => {
              val = val.toString()
              list3.push(val)
            })
            let tell = currentSample.insProduct.find(m => m.id == item.i).tell?currentSample.insProduct.find(m => m.id == item.i).tell.split('&'):null;
            isPoint = tell[0].includes('/') // 判断要求值是否为分数
            comResult = compute(item.v.f.replace(/=/g, ' '),comValue, isPoint)
            let list3 = list2.map(item=>item+'')
            isToExponential = list3.some(val => val.includes('e+'))
            // 装备项目检验值转化
            if (PROJECT === '装备电缆' && isToExponential) {
              let num2 = new Big(comResult)
              comResult = num2.toExponential()
              comResult = num2.toExponential(1)
            }
          }else{
            let valueList = [];
@@ -260,11 +259,13 @@
            if (a[0].r == item.r && comResult !== '') {
              for (var b in a) {
                if (a[b].c == item.c) {
                  console.log('comResult---', comResult)
                  try{
                    let val = parseFloat(comResult.toFixed(3))
                    a[b].v.v = isNaN(val) ? '' : val
                  }catch(e){
                  }catch(error){
                    a[b].v.v = comResult
                    console.log('error---', error)
                  }
                  break
                }
@@ -290,7 +291,7 @@
    }
    self.postMessage(JSON.stringify(result))
  } catch (error) {
    console.log('error---', error)
  }
}
@@ -418,7 +419,7 @@
    }
    return num;
  } catch (error) {
    console.log('error---', error)
  }
}
/**
@@ -440,7 +441,7 @@
    }
    return max;
  } catch (error) {
    console.log('error---', error)
  }
}
/**
@@ -460,7 +461,7 @@
    }
    return min;
  } catch (error) {
    console.log('error---', error)
  }
}
/**
@@ -487,7 +488,7 @@
      return null;
    }
  } catch (error) {
    console.log('error---', error)
  }
}
/**
@@ -500,7 +501,7 @@
  try {
    return Math.abs(val);
  } catch (error) {
    console.log('error---', error)
  }
}
/**
@@ -531,7 +532,7 @@
      return null;
    }
  } catch (error) {
    console.log('error---', error)
  }
}
@@ -552,7 +553,7 @@
      }
    }
  } catch (error) {
    console.log('error---', error)
  }
}
@@ -578,7 +579,7 @@
    letter += String.fromCharCode(65 + (i % 26));
    return letter + (parseInt(cellId[1]) + 1);
  }catch(e){
    console.log('error',cellId)
    console.log('error',e)
  }
}
/**
@@ -620,7 +621,7 @@
    }
    return id;
  }catch(e){
    console.log('error',id)
    console.log('error',e)
  }
}
@@ -654,7 +655,7 @@
    })
    return arr2;
  } catch (error) {
    console.log('error',error)
  }
}
/**
@@ -673,16 +674,16 @@
      'AVERAGE',
      'ABS',
    ]
    f = f.replace(regex, ',').replaceAll('"&','').replaceAll('&"','')
    f = f.replace(regex, ',').replace(new RegExp('"&', 'g'),'').replace(new RegExp('&"', 'g'),'')
    fouList.forEach(item=>{
      f = f.replaceAll(item,',')
      f = f.replace(new RegExp(item, 'g'),',')
    })
    let arr = f.split(',').filter(item=>{
      return item&& /[a-zA-Z]/.test(item)&&item!='undefined'&&item!='null'
    });
    return arr;
  } catch (error) {
    console.log('error',error)
  }
}
/**
@@ -700,7 +701,7 @@
    })
    return arr0;
  } catch (error) {
    console.log('error',error)
  }
}
@@ -712,7 +713,7 @@
 * @param comValue 对象类型,表示要替换的单元格值,键为单元格名称,值为替换后的值
 * @returns 返回计算后的结果,如果计算失败则返回0
 */
function compute(f,comValue){
function compute(f,comValue, isPoint){
  try {
    let str = f
    // 获取单元格对应值
@@ -754,25 +755,28 @@
        obj[item] = item
      }
    })
    str = str.replaceAll(':', '-')
    str = str.replace(new RegExp(':', 'g'),'-')
    // 替换参数
    for (var a in obj) {
      str = str.replaceAll(a, obj[a])
      str = str.replace(new RegExp(a, 'g'),obj[a])
    }
    // 计算
    for (var a in arr) {
      str = str.replaceAll(a, arr[a])
      str = str.replace(new RegExp(a, 'g'),arr[a])
    }
    if(str.includes(',,')){
      str = str.replaceAll(',,', '')
      str = str.replace(new RegExp(',,', 'g'),'')
    }
    if(str.includes('&"/"&')){
      return str.replace(new RegExp('&"/"&', 'g'),'/').replace(new RegExp('//', 'g'),'')
      return str.replaceAll('&"/"&', '/').replaceAll('//','')
    } else if (isPoint) {
      return str.replace('ABS', '').replace(/\(|\)/g, '')
    }else {
      return eval(str)
    }
  } catch (error) {
    console.log('error',error)
  }
}