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
3dc7d200
authored
Jan 09, 2025
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【代码评审】IoT:设备日志 TDengine 表与模拟设备
parent
f2f414a9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
23 deletions
+39
-23
src/api/iot/device/device/index.ts
+9
-9
src/api/iot/thingmodel/index.ts
+2
-1
src/views/iot/device/device/detail/DeviceDetailsLog.vue
+7
-5
src/views/iot/device/device/detail/DeviceDetailsSimulator.vue
+12
-5
src/views/iot/device/device/detail/index.vue
+9
-3
No files found.
src/api/iot/device/device/index.ts
View file @
3dc7d200
...
@@ -58,19 +58,20 @@ export interface DeviceHistoryDataVO {
...
@@ -58,19 +58,20 @@ export interface DeviceHistoryDataVO {
// IoT 设备状态枚举
// IoT 设备状态枚举
export
enum
DeviceStatusEnum
{
export
enum
DeviceStatusEnum
{
INACTIVE
=
0
,
// 未激活
INACTIVE
=
0
,
// 未激活
ONLINE
=
1
,
// 在线
ONLINE
=
1
,
// 在线
OFFLINE
=
2
,
// 离线
OFFLINE
=
2
,
// 离线
DISABLED
=
3
// 已禁用
DISABLED
=
3
// 已禁用
}
}
// IoT 模拟设备数据
// IoT 模拟设备数据
// TODO @super:DeviceSimulatorDataReqVO
export
interface
SimulatorDataVO
{
export
interface
SimulatorDataVO
{
productKey
:
string
productKey
:
string
deviceKey
:
string
deviceKey
:
string
type
:
string
type
:
string
subType
:
string
subType
:
string
reportTime
:
number
// 时间戳
reportTime
:
number
// 时间戳
content
:
string
// 存储 JSON 字符串
content
:
string
// 存储 JSON 字符串
}
}
// 设备 API
// 设备 API
...
@@ -101,10 +102,7 @@ export const DeviceApi = {
...
@@ -101,10 +102,7 @@ export const DeviceApi = {
},
},
// 修改设备分组
// 修改设备分组
updateDeviceGroup
:
async
(
data
:
{
updateDeviceGroup
:
async
(
data
:
{
ids
:
number
[];
groupIds
:
number
[]
})
=>
{
ids
:
number
[]
groupIds
:
number
[]
})
=>
{
return
await
request
.
put
({
url
:
`/iot/device/update-group`
,
data
})
return
await
request
.
put
({
url
:
`/iot/device/update-group`
,
data
})
},
},
...
@@ -150,10 +148,12 @@ export const DeviceApi = {
...
@@ -150,10 +148,12 @@ export const DeviceApi = {
// 模拟设备
// 模拟设备
simulatorDevice
:
async
(
data
:
SimulatorDataVO
)
=>
{
simulatorDevice
:
async
(
data
:
SimulatorDataVO
)
=>
{
// TODO @super:/iot/device/simulator
return
await
request
.
post
({
url
:
`/iot/device/data/simulator`
,
data
})
return
await
request
.
post
({
url
:
`/iot/device/data/simulator`
,
data
})
},
},
//查询设备日志分页
//
查询设备日志分页
getDeviceLogPage
:
async
(
params
:
any
)
=>
{
getDeviceLogPage
:
async
(
params
:
any
)
=>
{
// TODO @super:/iot/log-page 或者 /iot/log/page
return
await
request
.
get
({
url
:
`/iot/device/data/log/page`
,
params
})
return
await
request
.
get
({
url
:
`/iot/device/data/log/page`
,
params
})
}
}
}
}
src/api/iot/thingmodel/index.ts
View file @
3dc7d200
...
@@ -20,8 +20,9 @@ export interface ThingModelData {
...
@@ -20,8 +20,9 @@ export interface ThingModelData {
/**
/**
* IoT 模拟设备
* IoT 模拟设备
*/
*/
// TODO @super:和 ThingModelSimulatorData 会不会好点
export
interface
SimulatorData
extends
ThingModelData
{
export
interface
SimulatorData
extends
ThingModelData
{
simulateValue
?:
string
|
number
// 用于存储模拟值
simulateValue
?:
string
|
number
// 用于存储模拟值
TODO @super:字段使用 value 会不会好点
}
}
/**
/**
...
...
src/views/iot/device/device/detail/DeviceDetailsLog.vue
View file @
3dc7d200
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
<el-form-item>
<el-form-item>
<el-select
v-model=
"queryParams.type"
placeholder=
"所有"
class=
"!w-120px"
>
<el-select
v-model=
"queryParams.type"
placeholder=
"所有"
class=
"!w-120px"
>
<el-option
label=
"所有"
value=
""
/>
<el-option
label=
"所有"
value=
""
/>
<!-- TODO @super:搞成枚举 -->
<el-option
label=
"状态"
value=
"state"
/>
<el-option
label=
"状态"
value=
"state"
/>
<el-option
label=
"事件"
value=
"event"
/>
<el-option
label=
"事件"
value=
"event"
/>
<el-option
label=
"属性"
value=
"property"
/>
<el-option
label=
"属性"
value=
"property"
/>
...
@@ -48,7 +49,6 @@
...
@@ -48,7 +49,6 @@
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
DeviceApi
}
from
'@/api/iot/device/device'
import
{
DeviceApi
}
from
'@/api/iot/device/device'
import
{
DICT_TYPE
}
from
'@/utils/dict'
import
{
formatDate
}
from
'@/utils/formatTime'
import
{
formatDate
}
from
'@/utils/formatTime'
const
props
=
defineProps
<
{
const
props
=
defineProps
<
{
...
@@ -56,7 +56,7 @@ const props = defineProps<{
...
@@ -56,7 +56,7 @@ const props = defineProps<{
}
>
()
}
>
()
//TODO:后续看看使用什么查询条件 目前后端是留了时间范围 type subType
//TODO:后续看看使用什么查询条件 目前后端是留了时间范围 type subType
// 查询参数
// 查询参数
const
queryParams
=
reactive
({
const
queryParams
=
reactive
({
deviceKey
:
props
.
deviceKey
,
deviceKey
:
props
.
deviceKey
,
// type: '',
// type: '',
...
@@ -68,11 +68,12 @@ const queryParams = reactive({
...
@@ -68,11 +68,12 @@ const queryParams = reactive({
// 列表数据
// 列表数据
const
loading
=
ref
(
false
)
const
loading
=
ref
(
false
)
const
total
=
ref
(
0
)
const
total
=
ref
(
0
)
// TODO @super:字段的风格,还是类似一般 table 见面哈
const
logList
=
ref
([])
const
logList
=
ref
([])
const
autoRefresh
=
ref
(
false
)
const
autoRefresh
=
ref
(
false
)
let
timer
:
any
=
null
let
timer
:
any
=
null
// TODO @super:autoRefreshEnable,autoRefreshTimer;对应上
// 类型映射
// 类型映射
TODO @super:需要删除么?
const
typeMap
=
{
const
typeMap
=
{
lifetime
:
'生命周期'
,
lifetime
:
'生命周期'
,
state
:
'设备状态'
,
state
:
'设备状态'
,
...
@@ -88,6 +89,7 @@ const getLogList = async () => {
...
@@ -88,6 +89,7 @@ const getLogList = async () => {
try
{
try
{
const
res
=
await
DeviceApi
.
getDeviceLogPage
(
queryParams
)
const
res
=
await
DeviceApi
.
getDeviceLogPage
(
queryParams
)
total
.
value
=
res
.
total
total
.
value
=
res
.
total
// TODO @super:尽量不转换
logList
.
value
=
res
.
list
.
map
((
item
:
any
)
=>
{
logList
.
value
=
res
.
list
.
map
((
item
:
any
)
=>
{
const
log
=
{
const
log
=
{
time
:
item
.
reportTime
,
time
:
item
.
reportTime
,
...
@@ -138,7 +140,7 @@ watch(autoRefresh, (newValue) => {
...
@@ -138,7 +140,7 @@ watch(autoRefresh, (newValue) => {
}
}
})
})
/** 监听设备
ID
变化 */
/** 监听设备
ID
变化 */
watch
(
watch
(
()
=>
props
.
deviceKey
,
()
=>
props
.
deviceKey
,
(
newValue
)
=>
{
(
newValue
)
=>
{
...
...
src/views/iot/device/device/detail/DeviceDetailsSimulator.vue
View file @
3dc7d200
<
template
>
<
template
>
<ContentWrap>
<ContentWrap>
<!-- TODO @super:建议每个 tab 做成一个小的组件。命名为了排版整齐点,可以叫 DeviceDetailsSimulatorPropertyUpstream、DeviceDetailsSimulatorEventUpstream -->
<el-row
:gutter=
"20"
>
<el-row
:gutter=
"20"
>
<!-- 左侧指令调试区域 -->
<!-- 左侧指令调试区域 -->
<el-col
:span=
"12"
>
<el-col
:span=
"12"
>
...
@@ -10,7 +11,12 @@
...
@@ -10,7 +11,12 @@
<!-- 属性上报 -->
<!-- 属性上报 -->
<el-tab-pane
label=
"属性上报"
name=
"property"
>
<el-tab-pane
label=
"属性上报"
name=
"property"
>
<ContentWrap>
<ContentWrap>
<el-table
v-loading=
"loading"
:data=
"list"
:show-overflow-tooltip=
"true"
:stripe=
"true"
>
<el-table
v-loading=
"loading"
:data=
"list"
:show-overflow-tooltip=
"true"
:stripe=
"true"
>
<el-table-column
align=
"center"
label=
"功能名称"
prop=
"name"
/>
<el-table-column
align=
"center"
label=
"功能名称"
prop=
"name"
/>
<el-table-column
align=
"center"
label=
"标识符"
prop=
"identifier"
/>
<el-table-column
align=
"center"
label=
"标识符"
prop=
"identifier"
/>
<el-table-column
align=
"center"
label=
"数据类型"
prop=
"identifier"
>
<el-table-column
align=
"center"
label=
"数据类型"
prop=
"identifier"
>
...
@@ -188,8 +194,8 @@
...
@@ -188,8 +194,8 @@
<
script
setup
lang
=
"ts"
>
<
script
setup
lang
=
"ts"
>
import
{
ProductVO
}
from
'@/api/iot/product/product'
import
{
ProductVO
}
from
'@/api/iot/product/product'
import
{
ThingModelApi
,
ThingModelData
,
SimulatorData
}
from
'@/api/iot/thingmodel'
import
{
ThingModelApi
,
SimulatorData
}
from
'@/api/iot/thingmodel'
import
{
DeviceApi
,
DeviceVO
,
SimulatorDataVO
}
from
'@/api/iot/device/device'
import
{
DeviceApi
,
DeviceVO
,
SimulatorDataVO
}
from
'@/api/iot/device/device'
import
DeviceDetailsLog
from
'./DeviceDetailsLog.vue'
import
DeviceDetailsLog
from
'./DeviceDetailsLog.vue'
import
{
import
{
DataSpecsDataType
,
DataSpecsDataType
,
...
@@ -219,7 +225,7 @@ const getList = async () => {
...
@@ -219,7 +225,7 @@ const getList = async () => {
queryParams
.
productId
=
props
.
product
?.
id
||
-
1
queryParams
.
productId
=
props
.
product
?.
id
||
-
1
const
data
=
await
ThingModelApi
.
getThingModelList
(
queryParams
)
const
data
=
await
ThingModelApi
.
getThingModelList
(
queryParams
)
// 转换数据,添加 simulateValue 字段
// 转换数据,添加 simulateValue 字段
list
.
value
=
data
.
map
(
item
=>
({
list
.
value
=
data
.
map
(
(
item
)
=>
({
...
item
,
...
item
,
simulateValue
:
''
simulateValue
:
''
}
))
}
))
...
@@ -313,7 +319,7 @@ const handlePropertyReport = async () => {
...
@@ -313,7 +319,7 @@ const handlePropertyReport = async () => {
type
:
'property'
,
type
:
'property'
,
subType
:
'report'
,
subType
:
'report'
,
reportTime
:
Date
.
now
(),
// 将 reportTime 变为数字类型的时间戳
reportTime
:
Date
.
now
(),
// 将 reportTime 变为数字类型的时间戳
content
:
JSON
.
stringify
(
contentObj
)
// 转换为 JSON 字符串
content
:
JSON
.
stringify
(
contentObj
)
// 转换为 JSON 字符串
}
}
try
{
try
{
...
@@ -384,4 +390,5 @@ const handlePropertyGet = async () => {
...
@@ -384,4 +390,5 @@ const handlePropertyGet = async () => {
onMounted(() => {
onMounted(() => {
getList()
getList()
}
)
}
)
// TODO @芋艿:后续再详细 review 下;
</script>
</script>
src/views/iot/device/device/detail/index.vue
View file @
3dc7d200
...
@@ -17,11 +17,16 @@
...
@@ -17,11 +17,16 @@
<el-tab-pane
label=
"子设备管理"
v-if=
"product.deviceType === DeviceTypeEnum.GATEWAY"
/>
<el-tab-pane
label=
"子设备管理"
v-if=
"product.deviceType === DeviceTypeEnum.GATEWAY"
/>
<el-tab-pane
label=
"设备影子"
/>
<el-tab-pane
label=
"设备影子"
/>
<el-tab-pane
label=
"设备日志"
name=
"log"
>
<el-tab-pane
label=
"设备日志"
name=
"log"
>
<DeviceDetailsLog
v-if=
"activeTab === 'log'"
:deviceKey=
"device.deviceKey"
/>
<!-- TODO @super:字段类型,:device-key。idea 会告警,应该是 string -->
<DeviceDetailsLog
v-if=
"activeTab === 'log'"
:device-key=
"device.deviceKey"
/>
</el-tab-pane>
</el-tab-pane>
<el-tab-pane
label=
"模拟设备"
name=
"simulator"
>
<el-tab-pane
label=
"模拟设备"
name=
"simulator"
>
<DeviceDetailsSimulator
v-if=
"activeTab === 'simulator'"
:product=
"product"
:device=
"device"
/>
<DeviceDetailsSimulator
</el-tab-pane>
v-if=
"activeTab === 'simulator'"
:product=
"product"
:device=
"device"
/>
</el-tab-pane>
</el-tabs>
</el-tabs>
</el-col>
</el-col>
</
template
>
</
template
>
...
@@ -34,6 +39,7 @@ import DeviceDetailsInfo from './DeviceDetailsInfo.vue'
...
@@ -34,6 +39,7 @@ import DeviceDetailsInfo from './DeviceDetailsInfo.vue'
import
DeviceDetailsModel
from
'./DeviceDetailsModel.vue'
import
DeviceDetailsModel
from
'./DeviceDetailsModel.vue'
import
DeviceDetailsLog
from
'./DeviceDetailsLog.vue'
import
DeviceDetailsLog
from
'./DeviceDetailsLog.vue'
import
DeviceDetailsSimulator
from
'./DeviceDetailsSimulator.vue'
import
DeviceDetailsSimulator
from
'./DeviceDetailsSimulator.vue'
defineOptions
({
name
:
'IoTDeviceDetail'
})
defineOptions
({
name
:
'IoTDeviceDetail'
})
const
route
=
useRoute
()
const
route
=
useRoute
()
...
...
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