index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <ProductDetailsHeader :loading="loading" :product="product" @refresh="() => getProductData(id)" />
  3. <el-col>
  4. <el-tabs v-model="activeTab">
  5. <el-tab-pane label="产品信息" name="info">
  6. <ProductDetailsInfo v-if="activeTab === 'info'" :product="product" />
  7. </el-tab-pane>
  8. <el-tab-pane label="Topic 类列表" name="topic">
  9. <ProductTopic v-if="activeTab === 'topic'" :product="product" />
  10. </el-tab-pane>
  11. <el-tab-pane label="功能定义" name="function">
  12. <ThinkModelFunction v-if="activeTab === 'function'" :product="product" />
  13. </el-tab-pane>
  14. <el-tab-pane label="消息解析" name="message" />
  15. <el-tab-pane label="服务端订阅" name="subscription" />
  16. </el-tabs>
  17. </el-col>
  18. </template>
  19. <script lang="ts" setup>
  20. import { ProductApi, ProductVO } from '@/api/iot/product'
  21. import { DeviceApi } from '@/api/iot/device'
  22. import ProductDetailsHeader from '@/views/iot/product/detail/ProductDetailsHeader.vue'
  23. import ProductDetailsInfo from '@/views/iot/product/detail/ProductDetailsInfo.vue'
  24. import ProductTopic from '@/views/iot/product/detail/ProductTopic.vue'
  25. import ThinkModelFunction from '@/views/iot/product/detail/ThinkModelFunction.vue'
  26. defineOptions({ name: 'IoTProductDetail' })
  27. const route = useRoute()
  28. const message = useMessage()
  29. const id = Number(route.params.id) // 编号
  30. const loading = ref(true) // 加载中
  31. const product = ref<ProductVO>({} as ProductVO) // 详情
  32. const activeTab = ref('info') // 默认激活的标签页
  33. /** 获取详情 */
  34. const getProductData = async (id: number) => {
  35. loading.value = true
  36. try {
  37. product.value = await ProductApi.getProduct(id)
  38. console.log('Product data:', product.value)
  39. } finally {
  40. loading.value = false
  41. }
  42. }
  43. // 查询设备数量
  44. const getDeviceCount = async (productId: string) => {
  45. try {
  46. const count = await DeviceApi.getDeviceCount(productId)
  47. console.log('Device count response:', count)
  48. return count
  49. } catch (error) {
  50. console.error('Error fetching device count:', error)
  51. return 0
  52. }
  53. }
  54. /** 初始化 */
  55. onMounted(async () => {
  56. if (!id) {
  57. message.warning('参数错误,产品不能为空!')
  58. delView(unref(currentRoute))
  59. return
  60. }
  61. await getProductData(id)
  62. // 查询设备数量
  63. if (product.value.id) {
  64. product.value.deviceCount = await getDeviceCount(product.value.id)
  65. console.log('Device count:', product.value.deviceCount)
  66. } else {
  67. console.error('Product ID is undefined')
  68. }
  69. })
  70. </script>