From d975fc4756806f5b51f006c19c33571b9b8c0b3b Mon Sep 17 00:00:00 2001 From: licp <lichunping@guanfang.com.cn> Date: 星期五, 20 十二月 2024 09:30:19 +0800 Subject: [PATCH] 修改下单时要求值输入限制 --- static/js/worker.js | 599 +++++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 419 insertions(+), 180 deletions(-) diff --git a/static/js/worker.js b/static/js/worker.js index e3fe14a..e618e24 100644 --- a/static/js/worker.js +++ b/static/js/worker.js @@ -1,51 +1,120 @@ - +// 澶氱嚎绋嬮噷闈㈤渶瑕佷繚瀛樼殑鏁版嵁 let code = '' -let tableList = [] +// 琛ㄦ牸鏁版嵁锛堟覆鏌擄級 +let tableList = null +// 鏂规硶鍒楄〃 let excelMethodList = [] +// excel鍧愭爣姣旇緝鍒楄〃 let comparisonList = [] +// 褰撳墠鏍峰搧淇℃伅 let currentSample = {} +// 褰撳墠椤圭洰锛氭娴嬩腑蹇冦�佽澶囩數缂� let PROJECT = '' +// 濂楃 +let bushing = '' +// 澶氱嚎绋嬩紶閫掑埌涓荤嚎绋嬬殑鏁版嵁 let result = { method:'', value:null } +// 淇濆瓨鏃朵紶鍒板悗绔弬鏁� let param = null +// 褰撳墠鐨勬ā鏉� +let currentTable = '' +// 浼樺寲鏁伴噰杈冨鏁版嵁鏃�-璁板綍鏈�鍚庝竴涓楠岄」鐨刬d +let getDataTypeId = null +// 鎺ユ敹鍒颁富绾跨▼澶勭悊閫昏緫鐨勬秷鎭� 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 + } + if(data.bushing&&(data.bushing!=bushing)&&data.type=='saveData'){ + // 鏇存柊琛ㄦ牸鏁版嵁銆佷紶閫掑埌鍚庣鐨勫弬鏁板拰濂楃鏁版嵁 + tableList = data.tableList; + param = data.param; + bushing = data.bushing; + return + } code = data.code; - tableList = JSON.parse(JSON.stringify(data.tableList)); + if(data.getDataTypeId){ + // 璁板綍 浼樺寲鏁伴噰杈冨鏁版嵁鏃�-璁板綍鏈�鍚庝竴涓楠岄」鐨刬d + getDataTypeId = data.getDataTypeId + }else{ + getDataTypeId = null + } + 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; + } + // 鏇存柊鏂规硶鍒楄〃銆佸潗鏍囨瘮杈冨垪琛ㄣ�佸綋鍓嶆牱鍝佷俊鎭�侀」鐩� 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); }; function changeInput(m, code){ let str = code.split('-') - let r = str[1] - let c = str[2] + let r = str[1]//褰撳墠琛� + let c = str[2]//褰撳墠鍒� let id = str[0] - let pId = str[3] - var list = [] + let pId = str[3]//褰撳墠妫�楠岄」id锛宲aram[pId]涓哄綋鍓嶆楠岄」鐨勬墍鏈夊�硷紝鍖呭惈锛氳繃绋嬪�糹nsValue銆佽绠楀�糲omValue銆佽澶囩紪鐮乪quipValue銆佽澶囧悕绉癳quipName銆佹渶缁堝�紃esValue銆佺粨璁篿nsResult + var list = []//涓�涓弻灞傛暟缁勶紝閲岄潰淇濆瓨鏈夊綋鍓嶉〉闈㈡覆鏌撶殑鎵�鏈夋暟鎹� + // 璧嬪�煎綋鍓嶆ā鏉跨殑琛ㄦ牸鏁版嵁 for (let a in tableList) { if (tableList[a].templateId == id) { list = tableList[a].arr break } } - let isToExponential = '' - let list2 = [] - + let isToExponential = ''//鏄惁涓虹瀛﹁鏁版硶 + let list2 = [] //涓�涓暟缁勶紝閲岄潰淇濆瓨鏈夊綋鍓嶆楠岄」鐨勬墍鏈夊弬鏁板�� + let isPoint = '' //鏄惁涓哄皬鏁扮偣 + // 寰幆鎵�鏈塭xcel鏂规硶锛屾壘鍒板綋鍓嶈銆佸垪鐨勬楠岄」锛屽鏋滄鍗曞厓鏍硷紙r,c锛夋槸鏌愪釜excel鏂规硶閲岄潰鐨勫弬鏁帮紝鍒欐墽琛屾鏂规硶 excelMethodList.forEach(item => { - if (item.valueList.find(m => m.r == r && m.c == c)) { + // item.valueList 鏄綋鍓峞xcel鏂规硶鐨勫弬鏁板垪琛紝鎵惧埌褰撳墠濉叆鐨勫�兼槸鍚︽槸鍙傛暟 + if (item.valueList&&item.valueList.length>0&&item.valueList.find(m => m.r == r && m.c == c)) { + // 濡傛灉鏄紝鍒欏畾涔変竴涓弬鏁扮殑瀵硅薄闆嗗悎锛岀敤浜庝繚瀛樺綋鍓峞xcel鏂规硶鍙傛暟鐨勫�� var comValue = {} item.valueList.forEach(a => { list.forEach(b => { if (b[0].r == a.r) { b.forEach(c => { if (c.c == a.c) { + // 鑾峰彇褰撳墠鍙傛暟鐨凟xecl琛屽潗鏍�(ABCD)绛夌瓑 var tableCode = '' for (var d in comparisonList) { if (c.c == comparisonList[d].value) { @@ -54,14 +123,18 @@ } } list2.push(c.v.v) + // 缁勮鍙傛暟鐨勫璞¢泦鍚堝苟璧嬪�硷紝鍒楀{A3:12,B4:15} if(getInspectionValueType(item.i)==1&&!isNaN(parseFloat(c.v.v))){ + // 濡傛灉鏄暟瀛楄緭鍏ユ let n = String(c.v.v) if(n.includes('/')){ + // 濡傛灉鏄垎鏁帮紝鍒欒祴鍊� comValue[(tableCode + (c.r + 1))] = c.v.v }else{ comValue[(tableCode + (c.r + 1))] = parseFloat(c.v.v) } }else{ + // 濡傛灉鏄枃鏈�佷笅鎷夋绛夌瓑 comValue[(tableCode + (c.r + 1))] = c.v.v } } @@ -69,14 +142,17 @@ } }) }) + // 濡傛灉姝xcel鏂规硶鏄粨璁哄垽鏂柟娉曪紝鍒欐墽琛屾鏂规硶 if (item.v.ps != undefined && item.v.ps.value == '缁撹') { try { if (currentSample.insProduct.find(m => m.id == item.i)) { + // 濡傛灉褰撳墠妫�楠岄」鏄骇鍝佹楠岄」锛屽垯鎵ц姝ゆ柟娉曪紝鎵惧埌姝ゆ楠岄」鐨勮姹傚�� 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'){ + // 鍒ゆ柇褰撳墠缁撹鐨勫弬鏁帮紙褰撳墠妫�楠岄」鐨勬渶缁堝�硷級鏄惁涓虹┖锛屽鏋滀负绌猴紝鍒欑洿鎺ヨ祴鍊� + if(res===''||res===null||res===undefined||res==='Infinity'){ item.v.v = null list.forEach(a => { if (a[0].r == item.r) { @@ -89,156 +165,249 @@ } }) }else{ - // console.log(ask,res,item.v.f) - if(ask){ - comp = ask.map((m, i) => { - if (m.includes('RTS')) { - m = m.replace('RTS*', '') + // 濡傛灉涓嶄负绌猴紝鍒欏垽鏂綋鍓嶇粨璁哄氨闇�瑕佽繘琛屽垽鏂� + //瑕佹眰鍊间负-锛�/锛屸�旓紝鍒欑粨璁鸿缃负涓嶅垽瀹氾紝缁撹璧嬪�间负3 + console.log(3333,ask) + if(ask[0]=='-' || ask[0]=='/' || ask[0]=='鈥�'){ + item.v.v = 3 + 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 = 3 + break + } + } } - if (m.includes('=')) { - let str = handleFraction(m.split('=')[1]) - if(typeof res == 'string'&&typeof str == 'string'){ - if(res.includes('/')){ - return handleMoreParam(res,m.split('=')[1],'=') + }) + }else{ + // 瑕佹眰鍊间笉涓�-锛�/锛屸�旓紝鍒欒繘琛屽垽鏂� + if(ask){ + // 寰幆瑕佹眰鍊煎垪琛紝鍒ゆ柇褰撳墠缁撹鐨勫弬鏁版槸鍚︾鍚堣姹� + comp = ask.map((m, i) => { + // 瑁呭鐗规湁鐨勫垽鏂柟娉曪紙闇�瑕佺瀛﹁鏁版硶鐨勶級锛岃姹傚�艰繘琛屾浛鎹� + if (m.includes('RTS')) { + m = m.replace('RTS*', '') + } + // 濡傛灉瑕佹眰鍊煎寘鍚�=锛屽垯鍒ゆ柇褰撳墠缁撹鐨勫弬鏁版槸鍚︾瓑浜庤姹傚�硷紝 + // 浠ヤ笅鍒ゆ柇鍩烘湰涓�鑷达紝鍙槸鍒ゆ柇绫诲瀷涓嶄竴鏍凤紝灏变笉鍋氭敞閲婁簡 + if (m.includes('=')) { + // 澶勭悊瑕佹眰鍊� + let str = handleFraction(m.split('=')[1]) + if(typeof res == 'string'&&typeof str == 'string'){ + // 濡傛灉瑕佹眰鍊煎拰褰撳墠缁撹鐨勫弬鏁伴兘鏄瓧绗︿覆锛屽垯鎵ц + if(res.includes('/')){ + // 濡傛灉缁撹鐨勫弬鏁版槸鍒嗘暟锛屽垯鍒ゆ柇 + if (m.includes('/')) { + // 濡傛灉瑕佹眰鍊兼槸鍒嗘暟锛屽垯鍒ゆ柇 + return eval(res) == eval(str) + } else { + // 濡傛灉瑕佹眰鍊间笉鏄垎鏁帮紝鍒欏垽鏂� + return handleMoreParam(res,m.split('=')[1],'=') + } + }else{ + // 濡傛灉缁撹鐨勫弬鏁颁笉鏄垎鏁帮紝鍒欏垽鏂� + return res.trim().replace(/[.,銆傘�侊紱锛�'";?锛熲�滐紝]/g, '') == str.trim().replace(/[.,銆傘�侊紱锛�'";?锛熲�滐紝]/g, '') + } }else{ - return res.trim() == str.trim() + // 濡傛灉瑕佹眰鍊煎拰褰撳墠缁撹鐨勫弬鏁版湁涓�涓槸鏁板瓧锛屽垯鎵ц + return eval(res) == eval(str) } - }else{ - return eval(res) == eval(str) - } - } else if (m.includes('鈮�')) { - 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('鈮�')) { - 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('<')) { - 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('>')) { - 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('~')) { - 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('-')){ - 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('卤')){ - 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('锛�')){ - 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('锛�')){ - if(typeof res =='string'&&res.includes('/')){ - return handleMoreParam(res,m.split('锛�')[1],'<') - }else{ - let str = handleFraction(m.split('锛�')[1]) - return eval(res) < eval(str) - } - } - }) - } - if (comp.every(m => m)) { - item.v.v = 1 - 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 = 1 - break + } else if (m.includes('鈮�')) { + if(typeof res =='string'&&res.includes('/')){ + 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('/')){ + 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('/')){ + 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('/')){ + 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('/')){ + 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('/')){ + 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('/')){ + if (m.includes('/')) { + let k = m.split('卤') + return eval(res) >= eval((handleFraction(k[0]) - handleFraction(k[1]))) && eval(res) <= eval(Number((handleFraction(k[0])) + Number(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(Number((handleFraction(k[0]) )+ Number(handleFraction(k[1])))) + } + }else if(m.includes('锛�')){ + if(typeof res =='string'&&res.includes('/')){ + 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('/')){ + 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 { - console.log(333333) - item.v.v = 0 - 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 = 0 - break + }) + } + // 濡傛灉瑕佹眰鍊肩殑姣忎釜鏉′欢閮界鍚堬紝鍒欑粰缁撹璧嬪�间负1锛屽悎鏍� + if (comp.every(m => m)) { + item.v.v = 1 + 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 = 1 + break + } } } - } - }) + }) + }else { + // 鍚﹀垯缁欑粨璁鸿祴鍊间负0锛屼笉鍚堟牸 + item.v.v = 0 + 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 = 0 + break + } + } + } + }) + } } } + let getDataType0 = false + // 浼樺寲鏁伴噰杈冨鏁版嵁鏃�-璁板綍鏈�鍚庝竴涓楠岄」鐨刬d锛屽鏋滃綋鍓嶆楠岄」鐨刬d涓庤褰曠殑id鐩稿悓锛屽垯澶氫紶涓�涓弬鏁板埌涓荤嚎绋嬶紝杩涜鏁版嵁淇濆瓨锛屽惁鍒欐暟閲囧氨涓嶈繘琛屼繚瀛� + if(item.i==getDataTypeId){ + getDataType0 = true + } + // 璧嬪�间紶閫掑埌涓荤嚎绋嬬殑鏁版嵁锛宮ethod锛歴aveInsContext琛ㄧず姝ゆ秷鎭渶瑕佷繚瀛樻暟鎹� result = { method:'saveInsContext', value:{ - tableList, - param:getParam() + tableList,// 琛ㄦ牸鏁版嵁 + param:getParam(),//浼犵粰鍚庣鐨勫弬鏁� + getDataTypeId:getDataType0?getDataTypeId:'', + currentInsItemId: item.i,// 褰撳墠妫�楠岄」鐨刬d } } + console.log('result---', result) + // 鍙戞秷鎭粰涓荤嚎绋� self.postMessage(JSON.stringify(result)) } } catch (error) { - + console.log('error---', error) } } else { - let comResult = '' + // 濡傛灉鏄嚱鏁版柟娉曪紝鍒欐墽琛屾鏂规硶 + 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) - }) - isToExponential = list3.some(val => val.includes('e+')) - // 瑁呭椤圭洰妫�楠屽�艰浆鍖� - if (PROJECT === '瑁呭鐢电紗' && isToExponential) { + // 濡傛灉妫�楠屽�肩被鍨嬫槸鏁板瓧杈撳叆妗� + 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+')||val.includes('e-')) + // 妫�楠屽�艰浆鍖� + let findProduct = currentSample.insProduct.find(i=>i.inspectionItem=='浣撶Н鐢甸樆鐜�') + // 鍒ゆ柇妫�楠岄」鏄惁涓轰綋绉數闃荤巼锛屽鏋滀负浣撶Н鐢甸樆鐜囦笖澶т簬100000锛屽垯杩涜杞寲 + if (findProduct && isToExponential && comResult>=100000) { let num2 = new Big(comResult) - comResult = num2.toExponential() + comResult = num2.toExponential(1) } }else{ + // 濡傛灉妫�楠屽�肩被鍨嬫槸鏂囨湰杈撳叆妗嗐�佷笅鎷夋 let valueList = []; + // 澶勭悊excel鍑芥暟鍙傛暟鍒楄〃 item.valueList.forEach(a => { valueList.push({ name: `${comparisonList.find(e=>e.value==a.c).label}${a.r+1}`, value: 0, }) }) + // 缁檈xcel鍑芥暟鍙傛暟璧嬫枃鏈�� for (var a in comValue) { valueList.forEach(b => { if (b.name == a) { @@ -246,31 +415,53 @@ } }) } + // 璁$畻鍏紡锛屽幓鎺塭xcel鍑芥暟鐨勭瓑鍙凤紝骞舵浛鎹㈠弬鏁帮紝鍒楀锛�=A1 鍙樻垚 A1 鍙樻垚 鈥樻枃鏈緭鍏ョ殑鍊尖�� let str = item.v.f.replace(/=/g, ' ') valueList.forEach(b => { str = str.replace(b.name, b.value) }) + // 璁$畻缁撴灉璧嬪�� comResult = str } } catch (error) { console.log('error---', error) } try { + // 寰幆琛ㄦ牸鏁版嵁锛岀粰琛ㄦ牸鏁版嵁杩涜璧嬪�� list.forEach(a => { if (a[0].r == item.r && comResult !== '') { + // 鍒ゆ柇褰撳墠琛屾槸鍚︿负褰撳墠妫�楠岄」鎵�鍦ㄨ锛屽鏋滀负褰撳墠琛岋紝鍒欑粰琛ㄦ牸鏁版嵁璧嬪�� 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){ + // 鍒ゆ柇璁$畻缁撴灉鏄惁涓�0锛屽鏋滀负0锛屽垯缁欒〃鏍兼暟鎹祴鍊间负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):comResult + }else if(typeof comResult == 'string' && (comResult.includes('e+')|| comResult.includes('e-'))){ + // 鍒ゆ柇璁$畻缁撴灉鏄惁涓虹瀛﹁鏁版硶锛屽鏋滀负绉戝璁℃暟娉曪紝鍒欑粰琛ㄦ牸鏁版嵁璧嬪�间负绉戝璁℃暟娉� + a[b].v.v = comResult + }else{ + // 鍒ゆ柇璁$畻缁撴灉鏄惁涓烘暟瀛楋紝濡傛灉涓烘暟瀛楋紝鍒欑粰琛ㄦ牸鏁版嵁璧嬪�间负鏁板瓧 + let val = parseFloat(Number(comResult).toFixed(3)) + a[b].v.v = isNaN(val) ? comResult : val + } + }catch(error){ + // 濡傛灉浠ヤ笂鍒ゆ柇閮戒笉鏀寔锛屽垯鐩存帴璧嬪�� a[b].v.v = comResult + console.log('error---', error) } break } } } }) + // 濡傛灉姝よ绠楃粨鏋滄墍灞炲崟鍏冩牸锛屽悓鏃朵篃鏄彟涓�涓猠xcel鍑芥暟鐨勫弬鏁帮紝閭d箞灏遍渶瑕侀�掑綊杩涜璁$畻 changeInput(comResult, `${id}-${item.r}-${item.c}-${pId}`) //鏀瑰彉鏈�缁堝�� } catch (error) { console.log('error---', error) @@ -278,22 +469,31 @@ } } }) + // 璧嬪�煎绾跨▼浼犺緭鏁版嵁 result = { method:'tableList', value:tableList } + // 鍙戦�佷富绾跨▼鏁版嵁 self.postMessage(JSON.stringify(result)) try { + // 璧嬪�煎绾跨▼浼犺緭鏁版嵁 result = { method:'getCurrentInsProduct', value:pId } + // 鍙戦�佷富绾跨▼鏁版嵁 self.postMessage(JSON.stringify(result)) } catch (error) { - + console.log('error---', error) } } - +/** + * 鑾峰彇妫�娴嬪�肩被鍨� + * + * @param id 妫�娴嬪�肩被鍨嬪搴旂殑id + * @returns 杩斿洖妫�娴嬪�肩被鍨� + */ function getInspectionValueType(id) { for (var a in currentSample.insProduct) { if (currentSample.insProduct[a].id == id) { @@ -309,8 +509,10 @@ */ function handleFraction(str){ if(str&&typeof(str)=='string'&&str.includes('/')){ + // 澶勭悊鍒嗘暟 return eval(str.split('/')[0]/str.split('/')[1]) } else if (str && typeof(str) == 'string' && str.includes('*') && str.includes('^')) { + // 璁$畻涔樻柟 const num1 = str.split('*') const num2 = num1[1].split('^') let num3 = new Big(num2[0]); @@ -346,7 +548,7 @@ 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]))) + return item >= eval((handleFraction(k[0]) - handleFraction(k[1]))) && item <= eval(Number((handleFraction(k[0])) + Number(handleFraction(k[1])))) case '~': let j = str.split('~') return item >= eval(handleFraction((j[0]))) && item <= eval(handleFraction(j[1])) @@ -368,33 +570,49 @@ * @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 === '璁$畻鍊�') { - b.i &&b.v.v&& param[b.i].comValue.push(b) + // 璧嬪�艰绠楀�� + b.i &&b.v.v&&b.valueList&&b.valueList.length>0&& param[b.i].comValue.push(b) } if (b.v.ps != undefined && b.v.ps.value === '璁惧缂栫爜') { - b.i &&b.v.v&& param[b.i].equipValue.push(b) + // 璧嬪�艰澶囩紪鐮� + b.i &&b.v&& param[b.i].equipValue.push(b) } if (b.v.ps != undefined && b.v.ps.value === '璁惧鍚嶇О') { - b.i &&b.v.v&& param[b.i].equipName.push(b) + // 璧嬪�艰澶囧悕绉� + b.i &&b.v&& param[b.i].equipName.push(b) } if (b.v.ps != undefined && b.v.ps.value === '鏈�缁堝��') { - b.i &&b.v.v&& (param[b.i].resValue = b) + // 璧嬪�兼渶缁堝�� + b.i &&b.v&&b.valueList&&b.valueList.length>0&& (param[b.i].resValue = b) } if (b.v.ps != undefined && b.v.ps.value === '缁撹') { - b.i &&(b.v.v||b.v.v===0||b.v.v==='0')&& (param[b.i].insResult = b) + if(b.i &&(b.v.v||b.v.v===0||b.v.v==='0')){ + if(b.v.v != '鍚堟牸'&&b.v.v != '涓嶅悎鏍�'){ + // 璧嬪�肩粨璁� + param[b.i].insResult = b + } + } } }) }) @@ -411,14 +629,14 @@ function SUM(...val){ try { let num = null; - if(val&&val.length>0){ + if(val!=null&&val!=undefined&&val!='undefined'&&val!='NaN'&&val.length>0){ val.forEach(item=>{ num+=item; }) } return num; } catch (error) { - + console.log('error---', error) } } /** @@ -430,7 +648,7 @@ function MAX(...val){ try { let max = null; - if(val&&val.length>0){ + if(val!=null&&val!=undefined&&val!='undefined'&&val!='NaN'&&val.length>0){ val = val.filter(item=>item!=null&&item!=='') if(val.length>0){ max = Math.max(...val) @@ -440,7 +658,7 @@ } return max; } catch (error) { - + console.log('error---', error) } } /** @@ -452,7 +670,7 @@ function MIN(...val){ try { let min = null; - if(val&&val.length>0){ + if(val!=null&&val!=undefined&&val!='undefined'&&val!='NaN'&&val.length>0){ val = val.filter(item=>item!=null&&item!=='') if(val.length>0){ min = Math.min(...val) @@ -460,7 +678,7 @@ } return min; } catch (error) { - + console.log('error---', error) } } /** @@ -473,8 +691,8 @@ try { let num = null; let arr = []; - if(val&&val.length>0){ - arr = val.filter(item=>item!=null&&item!=='') + if(val!=null&&val!=undefined&&val!='undefined'&&val!='NaN'&&val.length>0){ + arr = val.filter(item=>item!==null&&item!==''&&item!=undefined) arr.forEach(item=>{ num+=item; }) @@ -487,7 +705,7 @@ return null; } } catch (error) { - + console.log('error---', error) } } /** @@ -500,7 +718,7 @@ try { return Math.abs(val); } catch (error) { - + console.log('error---', error) } } /** @@ -531,7 +749,7 @@ return null; } } catch (error) { - + console.log('error---', error) } } @@ -552,11 +770,9 @@ } } } catch (error) { - + console.log('error---', error) } } - - /** * 鏍规嵁鍧愭爣鑾峰彇鍒楀悕 @@ -578,7 +794,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 +836,7 @@ } return id; }catch(e){ - console.log('error',id) + console.log('error',e) } } @@ -635,6 +851,7 @@ let arr = getABCList(f) let arr2 = [] arr.forEach(item=>{ + // 鍒ゆ柇鏄惁涓鸿寖鍥达紝鍒楀MAX(A1:B2) if(item.includes(':')){ let r0 = getIdFromColumnName(item.split(':')[0]).r; let c0 = getIdFromColumnName(item.split(':')[0]).c; @@ -649,12 +866,13 @@ } } }else{ + // 娌℃湁鍒欑洿鎺ヨ幏鍙� arr2.push(getIdFromColumnName(item)) } }) return arr2; } catch (error) { - + console.log('error',error) } } /** @@ -666,6 +884,7 @@ function getABCList(f){ try { let regex = /[=\+\-\*\%\(\)\/\^\s]/g; + // 涓婇潰璁$畻鍑芥暟鏂板鍚庯紝杩欓噷涔熻鍚屾澧炲姞 let fouList = [ "SUM", 'MAX', @@ -673,16 +892,17 @@ '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 +920,7 @@ }) return arr0; } catch (error) { - + console.log('error',error) } } @@ -712,7 +932,7 @@ * @param comValue 瀵硅薄绫诲瀷锛岃〃绀鸿鏇挎崲鐨勫崟鍏冩牸鍊硷紝閿负鍗曞厓鏍煎悕绉帮紝鍊间负鏇挎崲鍚庣殑鍊� * @returns 杩斿洖璁$畻鍚庣殑缁撴灉锛屽鏋滆绠楀け璐ュ垯杩斿洖0 */ -function compute(f,comValue){ +function compute(f,comValue, isPoint){ try { let str = f // 鑾峰彇鍗曞厓鏍煎搴斿�� @@ -754,25 +974,44 @@ 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'),',') + } + 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) + // 璁$畻甯歌鐨� return eval(str) } } catch (error) { - + console.log('error',error) } } -- Gitblit v1.9.3