File tree Expand file tree Collapse file tree 3 files changed +80
-1
lines changed Expand file tree Collapse file tree 3 files changed +80
-1
lines changed Original file line number Diff line number Diff line change 8
8
"source.fixAll.eslint" : true
9
9
},
10
10
"[vue]" : {
11
- "editor.defaultFormatter" : " esbenp.prettier-vscode "
11
+ "editor.defaultFormatter" : " Vue.volar "
12
12
},
13
13
"[javascript]" : {
14
14
"editor.defaultFormatter" : " esbenp.prettier-vscode"
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { isDark } from '@/utils/is'
3
3
import { useAppStore } from ' @/store/modules/app'
4
4
import { useDesign } from ' @/hooks/web/useDesign'
5
5
import { CACHE_KEY , useCache } from ' @/hooks/web/useCache'
6
+ import routerSearch from ' @/components/RouterSearch/index.vue'
6
7
7
8
const { getPrefixCls } = useDesign ()
8
9
const prefixCls = getPrefixCls (' app' )
@@ -24,10 +25,12 @@ setDefaultTheme()
24
25
<template >
25
26
<ConfigGlobal :size =" currentSize" >
26
27
<RouterView :class =" greyMode ? `${prefixCls}-grey-mode` : ''" />
28
+ <routerSearch />
27
29
</ConfigGlobal >
28
30
</template >
29
31
<style lang="scss">
30
32
$prefix-cls : #{$namespace } - app;
33
+
31
34
.size {
32
35
width : 100% ;
33
36
height : 100% ;
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <ElDialog v-model =" showSearch" :show-close =" false" title =" 菜单搜索" >
3
+ <el-select
4
+ filterable
5
+ :reserve-keyword =" false"
6
+ remote
7
+ placeholder =" 请输入菜单内容"
8
+ :remote-method =" remoteMethod"
9
+ style =" width : 100% "
10
+ @change =" handleChange"
11
+ >
12
+ <el-option
13
+ v-for =" item in options"
14
+ :key =" item.value"
15
+ :label =" item.label"
16
+ :value =" item.value"
17
+ />
18
+ </el-select >
19
+ </ElDialog >
20
+ </template >
21
+
22
+ <script setup lang="ts">
23
+ const router = useRouter () // 路由对象
24
+ const showSearch = ref (false ) // 是否显示弹框
25
+ const value: Ref = ref (' ' ) // 用户输入的值
26
+
27
+ const routers = router .getRoutes () // 路由对象
28
+ const options = computed (() => {
29
+ // 提示选项
30
+ if (! value .value ) {
31
+ return []
32
+ }
33
+ const list = routers .filter ((item : any ) => {
34
+ if (item .meta .title ?.indexOf (value .value ) > - 1 || item .path .indexOf (value .value ) > - 1 ) {
35
+ return true
36
+ }
37
+ })
38
+ return list .map ((item ) => {
39
+ return {
40
+ label: ` ${item .meta .title }${item .path } ` ,
41
+ value: item .path
42
+ }
43
+ })
44
+ })
45
+
46
+ function remoteMethod(data ) {
47
+ // 这里可以执行相应的操作(例如打开搜索框等)
48
+ value .value = data
49
+ }
50
+
51
+ function handleChange(path ) {
52
+ router .push ({ path })
53
+ }
54
+
55
+ onMounted (() => {
56
+ window .addEventListener (' keydown' , listenKey )
57
+ })
58
+
59
+ onUnmounted (() => {
60
+ window .removeEventListener (' keydown' , listenKey )
61
+ })
62
+
63
+ // 监听 ctrl + k
64
+ function listenKey(event ) {
65
+ if ((event .ctrlKey || event .metaKey ) && event .key === ' k' ) {
66
+ showSearch .value = ! showSearch .value
67
+ // 这里可以执行相应的操作(例如打开搜索框等)
68
+ }
69
+ }
70
+
71
+ defineExpose ({
72
+ openSearch : () => {
73
+ showSearch .value = true
74
+ }
75
+ })
76
+ </script >
You can’t perform that action at this time.
0 commit comments