summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author陈劲松 <[email protected]>2024-05-09 09:08:56 +0000
committer陈劲松 <[email protected]>2024-05-09 09:08:56 +0000
commitf020fe33b5fae13de4292d4fde3128a3c2cbae78 (patch)
tree24eeaafefbd41f07533e8cebe84e3eb5b1159ce5
parenta26b0c848d47c2d5d609ba765832e4ff97dec6fa (diff)
parent75b47d7ba730c41087471ec751c56aab6766d2f3 (diff)
Merge branch 'cherry-pick-df183c18' into 'dev-24.01-m22'
fix: 修复entity和detection搜索时随意输入字段,没有错误提示且resource为空的问题 See merge request cyber-narrator/cn-ui!71
-rw-r--r--src/components/advancedSearch/meta/parser.js90
1 files changed, 79 insertions, 11 deletions
diff --git a/src/components/advancedSearch/meta/parser.js b/src/components/advancedSearch/meta/parser.js
index 8ca7e2ff..f43359a9 100644
--- a/src/components/advancedSearch/meta/parser.js
+++ b/src/components/advancedSearch/meta/parser.js
@@ -1135,12 +1135,12 @@ export default class Parser {
}
return returnObj
- } else if (q.indexOf(' LIKE ') > -1 || q.indexOf(' like ') > -1) {
+ } else if (q.toLowerCase().indexOf(' like ') > -1) {
return {
key: q,
isKey: true
}
- } else if (q.indexOf(' IN ') > -1 || q.indexOf(' in ') > -1) {
+ } else if (q.toLowerCase().indexOf(' in ') > -1) {
return {
key: q,
isKey: true
@@ -1154,15 +1154,79 @@ export default class Parser {
return { key: '[' + key + ']', isKey: false }
}
}
- } else if (q && (q.indexOf(' IN ') > -1 || q.indexOf(' in ') > -1 || q.indexOf(' LIKE ') > -1 || q.indexOf(' like ') > -1)) {
- return {
- key: q,
- isKey: true
- }
- } else if (q && (q.indexOf('has(') > -1)) {
- return {
- key: q,
- isKey: true
+ } else if (q && (q.toLowerCase().indexOf(' in ') > -1 || q.toLowerCase().indexOf(' like ') > -1 || q.toLowerCase().indexOf('has(') > -1)) {
+ const lowerQ = q.toLowerCase()
+ if (lowerQ.indexOf(' and ') > -1) {
+ if (this.checkStrIncludeAnd(q)) {
+ q = q.replace(/ and /g, ' AND ')
+ }
+ const arr = q.split(' AND ')
+
+ for (let i = 0; i < arr.length; i++) {
+ const item = arr[i].toLowerCase()
+ if (item.indexOf(' like ') > -1) {
+ const key = item.substring(0, item.indexOf(' like '))
+ const obj = this.columnList.find(t => t.label.toLowerCase() === key.toLowerCase())
+ if (!obj) {
+ return { key: '[' + key + ']', isKey: false }
+ }
+ } else if (item.indexOf(' in ') > -1) {
+ const key = q.substring(0, q.indexOf(' in '))
+ const obj = this.columnList.find(t => t.label.toLowerCase() === key.toLowerCase())
+ if (!obj) {
+ return { key: '[' + key + ']', isKey: false }
+ }
+ } else if (item.indexOf('has(') > -1) {
+ const key = item.substring(0, 4)
+ if (key === 'has(') {
+ const label = item.substring(4, item.indexOf(','))
+ if (label) {
+ const obj = this.columnList.find(t => t.label.toLowerCase() === label.toLowerCase())
+ if (!obj) {
+ return { key: '[' + key + ']', isKey: false }
+ }
+ } else {
+ return { key: 'in index ' + q.indexOf('has('), isKey: false }
+ }
+ } else {
+ return { key: 'in index ' + q.indexOf('has('), isKey: false }
+ }
+ }
+ }
+ return { key: q, isKey: true }
+ } else if (lowerQ.indexOf(' like ') > -1) {
+ const key = q.substring(0, q.indexOf(' like '))
+ const obj = this.columnList.find(t => t.label.toLowerCase() === key.toLowerCase())
+ if (obj) {
+ return { key: obj.label + q.substring(lowerQ.indexOf(' like '), q.length), isKey: true }
+ } else {
+ return { key: '[' + key + ']', isKey: false }
+ }
+ } else if (lowerQ.indexOf(' in ') > -1) {
+ const key = q.substring(0, q.indexOf(' in '))
+ const obj = this.columnList.find(t => t.label.toLowerCase() === key.toLowerCase())
+ if (obj) {
+ return { key: obj.label + q.substring(lowerQ.indexOf(' in '), q.length), isKey: true }
+ } else {
+ return { key: '[' + key + ']', isKey: false }
+ }
+ } else if (lowerQ.indexOf('has(') > -1) {
+ const key = lowerQ.substring(0, 4)
+ if (key === 'has(') {
+ const label = lowerQ.substring(4, lowerQ.indexOf(','))
+ if (label) {
+ const obj = this.columnList.find(t => t.label.toLowerCase() === label.toLowerCase())
+ if (obj) {
+ return { key: 'has(' + obj.label + q.substring(lowerQ.indexOf(','), lowerQ.length), isKey: true }
+ } else {
+ return { key: '[' + key + ']', isKey: false }
+ }
+ } else {
+ return { key: 'in index 5', isKey: false }
+ }
+ } else {
+ return { key: 'in index 5', isKey: false }
+ }
}
} else {
return {
@@ -1257,6 +1321,10 @@ export default class Parser {
})
return str
} else if (!result) {
+ // 此处为不能识别的字段,不能当成app处理
+ if (str.indexOf('=') > -1 || str.toLowerCase().indexOf(' in ') > -1 || str.toLowerCase().indexOf(' like ') > -1 || str.toLowerCase().indexOf('has(') > -1) {
+ return str
+ }
const regex = /^["']|["']$/
// 去除两侧引号,如'1.1.1.1',避免校验时被当作app
if (regex.test(str)) {