From c53cecad93cb47e839be60a26633d3b89a06661d 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, 29 Aug 2023 10:26:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A1=86=E5=9B=A0=E8=BE=93=E5=85=A5=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5=E5=8C=85=E5=90=ABand=E5=AF=BC=E8=87=B4=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=8F=8Aschema=E5=AD=97=E6=AE=B5=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E6=A8=A1=E7=B3=8A=E6=90=9C=E7=B4=A2?= =?UTF-8?q?domain=E5=92=8Capp=E4=B8=8D=E8=83=BD=E8=AF=86=E5=88=AB=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/tools.js | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/utils/tools.js b/src/utils/tools.js index 465d66b8..a01b6308 100644 --- a/src/utils/tools.js +++ b/src/utils/tools.js @@ -1398,7 +1398,7 @@ export function comparedEntityKey (str) { const regex = /\ = | =|= /g q = q.replace(regex, '=') - if (q.indexOf('AND') > -1) { + if (q.indexOf('AND') > -1 && checkStrIncludeAnd(q)) { const arr = q.split(' AND ') let newQ = '' let errorQ = '' @@ -1449,6 +1449,7 @@ export function comparedEntityKey (str) { } } else { const key = q.substring(0, q.indexOf('=')) + q = q.replace(/ AND /g, ' and ') const obj = columnList.find(t => t.label.toLowerCase() === key.toLowerCase()) if (obj) { return { key: obj.label + q.substring(q.indexOf('='), q.length), isKey: true } @@ -1511,11 +1512,15 @@ export const handleEntityTypeByStr = (str) => { const reg = /^(?=^.{3,255}$)(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*$/ if (regexIPv4.test(str) || regexIPv6.test(str)) { - return `IP='${str}'` + const obj = columnList.find(t => t.label.toLowerCase() === 'ip') + return `${obj.label}='${str}'` } else if (reg.test(str)) { - return `Domain LIKE '%${str}'` + // 只写作domain即可,schema字段更改几次,避免后续再更改,直接拿columnList的label进行替换 + const obj = columnList.find(t => t.label.toLowerCase() === 'domain') + return `${obj.label} LIKE '%${str}'` } else { - return `App LIKE '%${str}%'` + const obj = columnList.find(t => t.label.toLowerCase() === 'app') + return `${obj.label} LIKE '%${str}%'` } } } @@ -1609,3 +1614,28 @@ const combineLabel1 = (list) => { return acc }, {}) } +/** + * 检测传过来的字符串是否包含and, + * 例如 app='Computer and Internet'这种情况,需要单独甄别 + * @param str + */ +const checkStrIncludeAnd = (str) => { + const arr = str.split(' AND ') + let label = '' + + arr.forEach((item, index) => { + // and前后的语句,前面一段不需要甄别,因为前一段可能是app='Computer,但后一段肯定不属于columnList + // 如果后面一段属于columnList的关键字,整段字符串具有and的连接效果 + if (index % 2 !== 0) { + if (item.indexOf('=') > -1) { + label = item.substring(0, item.indexOf('=')) + } else if (item.toLowerCase().indexOf(' in ') > -1) { + label = item.substring(0, item.toLowerCase().indexOf(' in ')) + } else if (item.indexOf('has(') > -1) { + label = item.substring(4, item.indexOf(',')) + } + } + }) + + return columnList.find(t => t.label.toLowerCase() === label.toLowerCase()) +}