2018-08-28 09:58:31 +08:00
|
|
|
|
<template>
|
2018-08-28 17:00:09 +08:00
|
|
|
|
<div class="panel-search" flex="dir:top">
|
|
|
|
|
|
<div class="panel-search__input-group" flex-box="0" flex="dir:top main:center cross:center">
|
|
|
|
|
|
<el-autocomplete
|
2018-08-28 09:58:31 +08:00
|
|
|
|
class="panel-search__input"
|
|
|
|
|
|
ref="input"
|
|
|
|
|
|
v-model="input"
|
|
|
|
|
|
suffix-icon="el-icon-search"
|
2018-08-28 11:12:51 +08:00
|
|
|
|
placeholder="搜索页面"
|
2018-08-28 17:00:09 +08:00
|
|
|
|
:fetch-suggestions="querySearch"
|
|
|
|
|
|
:trigger-on-focus="false"
|
|
|
|
|
|
:clearable="true"
|
|
|
|
|
|
@keydown.esc.native="handleEsc"
|
|
|
|
|
|
@select="handleSelect">
|
|
|
|
|
|
<d2-panel-search-item slot-scope="{ item }" :item="item"/>
|
|
|
|
|
|
</el-autocomplete>
|
2018-08-28 13:19:50 +08:00
|
|
|
|
<div class="panel-search__tip">
|
|
|
|
|
|
您可以使用快捷键
|
|
|
|
|
|
<span class="panel-search__key">
|
|
|
|
|
|
{{hotkey.open}}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
唤醒搜索面板,按
|
|
|
|
|
|
<span class="panel-search__key">
|
|
|
|
|
|
{{hotkey.close}}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
关闭
|
|
|
|
|
|
</div>
|
2018-08-28 09:58:31 +08:00
|
|
|
|
</div>
|
2018-08-28 17:00:09 +08:00
|
|
|
|
<div
|
|
|
|
|
|
v-if="results.length > 0"
|
|
|
|
|
|
class="panel-search__results-group"
|
|
|
|
|
|
flex-box="1">
|
|
|
|
|
|
<el-card>
|
|
|
|
|
|
<div class="panel-search__results-group-inner">
|
|
|
|
|
|
<d2-panel-search-item
|
|
|
|
|
|
v-for="(item, index) in results"
|
|
|
|
|
|
:key="index"
|
|
|
|
|
|
:item="item"
|
|
|
|
|
|
:hover-mode="true"
|
|
|
|
|
|
@click.native="handleResultsGroupItemClick(item.path)"/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</div>
|
2018-08-28 09:58:31 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2018-08-28 13:19:50 +08:00
|
|
|
|
import { mapState } from 'vuex'
|
2018-08-28 17:00:09 +08:00
|
|
|
|
import mixin from '../mixin/menu'
|
2018-08-28 09:58:31 +08:00
|
|
|
|
export default {
|
2018-08-28 17:00:09 +08:00
|
|
|
|
mixins: [
|
|
|
|
|
|
mixin
|
|
|
|
|
|
],
|
|
|
|
|
|
components: {
|
|
|
|
|
|
'd2-panel-search-item': () => import('./components/panel-search-item/index.vue')
|
|
|
|
|
|
},
|
2018-08-28 09:58:31 +08:00
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
2018-08-28 17:00:09 +08:00
|
|
|
|
input: '',
|
|
|
|
|
|
results: []
|
2018-08-28 09:58:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2018-08-28 13:19:50 +08:00
|
|
|
|
computed: {
|
|
|
|
|
|
...mapState('d2admin/search', [
|
2018-08-28 17:00:09 +08:00
|
|
|
|
'hotkey',
|
|
|
|
|
|
'pool'
|
2018-08-28 13:19:50 +08:00
|
|
|
|
])
|
|
|
|
|
|
},
|
2018-08-28 09:58:31 +08:00
|
|
|
|
methods: {
|
2018-08-28 17:00:09 +08:00
|
|
|
|
querySearch (queryString, callback) {
|
|
|
|
|
|
var pool = this.pool
|
|
|
|
|
|
const results = (queryString ? pool : []).filter(item => {
|
|
|
|
|
|
const path = item.path || ''
|
|
|
|
|
|
const fullTitle = item.fullTitle || ''
|
|
|
|
|
|
return (`${fullTitle}${path}`.toLowerCase().indexOf(queryString.toLowerCase()) >= 0)
|
|
|
|
|
|
}).map(e => ({
|
|
|
|
|
|
value: e.fullTitle,
|
|
|
|
|
|
...e
|
|
|
|
|
|
}))
|
|
|
|
|
|
this.results = results
|
|
|
|
|
|
callback(results)
|
|
|
|
|
|
},
|
2018-08-28 09:58:31 +08:00
|
|
|
|
focus () {
|
2018-08-28 17:00:09 +08:00
|
|
|
|
this.input = ''
|
|
|
|
|
|
setTimeout(() => {
|
2018-08-28 09:58:31 +08:00
|
|
|
|
this.$refs.input.focus()
|
2018-08-28 17:00:09 +08:00
|
|
|
|
}, 500)
|
|
|
|
|
|
},
|
|
|
|
|
|
// 接收用户在列表中选择项目的事件
|
|
|
|
|
|
handleResultsGroupItemClick (path) {
|
|
|
|
|
|
// 如果用户选择的就是当前页面 就直接关闭搜索面板
|
|
|
|
|
|
if (path === this.$route.path) {
|
|
|
|
|
|
this.handleEsc()
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 用户选择的是其它页面
|
|
|
|
|
|
this.handleMenuSelect(path)
|
|
|
|
|
|
},
|
|
|
|
|
|
// 接收用户在下拉菜单中选中事件
|
|
|
|
|
|
handleSelect ({ path }) {
|
|
|
|
|
|
// 如果用户选择的就是当前页面 就直接关闭搜索面板
|
|
|
|
|
|
if (path === this.$route.path) {
|
|
|
|
|
|
this.handleEsc()
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 用户选择的是其它页面
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.handleMenuSelect(path)
|
2018-08-28 09:58:31 +08:00
|
|
|
|
})
|
2018-08-28 11:12:51 +08:00
|
|
|
|
},
|
2018-08-28 17:00:09 +08:00
|
|
|
|
closeSuggestion () {
|
|
|
|
|
|
if (this.$refs.input.activated) {
|
|
|
|
|
|
this.$refs.input.suggestions = []
|
|
|
|
|
|
this.$refs.input.activated = false
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2018-08-28 11:12:51 +08:00
|
|
|
|
handleEsc () {
|
2018-08-28 17:00:09 +08:00
|
|
|
|
this.closeSuggestion()
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.$emit('close')
|
|
|
|
|
|
})
|
2018-08-28 09:58:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2018-08-28 13:19:50 +08:00
|
|
|
|
@import '~@/assets/style/public.scss';
|
2018-08-28 09:58:31 +08:00
|
|
|
|
.panel-search {
|
|
|
|
|
|
margin: 20px;
|
|
|
|
|
|
.panel-search__input-group {
|
|
|
|
|
|
height: 200px;
|
|
|
|
|
|
.panel-search__input {
|
2018-08-28 17:00:09 +08:00
|
|
|
|
width: 500px;
|
2018-08-28 09:58:31 +08:00
|
|
|
|
}
|
2018-08-28 13:19:50 +08:00
|
|
|
|
.panel-search__tip {
|
|
|
|
|
|
@extend %unable-select;
|
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: $color-text-sub;
|
|
|
|
|
|
.panel-search__key {
|
|
|
|
|
|
padding: 1px 5px;
|
|
|
|
|
|
margin: 0px 2px;
|
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
|
background-color: $color-text-normal;
|
|
|
|
|
|
color: $color-bg;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-08-28 09:58:31 +08:00
|
|
|
|
}
|
2018-08-28 17:00:09 +08:00
|
|
|
|
.panel-search__results-group {
|
|
|
|
|
|
overflow: auto;
|
|
|
|
|
|
.panel-search__results-group-inner {
|
|
|
|
|
|
margin: -20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-08-28 09:58:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|