7f1a05107f5b21ec3154c4a244add11532c28454
## 主要改进 ### 1. 新增 batchUpdateRuleGroupStatus 函数(批量启用/禁用) - ✅ 参数验证(ID列表不为空,每个ID有效) - ✅ 逐个验证分组存在性 - ✅ 逐个执行更新操作 - ✅ 返回详细的操作结果 - updated_count: 成功更新的数量 - failed_ids: 失败的ID列表 - errors: 详细的错误信息(包含ID和错误原因) ### 2. 新增 batchDeleteRuleGroups 函数(批量删除) - ✅ 参数验证(ID列表不为空,每个ID有效) - ✅ 采用安全的阻止删除策略 - ✅ 逐个检查并删除分组 - ✅ 返回详细的操作结果和错误信息 - deleted_count: 成功删除的数量 - failed_ids: 失败的ID列表 - errors: 详细的错误信息(包含子分组/评查点检查结果) ### 3. 批量操作特性 - ✅ **逐个处理**:确保每个分组都能被正确处理 - ✅ **部分成功支持**:即使部分分组操作失败,成功的也会被处理 - ✅ **详细的错误追踪**:记录每个失败的ID及其失败原因 - ✅ **安全性优先**:批量删除继承单个删除的安全检查 ### 4. 返回值结构 ```typescript // 批量更新状态 { success: boolean; // 是否全部成功 updated_count: number; // 成功更新的数量 failed_ids: string[]; // 失败的ID列表 errors?: Array<{ // 详细错误(可选) id: string; error: string; }>; } // 批量删除 { success: boolean; // 是否全部成功 deleted_count: number; // 成功删除的数量 failed_ids: string[]; // 失败的ID列表 errors?: Array<{ // 详细错误(可选) id: string; error: string; details?: { // 删除失败详情 hasChildren?: boolean; hasPoints?: boolean; }; }>; } ``` ## 使用示例 ### 批量启用分组 ```typescript const result = await batchUpdateRuleGroupStatus( ['1', '2', '3'], true, token ); if (result.success) { console.log(`成功启用 ${result.updated_count} 个分组`); } else { console.log(`成功 ${result.updated_count} 个,失败 ${result.failed_ids.length} 个`); result.errors?.forEach(err => { console.log(`分组 ${err.id}: ${err.error}`); }); } ``` ### 批量删除分组 ```typescript const result = await batchDeleteRuleGroups(['1', '2'], token); if (result.success) { console.log(`成功删除 ${result.deleted_count} 个分组`); } else { result.errors?.forEach(err => { if (err.details?.hasChildren) { console.log(`分组 ${err.id} 有子分组,无法删除`); } if (err.details?.hasPoints) { console.log(`分组 ${err.id} 有评查点,无法删除`); } }); } ``` ## 相关文件 - app/api/evaluation_points/rule-groups.ts ## 验收清单 - [x] TypeScript 类型检查通过 - [x] 完整的参数验证 - [x] 支持部分成功场景 - [x] 详细的错误追踪 - [x] 安全的删除策略 Co-Authored-By: Claude <noreply@anthropic.com>
智慧法务系统 - 权限认证系统
认证系统概述
本系统实现了一个简单的基于角色的权限认证系统,支持以下功能:
-
用户可以以不同角色登录系统:
common:普通用户,只能访问基本功能developer:开发者,可以访问所有功能,包括系统设置
-
权限控制:
- 根据用户角色显示或隐藏菜单项
- 防止通过URL直接访问未授权页面
技术实现
权限系统基于以下核心技术实现:
- Cookie会话存储:使用Remix的
createCookieSessionStorage创建基于Cookie的会话存储 - 角色权限控制:将用户角色存储在会话中,并在全局loader中检查访问权限
- 界面适配:根据用户角色动态过滤显示菜单项
使用方法
登录系统
- 访问登录页面(
/login) - 输入用户名和密码
- 选择用户角色:
- 普通用户:只能看到基础功能菜单
- 开发者:可以看到所有菜单,包括系统设置
权限验证
系统会自动执行以下权限验证:
- 未登录用户会被重定向到登录页面
- 普通用户试图访问系统设置等受限页面会被重定向到首页
- 侧边栏菜单会根据用户角色动态显示
关键文件
app/root.tsx:实现会话管理和全局权限检查app/components/layout/Sidebar.tsx:根据用户角色显示不同菜单app/routes/login.tsx:提供角色选择功能
进一步优化建议
- 实现真实的用户认证系统,如接入数据库验证用户
- 添加更细粒度的权限控制
- 实现用户角色和权限的管理界面
- 使用环境变量管理会话密钥等敏感信息
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/serverbuild/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.
Description
Languages
JavaScript
72.4%
TypeScript
23.8%
CSS
3.6%