20251025-all-routes-auth-bypass.md 9.1 KB

所有路由域名限制跳过配置

📋 任务概述

临时跳过所有板块的企业微信授权限制,方便本地开发和调试。

✅ 完成内容

已跳过授权的板块

所有板块和模块的路由守卫都已临时注释:

  1. 客服板块 (/customer-service/*)
  2. 设计师板块 (/designer/*)
  3. 组长板块 (/team-leader/*)
  4. 财务板块 (/finance/*)
  5. 人事板块 (/hr/*)
  6. 管理员板块 (/admin/*)
  7. 企微项目管理模块 (/wxwork/:cid/*)

📝 修改详情

修改文件:yss-project/src/app/app.routes.ts

1. 客服路由

{
  path: 'customer-service',
  loadComponent: () => import('./pages/customer-service/customer-service-layout/customer-service-layout').then(m => m.CustomerServiceLayout),
  // canActivate: [WxworkAuthGuard], // 临时注释,方便本地开发
  children: [...]
}

2. 设计师路由

{
  path: 'designer',
  // canActivate: [WxworkAuthGuard], // 临时注释,方便本地开发
  children: [...]
}

3. 组长路由

{
  path: 'team-leader',
  // canActivate: [WxworkAuthGuard], // 临时注释,方便本地开发
  children: [...]
}

4. 财务路由

{
  path: 'finance',
  // canActivate: [WxworkAuthGuard], // 临时注释,方便本地开发
  children: [...]
}

5. 人事路由

{
  path: 'hr',
  loadComponent: () => import('./pages/hr/hr-layout/hr-layout').then(m => m.HrLayout),
  // canActivate: [WxworkAuthGuard], // 临时注释,方便本地开发
  children: [...]
}

6. 管理员路由

{
  path: 'admin',
  loadComponent: () => import('./pages/admin/admin-layout/admin-layout').then(m => m.AdminLayout),
  // canActivate: [WxworkAuthGuard], // 临时注释,方便本地开发
  children: [...]
}

7. 企微项目管理模块路由

{
  path: 'wxwork/:cid',
  // canActivate: [WxworkAuthGuard], // 临时注释,方便本地开发
  children: [
    // 项目详情、客户画像、项目问卷等
  ]
}

🚀 可访问的页面

客服板块

设计师板块

组长板块

财务板块

人事板块

管理员板块

企微项目管理模块

示例(假设公司ID为cDL6R1hgSi):

💡 使用说明

1. 启动开发服务器

cd yss-project
npm run start

cd yss-project
ng serve --port 4200

2. 直接访问任意页面

无需企业微信授权,直接在浏览器中访问任意页面URL。

3. 设置公司ID(如果需要)

如果页面需要加载数据,确保设置了公司ID:

// 在浏览器控制台运行
localStorage.setItem('company', 'your-company-id-here');

然后刷新页面。

⚠️ 重要提醒

生产环境部署前必须恢复

在部署到生产环境之前,必须取消所有路由守卫的注释,恢复企业微信授权验证:

// yss-project/src/app/app.routes.ts

// 客服路由
{
  path: 'customer-service',
  loadComponent: () => import('./pages/customer-service/customer-service-layout/customer-service-layout').then(m => m.CustomerServiceLayout),
  canActivate: [WxworkAuthGuard], // 取消注释
  children: [...]
}

// 设计师路由
{
  path: 'designer',
  canActivate: [WxworkAuthGuard], // 取消注释
  children: [...]
}

// 组长路由
{
  path: 'team-leader',
  canActivate: [WxworkAuthGuard], // 取消注释
  children: [...]
}

// 财务路由
{
  path: 'finance',
  canActivate: [WxworkAuthGuard], // 取消注释
  children: [...]
}

// 人事路由
{
  path: 'hr',
  loadComponent: () => import('./pages/hr/hr-layout/hr-layout').then(m => m.HrLayout),
  canActivate: [WxworkAuthGuard], // 取消注释
  children: [...]
}

// 管理员路由
{
  path: 'admin',
  loadComponent: () => import('./pages/admin/admin-layout/admin-layout').then(m => m.AdminLayout),
  canActivate: [WxworkAuthGuard], // 取消注释
  children: [...]
}

安全性考虑

  1. 本地开发专用:此配置仅用于本地开发环境
  2. 不要提交到生产分支:如果使用Git,建议将此修改保存在开发分支
  3. 定期检查:定期检查路由守卫是否正确配置
  4. 测试授权流程:部署前在测试环境验证企业微信授权流程

🔍 验证方法

1. 检查路由配置

查看 yss-project/src/app/app.routes.ts,确认所有 canActivate: [WxworkAuthGuard] 都已注释。

2. 测试页面访问

逐个访问各板块的页面,确认可以正常打开:

# 客服
http://localhost:4200/customer-service/dashboard

# 设计师
http://localhost:4200/designer/dashboard

# 组长
http://localhost:4200/team-leader/dashboard

# 财务
http://localhost:4200/finance/dashboard

# 人事
http://localhost:4200/hr/dashboard

# 管理员
http://localhost:4200/admin/dashboard

3. 检查浏览器控制台

打开浏览器开发者工具(F12),查看控制台:

  • 不应该有401授权错误
  • 不应该有重定向到企业微信授权页面

📊 影响范围

已修改的路由

  • ✅ 7个主要板块/模块路由
  • ✅ 所有子路由自动继承(无需单独配置)
  • ✅ 包含企微项目管理模块的所有路由

未修改的路由

  • 根路由 (/)
  • 404路由
  • 其他公共路由

🐛 常见问题

1. 页面仍然跳转到授权页面

原因:可能有子路由单独配置了守卫

解决方法

  1. 检查子路由是否有独立的 canActivate
  2. 逐个注释子路由的守卫

2. 页面显示401错误

原因:API请求可能需要授权token

解决方法

  1. 检查API请求的headers
  2. 确认后端API是否需要授权
  3. 临时修改API服务,跳过token验证

3. 数据加载失败

原因:缺少公司ID或用户信息

解决方法

// 在浏览器控制台设置
localStorage.setItem('company', 'your-company-id');
localStorage.setItem('Parse/ProfileId', 'your-profile-id');

📚 相关文档

📝 修改记录

日期 修改内容 修改人
2024-10-25 跳过客服板块授权 AI Assistant
2024-10-25 跳过所有板块授权 AI Assistant

完成时间: 2024-10-25
开发者: AI Assistant
状态: ✅ 已完成
环境: 本地开发专用
安全级别: ⚠️ 仅用于开发,生产环境必须恢复