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 ( + + ) + } +} + +GlobalSearch.install = function (Vue) { + Vue.component(GlobalSearch.name, GlobalSearch) +} + +export default GlobalSearch diff --git a/src/components/Search/index.less b/src/components/Search/index.less new file mode 100644 index 0000000000..d39785229f --- /dev/null +++ b/src/components/Search/index.less @@ -0,0 +1,25 @@ +@import "~ant-design-vue/es/style/themes/default"; + +.global-search-wrapper { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + z-index: @zindex-modal-mask; + background: @modal-mask-bg; + + .global-search-box { + position: absolute; + top: 20%; + left: 50%; + width: 450px; + transform: translate(-50%, -50%); + + .global-search-tips { + color: @white; + font-size: @font-size-lg; + text-align: right; + } + } +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 99f40ee97c..98bd4d0ae8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7438,10 +7438,10 @@ mkdirp@0.5.1, mkdirp@0.5.x, mkdirp@0.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0. dependencies: minimist "0.0.8" -mockjs2@1.0.7: - version "1.0.7" - resolved "https://registry.yarnpkg.com/mockjs2/-/mockjs2-1.0.7.tgz#3aca24630b6a49f13b3087deb174fd00ef5a5396" - integrity sha512-/CS9HBvBp0wIEFKssRT90z1fiE97/3pzFTUe8CYF4EVH1sKzckssCTJUmL6pPoEFBWvCIN07T/jrKNg23evFtw== +mockjs2@1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/mockjs2/-/mockjs2-1.0.8.tgz#37ca061d6c3319d888292aef656434380971c94c" + integrity sha512-IXY9wzq3Pr2tybkJnT+dzrTz0GBRTtgXc7Cke/UUQyyWtbjDrck8uZ3NmMF4LaWgAD8vm8EMGcBk4Itc6nzpRg== dependencies: commander "*"