2022-01-23 23:34:51 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div
|
|
|
|
|
|
class="advanced-search"
|
2023-08-14 15:00:55 +08:00
|
|
|
|
@mouseenter="showCloseIcon = true"
|
|
|
|
|
|
@mouseleave="showCloseIcon = false"
|
2022-01-23 23:34:51 +08:00
|
|
|
|
>
|
|
|
|
|
|
<text-mode
|
|
|
|
|
|
v-if="searchMode === 'text'"
|
2022-01-25 17:16:56 +08:00
|
|
|
|
ref="textMode"
|
|
|
|
|
|
:column-list="columnList"
|
2022-06-06 17:34:55 +08:00
|
|
|
|
:str="str"
|
2023-08-11 17:53:51 +08:00
|
|
|
|
:show-list="showList"
|
2022-01-23 23:34:51 +08:00
|
|
|
|
@changeMode="changeMode"
|
|
|
|
|
|
@search="search"
|
2023-08-14 15:00:55 +08:00
|
|
|
|
:show-close-icon="showCloseIcon"
|
2022-01-23 23:34:51 +08:00
|
|
|
|
></text-mode>
|
|
|
|
|
|
<tag-mode
|
|
|
|
|
|
v-if="searchMode === 'tag'"
|
2022-01-25 17:16:56 +08:00
|
|
|
|
ref="tagMode"
|
2022-01-23 23:34:51 +08:00
|
|
|
|
:column-list="columnList"
|
|
|
|
|
|
:operator-list="showOperatorList"
|
|
|
|
|
|
:connection-list="showConnectionList"
|
2022-01-25 17:16:56 +08:00
|
|
|
|
:convert-meta-list="metaList"
|
2023-08-11 17:53:51 +08:00
|
|
|
|
:show-list="showList"
|
2022-01-23 23:34:51 +08:00
|
|
|
|
@changeMode="changeMode"
|
|
|
|
|
|
@search="search"
|
|
|
|
|
|
></tag-mode>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import TagMode from '@/components/advancedSearch/TagMode'
|
|
|
|
|
|
import TextMode from '@/components/advancedSearch/TextMode'
|
|
|
|
|
|
import { defaultOperatorList, defaultConnectionList } from '@/components/advancedSearch/meta/meta'
|
|
|
|
|
|
import _ from 'lodash'
|
|
|
|
|
|
import { ref } from 'vue'
|
2022-06-06 17:34:55 +08:00
|
|
|
|
import Parser from '@/components/advancedSearch/meta/parser'
|
2022-01-23 23:34:51 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
name: 'Index',
|
|
|
|
|
|
components: {
|
|
|
|
|
|
TagMode,
|
|
|
|
|
|
TextMode
|
|
|
|
|
|
},
|
2022-01-25 17:16:56 +08:00
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
2022-06-06 17:34:55 +08:00
|
|
|
|
str: null,
|
2023-08-14 15:00:55 +08:00
|
|
|
|
metaList: null,
|
|
|
|
|
|
showCloseIcon: false
|
2022-01-25 17:16:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-01-23 23:34:51 +08:00
|
|
|
|
props: {
|
|
|
|
|
|
// 默认模式,tag | text
|
|
|
|
|
|
defaultMode: String,
|
|
|
|
|
|
// 使用全文检索
|
|
|
|
|
|
fullText: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: true
|
|
|
|
|
|
},
|
2023-08-11 17:53:51 +08:00
|
|
|
|
showList: {
|
|
|
|
|
|
type: Boolean
|
|
|
|
|
|
},
|
2022-01-23 23:34:51 +08:00
|
|
|
|
// 条件字段列表
|
|
|
|
|
|
columnList: {
|
|
|
|
|
|
type: Array,
|
|
|
|
|
|
required: true
|
|
|
|
|
|
},
|
|
|
|
|
|
// 操作符列表
|
|
|
|
|
|
operatorList: Array,
|
|
|
|
|
|
// 连接符列表
|
|
|
|
|
|
connectionList: Array
|
|
|
|
|
|
},
|
2022-12-14 15:01:48 +08:00
|
|
|
|
emits: ['search'],
|
2022-01-23 23:34:51 +08:00
|
|
|
|
methods: {
|
2022-06-06 17:34:55 +08:00
|
|
|
|
search (parseData) {
|
|
|
|
|
|
this.$emit('search', parseData)
|
2022-01-23 23:34:51 +08:00
|
|
|
|
},
|
2022-06-06 17:34:55 +08:00
|
|
|
|
changeMode (mode, { str, metaList }) {
|
2022-01-23 23:34:51 +08:00
|
|
|
|
this.searchMode = mode
|
2022-01-25 17:16:56 +08:00
|
|
|
|
if (mode === 'text') {
|
2022-06-06 17:34:55 +08:00
|
|
|
|
this.str = str
|
2022-01-25 17:16:56 +08:00
|
|
|
|
} else if (mode === 'tag') {
|
2022-06-06 17:34:55 +08:00
|
|
|
|
this.metaList = metaList
|
2022-01-25 17:16:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-02-18 10:07:43 +08:00
|
|
|
|
// params: [{column, operator, value}, ...]
|
2022-01-25 17:16:56 +08:00
|
|
|
|
addParams (params) {
|
|
|
|
|
|
this.$refs.tagMode && this.$refs.tagMode.addParams(params)
|
|
|
|
|
|
this.$refs.textMode && this.$refs.textMode.addParams(params)
|
2022-01-26 17:44:24 +08:00
|
|
|
|
},
|
2022-02-18 18:09:44 +08:00
|
|
|
|
// params: [{column, operator, value}, ...]
|
2022-02-18 10:07:43 +08:00
|
|
|
|
removeParams (params) {
|
|
|
|
|
|
this.$refs.tagMode && this.$refs.tagMode.removeParams(params)
|
|
|
|
|
|
this.$refs.textMode && this.$refs.textMode.removeParams(params)
|
|
|
|
|
|
},
|
2022-02-18 18:09:44 +08:00
|
|
|
|
// params: [{ newParam: {column, operator, value }, oldParam: { column, operator, value }], ...]
|
|
|
|
|
|
changeParams (params) {
|
|
|
|
|
|
this.$refs.tagMode && this.$refs.tagMode.changeParams(params)
|
|
|
|
|
|
this.$refs.textMode && this.$refs.textMode.changeParams(params)
|
2022-02-18 10:07:43 +08:00
|
|
|
|
},
|
2022-06-06 17:34:55 +08:00
|
|
|
|
setStr (str) {
|
2022-01-26 17:44:24 +08:00
|
|
|
|
if (this.searchMode === 'text') {
|
2022-06-06 17:34:55 +08:00
|
|
|
|
this.str = str
|
2022-01-26 17:44:24 +08:00
|
|
|
|
} else if (this.searchMode === 'tag') {
|
2022-06-06 17:34:55 +08:00
|
|
|
|
const parser = new Parser(this.columnList)
|
|
|
|
|
|
const errorList = parser.validateStr(str)
|
|
|
|
|
|
if (_.isEmpty(errorList)) {
|
|
|
|
|
|
const { metaList } = parser.parseStr(str)
|
2022-01-26 17:44:24 +08:00
|
|
|
|
this.metaList = metaList
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-12 16:56:46 +08:00
|
|
|
|
},
|
|
|
|
|
|
enterListener (event) {
|
|
|
|
|
|
if (event.keyCode === 13) {
|
2022-06-15 20:41:21 +08:00
|
|
|
|
this.$refs.tagMode && this.$refs.tagMode.enterSearch()
|
2022-03-12 16:56:46 +08:00
|
|
|
|
this.$refs.textMode && this.$refs.textMode.search()
|
|
|
|
|
|
}
|
2022-01-23 23:34:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-03-12 16:56:46 +08:00
|
|
|
|
mounted () {
|
|
|
|
|
|
document.addEventListener('keydown', this.enterListener)
|
|
|
|
|
|
},
|
|
|
|
|
|
unmounted () {
|
|
|
|
|
|
document.removeEventListener('keydown', this.enterListener)
|
|
|
|
|
|
},
|
2022-01-23 23:34:51 +08:00
|
|
|
|
setup (props) {
|
2022-01-25 19:47:08 +08:00
|
|
|
|
// 默认为文本模式
|
2023-06-16 16:33:58 +08:00
|
|
|
|
const searchMode = ref('text')
|
2022-01-23 23:34:51 +08:00
|
|
|
|
if (props.defaultMode) {
|
|
|
|
|
|
switch (props.defaultMode) {
|
|
|
|
|
|
case 'tag': {
|
2023-06-16 16:33:58 +08:00
|
|
|
|
searchMode.value = 'tag'
|
2022-01-23 23:34:51 +08:00
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 如果参数中的operatorList、connectionList为空,使用默认值
|
|
|
|
|
|
const showOperatorList = _.isEmpty(props.operatorList) ? defaultOperatorList : [...props.operatorList]
|
|
|
|
|
|
const showConnectionList = _.isEmpty(props.connectionList) ? defaultConnectionList : [...props.connectionList]
|
|
|
|
|
|
return {
|
|
|
|
|
|
searchMode,
|
|
|
|
|
|
showOperatorList,
|
|
|
|
|
|
showConnectionList
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|