This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/views/entityExplorer/search/ExplorerSearch.vue

149 lines
4.6 KiB
Vue
Raw Normal View History

<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}">
<div class="explorer-search__input explorer-search__input__border">
<advanced-search
ref="search"
2022-01-23 23:34:51 +08:00
:column-list="columnList"
:connection-list="connectionList"
:default-mode="defaultMode"
2022-01-23 23:34:51 +08:00
:full-text="true"
:show-list="showList"
2022-01-23 23:34:51 +08:00
:class="{'advanced-search--show-list': showList}"
@search="search"
></advanced-search>
</div>
<!-- <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>
<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>-->
</div>
2022-01-26 17:44:24 +08:00
<transition name="el-zoom-in-top">
<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>
</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'
import { useRoute } from 'vue-router'
import { ref } from 'vue'
import { columnList } from '@/utils/static-data'
export default {
name: 'CnSearch',
components: {
AdvancedSearch
},
props: {
showList: {
type: Boolean,
default: true
}
},
2022-01-23 23:34:51 +08:00
data () {
return {
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
}
},
setup () {
// 根据地址栏添加mode即text和tag模式默认text
const { query } = useRoute()
const defaultMode = ref(query.mode || 'text')
return {
defaultMode
}
},
methods: {
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)
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))
}
this.$emit('search', { str, q, metaList, keywordList })
},
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
}
}
}
</script>