【功能新增】IoT:产品详情,优化相关展示

pull/620/head
YunaiV 2024-12-07 20:17:00 +08:00
parent dc2dbcbc84
commit 48907bde60
5 changed files with 40 additions and 18 deletions

View File

@ -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 = {

View File

@ -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
}
/**
*
*/

View File

@ -45,8 +45,8 @@
</el-descriptions>
<el-descriptions :column="5" direction="horizontal">
<el-descriptions-item label="设备数">
{{ product.deviceCount }}
<el-button @click="goToManagement(product.id)"></el-button>
{{ product.deviceCount ?? '加载中...' }}
<el-button @click="goToDeviceList(product.id)"></el-button>
</el-descriptions-item>
</el-descriptions>
</ContentWrap>
@ -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)

View File

@ -3,6 +3,7 @@
<el-collapse v-model="activeNames">
<el-descriptions :column="3" title="产品信息">
<el-descriptions-item label="产品名称">{{ product.name }}</el-descriptions-item>
<el-descriptions-item label="所属分类">{{ product.categoryName }}</el-descriptions-item>
<el-descriptions-item label="设备类型">
<dict-tag :type="DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE" :value="product.deviceType" />
</el-descriptions-item>
@ -20,11 +21,14 @@
</el-descriptions-item>
<el-descriptions-item
label="联网方式"
v-if="product.deviceType === 0 || product.deviceType === 2"
v-if="[DeviceTypeEnum.DEVICE, DeviceTypeEnum.GATEWAY].includes(product.deviceType)"
>
<dict-tag :type="DICT_TYPE.IOT_NET_TYPE" :value="product.netType" />
</el-descriptions-item>
<el-descriptions-item label="接入网关协议" v-if="product.deviceType === 1">
<el-descriptions-item
label="接入网关协议"
v-if="product.deviceType === DeviceTypeEnum.GATEWAY_SUB"
>
<dict-tag :type="DICT_TYPE.IOT_PROTOCOL_TYPE" :value="product.protocolType" />
</el-descriptions-item>
<el-descriptions-item label="产品描述">{{ product.description }}</el-descriptions-item>
@ -34,7 +38,7 @@
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { ProductVO } from '@/api/iot/product/product'
import { DeviceTypeEnum, ProductVO } from '@/api/iot/product/product'
import { formatDate } from '@/utils/formatTime'
const { product } = defineProps<{ product: ProductVO }>()

View File

@ -33,7 +33,7 @@ const { currentRoute } = useRouter()
const route = useRoute()
const message = useMessage()
const id = route.params.id //
const id = Number(route.params.id) //
const loading = ref(true) //
const product = ref<ProductVO>({} as ProductVO) //
const activeTab = ref('info') //
@ -43,20 +43,17 @@ const getProductData = async (id: number) => {
loading.value = true
try {
product.value = await ProductApi.getProduct(id)
console.log('Product data:', product.value)
} finally {
loading.value = false
}
}
//
/** 查询设备数量 */
const getDeviceCount = async (productId: number) => {
try {
const count = await DeviceApi.getDeviceCount(productId)
console.log('Device count response:', count)
return count
return await DeviceApi.getDeviceCount(productId)
} catch (error) {
console.error('Error fetching device count:', error)
console.error('Error fetching device count:', error, 'productId:', productId)
return 0
}
}
@ -72,9 +69,6 @@ onMounted(async () => {
//
if (product.value.id) {
product.value.deviceCount = await getDeviceCount(product.value.id)
console.log('Device count:', product.value.deviceCount)
} else {
console.error('Product ID is undefined')
}
})
</script>