From 131abe876d5c698d03b2a8c821ac658c532e73e6 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Wed, 7 May 2025 13:22:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=90=9C=E7=B4=A2=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=94=AE=E7=9B=98=E9=80=89=E6=8B=A9&=E6=82=AC?= =?UTF-8?q?=E6=B5=AE=E4=B8=BB=E9=A2=98=E8=83=8C=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/assets/icons/svg/enter.svg | 1 + .../src/components/HeaderSearch/index.vue | 38 +++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 ruoyi-ui/src/assets/icons/svg/enter.svg diff --git a/ruoyi-ui/src/assets/icons/svg/enter.svg b/ruoyi-ui/src/assets/icons/svg/enter.svg new file mode 100644 index 00000000..f7cabf29 --- /dev/null +++ b/ruoyi-ui/src/assets/icons/svg/enter.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ruoyi-ui/src/components/HeaderSearch/index.vue b/ruoyi-ui/src/components/HeaderSearch/index.vue index 9159556a..41d9275c 100644 --- a/ruoyi-ui/src/components/HeaderSearch/index.vue +++ b/ruoyi-ui/src/components/HeaderSearch/index.vue @@ -16,11 +16,14 @@ prefix-icon="el-icon-search" placeholder="菜单搜索,支持标题、URL模糊查询" clearable + @keyup.enter.native="selectActiveResult" + @keydown.up.native="navigateResult('up')" + @keydown.down.native="navigateResult('down')" >
-
+
@@ -32,6 +35,7 @@ {{ item.path }}
+
@@ -51,11 +55,15 @@ export default { search: '', options: [], searchPool: [], + activeIndex: -1, show: false, fuse: undefined } }, computed: { + theme() { + return this.$store.state.settings.theme + }, routes() { return this.$store.getters.defaultRoutes } @@ -84,6 +92,7 @@ export default { this.search = '' this.options = [] this.show = false + this.activeIndex = -1 }, change(val) { const path = val.path @@ -162,11 +171,31 @@ export default { return res }, querySearch(query) { + this.activeIndex = -1 if (query !== '') { this.options = this.fuse.search(query).map((item) => item.item) ?? this.searchPool } else { 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 { height: 280px; - margin: 12px 0; + margin: 6px 0; .search-item { display: flex; height: 48px; + align-items: center; + padding-right: 10px; .left { width: 60px; @@ -202,16 +233,17 @@ export default { .menu-icon { width: 18px; height: 18px; - margin-top: 5px; } } .search-info { padding-left: 5px; + margin-top: 10px; width: 100%; display: flex; flex-direction: column; justify-content: flex-start; + flex: 1; .menu-title, .menu-path {