fix(other): 处理注册路由前获取用户信息和权限信息异常导致白屏的情况

ISSUES CLOSED: #54
This commit is contained in:
zclzone 2023-11-05 16:02:32 +08:00
parent be1884bd05
commit d1ed8bb933

View File

@ -28,6 +28,7 @@ export async function resetRouter() {
} }
export async function addDynamicRoutes() { export async function addDynamicRoutes() {
// return Promise.reject('123')
const token = getToken() const token = getToken()
// 没有token情况 // 没有token情况
@ -37,8 +38,8 @@ export async function addDynamicRoutes() {
} }
// 有token的情况 // 有token的情况
const userStore = useUserStore()
try { try {
const userStore = useUserStore()
const permissionStore = usePermissionStore() const permissionStore = usePermissionStore()
!userStore.userId && (await userStore.getUserInfo()) !userStore.userId && (await userStore.getUserInfo())
const accessRoutes = permissionStore.generateRoutes(userStore.role) const accessRoutes = permissionStore.generateRoutes(userStore.role)
@ -49,6 +50,8 @@ export async function addDynamicRoutes() {
router.addRoute(NOT_FOUND_ROUTE) router.addRoute(NOT_FOUND_ROUTE)
} catch (error) { } catch (error) {
console.error(error) console.error(error)
$message.error('初始化用户信息失败: ' + error)
userStore.logout()
} }
} }