2021-12-14 16:42:45 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="explorer-search">
|
|
|
|
|
|
<div class="explorer-search__title" v-show="!showList">{{$t('search.title')}}</div>
|
|
|
|
|
|
<div class="explorer-search__input-case" :class="{'explorer-search__input-case--question-mark-in-line': showList}">
|
2023-08-08 15:45:34 +08:00
|
|
|
|
<div class="explorer-search__input explorer-search__input__border">
|
2021-12-14 16:42:45 +08:00
|
|
|
|
<advanced-search
|
2021-12-31 10:55:49 +08:00
|
|
|
|
ref="search"
|
2022-01-23 23:34:51 +08:00
|
|
|
|
:column-list="columnList"
|
|
|
|
|
|
:connection-list="connectionList"
|
2023-06-16 16:33:58 +08:00
|
|
|
|
:default-mode="defaultMode"
|
2022-01-23 23:34:51 +08:00
|
|
|
|
:full-text="true"
|
2023-08-11 17:53:51 +08:00
|
|
|
|
:show-list="showList"
|
2022-01-23 23:34:51 +08:00
|
|
|
|
:class="{'advanced-search--show-list': showList}"
|
2021-12-14 16:42:45 +08:00
|
|
|
|
@search="search"
|
|
|
|
|
|
></advanced-search>
|
|
|
|
|
|
</div>
|
2023-09-12 16:43:03 +08:00
|
|
|
|
<!-- <div class="search-symbol-inline" v-if="showList">-->
|
|
|
|
|
|
<!-- <i class="cn-icon cn-icon-help"></i>-->
|
|
|
|
|
|
<!-- </div>-->
|
|
|
|
|
|
<div v-if="!showList" class="explorer-search__foot" v-ele-click-outside="esc">
|
2022-01-26 17:44:24 +08:00
|
|
|
|
<div class="foot__item" @click="triggerHistory">
|
|
|
|
|
|
<i class="el-icon-arrow-right" :class="{ 'arrow-rotate': showHistory }" style="padding-right: 5px;"></i>
|
2021-12-14 16:42:45 +08:00
|
|
|
|
<span>{{$t('search.searchHistory')}}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="foot__item">
|
2023-06-30 16:55:36 +08:00
|
|
|
|
<!-- <span @click="search">{{$t('overall.explore')}}</span>
|
|
|
|
|
|
<el-divider direction="vertical"></el-divider>
|
2023-06-07 15:58:59 +08:00
|
|
|
|
<span>{{$t('overall.help')}}</span>-->
|
2021-12-14 16:42:45 +08:00
|
|
|
|
</div>
|
2022-01-26 17:44:24 +08:00
|
|
|
|
<transition name="el-zoom-in-top">
|
2022-02-07 16:11:49 +08:00
|
|
|
|
<div class="search__history" v-show="showHistory">
|
2022-01-26 18:13:40 +08:00
|
|
|
|
<div class="history__items">
|
2022-06-06 17:34:55 +08:00
|
|
|
|
<div class="history__item" v-for="(h, i) in history" :key="i" @click="selectHistory(h.str)">
|
2022-01-26 18:13:40 +08:00
|
|
|
|
<span class="item-date">{{h.date}}</span>
|
2022-06-06 17:34:55 +08:00
|
|
|
|
<div class="item-value" :title="h.str">{{h.str}}</div>
|
2022-01-26 18:13:40 +08:00
|
|
|
|
</div>
|
2022-01-26 17:44:24 +08:00
|
|
|
|
</div>
|
2022-01-26 18:13:40 +08:00
|
|
|
|
<div class="clear-all">
|
2022-01-26 17:44:24 +08:00
|
|
|
|
<span @click="clearHistory" v-if="!$_.isEmpty(history)">{{$t('overall.clear')}}</span>
|
2023-06-07 15:58:59 +08:00
|
|
|
|
<div v-else>{{$t('overall.noRecords')}}</div>
|
2022-01-26 17:44:24 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</transition>
|
2021-12-14 16:42:45 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-01-23 23:34:51 +08:00
|
|
|
|
import AdvancedSearch from '@/components/advancedSearch/Index'
|
2022-06-06 17:34:55 +08:00
|
|
|
|
import _ from 'lodash'
|
2022-02-14 22:22:31 +08:00
|
|
|
|
import { storageKey } from '@/utils/constants'
|
2023-06-16 16:33:58 +08:00
|
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
|
import { columnList } from '@/utils/static-data'
|
2021-12-14 16:42:45 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
name: 'CnSearch',
|
|
|
|
|
|
components: {
|
|
|
|
|
|
AdvancedSearch
|
|
|
|
|
|
},
|
|
|
|
|
|
props: {
|
|
|
|
|
|
showList: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: true
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-01-23 23:34:51 +08:00
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
2023-06-16 16:33:58 +08:00
|
|
|
|
columnList: columnList,
|
2022-01-23 23:34:51 +08:00
|
|
|
|
connectionList: [
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'AND',
|
|
|
|
|
|
label: 'AND'
|
|
|
|
|
|
}
|
2023-08-18 09:32:58 +08:00
|
|
|
|
// {
|
|
|
|
|
|
// value: 'OR',
|
|
|
|
|
|
// label: 'OR'
|
|
|
|
|
|
// }
|
2022-01-26 17:44:24 +08:00
|
|
|
|
],
|
|
|
|
|
|
showHistory: false,
|
|
|
|
|
|
history: []
|
2022-01-23 23:34:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-06-16 16:33:58 +08:00
|
|
|
|
setup () {
|
|
|
|
|
|
// 根据地址栏添加mode,即text和tag模式,默认text
|
|
|
|
|
|
const { query } = useRoute()
|
|
|
|
|
|
const defaultMode = ref(query.mode || 'text')
|
|
|
|
|
|
return {
|
|
|
|
|
|
defaultMode
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-12-14 16:42:45 +08:00
|
|
|
|
methods: {
|
2023-11-06 19:50:29 +08:00
|
|
|
|
search ({ str, q, metaList, keywordList }) {
|
2022-06-06 17:34:55 +08:00
|
|
|
|
if (str) {
|
|
|
|
|
|
// 加入搜索记录,将记录数量控制在30以内
|
2022-01-26 17:44:24 +08:00
|
|
|
|
const oldHistory = localStorage.getItem(storageKey.entitySearchHistory)
|
|
|
|
|
|
let arr = []
|
2022-06-06 17:34:55 +08:00
|
|
|
|
const newItem = { str, date: this.dateFormatByAppearance(new Date()) }
|
|
|
|
|
|
if (!_.isEmpty(oldHistory)) {
|
2022-01-26 17:44:24 +08:00
|
|
|
|
const oldArr = JSON.parse(oldHistory)
|
2023-09-24 21:32:16 +08:00
|
|
|
|
const obj = oldArr.find(d => d.str === str)
|
|
|
|
|
|
if (obj) {
|
|
|
|
|
|
oldArr[0].date = this.dateFormatByAppearance(new Date())
|
|
|
|
|
|
} else {
|
|
|
|
|
|
oldArr.unshift(newItem)
|
|
|
|
|
|
}
|
2022-01-26 17:44:24 +08:00
|
|
|
|
arr = [...oldArr]
|
2022-01-26 18:13:40 +08:00
|
|
|
|
if (arr.length > 30) {
|
|
|
|
|
|
arr = arr.slice(0, 30)
|
|
|
|
|
|
}
|
2022-01-26 17:44:24 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
arr.push(newItem)
|
|
|
|
|
|
}
|
|
|
|
|
|
localStorage.setItem(storageKey.entitySearchHistory, JSON.stringify(arr))
|
|
|
|
|
|
}
|
2023-11-06 19:50:29 +08:00
|
|
|
|
this.$emit('search', { str, q, metaList, keywordList })
|
2021-12-31 10:55:49 +08:00
|
|
|
|
},
|
|
|
|
|
|
addParams (params) {
|
|
|
|
|
|
this.$refs.search.addParams(params)
|
2022-01-26 17:44:24 +08:00
|
|
|
|
},
|
2022-06-06 17:34:55 +08:00
|
|
|
|
selectHistory (str) {
|
|
|
|
|
|
this.$refs.search.setStr(str)
|
2022-01-26 17:44:24 +08:00
|
|
|
|
this.showHistory = false
|
2022-01-26 18:13:40 +08:00
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
if (this.$refs.search.$refs.textMode) {
|
|
|
|
|
|
this.$refs.search.$refs.textMode.focus()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2022-01-26 17:44:24 +08:00
|
|
|
|
},
|
|
|
|
|
|
clearHistory () {
|
|
|
|
|
|
localStorage.setItem(storageKey.entitySearchHistory, '')
|
|
|
|
|
|
this.history = []
|
|
|
|
|
|
},
|
|
|
|
|
|
triggerHistory () {
|
|
|
|
|
|
this.showHistory = !this.showHistory
|
|
|
|
|
|
if (this.showHistory) {
|
|
|
|
|
|
const history = localStorage.getItem(storageKey.entitySearchHistory)
|
2022-06-06 17:34:55 +08:00
|
|
|
|
if (!_.isEmpty(history)) {
|
2022-01-26 17:44:24 +08:00
|
|
|
|
this.history = JSON.parse(history)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
esc () {
|
|
|
|
|
|
this.showHistory = false
|
2021-12-14 16:42:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|