Skip to content

Commit

Permalink
feat: add global search
Browse files Browse the repository at this point in the history
  • Loading branch information
sendya committed Nov 6, 2019
1 parent e148a5d commit a7d6b16
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
63 changes: 63 additions & 0 deletions src/components/Search/GlobalSearch.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<div class={'global-search global-search-wrapper'}>
<div class={'global-search-box'}>
<Select
size={'large'}
showSearch
placeholder="Input search text.."
style={{ width: '100%' }}
defaultActiveFirstOption={false}
showArrow={false}
filterOption={false}
onSearch={handleSearch}
onChange={handleChange}
notFoundContent={null}
>
</Select>
<div class={'global-search-tips'}>Open with Ctrl/⌘ + K</div>
</div>
</div>
)
}
}

GlobalSearch.install = function (Vue) {
Vue.component(GlobalSearch.name, GlobalSearch)
}

export default GlobalSearch
25 changes: 25 additions & 0 deletions src/components/Search/index.less
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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 "*"

Expand Down

0 comments on commit a7d6b16

Please sign in to comment.