| | |
| | | |
| | | let code = '' |
| | | let tableList = [] |
| | | let tableList = null |
| | | let excelMethodList = [] |
| | | let comparisonList = [] |
| | | let currentSample = {} |
| | |
| | | value:null |
| | | } |
| | | let param = null |
| | | let currentTable = '' |
| | | self.onmessage = function(event) { |
| | | const data = JSON.parse(event.data); |
| | | if(currentTable!=data.currentTable){ |
| | | tableList = data.tableList; |
| | | } |
| | | currentTable = data.currentTable; |
| | | if(data.type&&data.type=='saveData'){ |
| | | tableList = data.tableList; |
| | | param = data.param; |
| | | return |
| | | } |
| | | code = data.code; |
| | | tableList = JSON.parse(JSON.stringify(data.tableList)); |
| | | if(tableList){ |
| | | let str = code.split('-') |
| | | let r = str[1] |
| | | let c = str[2] |
| | | tableList[0].arr.forEach((item,index)=>{ |
| | | item.forEach((m,i)=>{ |
| | | if(m.c==c&&m.r==r){ |
| | | tableList[0].arr[index] = data.tableList[0].arr[index] |
| | | } |
| | | }) |
| | | }) |
| | | }else{ |
| | | tableList = data.tableList; |
| | | } |
| | | if(param){ |
| | | let str = code.split('-') |
| | | let pId = str[3] |
| | | param[pId] = data.param[pId] |
| | | }else{ |
| | | param = data.param; |
| | | } |
| | | // tableList = data.tableList; |
| | | // param = data.param; |
| | | excelMethodList = JSON.parse(JSON.stringify(data.excelMethodList)); |
| | | comparisonList = JSON.parse(JSON.stringify(data.comparisonList)); |
| | | currentSample = JSON.parse(JSON.stringify(data.currentSample)); |
| | | param = data.param; |
| | | PROJECT = data.PROJECT |
| | | changeInput('', code); |
| | | }; |
| | |
| | | break |
| | | } |
| | | } |
| | | 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 => { |
| | |
| | | break |
| | | } |
| | | } |
| | | list2.push(c.v.v) |
| | | if(getInspectionValueType(item.i)==1&&!isNaN(parseFloat(c.v.v))){ |
| | | let n = String(c.v.v) |
| | | if(n.includes('/')){ |
| | |
| | | } |
| | | }) |
| | | }else{ |
| | | // 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*', '') |
| | | } |
| | |
| | | let str = handleFraction(m.split('=')[1]) |
| | | if(typeof res == 'string'&&typeof str == 'string'){ |
| | | if(res.includes('/')){ |
| | | return handleMoreParam(res,m.split('=')[1],'=') |
| | | if (m.includes('/')) { |
| | | return eval(res) == eval(str) |
| | | } else { |
| | | return handleMoreParam(res,m.split('=')[1],'=') |
| | | } |
| | | }else{ |
| | | // console.log(res.trim().replace(/[.,。、;:'";??“,]/g, ''),' == ',str.trim().replace(/[.,。、;:'";??“,]/g, '')) |
| | | return res.trim().replace(/[.,。、;:'";??“,]/g, '') == str.trim().replace(/[.,。、;:'";??“,]/g, '') |
| | |
| | | } |
| | | } else if (m.includes('≥')) { |
| | | if(typeof res =='string'&&res.includes('/')){ |
| | | return handleMoreParam(res,m.split('≥')[1],'≥') |
| | | if (m.includes('/')) { |
| | | // console.log('eval(res)----', eval(res)) |
| | | let str = handleFraction(m.split('≥')[1]) |
| | | // console.log('eval(str)----', eval(str)) |
| | | return eval(res) >= eval(str) |
| | | } else { |
| | | return handleMoreParam(res,m.split('≥')[1],'≥') |
| | | } |
| | | }else{ |
| | | let str = handleFraction(m.split('≥')[1]) |
| | | return eval(res) >= eval(str) |
| | | } |
| | | }else if (m.includes('≤')) { |
| | | if(typeof res =='string'&&res.includes('/')){ |
| | | return handleMoreParam(res,m.split('≤')[1],'≤') |
| | | if (m.includes('/')) { |
| | | let str = handleFraction(m.split('≤')[1]) |
| | | return eval(res) <= eval(str) |
| | | } else { |
| | | return handleMoreParam(res,m.split('≤')[1],'≤') |
| | | } |
| | | }else{ |
| | | let str = handleFraction(m.split('≤')[1]) |
| | | return eval(res) <= eval(str) |
| | | } |
| | | }else if (m.includes('<')) { |
| | | if(typeof res =='string'&&res.includes('/')){ |
| | | return handleMoreParam(res,m.split('<')[1],'<') |
| | | if (m.includes('/')) { |
| | | let str = handleFraction(m.split('<')[1]) |
| | | return eval(res) < eval(str) |
| | | } else { |
| | | return handleMoreParam(res,m.split('<')[1],'<') |
| | | } |
| | | }else{ |
| | | let str = handleFraction(m.split('<')[1]) |
| | | return eval(res) < eval(str) |
| | | } |
| | | }else if (m.includes('>')) { |
| | | if(typeof res =='string'&&res.includes('/')){ |
| | | return handleMoreParam(res,m.split('>')[1],'>') |
| | | if (m.includes('/')) { |
| | | let str = handleFraction(m.split('>')[1]) |
| | | return eval(res) > eval(str) |
| | | } else { |
| | | return handleMoreParam(res,m.split('>')[1],'>') |
| | | } |
| | | }else{ |
| | | let str = handleFraction(m.split('>')[1]) |
| | | return eval(res) > eval(str) |
| | | } |
| | | }else if (m.includes('~')) { |
| | | if(typeof res =='string'&&res.includes('/')){ |
| | | return handleMoreParam(res,m,'~') |
| | | if (m.includes('/')) { |
| | | let k = m.split('~') |
| | | return eval(res) >= eval(handleFraction((k[0]))) && eval(res) <= eval(handleFraction(k[1])) |
| | | } else { |
| | | return handleMoreParam(res,m,'~') |
| | | } |
| | | }else{ |
| | | let k = m.split('~') |
| | | return eval(res) >= eval(handleFraction((k[0]))) && eval(res) <= eval(handleFraction(k[1])) |
| | | } |
| | | }else if(m.includes('-')){ |
| | | if(typeof res =='string'&&res.includes('/')){ |
| | | return handleMoreParam(res,m,'-') |
| | | if (m.includes('/')) { |
| | | let k = m.split('-') |
| | | return eval(res) >= eval(handleFraction(k[0])) && eval(res) <= eval(handleFraction(k[1])) |
| | | } else { |
| | | return handleMoreParam(res,m,'-') |
| | | } |
| | | }else{ |
| | | let k = m.split('-') |
| | | // console.log(k,eval(res),eval(res) >= eval(handleFraction(k[0])) && eval(res) <= eval(handleFraction(k[1]))) |
| | | return eval(res) >= eval(handleFraction(k[0])) && eval(res) <= eval(handleFraction(k[1])) |
| | | } |
| | | }else if(m.includes('±')){ |
| | | if(typeof res =='string'&&res.includes('/')){ |
| | | return handleMoreParam(res,m,'±') |
| | | if (m.includes('/')) { |
| | | let k = m.split('±') |
| | | return eval(res) >= eval((handleFraction(k[0]) - handleFraction(k[1]))) && eval(res) <= eval((handleFraction(k[0]) + handleFraction(k[1]))) |
| | | } else { |
| | | return handleMoreParam(res,m,'±') |
| | | } |
| | | }else{ |
| | | let k = m.split('±') |
| | | return eval(res) >= eval((handleFraction(k[0]) - handleFraction(k[1]))) && eval(res) <= eval((handleFraction(k[0]) + handleFraction(k[1]))) |
| | | } |
| | | }else if(m.includes('>')){ |
| | | if(typeof res =='string'&&res.includes('/')){ |
| | | return handleMoreParam(res,m.split('>')[1],'>') |
| | | if (m.includes('/')) { |
| | | let str = handleFraction(m.split('>')[1]) |
| | | return eval(res) > eval(str) |
| | | } else { |
| | | return handleMoreParam(res,m.split('>')[1],'>') |
| | | } |
| | | }else{ |
| | | let str = handleFraction(m.split('>')[1]) |
| | | return eval(res) > eval(str) |
| | | } |
| | | }else if(m.includes('<')){ |
| | | if(typeof res =='string'&&res.includes('/')){ |
| | | return handleMoreParam(res,m.split('<')[1],'<') |
| | | if (m.includes('/')) { |
| | | let str = handleFraction(m.split('<')[1]) |
| | | return eval(res) < eval(str) |
| | | } else { |
| | | return handleMoreParam(res,m.split('<')[1],'<') |
| | | } |
| | | }else{ |
| | | let str = handleFraction(m.split('<')[1]) |
| | | return eval(res) < eval(str) |
| | |
| | | } |
| | | }) |
| | | } |
| | | console.log(tableList) |
| | | // console.log(tableList) |
| | | } |
| | | // console.log('1234567789', tableList,getParam()) |
| | | result = { |
| | | method:'saveInsContext', |
| | | value:{ |
| | |
| | | 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; |
| | | comResult = compute(item.v.f.replace(/=/g, ' '),comValue) |
| | | let tell = currentSample.insProduct.find(m => m.id == item.i).tell?currentSample.insProduct.find(m => m.id == item.i).tell.split('&'):null; |
| | | isPoint = PROJECT=='装备电缆'&&tell&&tell.length>0&&typeof tell[0] =='string'&&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 === '装备电缆' && ask[0].includes('RTS')) { |
| | | if (PROJECT === '装备电缆' && isToExponential) { |
| | | let num2 = new Big(comResult) |
| | | comResult = num2.toExponential() |
| | | comResult = num2.toExponential(1) |
| | | } |
| | | }else{ |
| | | let valueList = []; |
| | |
| | | comResult = str |
| | | } |
| | | } catch (error) { |
| | | console.log('error---', error) |
| | | } |
| | | try { |
| | | list.forEach(a => { |
| | |
| | | for (var b in a) { |
| | | if (a[b].c == item.c) { |
| | | try{ |
| | | let val = parseFloat(comResult.toFixed(3)) |
| | | a[b].v.v = isNaN(val) ? '' : val |
| | | }catch(e){ |
| | | if(comResult==0){ |
| | | a[b].v.v = 0 |
| | | }else if(a[b].v.ct&&a[b].v.ct.fa&&typeof a[b].v.ct.fa == 'string'&&a[b].v.ct.fa.includes('.')){ |
| | | let num = 0 |
| | | let str = a[b].v.ct.fa.split('.')[1] |
| | | num = str.length |
| | | a[b].v.v = comResult?Number(comResult).toFixed(num):0 |
| | | }else{ |
| | | let val = parseFloat(Number(comResult).toFixed(3)) |
| | | a[b].v.v = isNaN(val) ? comResult : val |
| | | } |
| | | // console.log('a[b].v.ct', comResult) |
| | | // console.log('a[b].v.v', a[b].v.v) |
| | | }catch(error){ |
| | | a[b].v.v = comResult |
| | | console.log('error---', error) |
| | | } |
| | | break |
| | | } |
| | |
| | | }) |
| | | changeInput(comResult, `${id}-${item.r}-${item.c}-${pId}`) //改变最终值 |
| | | } catch (error) { |
| | | |
| | | console.log('error---', error) |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | self.postMessage(JSON.stringify(result)) |
| | | } catch (error) { |
| | | |
| | | console.log('error---', error) |
| | | } |
| | | } |
| | | |
| | |
| | | * @returns 返回处理后的参数对象 |
| | | */ |
| | | function getParam(){ |
| | | for (var b in param){ |
| | | param[b].insValue = [] |
| | | param[b].comValue = [] |
| | | param[b].equipValue = [] |
| | | param[b].equipName = [] |
| | | param[b].resValue = null |
| | | param[b].insResult = null |
| | | } |
| | | tableList[0].arr.forEach(a=>{ |
| | | a.forEach(b=>{ |
| | | if(param[b.i]){ |
| | | param[b.i].insValue = [] |
| | | param[b.i].comValue = [] |
| | | param[b.i].equipValue = [] |
| | | param[b.i].equipName = [] |
| | | param[b.i].resValue = null |
| | | param[b.i].insResult = null |
| | | } |
| | | }) |
| | | }) |
| | | tableList[0].arr.forEach(a => { |
| | | a.forEach(b=>{ |
| | | if (b.v.ps != undefined && b.v.ps.value === '检验值') { |
| | | if (b.v.ps != undefined &&typeof b.v.ps.value =='string'&& b.v.ps.value.includes('检验值')) { |
| | | b.i &&b.v.v&& param[b.i].insValue.push(b) |
| | | } |
| | | if (b.v.ps != undefined && b.v.ps.value === '计算值') { |
| | |
| | | } |
| | | return num; |
| | | } catch (error) { |
| | | |
| | | console.log('error---', error) |
| | | } |
| | | } |
| | | /** |
| | |
| | | } |
| | | return max; |
| | | } catch (error) { |
| | | |
| | | console.log('error---', error) |
| | | } |
| | | } |
| | | /** |
| | |
| | | } |
| | | return min; |
| | | } catch (error) { |
| | | |
| | | console.log('error---', error) |
| | | } |
| | | } |
| | | /** |
| | |
| | | let num = null; |
| | | let arr = []; |
| | | if(val&&val.length>0){ |
| | | arr = val.filter(item=>item!=null&&item!=='') |
| | | arr = val.filter(item=>item!=null&&item!=''&&item!=undefined) |
| | | arr.forEach(item=>{ |
| | | num+=item; |
| | | }) |
| | |
| | | return null; |
| | | } |
| | | } catch (error) { |
| | | |
| | | console.log('error---', error) |
| | | } |
| | | } |
| | | /** |
| | |
| | | try { |
| | | return Math.abs(val); |
| | | } catch (error) { |
| | | |
| | | console.log('error---', error) |
| | | } |
| | | } |
| | | /** |
| | |
| | | return null; |
| | | } |
| | | } catch (error) { |
| | | |
| | | console.log('error---', error) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | } catch (error) { |
| | | |
| | | console.log('error---', error) |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据坐标获取列名 |
| | |
| | | letter += String.fromCharCode(65 + (i % 26)); |
| | | return letter + (parseInt(cellId[1]) + 1); |
| | | }catch(e){ |
| | | console.log('error',cellId) |
| | | console.log('error',e) |
| | | } |
| | | } |
| | | /** |
| | |
| | | } |
| | | return id; |
| | | }catch(e){ |
| | | console.log('error',id) |
| | | console.log('error',e) |
| | | } |
| | | } |
| | | |
| | |
| | | }) |
| | | return arr2; |
| | | } catch (error) { |
| | | |
| | | console.log('error',error) |
| | | } |
| | | } |
| | | /** |
| | |
| | | '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) |
| | | } |
| | | } |
| | | /** |
| | |
| | | }) |
| | | return arr0; |
| | | } catch (error) { |
| | | |
| | | console.log('error',error) |
| | | } |
| | | } |
| | | |
| | |
| | | * @param comValue 对象类型,表示要替换的单元格值,键为单元格名称,值为替换后的值 |
| | | * @returns 返回计算后的结果,如果计算失败则返回0 |
| | | */ |
| | | function compute(f,comValue){ |
| | | function compute(f,comValue, isPoint){ |
| | | try { |
| | | let str = f |
| | | // 获取单元格对应值 |
| | |
| | | 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(',,')){ |
| | | str = str.replace(new RegExp(',,', 'g'),',') |
| | | } |
| | | if(str.includes(',,')){ |
| | | str = str.replace(new RegExp(',,', 'g'),',') |
| | | } |
| | | // console.log('str', str) |
| | | if(str.includes('&"/"&')){ |
| | | return str.replaceAll('&"/"&', '/').replaceAll('//','') |
| | | return str.replace(new RegExp('&"/"&', 'g'),'/').replace(new RegExp('//', 'g'),'') |
| | | } else if (isPoint) { |
| | | return str.replace('ABS', '').replace(/\(|\)/g, '') |
| | | }else { |
| | | console.log('str', str,eval(str)) |
| | | return eval(str) |
| | | } |
| | | } catch (error) { |
| | | |
| | | console.log('error',error) |
| | | } |
| | | } |
| | | |