fetch(modify):修复BUG
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 3m27s
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 3m27s
This commit is contained in:
56
openspec/changes/add-iot-device-operations/proposal.md
Normal file
56
openspec/changes/add-iot-device-operations/proposal.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Change: Add IoT Card and Device Operations
|
||||
|
||||
## Why
|
||||
|
||||
运营人员和代理商需要更丰富的物联网卡和设备管理功能,包括查询流量使用情况、实名认证状态、卡片状态、启停操作,以及设备的重启、重置、限速、换卡、WiFi设置等操作。这些功能是物联网卡全生命周期管理的核心能力。
|
||||
|
||||
## What Changes
|
||||
|
||||
### IoT Card Operations (6 new APIs)
|
||||
- 查询流量使用情况 (GET /api/admin/iot-cards/{iccid}/gateway-flow)
|
||||
- 查询实名认证状态 (GET /api/admin/iot-cards/{iccid}/gateway-realname)
|
||||
- 查询卡片状态 (GET /api/admin/iot-cards/{iccid}/gateway-status)
|
||||
- 获取实名认证链接 (GET /api/admin/iot-cards/{iccid}/realname-link)
|
||||
- 启用物联网卡 (POST /api/admin/iot-cards/{iccid}/start)
|
||||
- 停用物联网卡 (POST /api/admin/iot-cards/{iccid}/stop)
|
||||
|
||||
### Device Operations (6 new APIs)
|
||||
- 重启设备 (POST /api/admin/devices/by-imei/{imei}/reboot)
|
||||
- 重置设备 (POST /api/admin/devices/by-imei/{imei}/reset)
|
||||
- 设置限速 (PUT /api/admin/devices/by-imei/{imei}/speed-limit)
|
||||
- 切换SIM卡 (POST /api/admin/devices/by-imei/{imei}/switch-card)
|
||||
- 设置WiFi (PUT /api/admin/devices/by-imei/{imei}/wifi)
|
||||
|
||||
### UI Changes
|
||||
- 在 `/asset-management/iot-card-management` 页面添加操作按钮:
|
||||
- "查询流量"按钮(主要操作)
|
||||
- "更多操作"下拉菜单(包含其他5个操作)
|
||||
- 在 `/asset-management/devices` 页面添加操作按钮:
|
||||
- "重启设备"按钮(主要操作)
|
||||
- "更多操作"下拉菜单(包含其他5个操作)
|
||||
|
||||
## Impact
|
||||
|
||||
### Affected Specs
|
||||
- **NEW**: `specs/iot-card-operations/spec.md` - IoT卡操作相关的所有需求
|
||||
- **NEW**: `specs/device-operations/spec.md` - 设备操作相关的所有需求
|
||||
|
||||
### Affected Code
|
||||
- **API层**:
|
||||
- 新增 `src/api/modules/iotCard.ts` - IoT卡操作API方法
|
||||
- 新增 `src/api/modules/device.ts` - 设备操作API方法
|
||||
- **类型定义**:
|
||||
- 新增 `src/types/api/iotCard.ts` - IoT卡相关类型
|
||||
- 新增 `src/types/api/device.ts` - 设备相关类型
|
||||
- **页面组件**:
|
||||
- 修改 `src/views/asset-management/iot-card-management/index.vue` - 添加操作按钮和对话框
|
||||
- 修改 `src/views/asset-management/devices/index.vue` - 添加操作按钮和对话框
|
||||
|
||||
### Breaking Changes
|
||||
无破坏性变更。所有变更都是增量式的新功能添加。
|
||||
|
||||
## Dependencies
|
||||
|
||||
- 后端API已实现(见 `docs/2-3新增接口.md`)
|
||||
- Element Plus UI组件库(已在项目中)
|
||||
- Axios HTTP客户端(已在项目中)
|
||||
@@ -0,0 +1,194 @@
|
||||
# Device Operations Specification
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Reboot Device
|
||||
|
||||
The system SHALL provide the ability to reboot an IoT device via its IMEI.
|
||||
|
||||
#### Scenario: Successfully reboot device
|
||||
|
||||
- **WHEN** an authenticated user initiates a reboot operation on a device with valid IMEI
|
||||
- **THEN** the system sends the reboot command to the device
|
||||
- **AND** returns a success response with operation confirmation
|
||||
|
||||
#### Scenario: Reboot operation with confirmation
|
||||
|
||||
- **WHEN** a user clicks the reboot device button
|
||||
- **THEN** the system prompts for confirmation with a warning message
|
||||
- **AND** only proceeds if the user confirms the action
|
||||
|
||||
#### Scenario: Reboot with invalid IMEI
|
||||
|
||||
- **WHEN** a user attempts to reboot a device with invalid or non-existent IMEI
|
||||
- **THEN** the system returns a 400 error with appropriate error message
|
||||
|
||||
### Requirement: Reset Device to Factory Settings
|
||||
|
||||
The system SHALL provide the ability to reset an IoT device to factory settings via its IMEI.
|
||||
|
||||
#### Scenario: Successfully reset device
|
||||
|
||||
- **WHEN** an authenticated user initiates a factory reset operation on a device
|
||||
- **THEN** the system sends the reset command to the device
|
||||
- **AND** returns a success response
|
||||
|
||||
#### Scenario: Reset operation with strong confirmation
|
||||
|
||||
- **WHEN** a user clicks the factory reset button
|
||||
- **THEN** the system displays a warning dialog explaining data loss
|
||||
- **AND** requires user confirmation before proceeding
|
||||
- **AND** only executes if the user explicitly confirms
|
||||
|
||||
#### Scenario: Insufficient permissions for reset
|
||||
|
||||
- **WHEN** a user without proper permissions attempts to reset a device
|
||||
- **THEN** the system returns a 403 forbidden error
|
||||
|
||||
### Requirement: Set Device Speed Limit
|
||||
|
||||
The system SHALL provide the ability to configure upload and download speed limits for an IoT device.
|
||||
|
||||
#### Scenario: Successfully set speed limit
|
||||
|
||||
- **WHEN** an authenticated user submits valid speed limit parameters
|
||||
- **THEN** the system applies the upload and download speed limits to the device
|
||||
- **AND** returns a success response
|
||||
|
||||
#### Scenario: Configure speed limits via dialog
|
||||
|
||||
- **WHEN** a user selects the speed limit option
|
||||
- **THEN** the system displays a dialog with input fields for upload_speed and download_speed (KB/s)
|
||||
- **AND** validates that both values are integers >= 1
|
||||
|
||||
#### Scenario: Invalid speed limit parameters
|
||||
|
||||
- **WHEN** a user submits speed limits less than 1 KB/s
|
||||
- **THEN** the system returns a 400 parameter error
|
||||
- **AND** displays validation error messages
|
||||
|
||||
### Requirement: Switch Device SIM Card
|
||||
|
||||
The system SHALL provide the ability to switch the active SIM card on a multi-SIM device.
|
||||
|
||||
#### Scenario: Successfully switch to target card
|
||||
|
||||
- **WHEN** an authenticated user initiates a card switch with valid target ICCID
|
||||
- **THEN** the system switches the device to use the specified card
|
||||
- **AND** returns a success response
|
||||
|
||||
#### Scenario: Switch card via dialog
|
||||
|
||||
- **WHEN** a user selects the switch card option
|
||||
- **THEN** the system displays a dialog prompting for target_iccid
|
||||
- **AND** validates the ICCID format
|
||||
|
||||
#### Scenario: Switch to non-existent card
|
||||
|
||||
- **WHEN** a user attempts to switch to an ICCID that doesn't exist or isn't available
|
||||
- **THEN** the system returns a 400 error with descriptive message
|
||||
|
||||
### Requirement: Configure Device WiFi Settings
|
||||
|
||||
The system SHALL provide the ability to configure WiFi settings including SSID, password, and enabled status.
|
||||
|
||||
#### Scenario: Successfully configure WiFi
|
||||
|
||||
- **WHEN** an authenticated user submits valid WiFi configuration
|
||||
- **THEN** the system applies the WiFi settings to the device
|
||||
- **AND** returns a success response
|
||||
|
||||
#### Scenario: Configure WiFi via dialog
|
||||
|
||||
- **WHEN** a user selects the WiFi configuration option
|
||||
- **THEN** the system displays a dialog with fields for:
|
||||
- enabled (启用状态: 0=禁用, 1=启用)
|
||||
- ssid (WiFi名称, 1-32 characters)
|
||||
- password (WiFi密码, 8-63 characters)
|
||||
- **AND** validates all field constraints
|
||||
|
||||
#### Scenario: Invalid WiFi parameters
|
||||
|
||||
- **WHEN** a user submits WiFi configuration with invalid parameters
|
||||
- **THEN** the system returns a 400 error
|
||||
- **AND** displays specific validation errors (e.g., "SSID too long", "Password too short")
|
||||
|
||||
### Requirement: Device Management UI Integration
|
||||
|
||||
The system SHALL integrate device operations into the device management page at `/asset-management/devices`.
|
||||
|
||||
#### Scenario: Display primary operation button
|
||||
|
||||
- **WHEN** a user views the device management page
|
||||
- **THEN** the system displays a "重启设备" (Reboot Device) button as the primary operation
|
||||
|
||||
#### Scenario: Display dropdown menu for additional operations
|
||||
|
||||
- **WHEN** a user views the device management page
|
||||
- **THEN** the system displays a "更多操作" (More Operations) dropdown menu
|
||||
- **AND** the dropdown contains: 恢复出厂, 设置限速, 切换SIM卡, 设置WiFi
|
||||
|
||||
#### Scenario: Show loading indicator during operations
|
||||
|
||||
- **WHEN** a device operation is in progress
|
||||
- **THEN** the system displays a loading indicator
|
||||
- **AND** disables the operation buttons to prevent duplicate requests
|
||||
|
||||
### Requirement: Authentication and Authorization
|
||||
|
||||
The system SHALL enforce JWT-based authentication for all device operations.
|
||||
|
||||
#### Scenario: Access with valid JWT token
|
||||
|
||||
- **WHEN** a user makes a request with a valid Bearer token
|
||||
- **THEN** the system processes the request normally
|
||||
|
||||
#### Scenario: Access with expired token
|
||||
|
||||
- **WHEN** a user makes a request with an expired JWT token
|
||||
- **THEN** the system returns a 401 unauthorized error
|
||||
- **AND** redirects to the login page
|
||||
|
||||
### Requirement: Error Handling and User Feedback
|
||||
|
||||
The system SHALL provide clear error messages and success notifications for all operations.
|
||||
|
||||
#### Scenario: Display success message
|
||||
|
||||
- **WHEN** a device operation completes successfully
|
||||
- **THEN** the system displays a success message notification
|
||||
- **AND** automatically closes the operation dialog
|
||||
|
||||
#### Scenario: Handle network errors
|
||||
|
||||
- **WHEN** a network error occurs during a device operation
|
||||
- **THEN** the system displays a user-friendly error message
|
||||
- **AND** allows the user to retry the operation
|
||||
|
||||
#### Scenario: Handle server errors
|
||||
|
||||
- **WHEN** a 500 server error occurs
|
||||
- **THEN** the system displays an error message with timestamp
|
||||
- **AND** logs the error for debugging
|
||||
|
||||
### Requirement: Operation Confirmation Dialogs
|
||||
|
||||
The system SHALL require user confirmation for destructive operations.
|
||||
|
||||
#### Scenario: Confirm reboot operation
|
||||
|
||||
- **WHEN** a user initiates a reboot
|
||||
- **THEN** the system shows a confirmation dialog stating "确定要重启该设备吗?"
|
||||
- **AND** requires explicit confirmation
|
||||
|
||||
#### Scenario: Confirm factory reset operation
|
||||
|
||||
- **WHEN** a user initiates a factory reset
|
||||
- **THEN** the system shows a strong warning dialog stating "确定要恢复出厂设置吗?此操作将清除所有数据!"
|
||||
- **AND** requires explicit confirmation
|
||||
|
||||
#### Scenario: No confirmation for query operations
|
||||
|
||||
- **WHEN** a user initiates speed limit, card switch, or WiFi configuration
|
||||
- **THEN** the system displays input dialogs without confirmation prompts
|
||||
- **AND** only executes after user submits valid parameters
|
||||
@@ -0,0 +1,151 @@
|
||||
# IoT Card Operations Specification
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Query IoT Card Flow Usage
|
||||
|
||||
The system SHALL provide the ability to query real-time flow usage for an IoT card via its ICCID.
|
||||
|
||||
#### Scenario: Successfully query flow usage
|
||||
|
||||
- **WHEN** an authenticated user requests flow usage for a valid ICCID
|
||||
- **THEN** the system returns flow usage data including used flow amount and unit
|
||||
|
||||
#### Scenario: Query with invalid ICCID
|
||||
|
||||
- **WHEN** a user requests flow usage for an invalid or non-existent ICCID
|
||||
- **THEN** the system returns a 400 error with appropriate error message
|
||||
|
||||
### Requirement: Query IoT Card Realname Status
|
||||
|
||||
The system SHALL provide the ability to query the realname authentication status for an IoT card via its ICCID.
|
||||
|
||||
#### Scenario: Successfully query realname status
|
||||
|
||||
- **WHEN** an authenticated user requests realname status for a valid ICCID
|
||||
- **THEN** the system returns the current realname authentication status
|
||||
|
||||
#### Scenario: Query status for unauthenticated user
|
||||
|
||||
- **WHEN** an unauthenticated user attempts to query realname status
|
||||
- **THEN** the system returns a 401 unauthorized error
|
||||
|
||||
### Requirement: Query IoT Card Real-time Status
|
||||
|
||||
The system SHALL provide the ability to query the real-time operational status of an IoT card via its ICCID.
|
||||
|
||||
#### Scenario: Successfully query card status
|
||||
|
||||
- **WHEN** an authenticated user requests card status for a valid ICCID
|
||||
- **THEN** the system returns card status information including ICCID and current status (准备/正常/停机)
|
||||
|
||||
#### Scenario: Query with unauthorized access
|
||||
|
||||
- **WHEN** a user without proper permissions attempts to query card status
|
||||
- **THEN** the system returns a 403 forbidden error
|
||||
|
||||
### Requirement: Get IoT Card Realname Link
|
||||
|
||||
The system SHALL provide the ability to generate and retrieve a realname authentication link for an IoT card.
|
||||
|
||||
#### Scenario: Successfully retrieve realname link
|
||||
|
||||
- **WHEN** an authenticated user requests the realname link for a valid ICCID
|
||||
- **THEN** the system returns an HTTPS URL that can be used for realname authentication
|
||||
|
||||
#### Scenario: Display realname link as QR code
|
||||
|
||||
- **WHEN** the system returns a realname authentication link
|
||||
- **THEN** the UI displays the link as a QR code for easy mobile scanning
|
||||
|
||||
### Requirement: Start IoT Card (复机)
|
||||
|
||||
The system SHALL provide the ability to start (restore service) an IoT card via its ICCID.
|
||||
|
||||
#### Scenario: Successfully start a stopped card
|
||||
|
||||
- **WHEN** an authenticated user initiates a start operation on a stopped card
|
||||
- **THEN** the system processes the request and restores card service
|
||||
- **AND** displays a success message to the user
|
||||
|
||||
#### Scenario: Start operation with confirmation
|
||||
|
||||
- **WHEN** a user clicks the start card button
|
||||
- **THEN** the system prompts for confirmation before executing the operation
|
||||
- **AND** only proceeds if the user confirms the action
|
||||
|
||||
#### Scenario: Insufficient permissions for start operation
|
||||
|
||||
- **WHEN** a user without proper permissions attempts to start a card
|
||||
- **THEN** the system returns a 403 forbidden error
|
||||
|
||||
### Requirement: Stop IoT Card (停机)
|
||||
|
||||
The system SHALL provide the ability to stop (suspend service) an IoT card via its ICCID.
|
||||
|
||||
#### Scenario: Successfully stop an active card
|
||||
|
||||
- **WHEN** an authenticated user initiates a stop operation on an active card
|
||||
- **THEN** the system processes the request and suspends card service
|
||||
- **AND** displays a success message to the user
|
||||
|
||||
#### Scenario: Stop operation with confirmation
|
||||
|
||||
- **WHEN** a user clicks the stop card button
|
||||
- **THEN** the system prompts for confirmation before executing the operation
|
||||
- **AND** only proceeds if the user confirms the action
|
||||
|
||||
#### Scenario: Server error during stop operation
|
||||
|
||||
- **WHEN** a server error occurs during the stop operation
|
||||
- **THEN** the system returns a 500 error with error details
|
||||
- **AND** displays an appropriate error message to the user
|
||||
|
||||
### Requirement: IoT Card Management UI Integration
|
||||
|
||||
The system SHALL integrate IoT card operations into the card management page at `/asset-management/iot-card-management`.
|
||||
|
||||
#### Scenario: Display primary operation button
|
||||
|
||||
- **WHEN** a user views the IoT card management page
|
||||
- **THEN** the system displays a "查询流量使用" (Query Flow Usage) button as the primary operation
|
||||
|
||||
#### Scenario: Display dropdown menu for additional operations
|
||||
|
||||
- **WHEN** a user views the IoT card management page
|
||||
- **THEN** the system displays a "更多操作" (More Operations) dropdown menu
|
||||
- **AND** the dropdown contains: 查询实名状态, 查询卡状态, 获取实名链接, 启用卡片, 停用卡片
|
||||
|
||||
#### Scenario: Show operation results in dialog
|
||||
|
||||
- **WHEN** a user executes a query operation (flow, realname status, or card status)
|
||||
- **THEN** the system displays results in a modal dialog with properly formatted data
|
||||
|
||||
### Requirement: Authentication and Authorization
|
||||
|
||||
The system SHALL enforce JWT-based authentication for all IoT card operations.
|
||||
|
||||
#### Scenario: Access with valid JWT token
|
||||
|
||||
- **WHEN** a user makes a request with a valid Bearer token
|
||||
- **THEN** the system processes the request normally
|
||||
|
||||
#### Scenario: Access with expired token
|
||||
|
||||
- **WHEN** a user makes a request with an expired JWT token
|
||||
- **THEN** the system returns a 401 unauthorized error
|
||||
|
||||
### Requirement: Error Handling
|
||||
|
||||
The system SHALL provide clear error messages for all failure scenarios.
|
||||
|
||||
#### Scenario: Handle 400 parameter errors
|
||||
|
||||
- **WHEN** a request contains invalid parameters
|
||||
- **THEN** the system returns a 400 error with specific validation failure details
|
||||
|
||||
#### Scenario: Handle 500 server errors
|
||||
|
||||
- **WHEN** an internal server error occurs
|
||||
- **THEN** the system returns a 500 error with error timestamp
|
||||
- **AND** logs the error for debugging purposes
|
||||
86
openspec/changes/add-iot-device-operations/tasks.md
Normal file
86
openspec/changes/add-iot-device-operations/tasks.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# Implementation Tasks
|
||||
|
||||
## 1. API Layer - IoT Card Operations
|
||||
|
||||
- [ ] 1.1 创建 `src/api/modules/iotCard.ts`
|
||||
- [ ] 1.2 实现 `getGatewayFlow(iccid)` - 查询流量使用
|
||||
- [ ] 1.3 实现 `getGatewayRealname(iccid)` - 查询实名状态
|
||||
- [ ] 1.4 实现 `getGatewayStatus(iccid)` - 查询卡片状态
|
||||
- [ ] 1.5 实现 `getRealnameLink(iccid)` - 获取实名链接
|
||||
- [ ] 1.6 实现 `startCard(iccid)` - 启用卡片
|
||||
- [ ] 1.7 实现 `stopCard(iccid)` - 停用卡片
|
||||
|
||||
## 2. API Layer - Device Operations
|
||||
|
||||
- [ ] 2.1 创建 `src/api/modules/device.ts`
|
||||
- [ ] 2.2 实现 `rebootDevice(imei)` - 重启设备
|
||||
- [ ] 2.3 实现 `resetDevice(imei)` - 重置设备
|
||||
- [ ] 2.4 实现 `setSpeedLimit(imei, params)` - 设置限速
|
||||
- [ ] 2.5 实现 `switchCard(imei, params)` - 切换SIM卡
|
||||
- [ ] 2.6 实现 `setWifi(imei, params)` - 设置WiFi
|
||||
|
||||
## 3. Type Definitions - IoT Card
|
||||
|
||||
- [ ] 3.1 创建 `src/types/api/iotCard.ts`
|
||||
- [ ] 3.2 定义流量使用响应类型 `GatewayFlowResponse`
|
||||
- [ ] 3.3 定义实名状态响应类型 `GatewayRealnameResponse`
|
||||
- [ ] 3.4 定义卡片状态响应类型 `GatewayStatusResponse`
|
||||
- [ ] 3.5 定义实名链接响应类型 `RealnameUrlResponse`
|
||||
- [ ] 3.6 定义启停操作请求类型 `StartStopCardRequest`
|
||||
|
||||
## 4. Type Definitions - Device
|
||||
|
||||
- [ ] 4.1 创建 `src/types/api/device.ts`
|
||||
- [ ] 4.2 定义限速参数类型 `SpeedLimitParams`
|
||||
- [ ] 4.3 定义换卡参数类型 `SwitchCardParams`
|
||||
- [ ] 4.4 定义WiFi参数类型 `WifiParams`
|
||||
- [ ] 4.5 定义操作响应类型 `DeviceOperationResponse`
|
||||
|
||||
## 5. UI - IoT Card Management Page
|
||||
|
||||
- [ ] 5.1 在表格操作列添加"查询流量"按钮
|
||||
- [ ] 5.2 在表格操作列添加"更多操作"下拉菜单
|
||||
- [ ] 5.3 创建"流量使用查询"对话框组件
|
||||
- [ ] 5.4 创建"实名状态查询"对话框组件
|
||||
- [ ] 5.5 创建"卡片状态查询"对话框组件
|
||||
- [ ] 5.6 创建"获取实名链接"对话框组件(显示二维码)
|
||||
- [ ] 5.7 实现"启用卡片"操作(带确认提示)
|
||||
- [ ] 5.8 实现"停用卡片"操作(带确认提示)
|
||||
|
||||
## 6. UI - Device Management Page
|
||||
|
||||
- [ ] 6.1 在表格操作列添加"重启设备"按钮
|
||||
- [ ] 6.2 在表格操作列添加"更多操作"下拉菜单
|
||||
- [ ] 6.3 实现"重启设备"操作(带确认提示)
|
||||
- [ ] 6.4 实现"重置设备"操作(带确认提示)
|
||||
- [ ] 6.5 创建"设置限速"对话框组件(包含上下行速率输入)
|
||||
- [ ] 6.6 创建"切换SIM卡"对话框组件(选择卡槽)
|
||||
- [ ] 6.7 创建"设置WiFi"对话框组件(SSID、密码、频段等)
|
||||
|
||||
## 7. Error Handling & User Feedback
|
||||
|
||||
- [ ] 7.1 为所有API调用添加错误处理
|
||||
- [ ] 7.2 添加操作成功提示消息
|
||||
- [ ] 7.3 添加操作失败错误提示
|
||||
- [ ] 7.4 添加加载状态指示器
|
||||
|
||||
## 8. Permission Control
|
||||
|
||||
- [ ] 8.1 检查IoT卡操作权限配置
|
||||
- [ ] 8.2 检查设备操作权限配置
|
||||
- [ ] 8.3 根据权限显示/隐藏操作按钮
|
||||
|
||||
## 9. Testing & Validation
|
||||
|
||||
- [ ] 9.1 测试所有IoT卡操作API调用
|
||||
- [ ] 9.2 测试所有设备操作API调用
|
||||
- [ ] 9.3 测试UI交互和对话框显示
|
||||
- [ ] 9.4 测试错误处理场景
|
||||
- [ ] 9.5 测试权限控制
|
||||
- [ ] 9.6 验证响应数据格式和显示
|
||||
|
||||
## 10. Documentation
|
||||
|
||||
- [ ] 10.1 更新API文档(如有需要)
|
||||
- [ ] 10.2 添加操作说明注释
|
||||
- [ ] 10.3 更新用户手册(如有需要)
|
||||
22
openspec/changes/add-shop-default-roles/proposal.md
Normal file
22
openspec/changes/add-shop-default-roles/proposal.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Change: Add Shop Default Roles Management
|
||||
|
||||
## Why
|
||||
|
||||
店铺管理模块需要支持为每个店铺配置默认角色的功能。当新账号加入店铺时,系统需要自动分配这些默认角色,以简化账号管理流程并确保权限一致性。
|
||||
|
||||
## What Changes
|
||||
|
||||
- 新增查询店铺默认角色列表的接口和UI
|
||||
- 新增为店铺分配默认角色的接口和UI
|
||||
- 新增删除店铺默认角色的接口和UI
|
||||
- 在店铺管理列表页(`/shop-management/list`)添加"设置默认角色"操作入口
|
||||
- 添加店铺默认角色管理对话框组件
|
||||
|
||||
## Impact
|
||||
|
||||
- 影响的规范: shop-management (新增)
|
||||
- 影响的代码:
|
||||
- `src/api/modules/shop.ts` - 新增3个API方法
|
||||
- `src/types/api/shop.ts` - 新增类型定义
|
||||
- `src/views/shop-management/list/index.vue` - 添加默认角色管理UI (假设该页面存在,如不存在需创建)
|
||||
- 依赖的现有功能: 角色管理系统
|
||||
@@ -0,0 +1,172 @@
|
||||
# Shop Management - Specification Delta
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Query Shop Default Roles
|
||||
|
||||
系统SHALL支持查询指定店铺的默认角色列表。
|
||||
|
||||
**API端点**: `GET /api/admin/shops/{shop_id}/roles`
|
||||
|
||||
**路径参数**:
|
||||
- `shop_id` (integer, required): 店铺ID
|
||||
|
||||
**响应数据**:
|
||||
```typescript
|
||||
{
|
||||
shop_id: number // 店铺ID
|
||||
roles: ShopRole[] | null // 角色列表
|
||||
}
|
||||
|
||||
interface ShopRole {
|
||||
role_id: number // 角色ID
|
||||
role_name: string // 角色名称
|
||||
role_desc: string // 角色描述
|
||||
shop_id: number // 店铺ID
|
||||
status: number // 状态 (0:禁用, 1:启用)
|
||||
}
|
||||
```
|
||||
|
||||
#### Scenario: 成功查询店铺默认角色
|
||||
|
||||
- **WHEN** 用户请求获取店铺ID为123的默认角色列表
|
||||
- **THEN** 系统返回该店铺配置的所有默认角色
|
||||
- **AND** 响应包含角色ID、名称、描述、状态等完整信息
|
||||
|
||||
#### Scenario: 查询不存在的店铺
|
||||
|
||||
- **WHEN** 用户请求获取不存在的店铺的默认角色
|
||||
- **THEN** 系统返回400错误
|
||||
- **AND** 错误消息说明店铺不存在
|
||||
|
||||
#### Scenario: 店铺没有配置默认角色
|
||||
|
||||
- **WHEN** 用户请求获取未配置默认角色的店铺
|
||||
- **THEN** 系统返回成功响应
|
||||
- **AND** `roles` 字段为空数组或null
|
||||
|
||||
---
|
||||
|
||||
### Requirement: Assign Shop Default Roles
|
||||
|
||||
系统SHALL支持为指定店铺分配一个或多个默认角色。
|
||||
|
||||
**API端点**: `POST /api/admin/shops/{shop_id}/roles`
|
||||
|
||||
**路径参数**:
|
||||
- `shop_id` (integer, required): 店铺ID
|
||||
|
||||
**请求体**:
|
||||
```typescript
|
||||
{
|
||||
role_ids: number[] | null // 角色ID列表
|
||||
}
|
||||
```
|
||||
|
||||
**响应数据**: 与"Query Shop Default Roles"相同的数据结构
|
||||
|
||||
#### Scenario: 成功分配单个默认角色
|
||||
|
||||
- **WHEN** 用户为店铺分配一个新的默认角色
|
||||
- **THEN** 系统成功保存该角色配置
|
||||
- **AND** 返回更新后的店铺默认角色列表
|
||||
- **AND** 新分配的角色出现在列表中
|
||||
|
||||
#### Scenario: 成功分配多个默认角色
|
||||
|
||||
- **WHEN** 用户为店铺分配多个默认角色
|
||||
- **THEN** 系统批量保存所有角色配置
|
||||
- **AND** 返回完整的默认角色列表
|
||||
- **AND** 所有新分配的角色都出现在列表中
|
||||
|
||||
#### Scenario: 分配已存在的角色
|
||||
|
||||
- **WHEN** 用户尝试分配店铺已配置的默认角色
|
||||
- **THEN** 系统应当优雅处理(不重复添加或返回明确提示)
|
||||
- **AND** 不影响其他正常角色的分配
|
||||
|
||||
#### Scenario: 分配不存在的角色
|
||||
|
||||
- **WHEN** 用户尝试分配不存在的角色ID
|
||||
- **THEN** 系统返回400错误
|
||||
- **AND** 错误消息说明哪些角色ID无效
|
||||
|
||||
#### Scenario: 空角色列表
|
||||
|
||||
- **WHEN** 用户提交空的角色ID列表
|
||||
- **THEN** 系统接受请求
|
||||
- **AND** 可能清空当前默认角色或保持不变(取决于业务需求)
|
||||
|
||||
---
|
||||
|
||||
### Requirement: Delete Shop Default Role
|
||||
|
||||
系统SHALL支持删除指定店铺的某个默认角色配置。
|
||||
|
||||
**API端点**: `DELETE /api/admin/shops/{shop_id}/roles/{role_id}`
|
||||
|
||||
**路径参数**:
|
||||
- `shop_id` (integer, required): 店铺ID
|
||||
- `role_id` (integer, required): 角色ID
|
||||
|
||||
**响应**: 标准成功/错误响应
|
||||
|
||||
#### Scenario: 成功删除默认角色
|
||||
|
||||
- **WHEN** 用户删除店铺的一个默认角色配置
|
||||
- **THEN** 系统成功移除该角色配置
|
||||
- **AND** 返回成功响应(code: 0)
|
||||
- **AND** 后续查询该店铺默认角色列表时不再包含该角色
|
||||
|
||||
#### Scenario: 删除不存在的角色配置
|
||||
|
||||
- **WHEN** 用户尝试删除店铺未配置的角色
|
||||
- **THEN** 系统返回400错误
|
||||
- **AND** 错误消息说明该角色不在店铺的默认角色列表中
|
||||
|
||||
#### Scenario: 删除不存在的店铺或角色
|
||||
|
||||
- **WHEN** 用户使用无效的shop_id或role_id
|
||||
- **THEN** 系统返回400错误
|
||||
- **AND** 错误消息说明参数无效
|
||||
|
||||
---
|
||||
|
||||
### Requirement: Shop Default Roles UI
|
||||
|
||||
店铺管理页面SHALL提供默认角色管理的用户界面。
|
||||
|
||||
#### Scenario: 在店铺列表中访问默认角色设置
|
||||
|
||||
- **WHEN** 用户在店铺管理列表页查看店铺列表
|
||||
- **THEN** 每个店铺的操作列应当包含"设置默认角色"按钮或菜单项
|
||||
- **AND** 点击后打开默认角色管理对话框
|
||||
|
||||
#### Scenario: 查看店铺当前默认角色
|
||||
|
||||
- **WHEN** 用户打开某店铺的默认角色管理对话框
|
||||
- **THEN** 对话框显示该店铺当前已配置的所有默认角色
|
||||
- **AND** 每个角色显示名称、描述和状态
|
||||
- **AND** 提供删除按钮用于移除默认角色
|
||||
|
||||
#### Scenario: 添加默认角色
|
||||
|
||||
- **WHEN** 用户在对话框中选择要添加的角色
|
||||
- **THEN** 系统提供角色选择器,展示可用的系统角色列表
|
||||
- **AND** 支持多选
|
||||
- **AND** 点击确认后调用分配接口
|
||||
- **AND** 成功后刷新默认角色列表
|
||||
|
||||
#### Scenario: 删除默认角色
|
||||
|
||||
- **WHEN** 用户点击某个默认角色的删除按钮
|
||||
- **THEN** 系统显示确认对话框
|
||||
- **AND** 用户确认后调用删除接口
|
||||
- **AND** 成功后从列表中移除该角色
|
||||
|
||||
#### Scenario: 加载状态和错误处理
|
||||
|
||||
- **WHEN** 进行任何API操作时
|
||||
- **THEN** 界面应当显示加载状态(loading indicator)
|
||||
- **AND** 如果操作失败,应当显示友好的错误消息
|
||||
- **AND** 允许用户重试或关闭对话框
|
||||
62
openspec/changes/add-shop-default-roles/tasks.md
Normal file
62
openspec/changes/add-shop-default-roles/tasks.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# Implementation Tasks
|
||||
|
||||
## 1. 类型定义
|
||||
|
||||
- [x] 1.1 在 `src/types/api/shop.ts` 中添加 `ShopRoleResponse` 接口
|
||||
- [x] 1.2 在 `src/types/api/shop.ts` 中添加 `ShopRolesResponse` 接口
|
||||
- [x] 1.3 在 `src/types/api/shop.ts` 中添加 `AssignShopRolesRequest` 接口
|
||||
|
||||
## 2. API 服务层
|
||||
|
||||
- [x] 2.1 在 `ShopService` 中添加 `getShopRoles(shopId)` 方法
|
||||
- [x] 2.2 在 `ShopService` 中添加 `assignShopRoles(shopId, roleIds)` 方法
|
||||
- [x] 2.3 在 `ShopService` 中添加 `deleteShopRole(shopId, roleId)` 方法
|
||||
|
||||
## 3. UI 组件开发
|
||||
|
||||
- [x] 3.1 检查店铺管理列表页面 (`src/views/product/shop/index.vue` 已存在)
|
||||
- [x] 3.2 在店铺列表操作列中添加"默认角色"按钮
|
||||
- [x] 3.3 创建店铺默认角色管理对话框组件
|
||||
- [x] 3.4 实现查询店铺默认角色列表功能
|
||||
- [x] 3.5 实现添加默认角色功能(支持多选角色)
|
||||
- [x] 3.6 实现删除默认角色功能
|
||||
- [x] 3.7 添加角色选择器(从系统角色列表中选择)
|
||||
- [x] 3.8 添加加载状态和错误处理
|
||||
|
||||
## 4. 验证和测试
|
||||
|
||||
- [ ] 4.1 测试查询店铺默认角色列表
|
||||
- [ ] 4.2 测试添加默认角色(单个和多个)
|
||||
- [ ] 4.3 测试删除默认角色
|
||||
- [ ] 4.4 测试边界情况(角色已存在、店铺不存在等)
|
||||
- [ ] 4.5 测试权限控制(只有有权限的用户才能操作)
|
||||
|
||||
## 实现说明
|
||||
|
||||
### 完成的功能
|
||||
|
||||
1. **类型定义** - 已在 `src/types/api/shop.ts` 添加了三个接口:
|
||||
- `ShopRoleResponse`: 店铺角色响应实体
|
||||
- `ShopRolesResponse`: 店铺角色列表响应
|
||||
- `AssignShopRolesRequest`: 分配角色请求
|
||||
|
||||
2. **API 服务层** - 已在 `src/api/modules/shop.ts` 的 `ShopService` 类中添加:
|
||||
- `getShopRoles(shopId)`: 获取店铺默认角色列表
|
||||
- `assignShopRoles(shopId, data)`: 分配店铺默认角色
|
||||
- `deleteShopRole(shopId, roleId)`: 删除店铺默认角色
|
||||
|
||||
3. **UI 实现** - 已在 `src/views/product/shop/index.vue` 中实现:
|
||||
- 操作列新增"默认角色"按钮 (宽度从220改为280)
|
||||
- 默认角色管理对话框,显示当前默认角色列表,支持删除操作
|
||||
- 添加角色对话框,支持多选角色,已分配的角色显示为禁用状态
|
||||
- 完整的加载状态(loading indicators)
|
||||
- 错误处理和友好的提示消息
|
||||
- 使用 `ShopService` 和 `RoleService` 调用后端API
|
||||
|
||||
### 待测试项
|
||||
|
||||
所有开发任务已完成,现在需要进行功能测试以确保:
|
||||
- API 调用正常工作
|
||||
- UI 交互符合预期
|
||||
- 边界情况处理正确
|
||||
- 权限控制生效
|
||||
Reference in New Issue
Block a user