-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters