2024-09-07 09:46:52 +08:00
|
|
|
<template>
|
2024-09-23 23:34:21 +08:00
|
|
|
<ProductDetailsHeader :loading="loading" :product="product" @refresh="() => getProductData(id)" />
|
2024-09-07 09:46:52 +08:00
|
|
|
<el-col>
|
2024-09-29 21:58:03 +08:00
|
|
|
<el-tabs v-model="activeTab">
|
|
|
|
<el-tab-pane label="产品信息" name="info">
|
|
|
|
<ProductDetailsInfo v-if="activeTab === 'info'" :product="product" />
|
2024-09-07 09:46:52 +08:00
|
|
|
</el-tab-pane>
|
2024-09-29 21:58:03 +08:00
|
|
|
<el-tab-pane label="Topic 类列表" name="topic">
|
|
|
|
<ProductTopic v-if="activeTab === 'topic'" :product="product" />
|
2024-09-23 23:34:21 +08:00
|
|
|
</el-tab-pane>
|
2024-09-29 21:58:03 +08:00
|
|
|
<el-tab-pane label="功能定义" name="function">
|
|
|
|
<ThinkModelFunction v-if="activeTab === 'function'" :product="product" />
|
2024-09-07 09:46:52 +08:00
|
|
|
</el-tab-pane>
|
2024-09-29 21:58:03 +08:00
|
|
|
<el-tab-pane label="消息解析" name="message" />
|
|
|
|
<el-tab-pane label="服务端订阅" name="subscription" />
|
2024-09-07 09:46:52 +08:00
|
|
|
</el-tabs>
|
|
|
|
</el-col>
|
|
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { ProductApi, ProductVO } from '@/api/iot/product'
|
2024-09-24 23:18:42 +08:00
|
|
|
import { DeviceApi } from '@/api/iot/device'
|
2024-09-07 09:46:52 +08:00
|
|
|
import ProductDetailsHeader from '@/views/iot/product/detail/ProductDetailsHeader.vue'
|
|
|
|
import ProductDetailsInfo from '@/views/iot/product/detail/ProductDetailsInfo.vue'
|
2024-09-24 23:18:42 +08:00
|
|
|
import ProductTopic from '@/views/iot/product/detail/ProductTopic.vue'
|
2024-09-29 21:58:03 +08:00
|
|
|
import ThinkModelFunction from '@/views/iot/product/detail/ThinkModelFunction.vue'
|
2024-09-07 09:46:52 +08:00
|
|
|
|
2024-09-21 09:15:27 +08:00
|
|
|
defineOptions({ name: 'IoTProductDetail' })
|
2024-09-07 09:46:52 +08:00
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
const message = useMessage()
|
|
|
|
const id = Number(route.params.id) // 编号
|
|
|
|
const loading = ref(true) // 加载中
|
|
|
|
const product = ref<ProductVO>({} as ProductVO) // 详情
|
2024-09-29 21:58:03 +08:00
|
|
|
const activeTab = ref('info') // 默认激活的标签页
|
2024-09-07 09:46:52 +08:00
|
|
|
|
|
|
|
/** 获取详情 */
|
|
|
|
const getProductData = async (id: number) => {
|
|
|
|
loading.value = true
|
|
|
|
try {
|
|
|
|
product.value = await ProductApi.getProduct(id)
|
2024-09-23 23:34:21 +08:00
|
|
|
console.log('Product data:', product.value)
|
2024-09-07 09:46:52 +08:00
|
|
|
} finally {
|
|
|
|
loading.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-23 23:34:21 +08:00
|
|
|
// 查询设备数量
|
|
|
|
const getDeviceCount = async (productId: string) => {
|
|
|
|
try {
|
|
|
|
const count = await DeviceApi.getDeviceCount(productId)
|
|
|
|
console.log('Device count response:', count)
|
|
|
|
return count
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error fetching device count:', error)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
2024-09-07 09:46:52 +08:00
|
|
|
|
|
|
|
/** 初始化 */
|
|
|
|
onMounted(async () => {
|
|
|
|
if (!id) {
|
|
|
|
message.warning('参数错误,产品不能为空!')
|
|
|
|
delView(unref(currentRoute))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
await getProductData(id)
|
2024-09-23 23:34:21 +08:00
|
|
|
// 查询设备数量
|
|
|
|
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')
|
|
|
|
}
|
2024-09-07 09:46:52 +08:00
|
|
|
})
|
|
|
|
</script>
|