TanWenyan da7e565bbb fix(evaluation-groups): 修复 Authorization 头缺失问题
## 问题
GET 和 DELETE 请求在 token 为 undefined 时,传递空对象 `{}` 作为 headers,导致 axios-client 拦截器无法自动添加 Authorization 头。

## 根本原因
```typescript
//  错误写法
headers: token ? { 'Authorization': `Bearer ${token}` } : {}
```
当 token 为 undefined 时,传递的是空对象 `{}`,axios-client 认为已经提供了 headers,就跳过拦截器。

## 修复方案
```typescript
//  正确写法
...(token ? { headers: { 'Authorization': `Bearer ${token}` } } : {})
```
当 token 为 undefined 时,完全不传 headers 参数,让 axios-client 拦截器自动添加。

## 修复的函数
1.  getEvaluationPointGroups (GET)
2.  getAllEvaluationPointGroups (GET)
3.  getEvaluationPointGroup (GET)
4.  getEvaluationPointGroupChildren (GET)
5.  deleteEvaluationPointGroup (DELETE)

## 未修复的函数(无需修复)
- createEvaluationPointGroup (POST) - headers 总是包含 Content-Type
- updateEvaluationPointGroup (PUT) - headers 总是包含 Content-Type
- batchUpdateEvaluationPointGroupStatus (PATCH) - headers 总是包含 Content-Type
- batchDeleteEvaluationPointGroups (DELETE) - headers 总是包含 Content-Type

POST/PUT/PATCH 请求因为总是需要设置 Content-Type,所以 headers 对象总是存在,拦截器会正常工作。

## 影响
修复后,即使 token 参数为 undefined,axios-client 拦截器也能正常添加 Authorization 头。

## 文件
- app/api/evaluation_points/rule-groups.ts

## 相关日志
解决了控制台警告:
⚠️ [apiRequest] 请求缺少 Authorization 头!headers:
2025-11-26 10:37:36 +08:00
2025-08-01 16:05:41 +08:00
2025-11-25 11:02:40 +08:00
2025-11-05 21:05:44 +08:00
2025-06-04 11:18:52 +08:00
2025-03-24 15:12:24 +08:00
2025-10-30 09:50:14 +08:00
2025-10-30 09:50:14 +08:00
2025-11-24 18:41:14 +08:00
2025-11-24 18:41:14 +08:00
2025-03-24 15:12:24 +08:00
2025-11-24 18:41:14 +08:00

智慧法务系统 - 权限认证系统

认证系统概述

本系统实现了一个简单的基于角色的权限认证系统,支持以下功能:

  1. 用户可以以不同角色登录系统:

    • common:普通用户,只能访问基本功能
    • developer:开发者,可以访问所有功能,包括系统设置
  2. 权限控制:

    • 根据用户角色显示或隐藏菜单项
    • 防止通过URL直接访问未授权页面

技术实现

权限系统基于以下核心技术实现:

  1. Cookie会话存储:使用Remix的createCookieSessionStorage创建基于Cookie的会话存储
  2. 角色权限控制:将用户角色存储在会话中,并在全局loader中检查访问权限
  3. 界面适配:根据用户角色动态过滤显示菜单项

使用方法

登录系统

  1. 访问登录页面(/login)
  2. 输入用户名和密码
  3. 选择用户角色:
    • 普通用户:只能看到基础功能菜单
    • 开发者:可以看到所有菜单,包括系统设置

权限验证

系统会自动执行以下权限验证:

  1. 未登录用户会被重定向到登录页面
  2. 普通用户试图访问系统设置等受限页面会被重定向到首页
  3. 侧边栏菜单会根据用户角色动态显示

关键文件

  • app/root.tsx:实现会话管理和全局权限检查
  • app/components/layout/Sidebar.tsx:根据用户角色显示不同菜单
  • app/routes/login.tsx:提供角色选择功能

进一步优化建议

  1. 实现真实的用户认证系统,如接入数据库验证用户
  2. 添加更细粒度的权限控制
  3. 实现用户角色和权限的管理界面
  4. 使用环境变量管理会话密钥等敏感信息

Welcome to Remix!

Development

Run the dev server:

npm run dev

Deployment

First, build your app for production:

npm run build

Then run the app in production mode:

npm start

Now you'll need to pick a host to deploy it to.

DIY

If you're familiar with deploying Node applications, the built-in Remix app server is production-ready.

Make sure to deploy the output of npm run build

  • build/server
  • build/client

Styling

This template comes with Tailwind CSS already configured for a simple default starting experience. You can use whatever css framework you prefer. See the Vite docs on css for more information.

S
Description
No description provided
Readme 39 MiB
Languages
JavaScript 72.4%
TypeScript 23.8%
CSS 3.6%