优化路由参数

This commit is contained in:
不做码农 2023-11-26 21:23:46 +08:00
parent 43485dddfa
commit 7c6e21531b
4 changed files with 25 additions and 4 deletions

View File

@ -22,7 +22,7 @@ export function getUser(userId) {
// 新增用户
export function addUser(data) {
return request({
url: '/system/user/edit',
url: '/system/user/add',
method: 'post',
data: data
})

View File

@ -68,13 +68,18 @@ function close() {
}
function change(val) {
const path = val.path
const query = val.query
if (isHttp(path)) {
// http(s)://
const pindex = path.indexOf('http')
window.open(path.substr(pindex, path.length), '_blank')
} else {
if (query) {
router.push({ path: path, query: JSON.parse(query) })
} else {
router.push(path)
}
}
search.value = ''
options.value = []
@ -104,7 +109,7 @@ function initFuse(list) {
}
// Filter out the routes that can be displayed in the sidebar
// And generate the internationalized title
function generateRoutes(routes, basePath = '', prefixTitle = []) {
function generateRoutes(routes, basePath = '', prefixTitle = [], query = {}) {
let res = []
for (const r of routes) {
@ -130,6 +135,9 @@ function generateRoutes(routes, basePath = '', prefixTitle = []) {
res.push(data)
}
}
if (r.query) {
data.query = r.query
}
// recursive child routes
if (r.children) {

View File

@ -126,7 +126,13 @@ function handleSelect(key, keyPath) {
window.open(key, '_blank')
} else if (!route || !route.children) {
//
const routeMenu = childrenMenus.value.find((item) => item.path === key)
if (routeMenu && routeMenu.query) {
let query = JSON.parse(routeMenu.query)
router.push({ path: key, query: query })
} else {
router.push({ path: key })
}
appStore.toggleSideBarHide(true)
} else {
//

View File

@ -123,6 +123,13 @@ fpPromise
visitorId = result.visitorId
userStore.setClientId(visitorId)
})
watch(
route,
(newRoute) => {
redirect.value = newRoute.query && newRoute.query.redirect
},
{ immediate: true }
)
function handleLogin() {
proxy.$refs.loginRef.validate((valid) => {
if (valid) {