fix(路由守卫): 修复页面进入不了的问题
This commit is contained in:
parent
2895ad5fc2
commit
c8c0301e22
@ -19,7 +19,7 @@ import { appConnectionManager, isAppConnected } from './appConnectionManager.js'
|
|||||||
* APP连接检查器
|
* APP连接检查器
|
||||||
*/
|
*/
|
||||||
class AppConnectionChecker {
|
class AppConnectionChecker {
|
||||||
constructor() {
|
constructor () {
|
||||||
this.isConnecting = false
|
this.isConnecting = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class AppConnectionChecker {
|
|||||||
* 确保APP连接
|
* 确保APP连接
|
||||||
* @returns {Promise<boolean>} 连接是否成功
|
* @returns {Promise<boolean>} 连接是否成功
|
||||||
*/
|
*/
|
||||||
async ensureConnection() {
|
async ensureConnection () {
|
||||||
console.debug('🔗 Checking APP connection...')
|
console.debug('🔗 Checking APP connection...')
|
||||||
|
|
||||||
// 如果不在APP环境中,直接返回成功
|
// 如果不在APP环境中,直接返回成功
|
||||||
@ -66,7 +66,7 @@ class AppConnectionChecker {
|
|||||||
* 执行APP连接
|
* 执行APP连接
|
||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
async _performConnection() {
|
async _performConnection () {
|
||||||
try {
|
try {
|
||||||
console.debug('📱 Starting new APP connection...')
|
console.debug('📱 Starting new APP connection...')
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ class AppConnectionChecker {
|
|||||||
* APP连接成功后获取用户信息
|
* APP连接成功后获取用户信息
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _fetchUserInfoAfterConnection() {
|
async _fetchUserInfoAfterConnection () {
|
||||||
try {
|
try {
|
||||||
console.debug('👤 Fetching user info after connection...')
|
console.debug('👤 Fetching user info after connection...')
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ class AppConnectionChecker {
|
|||||||
/**
|
/**
|
||||||
* 重置连接状态
|
* 重置连接状态
|
||||||
*/
|
*/
|
||||||
reset() {
|
reset () {
|
||||||
appConnectionManager.reset()
|
appConnectionManager.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ class AppConnectionChecker {
|
|||||||
* 身份检查器
|
* 身份检查器
|
||||||
*/
|
*/
|
||||||
class IdentityChecker {
|
class IdentityChecker {
|
||||||
constructor() {
|
constructor () {
|
||||||
this.isChecking = false
|
this.isChecking = false
|
||||||
this.checkPromise = null
|
this.checkPromise = null
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ class IdentityChecker {
|
|||||||
* @param {string} userId - 用户ID
|
* @param {string} userId - 用户ID
|
||||||
* @returns {Promise<string>} 返回主要身份
|
* @returns {Promise<string>} 返回主要身份
|
||||||
*/
|
*/
|
||||||
async checkUserIdentity(userId) {
|
async checkUserIdentity (userId) {
|
||||||
if (!userId) {
|
if (!userId) {
|
||||||
console.warn('⚠️ No user ID provided')
|
console.warn('⚠️ No user ID provided')
|
||||||
permissionManager.setUserIdentity(null)
|
permissionManager.setUserIdentity(null)
|
||||||
@ -192,7 +192,7 @@ class IdentityChecker {
|
|||||||
* @param {string} userId - 用户ID
|
* @param {string} userId - 用户ID
|
||||||
* @returns {Promise<string>} 主要身份
|
* @returns {Promise<string>} 主要身份
|
||||||
*/
|
*/
|
||||||
async _performIdentityCheck(userId) {
|
async _performIdentityCheck (userId) {
|
||||||
try {
|
try {
|
||||||
console.debug('🔍 Checking user identity for:', userId)
|
console.debug('🔍 Checking user identity for:', userId)
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ class IdentityChecker {
|
|||||||
/**
|
/**
|
||||||
* 重置检查状态
|
* 重置检查状态
|
||||||
*/
|
*/
|
||||||
reset() {
|
reset () {
|
||||||
this.isChecking = false
|
this.isChecking = false
|
||||||
this.checkPromise = null
|
this.checkPromise = null
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ class PageRedirector {
|
|||||||
* @param {string} currentPath - 当前页面路径
|
* @param {string} currentPath - 当前页面路径
|
||||||
* @returns {Promise<boolean>} 是否进行了重定向
|
* @returns {Promise<boolean>} 是否进行了重定向
|
||||||
*/
|
*/
|
||||||
async redirectToCorrectPage(router, targetPath, currentPath) {
|
async redirectToCorrectPage (router, targetPath, currentPath) {
|
||||||
const primaryRole = permissionManager.getPrimaryRole()
|
const primaryRole = permissionManager.getPrimaryRole()
|
||||||
|
|
||||||
// 检查目标页面权限
|
// 检查目标页面权限
|
||||||
@ -277,7 +277,7 @@ class PageRedirector {
|
|||||||
* @param {Object} router - Vue Router 实例
|
* @param {Object} router - Vue Router 实例
|
||||||
* @param {string} attemptedPage - 尝试访问的页面
|
* @param {string} attemptedPage - 尝试访问的页面
|
||||||
*/
|
*/
|
||||||
async handleUnauthorizedAccess(router, attemptedPage) {
|
async handleUnauthorizedAccess (router, attemptedPage) {
|
||||||
const primaryRole = permissionManager.getPrimaryRole()
|
const primaryRole = permissionManager.getPrimaryRole()
|
||||||
const defaultPage = permissionManager.getDefaultPage()
|
const defaultPage = permissionManager.getDefaultPage()
|
||||||
|
|
||||||
@ -296,7 +296,7 @@ class PageRedirector {
|
|||||||
* 路由守卫类
|
* 路由守卫类
|
||||||
*/
|
*/
|
||||||
class RouteGuard {
|
class RouteGuard {
|
||||||
constructor() {
|
constructor () {
|
||||||
this.appConnectionChecker = new AppConnectionChecker()
|
this.appConnectionChecker = new AppConnectionChecker()
|
||||||
this.identityChecker = new IdentityChecker()
|
this.identityChecker = new IdentityChecker()
|
||||||
this.pageRedirector = new PageRedirector()
|
this.pageRedirector = new PageRedirector()
|
||||||
@ -307,7 +307,7 @@ class RouteGuard {
|
|||||||
* 安装路由守卫
|
* 安装路由守卫
|
||||||
* @param {Object} router - Vue Router 实例
|
* @param {Object} router - Vue Router 实例
|
||||||
*/
|
*/
|
||||||
install(router) {
|
install (router) {
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
await this.handleRouteChange(to, from, next)
|
await this.handleRouteChange(to, from, next)
|
||||||
})
|
})
|
||||||
@ -322,7 +322,7 @@ class RouteGuard {
|
|||||||
* @param {Object} from - 来源路由
|
* @param {Object} from - 来源路由
|
||||||
* @param {Function} next - 路由继续函数
|
* @param {Function} next - 路由继续函数
|
||||||
*/
|
*/
|
||||||
async handleRouteChange(to, from, next) {
|
async handleRouteChange (to, from, next) {
|
||||||
console.group('🛡️ Route Guard Check')
|
console.group('🛡️ Route Guard Check')
|
||||||
console.debug('📍 Route change:', from.path, '→', to.path)
|
console.debug('📍 Route change:', from.path, '→', to.path)
|
||||||
|
|
||||||
@ -394,7 +394,7 @@ class RouteGuard {
|
|||||||
* @param {string} path - 页面路径
|
* @param {string} path - 页面路径
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isPublicPage(path) {
|
isPublicPage (path) {
|
||||||
const publicPages = [
|
const publicPages = [
|
||||||
PAGES.APPLY, // 申请页面 - 重要:申请页面不需要权限检查
|
PAGES.APPLY, // 申请页面 - 重要:申请页面不需要权限检查
|
||||||
PAGES.NOT_APP, // 错误页面 - APP连接失败时的页面
|
PAGES.NOT_APP, // 错误页面 - APP连接失败时的页面
|
||||||
@ -404,6 +404,8 @@ class RouteGuard {
|
|||||||
'/recharge',
|
'/recharge',
|
||||||
'/recharge-freight-agent',
|
'/recharge-freight-agent',
|
||||||
'/pay-result',
|
'/pay-result',
|
||||||
|
'/top-list', //排行榜
|
||||||
|
'/weekly-star', //每周明星
|
||||||
]
|
]
|
||||||
return publicPages.includes(path)
|
return publicPages.includes(path)
|
||||||
}
|
}
|
||||||
@ -413,7 +415,7 @@ class RouteGuard {
|
|||||||
* @param {Object} router - Vue Router 实例
|
* @param {Object} router - Vue Router 实例
|
||||||
* @param {string} userId - 用户ID
|
* @param {string} userId - 用户ID
|
||||||
*/
|
*/
|
||||||
async checkAndRedirect(router, userId) {
|
async checkAndRedirect (router, userId) {
|
||||||
try {
|
try {
|
||||||
console.debug('🔄 Manual identity check and redirect')
|
console.debug('🔄 Manual identity check and redirect')
|
||||||
|
|
||||||
@ -441,7 +443,7 @@ class RouteGuard {
|
|||||||
/**
|
/**
|
||||||
* 重置守卫状态
|
* 重置守卫状态
|
||||||
*/
|
*/
|
||||||
reset() {
|
reset () {
|
||||||
this.appConnectionChecker.reset()
|
this.appConnectionChecker.reset()
|
||||||
this.identityChecker.reset()
|
this.identityChecker.reset()
|
||||||
permissionManager.reset()
|
permissionManager.reset()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user