feat: 添加路由参数
This commit is contained in:
@@ -43,14 +43,6 @@ export const usePermisstionStroe = defineStore('permisstion', () => {
|
||||
route.component = loadView(route.component)
|
||||
}
|
||||
}
|
||||
if (route.pathParams != null) {
|
||||
let pathParams = route.pathParams
|
||||
route.pathParams = JSON.parse(route.pathParams)
|
||||
route.query = {}
|
||||
for (const key in route.pathParams) {
|
||||
route.query = {[key]: route.pathParams[key]}
|
||||
}
|
||||
}
|
||||
if (route.children !== null && route.children && route.children.length !== 0) {
|
||||
route.children = formatAsyncRouters(route.children)
|
||||
}
|
||||
@@ -69,12 +61,32 @@ export const usePermisstionStroe = defineStore('permisstion', () => {
|
||||
if (item.children && item.children.length !== 0) {
|
||||
generateMenu(item.children)
|
||||
}
|
||||
if (item.pathParams != null) {
|
||||
item.path = formatPath(item.path, JSON.parse(item.pathParams))
|
||||
}
|
||||
item.title = item.meta.title
|
||||
item.icon = item.meta.icon
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// 拼接地址
|
||||
const formatPath = (path, query) => {
|
||||
const queryArr = []
|
||||
let newPath = path
|
||||
for (const key in query) {
|
||||
queryArr.push({label: key, value: query[key]})
|
||||
}
|
||||
queryArr.forEach((item, index)=>{
|
||||
if(!index) {
|
||||
newPath += `?${item.label}=${item.value}`
|
||||
} else {
|
||||
newPath += `&${item.label}=${item.value}`
|
||||
}
|
||||
})
|
||||
return newPath
|
||||
}
|
||||
|
||||
|
||||
const loadView = (view) => {
|
||||
if (import.meta.env.MODE === 'development') {
|
||||
|
||||
Reference in New Issue
Block a user