From 48907bde60ef2cf9c366e82acff2b0054a50c856 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 7 Dec 2024 20:17:00 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E3=80=91IoT=EF=BC=9A=E4=BA=A7=E5=93=81=E8=AF=A6=E6=83=85?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E7=9B=B8=E5=85=B3=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/iot/product/product/index.ts | 6 ++++++ src/utils/index.ts | 14 ++++++++++++++ .../product/detail/ProductDetailsHeader.vue | 14 +++++++++----- .../product/product/detail/ProductDetailsInfo.vue | 10 +++++++--- src/views/iot/product/product/detail/index.vue | 14 ++++---------- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/api/iot/product/product/index.ts b/src/api/iot/product/product/index.ts index 047dc716..0fa58d54 100644 --- a/src/api/iot/product/product/index.ts +++ b/src/api/iot/product/product/index.ts @@ -7,6 +7,7 @@ export interface ProductVO { productKey: string // 产品标识 protocolId: number // 协议编号 categoryId: number // 产品所属品类标识符 + categoryName?: string // 产品所属品类名称 description: string // 产品描述 validateType: number // 数据校验级别 status: number // 产品状态 @@ -29,6 +30,11 @@ export enum DeviceTypeEnum { GATEWAY_SUB = 1, // 网关子设备 GATEWAY = 2 // 网关设备 } +// IOT 数据格式枚举类 +export enum DataFormatEnum { + JSON = 0, // 标准数据格式(JSON) + CUSTOMIZE = 1 // 透传/自定义 +} // IoT 产品 API export const ProductApi = { diff --git a/src/utils/index.ts b/src/utils/index.ts index 2c2fbbd0..059571e7 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -116,6 +116,20 @@ export function toAnyString() { return str } +/** + * 生成指定长度的随机字符串 + * + * @param length 字符串长度 + */ +export function generateRandomStr(length: number): string { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' + let result = '' + for (let i = 0; i < length; i++) { + result += chars.charAt(Math.floor(Math.random() * chars.length)) + } + return result +} + /** * 首字母大写 */ diff --git a/src/views/iot/product/product/detail/ProductDetailsHeader.vue b/src/views/iot/product/product/detail/ProductDetailsHeader.vue index 528e174a..841aef9f 100644 --- a/src/views/iot/product/product/detail/ProductDetailsHeader.vue +++ b/src/views/iot/product/product/detail/ProductDetailsHeader.vue @@ -45,8 +45,8 @@ - {{ product.deviceCount }} - 前往管理 + {{ product.deviceCount ?? '加载中...' }} + 前往管理 @@ -73,16 +73,18 @@ const copyToClipboard = async (text: string) => { /** 路由跳转到设备管理 */ const { push } = useRouter() -const goToManagement = (productId: string) => { - push({ name: 'IoTDevice', query: { productId } }) +const goToDeviceList = (productId: number) => { + push({ name: 'IoTDevice', params: { productId } }) } -/** 操作修改 */ +/** 修改操作 */ const emit = defineEmits(['refresh']) // 定义 Emits const formRef = ref() const openForm = (type: string, id?: number) => { formRef.value.open(type, id) } + +/** 发布操作 */ const confirmPublish = async (id: number) => { try { await ProductApi.updateProductStatus(id, 1) @@ -93,6 +95,8 @@ const confirmPublish = async (id: number) => { message.error('发布失败') } } + +/** 撤销发布操作 */ const confirmUnpublish = async (id: number) => { try { await ProductApi.updateProductStatus(id, 0) diff --git a/src/views/iot/product/product/detail/ProductDetailsInfo.vue b/src/views/iot/product/product/detail/ProductDetailsInfo.vue index 3eaa5c14..2601fc85 100644 --- a/src/views/iot/product/product/detail/ProductDetailsInfo.vue +++ b/src/views/iot/product/product/detail/ProductDetailsInfo.vue @@ -3,6 +3,7 @@ {{ product.name }} + {{ product.categoryName }} @@ -20,11 +21,14 @@ - + {{ product.description }} @@ -34,7 +38,7 @@