Commit 3dc7d200 by YunaiV

【代码评审】IoT:设备日志 TDengine 表与模拟设备

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