CN-1187: 手动输入不符合准确格式的筛选条件时,既无筛选效果,也无错误提示
This commit is contained in:
@@ -100,7 +100,7 @@ import Meta, { connection, condition, columnType } from './meta/meta'
|
||||
import _ from 'lodash'
|
||||
import { handleErrorTip } from '@/components/advancedSearch/meta/error'
|
||||
import Parser, { stringInQuot } from '@/components/advancedSearch/meta/parser'
|
||||
import { overwriteUrl, urlParamsHandler } from '@/utils/tools'
|
||||
import { comparedEntityKey, overwriteUrl, urlParamsHandler } from '@/utils/tools'
|
||||
export default {
|
||||
name: 'TagMode',
|
||||
props: {
|
||||
@@ -435,8 +435,9 @@ export default {
|
||||
mounted () {
|
||||
const vm = this
|
||||
// 如果地址栏包含参数q,则匹配出metaList到搜索栏回显使用
|
||||
const { q } = this.$route.query
|
||||
let { q } = this.$route.query
|
||||
if (q) {
|
||||
q = comparedEntityKey(q).key
|
||||
const parser = new Parser(this.columnList)
|
||||
this.metaList = parser.parseStr(q).metaList
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import { toRaw } from 'vue'
|
||||
import _ from 'lodash'
|
||||
import { columnType } from '@/components/advancedSearch/meta/meta'
|
||||
import { handleErrorTip } from '@/components/advancedSearch/meta/error'
|
||||
import { overwriteUrl, urlParamsHandler } from '@/utils/tools'
|
||||
import { comparedEntityKey, overwriteUrl, urlParamsHandler } from '@/utils/tools'
|
||||
|
||||
export default {
|
||||
name: 'TextMode',
|
||||
@@ -73,12 +73,17 @@ export default {
|
||||
const str = this.codeMirror.getValue().trim()
|
||||
if (str) {
|
||||
const parser = new Parser(this.columnList)
|
||||
const errorList = parser.validateStr(str)
|
||||
const keyInfo = comparedEntityKey(str)
|
||||
if (keyInfo.isKey) {
|
||||
const errorList = parser.validateStr(keyInfo.key)
|
||||
if (_.isEmpty(errorList)) {
|
||||
this.$emit('search', parser.parseStr(str))
|
||||
this.$emit('search', { ...parser.parseStr(keyInfo.key), str: str })
|
||||
} else {
|
||||
this.$message.error(handleErrorTip(errorList[0]))
|
||||
}
|
||||
} else {
|
||||
this.$message.error(this.$t('tip.invalidQueryField') + keyInfo.key)
|
||||
}
|
||||
} else {
|
||||
this.$emit('search', { q: '', str: '', metaList: [] })
|
||||
}
|
||||
@@ -87,8 +92,9 @@ export default {
|
||||
this.codeMirror.focus()
|
||||
},
|
||||
changeMode () {
|
||||
const str = this.codeMirror.getValue().trim()
|
||||
let str = this.codeMirror.getValue().trim()
|
||||
if (str) {
|
||||
str = comparedEntityKey(str).key
|
||||
const parser = new Parser(this.columnList)
|
||||
const errorList = parser.validateStr(str)
|
||||
if (_.isEmpty(errorList)) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { getIso36112JsonData, getDictList } from '@/utils/api'
|
||||
import { format } from 'echarts'
|
||||
import router from '@/router'
|
||||
import indexedDBUtils from '@/indexedDB'
|
||||
import { columnList } from '@/utils/static-data'
|
||||
|
||||
export const tableSort = {
|
||||
// 是否需要排序
|
||||
@@ -1314,3 +1315,53 @@ export function switchStatus (status) {
|
||||
return 'Enabled'
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 将key与columnList的label都进行转小写进行对比
|
||||
* 如果一致,返回columnList的label,不一致则返回false,并弹窗提示
|
||||
* @param q
|
||||
*/
|
||||
export function comparedEntityKey (q) {
|
||||
if (q && q.indexOf('=') > -1) {
|
||||
if (q.indexOf('AND') > -1) {
|
||||
const arr = q.split(' AND ')
|
||||
let newQ = ''
|
||||
let errorQ = ''
|
||||
const returnObj = {
|
||||
key: '',
|
||||
isKey: true
|
||||
}
|
||||
|
||||
arr.forEach(item => {
|
||||
const key = item.substring(0, item.indexOf('='))
|
||||
const obj = columnList.find(t => t.label.toLowerCase() === key.toLowerCase())
|
||||
if (obj) {
|
||||
newQ += obj.label + item.substring(item.indexOf('='), item.length) + ' AND '
|
||||
} else {
|
||||
errorQ += '[' + key + ']' + '、'
|
||||
returnObj.isKey = false
|
||||
}
|
||||
})
|
||||
newQ = newQ.substring(0, newQ.length - 5)
|
||||
returnObj.key = newQ
|
||||
if (!returnObj.isKey) {
|
||||
errorQ = errorQ.substring(0, errorQ.length - 1)
|
||||
returnObj.key = errorQ
|
||||
}
|
||||
|
||||
return returnObj
|
||||
} else {
|
||||
const key = q.substring(0, q.indexOf('='))
|
||||
const obj = columnList.find(t => t.label.toLowerCase() === key.toLowerCase())
|
||||
if (obj) {
|
||||
return { key: obj.label + q.substring(q.indexOf('='), q.length), isKey: true }
|
||||
} else {
|
||||
return { key: '[' + key + ']', isKey: false }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
key: q,
|
||||
isKey: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ import { getNowTime, getSecond } from '@/utils/date-util'
|
||||
import { ref } from 'vue'
|
||||
import _ from 'lodash'
|
||||
import Loading from '@/components/common/Loading'
|
||||
import { overwriteUrl, urlParamsHandler, numberWithCommas } from '@/utils/tools'
|
||||
import { overwriteUrl, urlParamsHandler, numberWithCommas, comparedEntityKey } from '@/utils/tools'
|
||||
import Parser from '@/components/advancedSearch/meta/parser'
|
||||
import { handleErrorTip } from '@/components/advancedSearch/meta/error'
|
||||
import { columnList } from '@/utils/static-data'
|
||||
@@ -442,7 +442,7 @@ export default {
|
||||
|
||||
this.reloadUrl({
|
||||
listMode: this.listMode,
|
||||
q: q,
|
||||
q: param.str,
|
||||
mode: mode,
|
||||
startTime: getSecond(this.timeFilter.startTime),
|
||||
endTime: getSecond(this.timeFilter.endTime),
|
||||
@@ -455,7 +455,7 @@ export default {
|
||||
path: '/entityExplorer',
|
||||
query: {
|
||||
listMode: this.listMode,
|
||||
q: q,
|
||||
q: param.str,
|
||||
mode: mode,
|
||||
startTime: getSecond(this.timeFilter.startTime),
|
||||
endTime: getSecond(this.timeFilter.endTime),
|
||||
@@ -836,12 +836,17 @@ export default {
|
||||
}
|
||||
}
|
||||
const parser = new Parser(columnList)
|
||||
const errorList = parser.validateStr(str)
|
||||
const keyInfo = comparedEntityKey(str)
|
||||
if (keyInfo.isKey) {
|
||||
const errorList = parser.validateStr(keyInfo.key)
|
||||
if (_.isEmpty(errorList)) {
|
||||
this.search(parser.parseStr(str))
|
||||
this.search({ ...parser.parseStr(keyInfo.key), str: str })
|
||||
} else {
|
||||
this.$message.error(handleErrorTip(errorList[0]))
|
||||
}
|
||||
} else {
|
||||
this.$message.error('无效的查询字段靓仔' + keyInfo.key)
|
||||
}
|
||||
} else {
|
||||
this.search({ q: '', str: '', metaList: [] })
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ export default {
|
||||
}
|
||||
localStorage.setItem(storageKey.entitySearchHistory, JSON.stringify(arr))
|
||||
}
|
||||
this.$emit('search', { q, metaList })
|
||||
this.$emit('search', { str, q, metaList })
|
||||
},
|
||||
addParams (params) {
|
||||
this.$refs.search.addParams(params)
|
||||
|
||||
Reference in New Issue
Block a user