mirror of
https://gitee.com/myxzgzs/boyue-ui-admin-vue3
synced 2025-08-09 00:42:42 +08:00
【代码评审】IoT:设备日志 TDengine 表与模拟设备
This commit is contained in:
parent
f2f414a965
commit
3dc7d20005
@ -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 = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 修改设备分组
|
// 修改设备分组
|
||||||
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 = {
|
|||||||
|
|
||||||
// 模拟设备
|
// 模拟设备
|
||||||
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 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 会不会好点
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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 @@
|
|||||||
|
|
||||||
<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<{
|
||||||
@ -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 () => {
|
|||||||
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) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/** 监听设备ID变化 */
|
/** 监听设备 ID 变化 */
|
||||||
watch(
|
watch(
|
||||||
() => props.deviceKey,
|
() => props.deviceKey,
|
||||||
(newValue) => {
|
(newValue) => {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<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 @@
|
|||||||
<!-- 属性上报 -->
|
<!-- 属性上报 -->
|
||||||
<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 @@
|
|||||||
|
|
||||||
<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 () => {
|
|||||||
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 () => {
|
|||||||
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 () => {
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getList()
|
getList()
|
||||||
})
|
})
|
||||||
|
// TODO @芋艿:后续再详细 review 下;
|
||||||
</script>
|
</script>
|
||||||
|
@ -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'
|
|||||||
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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user