feat(iot):【协议改造】移除 codecType,使用 protocolType 替代

pull/854/head
YunaiV 2026-02-04 22:05:03 +08:00
parent 04a6987211
commit 57a77b2ba9
4 changed files with 68 additions and 25 deletions

View File

@ -16,7 +16,8 @@ export interface ProductVO {
status: number // 产品状态 status: number // 产品状态
deviceType: number // 设备类型 deviceType: number // 设备类型
netType: number // 联网方式 netType: number // 联网方式
codecType: string // 数据格式(编解码器类型) protocolType: string // 协议类型
serializeType: string // 序列化类型
deviceCount: number // 设备数量 deviceCount: number // 设备数量
createTime: Date // 创建时间 createTime: Date // 创建时间
} }
@ -27,9 +28,22 @@ export enum DeviceTypeEnum {
GATEWAY_SUB = 1, // 网关子设备 GATEWAY_SUB = 1, // 网关子设备
GATEWAY = 2 // 网关设备 GATEWAY = 2 // 网关设备
} }
// IOT 数据格式(编解码器类型)枚举类 // IoT 协议类型枚举
export enum CodecTypeEnum { export enum ProtocolTypeEnum {
ALINK = 'Alink' // 阿里云 Alink 协议 TCP = 'tcp',
UDP = 'udp',
WEBSOCKET = 'websocket',
HTTP = 'http',
MQTT = 'mqtt',
EMQX = 'emqx',
COAP = 'coap',
MODBUS_TCP = 'modbus_tcp'
}
// IoT 序列化类型枚举
export enum SerializeTypeEnum {
JSON = 'json',
BINARY = 'binary'
} }
// IoT 产品 API // IoT 产品 API

View File

