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 更新用户手册(如有需要)
|
||||
Reference in New Issue
Block a user