Skip to content

Commit a7d6b16

Browse files
committed
feat: add global search
1 parent e148a5d commit a7d6b16

File tree

4 files changed

+93
-5
lines changed

4 files changed

+93
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"lodash.get": "^4.4.2",
2121
"lodash.pick": "^4.4.0",
2222
"md5": "^2.2.1",
23-
"mockjs2": "1.0.7",
23+
"mockjs2": "1.0.8",
2424
"moment": "^2.24.0",
2525
"nprogress": "^0.2.0",
2626
"viser-vue": "^2.4.6",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Select } from 'ant-design-vue'
2+
import './index.less'
3+
4+
const GlobalSearch = {
5+
name: 'GlobalSearch',
6+
data () {
7+
return {
8+
visible: false
9+
}
10+
},
11+
mounted () {
12+
const keyboardHandle = (e) => {
13+
e.preventDefault()
14+
e.stopPropagation()
15+
const { ctrlKey, shiftKey, altKey, keyCode } = e
16+
console.log('keyCode:', e.keyCode, e)
17+
// key is `K` and hold ctrl
18+
if (keyCode === 75 && ctrlKey && !shiftKey && !altKey) {
19+
this.visible = !this.visible
20+
}
21+
}
22+
document.addEventListener('keydown', keyboardHandle)
23+
},
24+
render () {
25+
const { visible } = this
26+
const handleSearch = (e) => {
27+
this.$emit('search', e)
28+
}
29+
30+
const handleChange = (e) => {
31+
this.$emit('change', e)
32+
}
33+
if (!visible) {
34+
return null
35+
}
36+
return (
37+
<div class={'global-search global-search-wrapper'}>
38+
<div class={'global-search-box'}>
39+
<Select
40+
size={'large'}
41+
showSearch
42+
placeholder="Input search text.."
43+
style={{ width: '100%' }}
44+
defaultActiveFirstOption={false}
45+
showArrow={false}
46+
filterOption={false}
47+
onSearch={handleSearch}
48+
onChange={handleChange}
49+
notFoundContent={null}
50+
>
51+
</Select>
52+
<div class={'global-search-tips'}>Open with Ctrl/⌘ + K</div>
53+
</div>
54+
</div>
55+
)
56+
}
57+
}
58+
59+
GlobalSearch.install = function (Vue) {
60+
Vue.component(GlobalSearch.name, GlobalSearch)
61+
}
62+
63+
export default GlobalSearch

src/components/Search/index.less

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@import "~ant-design-vue/es/style/themes/default";
2+
3+
.global-search-wrapper {
4+
position: fixed;
5+
top: 0;
6+
left: 0;
7+
right: 0;
8+
bottom: 0;
9+
z-index: @zindex-modal-mask;
10+
background: @modal-mask-bg;
11+
12+
.global-search-box {
13+
position: absolute;
14+
top: 20%;
15+
left: 50%;
16+
width: 450px;
17+
transform: translate(-50%, -50%);
18+
19+
.global-search-tips {
20+
color: @white;
21+
font-size: @font-size-lg;
22+
text-align: right;
23+
}
24+
}
25+
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
74387438
dependencies:
74397439
minimist "0.0.8"
74407440

7441-
mockjs2@1.0.7:
7442-
version "1.0.7"
7443-
resolved "https://registry.yarnpkg.com/mockjs2/-/mockjs2-1.0.7.tgz#3aca24630b6a49f13b3087deb174fd00ef5a5396"
7444-
integrity sha512-/CS9HBvBp0wIEFKssRT90z1fiE97/3pzFTUe8CYF4EVH1sKzckssCTJUmL6pPoEFBWvCIN07T/jrKNg23evFtw==
7441+
mockjs2@1.0.8:
7442+
version "1.0.8"
7443+
resolved "https://registry.yarnpkg.com/mockjs2/-/mockjs2-1.0.8.tgz#37ca061d6c3319d888292aef656434380971c94c"
7444+
integrity sha512-IXY9wzq3Pr2tybkJnT+dzrTz0GBRTtgXc7Cke/UUQyyWtbjDrck8uZ3NmMF4LaWgAD8vm8EMGcBk4Itc6nzpRg==
74457445
dependencies:
74467446
commander "*"
74477447

0 commit comments

Comments
 (0)