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 @@ -