@ -233,7 +233,8 @@ export enum DICT_TYPE {
IOT_NET_TYPE = 'iot_net_type', // IOT 联网方式 IOT_NET_TYPE = 'iot_net_type', // IOT 联网方式
IOT_PRODUCT_STATUS = 'iot_product_status', // IOT 产品状态 IOT_PRODUCT_STATUS = 'iot_product_status', // IOT 产品状态
IOT_PRODUCT_DEVICE_TYPE = 'iot_product_device_type', // IOT 产品设备类型 IOT_PRODUCT_DEVICE_TYPE = 'iot_product_device_type', // IOT 产品设备类型
IOT_CODEC_TYPE = 'iot_codec_type', // IOT 数据格式(编解码器类型) IOT_PROTOCOL_TYPE = 'iot_protocol_type', // IOT 协议类型
IOT_SERIALIZE_TYPE = 'iot_serialize_type', // IOT 序列化类型
IOT_LOCATION_TYPE = 'iot_location_type', // IOT 定位类型 IOT_LOCATION_TYPE = 'iot_location_type', // IOT 定位类型
IOT_DEVICE_STATE = 'iot_device_state', // IOT 设备状态 IOT_DEVICE_STATE = 'iot_device_state', // IOT 设备状态
IOT_THING_MODEL_TYPE = 'iot_thing_model_type', // IOT 产品功能类型 IOT_THING_MODEL_TYPE = 'iot_thing_model_type', // IOT 产品功能类型

View File

@ -4,7 +4,7 @@
ref="formRef" ref="formRef"
:model="formData" :model="formData"
:rules="formRules" :rules="formRules"
label-width="110px" label-width="120px"
v-loading="formLoading" v-loading="formLoading"
> >
<el-form-item label="ProductKey" prop="productKey"> <el-form-item label="ProductKey" prop="productKey">
@ -49,11 +49,7 @@
label="联网方式" label="联网方式"
prop="netType" prop="netType"
> >
<el-select <el-select v-model="formData.netType" placeholder="请选择联网方式">
v-model="formData.netType"
placeholder="请选择联网方式"
:disabled="formType === 'update'"
>
<el-option <el-option
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_NET_TYPE)" v-for="dict in getIntDictOptions(DICT_TYPE.IOT_NET_TYPE)"
:key="dict.value" :key="dict.value"
@ -62,16 +58,36 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="数据格式" prop="codecType"> <el-form-item label="协议类型" prop="protocolType">
<el-radio-group v-model="formData.codecType" :disabled="formType === 'update'"> <el-select v-model="formData.protocolType" placeholder="请选择协议类型">
<el-radio <el-option
v-for="dict in getStrDictOptions(DICT_TYPE.IOT_CODEC_TYPE)" v-for="dict in getStrDictOptions(DICT_TYPE.IOT_PROTOCOL_TYPE)"
:key="dict.value" :key="dict.value"
:label="dict.value" :label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item prop="serializeType">
<template #label>
<el-tooltip
content="iot-gateway-server 默认根据接入的协议类型确定数据格式,仅 MQTT、EMQX 协议支持自定义序列化类型"
placement="top"
> >
{{ dict.label }} <span>
</el-radio> 序列化类型
</el-radio-group> <Icon icon="ep:question-filled" class="ml-2px" />
</span>
</el-tooltip>
</template>
<el-select v-model="formData.serializeType" placeholder="请选择序列化类型">
<el-option
v-for="dict in getStrDictOptions(DICT_TYPE.IOT_SERIALIZE_TYPE)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item> </el-form-item>
<el-collapse> <el-collapse>
<el-collapse-item title="更多配置"> <el-collapse-item title="更多配置">
@ -109,7 +125,13 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ProductApi, ProductVO, CodecTypeEnum, DeviceTypeEnum } from '@/api/iot/product/product' import {
ProductApi,
ProductVO,
ProtocolTypeEnum,
SerializeTypeEnum,
DeviceTypeEnum
} from '@/api/iot/product/product'
import { DICT_TYPE, getIntDictOptions, getStrDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions, getStrDictOptions } from '@/utils/dict'
import { ProductCategoryApi, ProductCategoryVO } from '@/api/iot/product/category' import { ProductCategoryApi, ProductCategoryVO } from '@/api/iot/product/category'
import { UploadImg } from '@/components/UploadFile' import { UploadImg } from '@/components/UploadFile'
@ -134,7 +156,8 @@ const formData = ref({
description: undefined, description: undefined,
deviceType: undefined, deviceType: undefined,
netType: undefined, netType: undefined,
codecType: CodecTypeEnum.ALINK, protocolType: ProtocolTypeEnum.MQTT,
serializeType: SerializeTypeEnum.JSON,
registerEnabled: false registerEnabled: false
}) })
const formRules = reactive({ const formRules = reactive({
@ -149,7 +172,8 @@ const formRules = reactive({
trigger: 'change' trigger: 'change'
} }
], ],
codecType: [{ required: true, message: '数据格式不能为空', trigger: 'change' }] protocolType: [{ required: true, message: '协议类型不能为空', trigger: 'change' }],
serializeType: [{ required: true, message: '序列化类型不能为空', trigger: 'change' }]
}) })
const formRef = ref() const formRef = ref()
const categoryList = ref<ProductCategoryVO[]>([]) // const categoryList = ref<ProductCategoryVO[]>([]) //
@ -209,7 +233,8 @@ const resetForm = () => {
description: undefined, description: undefined,
deviceType: undefined, deviceType: undefined,
netType: undefined, netType: undefined,
codecType: CodecTypeEnum.ALINK, protocolType: ProtocolTypeEnum.MQTT,
serializeType: SerializeTypeEnum.JSON,
registerEnabled: false registerEnabled: false
} }
formRef.value?.resetFields() formRef.value?.resetFields()

View File

@ -9,8 +9,11 @@
<el-descriptions-item label="创建时间"> <el-descriptions-item label="创建时间">
{{ formatDate(product.createTime) }} {{ formatDate(product.createTime) }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="数据格式"> <el-descriptions-item label="协议类型">
<dict-tag :type="DICT_TYPE.IOT_CODEC_TYPE" :value="product.codecType" /> <dict-tag :type="DICT_TYPE.IOT_PROTOCOL_TYPE" :value="product.protocolType" />
</el-descriptions-item>
<el-descriptions-item label="序列化类型">
<dict-tag :type="DICT_TYPE.IOT_SERIALIZE_TYPE" :value="product.serializeType" />
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="产品状态"> <el-descriptions-item label="产品状态">
<dict-tag :type="DICT_TYPE.IOT_PRODUCT_STATUS" :value="product.status" /> <dict-tag :type="DICT_TYPE.IOT_PRODUCT_STATUS" :value="product.status" />