Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6768cdea
authored
May 29, 2023
by
wangding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增路由搜索功能
parent
9f0065f8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
src/App.vue
+3
-0
src/components/RouterSearch/index.vue
+77
-0
No files found.
src/App.vue
View file @
6768cdea
...
@@ -3,6 +3,8 @@ import { isDark } from '@/utils/is'
...
@@ -3,6 +3,8 @@ import { isDark } from '@/utils/is'
import
{
useAppStore
}
from
'@/store/modules/app'
import
{
useAppStore
}
from
'@/store/modules/app'
import
{
useDesign
}
from
'@/hooks/web/useDesign'
import
{
useDesign
}
from
'@/hooks/web/useDesign'
import
{
CACHE_KEY
,
useCache
}
from
'@/hooks/web/useCache'
import
{
CACHE_KEY
,
useCache
}
from
'@/hooks/web/useCache'
import
routerSearch
from
'@/components/RouterSearch'
const
{
getPrefixCls
}
=
useDesign
()
const
{
getPrefixCls
}
=
useDesign
()
const
prefixCls
=
getPrefixCls
(
'app'
)
const
prefixCls
=
getPrefixCls
(
'app'
)
...
@@ -24,6 +26,7 @@ setDefaultTheme()
...
@@ -24,6 +26,7 @@ setDefaultTheme()
<
template
>
<
template
>
<ConfigGlobal
:size=
"currentSize"
>
<ConfigGlobal
:size=
"currentSize"
>
<RouterView
:class=
"greyMode ? `$
{prefixCls}-grey-mode` : ''" />
<RouterView
:class=
"greyMode ? `$
{prefixCls}-grey-mode` : ''" />
<routerSearch/>
</ConfigGlobal>
</ConfigGlobal>
</
template
>
</
template
>
<
style
lang=
"scss"
>
<
style
lang=
"scss"
>
...
...
src/components/RouterSearch/index.vue
0 → 100644
View file @
6768cdea
<
template
>
<ElDialog
v-model=
"showSearch"
:show-close=
"false"
title=
"菜单搜索"
>
<el-select
filterable
:reserve-keyword=
"false"
remote
placeholder=
"请输入菜单内容"
:remote-method=
"remoteMethod"
style=
"width: 100%;"
@
change=
"handleChange"
>
<el-option
v-for=
"item in options"
:key=
"item.value"
:label=
"item.label"
:value=
"item.value"
/>
</el-select>
</ElDialog>
</
template
>
<
script
setup
lang=
"ts"
>
const
router
=
useRouter
()
// 路由对象
const
showSearch
=
ref
(
false
)
// 是否显示弹框
const
value
:
Ref
=
ref
(
''
)
// 用户输入的值
const
routers
=
router
.
getRoutes
()
// 路由对象
const
options
=
computed
(()
=>
{
// 提示选项
if
(
!
value
.
value
)
{
return
[]
}
const
list
=
routers
.
filter
((
item
:
any
)
=>
{
if
(
item
.
meta
.
title
?.
indexOf
(
value
.
value
)
>
-
1
||
item
.
path
.
indexOf
(
value
.
value
)
>
-
1
)
{
return
true
}
})
return
list
.
map
((
item
)
=>
{
return
{
label
:
`
${
item
.
meta
.
title
}${
item
.
path
}
`
,
value
:
item
.
path
}
})
})
function
remoteMethod
(
data
)
{
// 这里可以执行相应的操作(例如打开搜索框等)
value
.
value
=
data
}
function
handleChange
(
path
)
{
router
.
push
({
path
})
}
onMounted
(()
=>
{
window
.
addEventListener
(
'keydown'
,
listenKey
)
})
onUnmounted
(()
=>
{
window
.
removeEventListener
(
'keydown'
,
listenKey
)
})
// 监听 ctrl + k
function
listenKey
(
event
)
{
if
((
event
.
ctrlKey
||
event
.
metaKey
)
&&
event
.
key
===
'k'
)
{
showSearch
.
value
=
!
showSearch
.
value
// 这里可以执行相应的操作(例如打开搜索框等)
}
}
defineExpose
({
openSearch
:
()
=>
{
showSearch
.
value
=
true
}
})
</
script
>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment