设备分组
获取设备分组列表,支持分页与关键词、状态、父分组等条件筛选。
| 项目 | 内容 |
|---|---|
| 方法 | GET |
| URL | https://devapi.fengshengshou.com/api/admin/device-groups |
| 鉴权 | 是,请求头携带 Authorization: Bearer your_token_here |
以下参数均为查询参数(Query),全部可选。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| page | int | 否 | 页码,默认 1 |
| per_page | int | 否 | 每页条数,默认 15 |
| keyword | string | 否 | 按分组名称关键词搜索 |
| status | int | 否 | 分组状态筛选 |
| parent_id | int | 否 | 按父分组 ID 筛选 |
curl -X GET "https://devapi.fengshengshou.com/api/admin/device-groups?page=1&per_page=15" \ -H "Authorization: Bearer your_token_here" \ -H "Accept: application/json"| 字段 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码,0 表示成功 |
| message | string | 响应描述 |
| data.items | array | 分组对象数组 |
| data.items[].id | int | 分组 ID |
| data.items[].name | string | 分组名称 |
| data.items[].description | string | 分组描述 |
| data.items[].parent_id | int|null | 父分组 ID,顶级分组为 null |
| data.items[].sort_order | int | 排序权重 |
| data.items[].status | int | 分组状态 |
| data.pagination | object | 分页信息(含 current_page、per_page、total、total_pages) |
{ "code": 0, "message": "success", "data": { "items": [ { "id": 10, "name": "A区设备", "description": "A区所有巡检设备", "parent_id": null, "sort_order": 1, "status": 1 } ], "pagination": { "current_page": 1, "per_page": 15, "total": 8, "total_pages": 1 } }}{ "code": 401, "message": "未授权,请先登录", "data": null}获取设备分组的完整树形结构,适用于前端树形选择组件渲染。每个节点包含 children 子分组数组。
| 项目 | 内容 |
|---|---|
| 方法 | GET |
| URL | https://devapi.fengshengshou.com/api/admin/device-groups/tree |
| 鉴权 | 是,请求头携带 Authorization: Bearer your_token_here |
本接口无请求参数。
curl -X GET "https://devapi.fengshengshou.com/api/admin/device-groups/tree" \ -H "Authorization: Bearer your_token_here" \ -H "Accept: application/json"| 字段 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码,0 表示成功 |
| message | string | 响应描述 |
| data | array | 根节点数组,每个节点含 id、name、description、parent_id、sort_order、status、children |
| data[].children | array | 子分组数组,结构与父节点相同,递归嵌套 |
{ "code": 0, "message": "success", "data": [ { "id": 10, "name": "A区设备", "description": "A区所有巡检设备", "parent_id": null, "sort_order": 1, "status": 1, "children": [ { "id": 11, "name": "A区1号楼", "description": "", "parent_id": 10, "sort_order": 1, "status": 1, "children": [] } ] } ]}{ "code": 401, "message": "未授权,请先登录", "data": null}创建新的设备分组,可在创建时指定父分组并将设备加入该分组。
| 项目 | 内容 |
|---|---|
| 方法 | POST |
| URL | https://devapi.fengshengshou.com/api/admin/device-groups |
| 鉴权 | 是,请求头携带 Authorization: Bearer your_token_here |
请求体为 JSON 格式。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 是 | 分组名称,最长 100 个字符 |
| description | string | 否 | 分组描述,最长 500 个字符 |
| parent_id | int | 否 | 父分组 ID,不填则创建为顶级分组 |
| sort_order | int | 否 | 排序权重,数值越小越靠前 |
| device_ids | int[] | 否 | 创建时同时加入该分组的设备 ID 数组 |
curl -X POST "https://devapi.fengshengshou.com/api/admin/device-groups" \ -H "Authorization: Bearer your_token_here" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d '{ "name": "B区设备", "description": "B区所有设备", "parent_id": null, "sort_order": 2, "device_ids": [101, 102] }'| 字段 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码,0 表示成功 |
| message | string | 响应描述 |
| data.id | int | 新创建的分组 ID |
{ "code": 0, "message": "分组创建成功", "data": { "id": 20 }}{ "code": 422, "message": "name 字段不能为空", "data": null}添加设备到分组
Section titled “添加设备到分组”将一个或多个设备添加到指定分组中。
| 项目 | 内容 |
|---|---|
| 方法 | POST |
| URL | https://devapi.fengshengshou.com/api/admin/device-groups/{id}/devices |
| 鉴权 | 是,请求头携带 Authorization: Bearer your_token_here |
路径参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | int | 是 | 分组 ID |
请求体(JSON):
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| device_ids | int[] | 是 | 要添加到分组的设备 ID 数组 |
curl -X POST "https://devapi.fengshengshou.com/api/admin/device-groups/20/devices" \ -H "Authorization: Bearer your_token_here" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d '{ "device_ids": [103, 104, 105] }'| 字段 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码,0 表示成功 |
| message | string | 响应描述 |
| data | null | 本接口成功时 data 为 null |
{ "code": 0, "message": "设备添加成功", "data": null}{ "code": 404, "message": "分组不存在", "data": null}