ai-coding
2026-07-22 32fdec7c45c5e1ed66cda15f7a42acebd801ddaf
feat: 修复无权限拦截

Co-Authored-By: 王心悦 <wangxy84@xiaopeng.com>
1个文件已修改
11 ■■■■■ 已修改文件
src/router/guard.ts 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/guard.ts
@@ -50,8 +50,11 @@
    if (isStaticRouteMode && !routeStore.isInitAuthRoute && to.name !== 'login') {
      try {
        await routeStore.initAuthRoute()
        // 初始化后菜单为空 = 无权限,静态模式下也需重定向到无权限页
        if (to.name !== 'noPermission' && routeStore.menus.length === 0) {
        // 仅对"已登录且非 SSO 回调"的用户,在菜单为空时才判为无权限并跳转。
        // 未登录 / 带 code&state 的 SSO 回调必须放行给登录流程处理,否则会丢失回调参数、
        // 拿不到 token,被卡死在无权限页并与首页无限来回跳转。
        const inSsoCallback = Boolean((to.query as any).code && (to.query as any).state)
        if (isLogin && !inSsoCallback && to.name !== 'noPermission' && routeStore.menus.length === 0) {
          tabStore.clearAllTabs()
          next({ path: '/no-permission', replace: true })
          return
@@ -122,8 +125,8 @@
      try {
        await routeStore.initAuthRoute()
        // 检测后端返回路由为空(无权限)
        if (routeStore.menus.length === 0) {
        // 检测后端返回路由为空(无权限)——仅对已登录用户判定,未登录交给上面的登录流程
        if (isLogin && routeStore.menus.length === 0) {
          tabStore.clearAllTabs()
          next({ path: '/no-permission', replace: true })
          return