Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
18617d30
authored
Jan 29, 2025
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【功能新增】IoT:支持 state 模拟上报(上线、下线)
parent
3c73a672
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
31 deletions
+24
-31
src/api/iot/device/device/index.ts
+3
-4
src/views/iot/device/device/detail/DeviceDetailsSimulator.vue
+17
-23
src/views/iot/device/device/index.vue
+4
-4
No files found.
src/api/iot/device/device/index.ts
View file @
18617d30
...
...
@@ -50,11 +50,10 @@ export interface DeviceHistoryDataVO {
}
// IoT 设备状态枚举
export
enum
DeviceStat
us
Enum
{
export
enum
DeviceStat
e
Enum
{
INACTIVE
=
0
,
// 未激活
ONLINE
=
1
,
// 在线
OFFLINE
=
2
,
// 离线
DISABLED
=
3
// 已禁用
OFFLINE
=
2
// 离线
}
// IoT 模拟设备上报数据 Request VO
...
...
@@ -62,7 +61,7 @@ export interface IotDeviceSimulationReportReqVO {
id
:
number
// 设备编号
type
:
string
// 消息类型
identifier
:
string
// 标识符
data
:
object
// 请求参数
data
:
any
// 请求参数
}
// 设备 API
...
...
src/views/iot/device/device/detail/DeviceDetailsSimulator.vue
View file @
18617d30
...
...
@@ -142,10 +142,10 @@
<
el
-
tab
-
pane
label
=
"状态变更"
name
=
"status"
>
<
ContentWrap
>
<
div
class
=
"flex gap-4"
>
<
el
-
button
type
=
"primary"
@
click
=
"handleDeviceState(
'online'
)"
>
<
el
-
button
type
=
"primary"
@
click
=
"handleDeviceState(
DeviceStateEnum.ONLINE
)"
>
设备上线
<
/el-button
>
<
el
-
button
type
=
"
primary"
@
click
=
"handleDeviceState('offline'
)"
>
<
el
-
button
type
=
"
danger"
@
click
=
"handleDeviceState(DeviceStateEnum.OFFLINE
)"
>
设备下线
<
/el-button
>
<
/div
>
...
...
@@ -210,7 +210,7 @@
<
script
setup
lang
=
"ts"
>
import
{
ProductVO
}
from
'@/api/iot/product/product'
import
{
ThingModelApi
,
SimulatorData
}
from
'@/api/iot/thingmodel'
import
{
DeviceApi
,
DeviceVO
}
from
'@/api/iot/device/device'
import
{
DeviceApi
,
Device
StateEnum
,
Device
VO
}
from
'@/api/iot/device/device'
import
DeviceDetailsLog
from
'./DeviceDetailsLog.vue'
import
{
DataSpecsDataType
,
...
...
@@ -372,26 +372,20 @@ const handlePropertyReport = async () => {
//
}
//
}
// // 处理设备状态变更
// const handleDeviceState = async (state: 'online' | 'offline') =>
{
// const reportData: ReportData =
{
// productKey: props.product.productKey,
// deviceKey: props.device.deviceKey,
// type: 'status',
// subType: state,
// reportTime: new Date().toISOString(),
// content: JSON.stringify(
{
status
:
state
}
)
// 转换为 JSON 字符串
//
}
// try
{
// // TODO: 调用API发送数据
// console.log('状态变更数据:', reportData)
// console.log('reportData.content111111111', reportData.content)
// message.success(`设备$
{
state
===
'online'
?
'上线'
:
'下线'
}成功
`)
//
}
catch (error) {
// message.error(`
设备
$
{
state
===
'online'
?
'上线'
:
'下线'
}失败
`)
//
}
//
}
/** 处理设备状态 */
const
handleDeviceState
=
async
(
state
:
number
)
=>
{
try
{
await
DeviceApi
.
simulationReportDevice
({
id
:
props
.
device
.
id
,
type
:
'state'
,
identifier
:
'report'
,
data
:
state
}
)
message
.
success
(
`设备${state === DeviceStateEnum.ONLINE ? '上线' : '下线'
}
成功`
)
}
catch
(
error
)
{
message
.
error
(
`设备${state === DeviceStateEnum.ONLINE ? '上线' : '下线'
}
失败`
)
}
}
// 处理属性获取
const
handlePropertyGet
=
async
()
=>
{
...
...
src/views/iot/device/device/index.vue
View file @
18617d30
...
...
@@ -161,7 +161,7 @@
<div
class=
"absolute top-0 left-0 right-0 h-[50px] pointer-events-none"
:class=
"[
item.state === DeviceStat
us
Enum.ONLINE
item.state === DeviceStat
e
Enum.ONLINE
? 'bg-gradient-to-b from-[#eefaff] to-transparent'
: 'bg-gradient-to-b from-[#fff1f1] to-transparent'
]"
...
...
@@ -179,7 +179,7 @@
<div
class=
"w-1 h-1 rounded-full mr-1.5"
:class=
"
item.state === DeviceStat
us
Enum.ONLINE
item.state === DeviceStat
e
Enum.ONLINE
? 'bg-[var(--el-color-success)]'
: 'bg-[var(--el-color-danger)]'
"
...
...
@@ -187,7 +187,7 @@
</div>
<el-text
class=
"!text-xs font-bold"
:type=
"item.state === DeviceStat
us
Enum.ONLINE ? 'success' : 'danger'"
:type=
"item.state === DeviceStat
e
Enum.ONLINE ? 'success' : 'danger'"
>
{{
getDictLabel
(
DICT_TYPE
.
IOT_DEVICE_STATE
,
item
.
state
)
}}
</el-text>
...
...
@@ -369,7 +369,7 @@
<
script
setup
lang=
"ts"
>
import
{
DICT_TYPE
,
getIntDictOptions
,
getDictLabel
}
from
'@/utils/dict'
import
{
dateFormatter
}
from
'@/utils/formatTime'
import
{
DeviceApi
,
DeviceVO
,
DeviceStat
us
Enum
}
from
'@/api/iot/device/device'
import
{
DeviceApi
,
DeviceVO
,
DeviceStat
e
Enum
}
from
'@/api/iot/device/device'
import
DeviceForm
from
'./DeviceForm.vue'
import
{
ProductApi
,
ProductVO
}
from
'@/api/iot/product/product'
import
{
DeviceGroupApi
,
DeviceGroupVO
}
from
'@/api/iot/device/group'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment