From 3d9d07a04299d9d43c8b4faa3192c7233c338026 Mon Sep 17 00:00:00 2001 From: gaoluyang <gaoluyang@rengu.cc> Date: 星期四, 11 七月 2024 15:09:30 +0800 Subject: [PATCH] 科学计数法逻辑修改 --- static/js/worker.js | 168 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 138 insertions(+), 30 deletions(-) diff --git a/static/js/worker.js b/static/js/worker.js index df98533..d23711c 100644 --- a/static/js/worker.js +++ b/static/js/worker.js @@ -35,6 +35,9 @@ break } } + let isToExponential = '' + let list2 = [] + excelMethodList.forEach(item => { if (item.valueList.find(m => m.r == r && m.c == c)) { var comValue = {} @@ -50,6 +53,7 @@ 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('/')){ @@ -71,9 +75,21 @@ let ask = currentSample.insProduct.find(m => m.id == item.i).ask?currentSample.insProduct.find(m => m.id == item.i).ask.split('&'):null; let res = Object.values(comValue)[0] let comp = [] + if(res==''||res==null||res==undefined||res=='Infinity'){ - item.v.v = '' + item.v.v = null + list.forEach(a => { + if (a[0].r == item.r) { + for (let b=0; b<a.length; b++) { + if (a[b].c == item.c) { + a[b].v.v = null + break + } + } + } + }) }else{ + // console.log(ask,res,item.v.f) if(ask){ comp = ask.map((m, i) => { if (m.includes('RTS')) { @@ -82,38 +98,78 @@ if (m.includes('=')) { let str = handleFraction(m.split('=')[1]) if(typeof res == 'string'&&typeof str == 'string'){ - return res.trim() == str.trim() + if(res.includes('/')){ + return handleMoreParam(res,m.split('=')[1],'=') + }else{ + return res.trim() == str.trim() + } }else{ return eval(res) == eval(str) } } else if (m.includes('鈮�')) { - let str = handleFraction(m.split('鈮�')[1]) - return eval(res) >= eval(str) + if(typeof res =='string'&&res.includes('/')){ + return handleMoreParam(res,m.split('鈮�')[1],'鈮�') + }else{ + let str = handleFraction(m.split('鈮�')[1]) + return eval(res) >= eval(str) + } }else if (m.includes('鈮�')) { - let str = handleFraction(m.split('鈮�')[1]) - console.log(eval(res),eval(str)) - return eval(res) <= eval(str) + if(typeof res =='string'&&res.includes('/')){ + return handleMoreParam(res,m.split('鈮�')[1],'鈮�') + }else{ + let str = handleFraction(m.split('鈮�')[1]) + return eval(res) <= eval(str) + } }else if (m.includes('<')) { - let str = handleFraction(m.split('<')[1]) - return eval(res) < eval(str) + if(typeof res =='string'&&res.includes('/')){ + return handleMoreParam(res,m.split('<')[1],'<') + }else{ + let str = handleFraction(m.split('<')[1]) + return eval(res) < eval(str) + } }else if (m.includes('>')) { - let str = handleFraction(m.split('>')[1]) - return eval(res) > eval(str) + if(typeof res =='string'&&res.includes('/')){ + return handleMoreParam(res,m.split('>')[1],'>') + }else{ + let str = handleFraction(m.split('>')[1]) + return eval(res) > eval(str) + } }else if (m.includes('~')) { - let k = m.split('~') - return eval(res) >= eval(handleFraction((k[0]))) && eval(res) <= eval(handleFraction(k[1])) + if(typeof res =='string'&&res.includes('/')){ + 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('-')){ - let k = m.split('-') - return eval(res) >= eval(handleFraction(k[0])) && eval(res) <= eval(handleFraction(k[1])) + if(typeof res =='string'&&res.includes('/')){ + 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('卤')){ - let k = m.split('卤') - return eval(res) >= eval((handleFraction(k[0]) - handleFraction(k[1]))) && eval(res) <= eval((handleFraction(k[0]) + handleFraction(k[1]))) + if(typeof res =='string'&&res.includes('/')){ + 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('锛�')){ - let str = handleFraction(m.split('锛�')[1]) - return eval(res) > eval(str) + if(typeof res =='string'&&res.includes('/')){ + return handleMoreParam(res,m.split('锛�')[1],'>') + }else{ + let str = handleFraction(m.split('锛�')[1]) + return eval(res) > eval(str) + } }else if(m.includes('锛�')){ - let str = handleFraction(m.split('锛�')[1]) - return eval(res) < eval(str) + if(typeof res =='string'&&res.includes('/')){ + return handleMoreParam(res,m.split('锛�')[1],'<') + }else{ + let str = handleFraction(m.split('锛�')[1]) + return eval(res) < eval(str) + } } }) } @@ -130,6 +186,7 @@ } }) } else { + console.log(333333) item.v.v = 0 list.forEach(a => { if (a[0].r == item.r) { @@ -158,14 +215,15 @@ } else { let comResult = '' - console.log('item.v.f',item.v.f) 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 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) - console.log(1111,comResult) + 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() } @@ -191,6 +249,7 @@ comResult = str } } catch (error) { + console.log('error---', error) } try { list.forEach(a => { @@ -210,7 +269,7 @@ }) changeInput(comResult, `${id}-${item.r}-${item.c}-${pId}`) //鏀瑰彉鏈�缁堝�� } catch (error) { - + console.log('error---', error) } } } @@ -238,7 +297,12 @@ } } } - +/** + * 澶勭悊鍒嗘暟鎴栧甫鏈変箻娉曞拰涔樻柟鐨勫瓧绗︿覆 + * + * @param str 瀛楃涓茬被鍨嬶紝琛ㄧず瑕佸鐞嗙殑鍒嗘暟鎴栦箻鏂硅〃杈惧紡 + * @returns 杩斿洖涓�涓暟瀛楁垨鍘熷瓧绗︿覆锛屽鏋滃瓧绗︿覆涓烘湁鏁堢殑鍒嗘暟鎴栦箻鏂硅〃杈惧紡锛屽垯杩斿洖璁$畻缁撴灉锛涘惁鍒欒繑鍥炲師瀛楃涓� + */ function handleFraction(str){ if(str&&typeof(str)=='string'&&str.includes('/')){ return eval(str.split('/')[0]/str.split('/')[1]) @@ -254,6 +318,51 @@ } } +/** + * 澶勭悊甯︽湁澶氫釜鍙傛暟鐨勫嚱鏁� + * + * @param res 瀛楃涓诧紝闇�瑕佽鍒嗗壊骞跺鐞嗙殑瀛楃涓� + * @param str 瀛楃涓诧紝涓巖es涓殑姣忎竴椤硅繘琛屾瘮杈冪殑瀛楃涓诧紝鍙兘鏄垎鏁版垨鑰呭甫鏈夋瘮杈冪鍙风殑瀛楃涓� + * @param comp 瀛楃涓诧紝琛ㄧず姣旇緝绫诲瀷鐨勫瓧绗︼紙濡� '>'銆�'<'銆�'='銆�'鈮�'銆�'鈮�'銆�'卤'銆�'~'銆�'-'锛� + * @returns 杩斿洖甯冨皵鍊硷紝濡傛灉res涓瘡涓�椤归兘婊¤冻涓巗tr鐨勬瘮杈冩潯浠讹紝鍒欒繑鍥瀟rue锛屽惁鍒欒繑鍥瀎alse + */ +function handleMoreParam(res,str,comp){ + let arr = res.split('/') + let arr0 = arr.every(item=>{ + switch (comp){ + case '>': + return item > handleFraction(str) + case '<': + return item < handleFraction(str) + case '=': + return item == handleFraction(str) + case '鈮�': + return item >= handleFraction(str) + case '鈮�': + return item <= handleFraction(str) + case '卤': + let k = str.split('卤') + return item >= eval((handleFraction(k[0]) - handleFraction(k[1]))) && item <= eval((handleFraction(k[0]) + handleFraction(k[1]))) + case '~': + let j = str.split('~') + return item >= eval(handleFraction((j[0]))) && item <= eval(handleFraction(j[1])) + case '-': + let o = str.split('-') + return item >= eval(handleFraction(o[0])) && item <= eval(handleFraction(o[1])) + } + }) + if(arr0){ + return true + }else{ + return false + } + } + +/** + * 鑾峰彇鍙傛暟 + * + * @returns 杩斿洖澶勭悊鍚庣殑鍙傛暟瀵硅薄 + */ function getParam(){ for (var b in param){ param[b].insValue = [] @@ -591,6 +700,7 @@ } } + /** * 璁$畻鍑芥暟 * @@ -608,8 +718,6 @@ if(typeof(comValue[a])=='string'&&comValue[a].includes('^')){ // 璁$畻骞傛 arr[a] = CalculatePower(comValue[a]) - } else if (typeof(comValue[a])=='string'&&comValue[a].includes('/')) { - arr[a] = comValue[a].split('/')[0] / comValue[a].split('/')[1]; } else{ arr[a] = comValue[a] } @@ -656,7 +764,7 @@ } if(str.includes('&"/"&')){ return str.replaceAll('&"/"&', '/').replaceAll('//','') - }else{ + }else { return eval(str) } } catch (error) { -- Gitblit v1.9.3