wip: Form改造中
This commit is contained in:
parent
8e33e5c360
commit
46ac7f88c9
|
@ -26,52 +26,52 @@ const whiteList = ['/login'] // 不重定向白名单
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
start()
|
start()
|
||||||
loadStart()
|
loadStart()
|
||||||
if (!wsCache.get(appStore.getUserInfo)) {
|
// if (!wsCache.get(appStore.getUserInfo)) {
|
||||||
if (to.path === '/login') {
|
if (to.path === '/login') {
|
||||||
next({ path: '/' })
|
next({ path: '/' })
|
||||||
} else {
|
|
||||||
if (!dictStore.getIsSetDict) {
|
|
||||||
// 获取所有字典
|
|
||||||
const res = await getDictApi()
|
|
||||||
if (res) {
|
|
||||||
dictStore.setDictObj(res.data)
|
|
||||||
dictStore.setIsSetDict(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (permissionStore.getIsAddRouters) {
|
|
||||||
next()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 开发者可根据实际情况进行修改
|
|
||||||
const roleRouters = wsCache.get('roleRouters') || []
|
|
||||||
const userInfo = wsCache.get(appStore.getUserInfo)
|
|
||||||
|
|
||||||
// 是否使用动态路由
|
|
||||||
if (appStore.getDynamicRouter) {
|
|
||||||
userInfo.role === 'admin'
|
|
||||||
? await permissionStore.generateRoutes('admin', roleRouters as AppCustomRouteRecordRaw[])
|
|
||||||
: await permissionStore.generateRoutes('test', roleRouters as string[])
|
|
||||||
} else {
|
|
||||||
await permissionStore.generateRoutes('none')
|
|
||||||
}
|
|
||||||
|
|
||||||
permissionStore.getAddRouters.forEach((route) => {
|
|
||||||
router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表
|
|
||||||
})
|
|
||||||
const redirectPath = from.query.redirect || to.path
|
|
||||||
const redirect = decodeURIComponent(redirectPath as string)
|
|
||||||
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect }
|
|
||||||
permissionStore.setIsAddRouters(true)
|
|
||||||
next(nextData)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (whiteList.indexOf(to.path) !== -1) {
|
if (!dictStore.getIsSetDict) {
|
||||||
next()
|
// 获取所有字典
|
||||||
} else {
|
const res = await getDictApi()
|
||||||
next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
|
if (res) {
|
||||||
|
dictStore.setDictObj(res.data)
|
||||||
|
dictStore.setIsSetDict(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (permissionStore.getIsAddRouters) {
|
||||||
|
next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开发者可根据实际情况进行修改
|
||||||
|
const roleRouters = wsCache.get('roleRouters') || []
|
||||||
|
const userInfo = wsCache.get(appStore.getUserInfo)
|
||||||
|
|
||||||
|
// 是否使用动态路由
|
||||||
|
if (appStore.getDynamicRouter) {
|
||||||
|
userInfo.role === 'admin'
|
||||||
|
? await permissionStore.generateRoutes('admin', roleRouters as AppCustomRouteRecordRaw[])
|
||||||
|
: await permissionStore.generateRoutes('test', roleRouters as string[])
|
||||||
|
} else {
|
||||||
|
await permissionStore.generateRoutes('none')
|
||||||
|
}
|
||||||
|
|
||||||
|
permissionStore.getAddRouters.forEach((route) => {
|
||||||
|
router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表
|
||||||
|
})
|
||||||
|
const redirectPath = from.query.redirect || to.path
|
||||||
|
const redirect = decodeURIComponent(redirectPath as string)
|
||||||
|
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect }
|
||||||
|
permissionStore.setIsAddRouters(true)
|
||||||
|
next(nextData)
|
||||||
}
|
}
|
||||||
|
// } else {
|
||||||
|
// if (whiteList.indexOf(to.path) !== -1) {
|
||||||
|
// next()
|
||||||
|
// } else {
|
||||||
|
// next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
|
||||||
|
// }
|
||||||
|
// }
|
||||||
})
|
})
|
||||||
|
|
||||||
router.afterEach((to) => {
|
router.afterEach((to) => {
|
||||||
|
|
Loading…
Reference in New Issue