From b60e86540ad44f6ebed1544c514a2e5642ae49d0 Mon Sep 17 00:00:00 2001 From: Cc-Mac <840054486@qq.com> Date: Wed, 2 Nov 2022 16:30:22 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snowy-admin-web/package.json | 3 + .../src/layout/components/mixins/search.js | 63 ++++ .../layout/components/panel-search/index.vue | 295 ++++++++++++++++++ .../layout/components/panel-search/item.vue | 102 ++++++ .../src/layout/components/userbar.vue | 35 ++- snowy-admin-web/src/router/index.js | 1 + snowy-admin-web/src/store/index.js | 4 +- snowy-admin-web/src/store/modules/search.js | 72 +++++ snowy-admin-web/src/utils/objects.js | 38 +++ 9 files changed, 609 insertions(+), 4 deletions(-) create mode 100755 snowy-admin-web/src/layout/components/mixins/search.js create mode 100644 snowy-admin-web/src/layout/components/panel-search/index.vue create mode 100755 snowy-admin-web/src/layout/components/panel-search/item.vue create mode 100755 snowy-admin-web/src/store/modules/search.js create mode 100644 snowy-admin-web/src/utils/objects.js diff --git a/snowy-admin-web/package.json b/snowy-admin-web/package.json index 1fdb8073..f0b77297 100644 --- a/snowy-admin-web/package.json +++ b/snowy-admin-web/package.json @@ -30,7 +30,10 @@ "echarts": "5.2.2", "echarts-stat": "^1.2.0", "enquire.js": "^2.1.6", + "fuse.js": "^6.4.6", "highlight.js": "^11.6.0", + "hotkeys-js": "^3.10.0", + "js-pinyin": "^0.1.9", "lodash-es": "^4.17.21", "nprogress": "0.2.0", "screenfull": "^6.0.2", diff --git a/snowy-admin-web/src/layout/components/mixins/search.js b/snowy-admin-web/src/layout/components/mixins/search.js new file mode 100755 index 00000000..9b80123e --- /dev/null +++ b/snowy-admin-web/src/layout/components/mixins/search.js @@ -0,0 +1,63 @@ +import { mapState, mapMutations } from 'vuex' + +import hotkeys from 'hotkeys-js' + +export default { + mounted() { + // 绑定搜索功能快捷键 [ 打开 ] + hotkeys(this.searchHotkey.open, (event) => { + event.preventDefault() + this.searchPanelOpen() + }) + // 绑定搜索功能快捷键 [ 关闭 ] + hotkeys(this.searchHotkey.close, (event) => { + event.preventDefault() + this.searchPanelClose() + }) + }, + beforeDestroy() { + hotkeys.unbind(this.searchHotkey.open) + hotkeys.unbind(this.searchHotkey.close) + }, + computed: { + ...mapState('search', { + searchActive: (state) => state.active, + searchHotkey: (state) => state.hotkey + }) + }, + methods: { + ...mapMutations({ + searchToggle: 'search/toggle', + searchSet: 'search/set' + }), + /** + * 接收点击搜索按钮 + */ + handleSearchClick() { + this.searchToggle() + if (this.searchActive) { + setTimeout(() => { + if (this.$refs.panelSearch) { + this.$refs.panelSearch.focus() + } + }, 300) + } + }, + searchPanelOpen() { + if (!this.searchActive) { + this.searchSet(true) + setTimeout(() => { + if (this.$refs.panelSearch) { + this.$refs.panelSearch.focus() + } + }, 300) + } + }, + // 关闭搜索面板 + searchPanelClose() { + if (this.searchActive) { + this.searchSet(false) + } + } + } +} diff --git a/snowy-admin-web/src/layout/components/panel-search/index.vue b/snowy-admin-web/src/layout/components/panel-search/index.vue new file mode 100644 index 00000000..2cb7c90b --- /dev/null +++ b/snowy-admin-web/src/layout/components/panel-search/index.vue @@ -0,0 +1,295 @@ + + + + + diff --git a/snowy-admin-web/src/layout/components/panel-search/item.vue b/snowy-admin-web/src/layout/components/panel-search/item.vue new file mode 100755 index 00000000..764aaa7e --- /dev/null +++ b/snowy-admin-web/src/layout/components/panel-search/item.vue @@ -0,0 +1,102 @@ + + + + + diff --git a/snowy-admin-web/src/layout/components/userbar.vue b/snowy-admin-web/src/layout/components/userbar.vue index 0bff7481..133c3e91 100644 --- a/snowy-admin-web/src/layout/components/userbar.vue +++ b/snowy-admin-web/src/layout/components/userbar.vue @@ -1,5 +1,8 @@ -