Skip to content

Commit 9fbefc9

Browse files
author
piexlmax
committed
修复路由参数丢失的bug
1 parent 71e1172 commit 9fbefc9

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"axios": "^0.19.2",
1515
"core-js": "^3.6.5",
1616
"echarts": "4.9.0",
17-
"element-plus": "1.2.0-beta.6",
17+
"element-plus": "1.3.0-beta.8",
1818
"highlight.js": "^10.6.0",
1919
"marked": "^2.0.0",
2020
"mitt": "^3.0.0",

web/src/pinia/modules/router.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import { ref } from 'vue'
77
const routerListArr = []
88
const keepAliveRoutersArr = []
99

10-
const formatRouter = (routes) => {
10+
const formatRouter = (routes, routeMap) => {
1111
routes && routes.forEach(item => {
1212
if ((!item.children || item.children.every(ch => ch.hidden)) && item.name !== '404' && !item.hidden) {
1313
routerListArr.push({ label: item.meta.title, value: item.name })
1414
}
1515
item.meta.hidden = item.hidden
16+
routeMap[item.name] = item
1617
if (item.children && item.children.length > 0) {
17-
formatRouter(item.children)
18+
formatRouter(item.children, routeMap)
1819
}
1920
})
2021
}
@@ -35,6 +36,7 @@ export const useRouterStore = defineStore('router', () => {
3536
const asyncRouters = ref([])
3637
const routerList = ref(routerListArr)
3738
const keepAliveRouters = ref(keepAliveRoutersArr)
39+
const routeMap = ({})
3840
// 从后台获取动态路由
3941
const SetAsyncRouter = async() => {
4042
const baseRouter = [{
@@ -57,7 +59,7 @@ export const useRouterStore = defineStore('router', () => {
5759
},
5860
component: 'view/error/index.vue'
5961
})
60-
formatRouter(asyncRouter)
62+
formatRouter(asyncRouter, routeMap)
6163
baseRouter[0].children = asyncRouter
6264
baseRouter.push({
6365
path: '/:catchAll(.*)',
@@ -76,7 +78,8 @@ export const useRouterStore = defineStore('router', () => {
7678
asyncRouters,
7779
routerList,
7880
keepAliveRouters,
79-
SetAsyncRouter
81+
SetAsyncRouter,
82+
routeMap
8083
}
8184
})
8285

web/src/view/layout/aside/asideComponent/menuItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<el-menu-item :index="routerInfo.name" :route="{parameters:routerInfo.parameters}">
2+
<el-menu-item :index="routerInfo.name">
33
<el-icon>
44
<component :is="routerInfo.meta.icon" />
55
</el-icon>

web/src/view/layout/aside/index.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ onUnmounted(() => {
7474
emitter.off('collapse')
7575
})
7676
77-
const selectMenuItem = (index, _, ele) => {
77+
const selectMenuItem = (index, _, ele, aaa) => {
7878
const query = {}
7979
const params = {}
80-
ele?.route?.parameters &&
81-
ele.route.parameters.forEach((item) => {
80+
routerStore.routeMap[index]?.parameters &&
81+
routerStore.routeMap[index]?.parameters.forEach((item) => {
8282
if (item.type === 'query') {
8383
query[item.key] = item.value
8484
} else {
8585
params[item.key] = item.value
8686
}
8787
})
88-
if (index === route.name) return
89-
if (index.indexOf('http://') > -1 || index.indexOf('https://') > -1) {
90-
window.open(index)
91-
} else {
92-
router.push({ name: index, query, params })
93-
}
88+
if (index === route.name) return
89+
if (index.indexOf('http://') > -1 || index.indexOf('https://') > -1) {
90+
window.open(index)
91+
} else {
92+
router.push({ name: index, query, params })
93+
}
9494
}
9595
</script>
9696

0 commit comments

Comments
 (0)