add router search

This commit is contained in:
wangding 2023-05-29 11:26:51 +08:00
parent 6768cdea05
commit 43f3c67434
3 changed files with 51 additions and 51 deletions

View File

@ -8,7 +8,7 @@
"source.fixAll.eslint": true "source.fixAll.eslint": true
}, },
"[vue]": { "[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "Vue.volar"
}, },
"[javascript]": { "[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "esbenp.prettier-vscode"

View File

@ -3,8 +3,7 @@ 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' import routerSearch from '@/components/RouterSearch/index.vue'
const { getPrefixCls } = useDesign() const { getPrefixCls } = useDesign()
const prefixCls = getPrefixCls('app') const prefixCls = getPrefixCls('app')
@ -26,11 +25,12 @@ setDefaultTheme()
<template> <template>
<ConfigGlobal :size="currentSize"> <ConfigGlobal :size="currentSize">
<RouterView :class="greyMode ? `${prefixCls}-grey-mode` : ''" /> <RouterView :class="greyMode ? `${prefixCls}-grey-mode` : ''" />
<routerSearch/> <routerSearch />
</ConfigGlobal> </ConfigGlobal>
</template> </template>
<style lang="scss"> <style lang="scss">
$prefix-cls: #{$namespace}-app; $prefix-cls: #{$namespace}-app;
.size { .size {
width: 100%; width: 100%;
height: 100%; height: 100%;

View File

@ -6,7 +6,7 @@
remote remote
placeholder="请输入菜单内容" placeholder="请输入菜单内容"
:remote-method="remoteMethod" :remote-method="remoteMethod"
style="width: 100%;" style="width: 100%"
@change="handleChange" @change="handleChange"
> >
<el-option <el-option
@ -22,15 +22,16 @@
<script setup lang="ts"> <script setup lang="ts">
const router = useRouter() // const router = useRouter() //
const showSearch = ref(false) // const showSearch = ref(false) //
const value:Ref = ref('') // const value: Ref = ref('') //
const routers = router.getRoutes() // const routers = router.getRoutes() //
const options = computed(() => { // const options = computed(() => {
if(!value.value) { //
if (!value.value) {
return [] return []
} }
const list = routers.filter((item:any) => { const list = routers.filter((item: any) => {
if(item.meta.title?.indexOf(value.value) > -1 || item.path.indexOf(value.value) > -1) { if (item.meta.title?.indexOf(value.value) > -1 || item.path.indexOf(value.value) > -1) {
return true return true
} }
}) })
@ -42,14 +43,13 @@ const options = computed(() => { // 提示选项
}) })
}) })
function remoteMethod(data) { function remoteMethod(data) {
// //
value.value = data value.value = data
} }
function handleChange(path) { function handleChange(path) {
router.push({path}) router.push({ path })
} }
onMounted(() => { onMounted(() => {