HaniBlindBox/.kiro/specs/menu-crud/requirements.md
2026-01-05 00:05:04 +08:00

85 lines
4.0 KiB
Markdown

# Requirements Document
## Introduction
完善 HoneyBox.Admin 后台管理系统的菜单管理页面功能。当前菜单管理页面只有展示功能,需要实现完整的 CRUD 操作,包括新增菜单、编辑菜单、添加子菜单和删除菜单。
## Glossary
- **Menu_Page**: 菜单管理页面组件
- **Menu_API**: 前端菜单 API 模块
- **Menu_Form**: 菜单表单对话框组件
- **Menu_Tree**: 菜单树形表格
## Requirements
### Requirement 1: 前端 API 补充
**User Story:** As a developer, I want to have complete menu API functions, so that the frontend can call backend CRUD operations.
#### Acceptance Criteria
1. THE Menu_API SHALL export createMenu function to call POST /api/admin/menus
2. THE Menu_API SHALL export updateMenu function to call PUT /api/admin/menus/{id}
3. THE Menu_API SHALL export deleteMenu function to call DELETE /api/admin/menus/{id}
4. THE Menu_API SHALL export getMenuById function to call GET /api/admin/menus/{id}
5. THE Menu_API SHALL define CreateMenuRequest and UpdateMenuRequest TypeScript interfaces
### Requirement 2: 新增菜单功能
**User Story:** As an administrator, I want to add new menus, so that I can expand the system navigation structure.
#### Acceptance Criteria
1. WHEN the user clicks "新增菜单" button, THE Menu_Page SHALL display a form dialog
2. THE Menu_Form SHALL include fields: parentId (tree select), name, path, component, icon, menuType, permission, sortOrder, status, isExternal, isCache
3. WHEN the user submits a valid form, THE Menu_Page SHALL call createMenu API and refresh the menu tree
4. IF the API returns an error, THEN THE Menu_Page SHALL display the error message
5. WHEN the form is submitted successfully, THE Menu_Page SHALL close the dialog and show success message
### Requirement 3: 添加子菜单功能
**User Story:** As an administrator, I want to add child menus under existing menus, so that I can create hierarchical navigation.
#### Acceptance Criteria
1. WHEN the user clicks "添加子菜单" button on a menu row, THE Menu_Page SHALL display the form dialog with parentId pre-filled
2. THE Menu_Form SHALL show the parent menu name in the parentId field
3. WHEN the user submits the form, THE Menu_Page SHALL create the menu as a child of the selected parent
### Requirement 4: 编辑菜单功能
**User Story:** As an administrator, I want to edit existing menus, so that I can update menu information.
#### Acceptance Criteria
1. WHEN the user clicks "编辑" button on a menu row, THE Menu_Page SHALL display the form dialog with existing data
2. THE Menu_Form SHALL populate all fields with the current menu data
3. THE Menu_Form SHALL allow changing the parent menu (with validation to prevent circular reference)
4. WHEN the user submits a valid form, THE Menu_Page SHALL call updateMenu API and refresh the menu tree
5. IF the API returns an error, THEN THE Menu_Page SHALL display the error message
### Requirement 5: 删除菜单功能
**User Story:** As an administrator, I want to delete menus, so that I can remove unused navigation items.
#### Acceptance Criteria
1. WHEN the user clicks "删除" button on a menu row, THE Menu_Page SHALL display a confirmation dialog
2. THE confirmation dialog SHALL warn about deleting child menus if the menu has children
3. WHEN the user confirms deletion, THE Menu_Page SHALL call deleteMenu API and refresh the menu tree
4. IF the API returns an error, THEN THE Menu_Page SHALL display the error message
5. WHEN deletion is successful, THE Menu_Page SHALL show success message
### Requirement 6: 表单验证
**User Story:** As an administrator, I want form validation, so that I can ensure data integrity.
#### Acceptance Criteria
1. THE Menu_Form SHALL require name field (non-empty)
2. WHEN menuType is "菜单" (type 2), THE Menu_Form SHALL require path and component fields
3. WHEN menuType is "按钮" (type 3), THE Menu_Form SHALL require permission field
4. THE Menu_Form SHALL validate path format (must start with / for internal routes)
5. THE Menu_Form SHALL validate sortOrder as a non-negative integer