优化路由参数

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) { export function addUser(data) {
return request({ return request({
url: '/system/user/edit', url: '/system/user/add',
method: 'post', method: 'post',
data: data data: data
}) })

View File

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

View File

@ -126,7 +126,13 @@ function handleSelect(key, keyPath) {
window.open(key, '_blank') window.open(key, '_blank')
} else if (!route || !route.children) { } else if (!route || !route.children) {
// //
router.push({ path: key }) 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) appStore.toggleSideBarHide(true)
} else { } else {
// //

View File

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