【代码评审】IoT:数据桥梁的接入

This commit is contained in:
YunaiV 2025-03-16 23:44:56 +08:00
parent 79507aef6d
commit c87ed7fe17
12 changed files with 52 additions and 39 deletions

View File

@ -11,27 +11,27 @@ export interface DeviceGroupVO {
// IoT 设备分组 API
export const DeviceGroupApi = {
// 查询IoT 设备分组分页
// 查询设备分组分页
getDeviceGroupPage: async (params: any) => {
return await request.get({ url: `/iot/device-group/page`, params })
},
// 查询IoT 设备分组详情
// 查询设备分组详情
getDeviceGroup: async (id: number) => {
return await request.get({ url: `/iot/device-group/get?id=` + id })
},
// 新增IoT 设备分组
// 新增设备分组
createDeviceGroup: async (data: DeviceGroupVO) => {
return await request.post({ url: `/iot/device-group/create`, data })
},
// 修改IoT 设备分组
// 修改设备分组
updateDeviceGroup: async (data: DeviceGroupVO) => {
return await request.put({ url: `/iot/device-group/update`, data })
},
// 删除IoT 设备分组
// 删除设备分组
deleteDeviceGroup: async (id: number) => {
return await request.delete({ url: `/iot/device-group/delete?id=` + id })
},

View File

@ -1,6 +1,6 @@
import request from '@/config/axios'
/** 统计数据类型 */
/** IoT 统计数据类型 */
export interface IotStatisticsSummaryRespVO {
productCategoryCount: number
productCount: number
@ -16,7 +16,7 @@ export interface IotStatisticsSummaryRespVO {
productCategoryDeviceCounts: Record<string, number>
}
/** 消息统计数据类型 */
/** IoT 消息统计数据类型 */
export interface IotStatisticsDeviceMessageSummaryRespVO {
upstreamCounts: Record<number, number>
downstreamCounts: Record<number, number>
@ -24,21 +24,18 @@ export interface IotStatisticsDeviceMessageSummaryRespVO {
// IoT 数据统计 API
export const ProductCategoryApi = {
// 查询IoT基础数据统计
// 查询基础数据统计
getIotStatisticsSummary: async () => {
return await request.get<IotStatisticsSummaryRespVO>({
return await request.get<IotStatisticsSummaryRespVO>({
url: `/iot/statistics/get-summary`
})
},
// 查询IoT上下行消息数据统计
getIotStatisticsDeviceMessageSummary: async (params: {
startTime: number
endTime: number
}) => {
return await request.get<IotStatisticsDeviceMessageSummaryRespVO>({
url: `/iot/statistics/get-log-summary`,
params
// 查询设备上下行消息的数据统计
getIotStatisticsDeviceMessageSummary: async (params: { startTime: number; endTime: number }) => {
return await request.get<IotStatisticsDeviceMessageSummaryRespVO>({
url: `/iot/statistics/get-log-summary`,
params
})
}
}
}

View File

@ -43,7 +43,11 @@
:disabled="formType === 'update'"
/>
</el-form-item>
<el-form-item v-if="formData.deviceType === 1" label="网关设备" prop="gatewayId">
<el-form-item
v-if="formData.deviceType === DeviceTypeEnum.GATEWAY_SUB"
label="网关设备"
prop="gatewayId"
>
<el-select v-model="formData.gatewayId" placeholder="子设备可选择父设备" clearable>
<el-option
v-for="gateway in gatewayDevices"

View File

@ -59,7 +59,7 @@ import { beginOfDay, dateFormatter, endOfDay, formatDate } from '@/utils/formatT
defineProps<{ product: ProductVO; device: DeviceVO }>()
/** IoT 设备 数据详情 */
/** IoT 设备数据详情 */
defineOptions({ name: 'IoTDeviceDataDetail' })
const dialogVisible = ref(false) //
@ -78,9 +78,9 @@ const queryParams = reactive({
formatDate(endOfDay(new Date()))
]
})
const queryFormRef = ref() //
/** 获得设备历史数据 */
const getList = async () => {
detailLoading.value = true
try {

View File

@ -30,9 +30,9 @@
/>
<div class="mt-5 text-center">
<el-button v-if="isEditing" @click="cancelEdit">取消</el-button>
<el-button v-if="isEditing" type="primary" @click="saveConfig" :disabled="hasJsonError"
>保存</el-button
>
<el-button v-if="isEditing" type="primary" @click="saveConfig" :disabled="hasJsonError">
保存
</el-button>
<el-button v-else @click="enableEdit">编辑</el-button>
<!-- TODO @芋艿缺一个下发按钮 -->
</div>

View File

@ -120,18 +120,19 @@ const copyToClipboard = async (text: string) => {
/** 打开 MQTT 参数弹框的方法 */
const openMqttParams = async () => {
try {
const res = await DeviceApi.getMqttConnectionParams(device.id)
const data = await DeviceApi.getMqttConnectionParams(device.id)
// API
// TODO @haohao'N/A' ui
mqttParams.value = {
mqttClientId: res.mqttClientId || 'N/A',
mqttUsername: res.mqttUsername || 'N/A',
mqttPassword: res.mqttPassword || 'N/A'
mqttClientId: data.mqttClientId || 'N/A',
mqttUsername: data.mqttUsername || 'N/A',
mqttPassword: data.mqttPassword || 'N/A'
}
// MQTT
mqttDialogVisible.value = true
} catch (error) {
console.error('获取MQTT连接参数出错', error)
console.error('获取 MQTT 连接参数出错:', error)
message.error('获取MQTT连接参数失败请检查网络连接或联系管理员')
}
}

View File

@ -51,7 +51,7 @@ defineOptions({ name: 'IoTDeviceDetail' })
const route = useRoute()
const message = useMessage()
const id = Number(route.params.id) //
const id = route.params.id //
const loading = ref(true) //
const product = ref<ProductVO>({} as ProductVO) //
const device = ref<DeviceVO>({} as DeviceVO) //

View File

@ -45,7 +45,7 @@
</el-radio-group>
</el-form-item>
<el-form-item
v-if="formData.deviceType === 0 || formData.deviceType === 2"
v-if="[DeviceTypeEnum.DEVICE, DeviceTypeEnum.GATEWAY].includes(formData.deviceType)"
label="联网方式"
prop="netType"
>
@ -62,7 +62,11 @@
/>
</el-select>
</el-form-item>
<el-form-item v-if="formData.deviceType === 1" label="接入网关协议" prop="protocolType">
<el-form-item
v-if="formData.deviceType === DeviceTypeEnum.GATEWAY_SUB"
label="接入网关协议"
prop="protocolType"
>
<el-select
v-model="formData.protocolType"
placeholder="请选择接入网关协议"
@ -120,7 +124,13 @@
</template>
<script setup lang="ts">
import { ValidateTypeEnum, ProductApi, ProductVO, DataFormatEnum } from '@/api/iot/product/product'
import {
ValidateTypeEnum,
ProductApi,
ProductVO,
DataFormatEnum,
DeviceTypeEnum
} from '@/api/iot/product/product'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { ProductCategoryApi, ProductCategoryVO } from '@/api/iot/product/category'
import { UploadImg } from '@/components/UploadFile'

View File

@ -34,7 +34,7 @@ const { currentRoute } = useRouter()
const route = useRoute()
const message = useMessage()
const id = Number(route.params.id) //
const id = route.params.id //
const loading = ref(true) //
const product = ref<ProductVO>({} as ProductVO) //
const activeTab = ref('info') // info

View File

@ -83,7 +83,7 @@ import {
RocketMQConfigForm
} from './config'
/** IoT 数据桥梁 表单 */
/** IoT 数据桥梁表单 */
defineOptions({ name: 'IoTDataBridgeForm' })
const { t } = useI18n() //
@ -95,8 +95,8 @@ const formLoading = ref(false) // 表单的加载中1修改时的数据加
const formType = ref('') // create - update -
const formData = ref<DataBridgeVO>({
status: 0,
direction: 1,
type: 1,
direction: 1, // TODO @puhui999:
type: 1, // TODO @puhui999:
config: {} as any
})
const formRules = reactive({

View File

@ -49,7 +49,7 @@ const fullUrl = computed(() => {
return urlPath.value ? urlPrefix.value + urlPath.value : ''
})
/** 监听URL变化 */
/** 监听 URL 变化 */
watch([urlPrefix, urlPath], () => {
config.value.url = fullUrl.value
})
@ -57,7 +57,7 @@ watch([urlPrefix, urlPath], () => {
/** 组件初始化 */
onMounted(() => {
if (!isEmpty(config.value)) {
// URL
// URL
if (config.value.url) {
if (config.value.url.startsWith('https://')) {
urlPrefix.value = 'https://'

View File

@ -1,3 +1,4 @@
<!-- TODO @puhui999去掉 MQ 关键字哈 -->
<template>
<el-form-item label="主机地址" prop="config.host">
<el-input v-model="config.host" placeholder="请输入主机地址localhost" />