|
|
@ -16,11 +16,14 @@ |
|
|
prefix-icon="el-icon-search" |
|
|
prefix-icon="el-icon-search" |
|
|
placeholder="菜单搜索,支持标题、URL模糊查询" |
|
|
placeholder="菜单搜索,支持标题、URL模糊查询" |
|
|
clearable |
|
|
clearable |
|
|
|
|
|
@keyup.enter.native="selectActiveResult" |
|
|
|
|
|
@keydown.up.native="navigateResult('up')" |
|
|
|
|
|
@keydown.down.native="navigateResult('down')" |
|
|
> |
|
|
> |
|
|
</el-input> |
|
|
</el-input> |
|
|
<el-scrollbar wrap-class="right-scrollbar-wrapper"> |
|
|
<el-scrollbar wrap-class="right-scrollbar-wrapper"> |
|
|
<div class="result-wrap"> |
|
|
<div class="result-wrap"> |
|
|
<div class="search-item" v-for="item in options" :key="item.path"> |
|
|
<div class="search-item" v-for="(item, index) in options" :key="item.path" :style="activeStyle(index)" @mouseenter="activeIndex = index" @mouseleave="activeIndex = -1"> |
|
|
<div class="left"> |
|
|
<div class="left"> |
|
|
<svg-icon class="menu-icon" :icon-class="item.icon" /> |
|
|
<svg-icon class="menu-icon" :icon-class="item.icon" /> |
|
|
</div> |
|
|
</div> |
|
|
@ -32,6 +35,7 @@ |
|
|
{{ item.path }} |
|
|
{{ item.path }} |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<svg-icon icon-class="enter" v-show="index === activeIndex"/> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</el-scrollbar> |
|
|
</el-scrollbar> |
|
|
@ -51,11 +55,15 @@ export default { |
|
|
search: '', |
|
|
search: '', |
|
|
options: [], |
|
|
options: [], |
|
|
searchPool: [], |
|
|
searchPool: [], |
|
|
|
|
|
activeIndex: -1, |
|
|
show: false, |
|
|
show: false, |
|
|
fuse: undefined |
|
|
fuse: undefined |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
computed: { |
|
|
computed: { |
|
|
|
|
|
theme() { |
|
|
|
|
|
return this.$store.state.settings.theme |
|
|
|
|
|
}, |
|
|
routes() { |
|
|
routes() { |
|
|
return this.$store.getters.defaultRoutes |
|
|
return this.$store.getters.defaultRoutes |
|
|
} |
|
|
} |
|
|
@ -84,6 +92,7 @@ export default { |
|
|
this.search = '' |
|
|
this.search = '' |
|
|
this.options = [] |
|
|
this.options = [] |
|
|
this.show = false |
|
|
this.show = false |
|
|
|
|
|
this.activeIndex = -1 |
|
|
}, |
|
|
}, |
|
|
change(val) { |
|
|
change(val) { |
|
|
const path = val.path |
|
|
const path = val.path |
|
|
@ -162,11 +171,31 @@ export default { |
|
|
return res |
|
|
return res |
|
|
}, |
|
|
}, |
|
|
querySearch(query) { |
|
|
querySearch(query) { |
|
|
|
|
|
this.activeIndex = -1 |
|
|
if (query !== '') { |
|
|
if (query !== '') { |
|
|
this.options = this.fuse.search(query).map((item) => item.item) ?? this.searchPool |
|
|
this.options = this.fuse.search(query).map((item) => item.item) ?? this.searchPool |
|
|
} else { |
|
|
} else { |
|
|
this.options = this.searchPool |
|
|
this.options = this.searchPool |
|
|
} |
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
activeStyle(index) { |
|
|
|
|
|
if (index !== this.activeIndex) return {} |
|
|
|
|
|
return { |
|
|
|
|
|
"background-color": this.theme, |
|
|
|
|
|
"color": "#fff" |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
navigateResult(direction) { |
|
|
|
|
|
if (direction === "up") { |
|
|
|
|
|
this.activeIndex = this.activeIndex <= 0 ? this.options.length - 1 : this.activeIndex - 1 |
|
|
|
|
|
} else if (direction === "down") { |
|
|
|
|
|
this.activeIndex = this.activeIndex >= this.options.length - 1 ? 0 : this.activeIndex + 1 |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
selectActiveResult() { |
|
|
|
|
|
if (this.options.length > 0 && this.activeIndex >= 0) { |
|
|
|
|
|
this.change(this.options[this.activeIndex]) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -189,11 +218,13 @@ export default { |
|
|
|
|
|
|
|
|
.result-wrap { |
|
|
.result-wrap { |
|
|
height: 280px; |
|
|
height: 280px; |
|
|
margin: 12px 0; |
|
|
margin: 6px 0; |
|
|
|
|
|
|
|
|
.search-item { |
|
|
.search-item { |
|
|
display: flex; |
|
|
display: flex; |
|
|
height: 48px; |
|
|
height: 48px; |
|
|
|
|
|
align-items: center; |
|
|
|
|
|
padding-right: 10px; |
|
|
|
|
|
|
|
|
.left { |
|
|
.left { |
|
|
width: 60px; |
|
|
width: 60px; |
|
|
@ -202,16 +233,17 @@ export default { |
|
|
.menu-icon { |
|
|
.menu-icon { |
|
|
width: 18px; |
|
|
width: 18px; |
|
|
height: 18px; |
|
|
height: 18px; |
|
|
margin-top: 5px; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
.search-info { |
|
|
.search-info { |
|
|
padding-left: 5px; |
|
|
padding-left: 5px; |
|
|
|
|
|
margin-top: 10px; |
|
|
width: 100%; |
|
|
width: 100%; |
|
|
display: flex; |
|
|
display: flex; |
|
|
flex-direction: column; |
|
|
flex-direction: column; |
|
|
justify-content: flex-start; |
|
|
justify-content: flex-start; |
|
|
|
|
|
flex: 1; |
|
|
|
|
|
|
|
|
.menu-title, |
|
|
.menu-title, |
|
|
.menu-path { |
|
|
.menu-path { |
|
|
|