From e3c3ed42009c89bdc4a3d5e0d8bfcc04ea8e8b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B4=AA=E6=B4=AA?= <2498601771@qq.com> Date: Tue, 19 Sep 2023 16:45:18 +0800 Subject: [PATCH] =?UTF-8?q?CN-1319=20fix:=20=E5=9C=A8=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A8=A1=E5=BC=8F=E4=B8=8B=EF=BC=8C=E5=8F=AA?= =?UTF-8?q?=E8=A6=81=E8=BE=93=E5=85=A5=E7=9A=84=E6=96=87=E6=9C=AC=E4=B8=AD?= =?UTF-8?q?=E5=8C=85=E5=90=ABip=E7=AD=89=E9=BB=98=E8=AE=A4=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=AD=97=E6=AE=B5=E6=97=B6=EF=BC=8C=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=B0=B1=E4=BC=9A=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/advancedSearch/meta/parser.js | 28 +++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/components/advancedSearch/meta/parser.js b/src/components/advancedSearch/meta/parser.js index 3b728d5e..205b9335 100644 --- a/src/components/advancedSearch/meta/parser.js +++ b/src/components/advancedSearch/meta/parser.js @@ -10,6 +10,7 @@ const strReg = { key: /^(?![\d])[\da-zA-Z\s.'-_]$/, value: /^[\da-zA-Z\s.'-_%]$/ } +const operatorList = ['=', ' in ', ' IN ', ' like ', ' LIKE ', ' HAS(', ' has('] export default class Parser { constructor (columnList) { @@ -1061,7 +1062,7 @@ export default class Parser { q = q.replace(/ and /g, ' AND ') } const arr = q.split(' AND ') - const returnObj = { key: '', isKey: false } + const returnObj = { key: '', isKey: true } arr.forEach(item => { let label = '' let key = '' @@ -1077,21 +1078,30 @@ export default class Parser { } else if (item.toLowerCase().indexOf('has(') > -1) { label = item.substring(item.toLowerCase().indexOf('(') + 1, item.indexOf(',')) key = 'has' + } else if (this.columnList.some(ite => ite.label.toLowerCase() === item.toLowerCase())) { + label = 'item' + key = item } const obj = this.columnList.find(t => t.label.toLowerCase() === label.toLowerCase()) - if (obj) { + if (obj && returnObj.isKey) { + returnObj.isKey = true if (key === 'has') { returnObj.key += 'has(' + obj.label + item.substring(item.indexOf(','), item.length) + ' AND ' } else { returnObj.key += obj.label + ' ' + item.substring(item.toLowerCase().indexOf(key.toLowerCase()), item.length) + ' AND ' } - returnObj.isKey = true - } else { - return { key: '[' + key + ']', isKey: false } + } else if (returnObj.isKey) { + returnObj.key = '[' + key + ']' + if (key === item) { + returnObj.key = key + } + returnObj.isKey = false } }) - returnObj.key = returnObj.key.substring(0, returnObj.key.length - 5) + if (returnObj.isKey) { + returnObj.key = returnObj.key.substring(0, returnObj.key.length - 5) + } return returnObj } else if (q.indexOf(' LIKE ') > -1 || q.indexOf(' like ') > -1) { @@ -1190,6 +1200,9 @@ export default class Parser { if (!arr.some(ite => item.includes(ite))) { newArr[index] = this.checkFormatByStr(item, 'list') } + if (arr.some(ite => item.includes(ite)) && !operatorList.some(ite => item.includes(ite)) && !arr.some(ite => item.toLowerCase() === ite.toLowerCase())) { + newArr[index] = this.checkFormatByStr(item, 'list') + } }) newStr = newArr.join(' AND ') @@ -1200,6 +1213,9 @@ export default class Parser { arr.forEach(item => { if (str.toLowerCase().indexOf(item.toLowerCase()) > -1) { str = str.replace(new RegExp(item, 'gi'), item) + if (!operatorList.some(ite => str.includes(ite)) && str.toLowerCase() !== item.toLowerCase()) { + str = this.checkFormatByStr(str) + } } }) return str