From a7d6b16f0d2c4b6da08f58194ba57cfc07310c9d Mon Sep 17 00:00:00 2001 From: Sendya <18x@loacg.com> Date: Mon, 28 Oct 2019 18:24:27 +0800 Subject: [PATCH] feat: add global search --- package.json | 2 +- src/components/Search/GlobalSearch.jsx | 63 ++++++++++++++++++++++++++ src/components/Search/index.less | 25 ++++++++++ yarn.lock | 8 ++-- 4 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 src/components/Search/GlobalSearch.jsx create mode 100644 src/components/Search/index.less diff --git a/package.json b/package.json index fb233c8b16..1766b4bb54 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "lodash.get": "^4.4.2", "lodash.pick": "^4.4.0", "md5": "^2.2.1", - "mockjs2": "1.0.7", + "mockjs2": "1.0.8", "moment": "^2.24.0", "nprogress": "^0.2.0", "viser-vue": "^2.4.6", diff --git a/src/components/Search/GlobalSearch.jsx b/src/components/Search/GlobalSearch.jsx new file mode 100644 index 0000000000..bd9e604d1c --- /dev/null +++ b/src/components/Search/GlobalSearch.jsx @@ -0,0 +1,63 @@ +import { Select } from 'ant-design-vue' +import './index.less' + +const GlobalSearch = { + name: 'GlobalSearch', + data () { + return { + visible: false + } + }, + mounted () { + const keyboardHandle = (e) => { + e.preventDefault() + e.stopPropagation() + const { ctrlKey, shiftKey, altKey, keyCode } = e + console.log('keyCode:', e.keyCode, e) + // key is `K` and hold ctrl + if (keyCode === 75 && ctrlKey && !shiftKey && !altKey) { + this.visible = !this.visible + } + } + document.addEventListener('keydown', keyboardHandle) + }, + render () { + const { visible } = this + const handleSearch = (e) => { + this.$emit('search', e) + } + + const handleChange = (e) => { + this.$emit('change', e) + } + if (!visible) { + return null + } + return ( +