index.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. import { useTagsViewStore } from '@/store/modules/tagsView'
  27. import { useRouter } from 'vue-router'
  28. defineOptions({ name: 'IoTProductDetail' })
  29. const { delView } = useTagsViewStore() // 视图操作
  30. const { currentRoute } = useRouter()
  31. const route = useRoute()
  32. const message = useMessage()
  33. const id = route.params.id // 编号
  34. const loading = ref(true) // 加载中
  35. const product = ref<ProductVO>({} as ProductVO) // 详情
  36. const activeTab = ref('info') // 默认激活的标签页
  37. /** 获取详情 */
  38. const getProductData = async (id: number) => {
  39. loading.value = true
  40. try {
  41. product.value = await ProductApi.getProduct(id)
  42. console.log('Product data:', product.value)
  43. } finally {
  44. loading.value = false
  45. }
  46. }
  47. // 查询设备数量
  48. const getDeviceCount = async (productId: number) => {
  49. try {
  50. const count = await DeviceApi.getDeviceCount(productId)
  51. console.log('Device count response:', count)
  52. return count
  53. } catch (error) {
  54. console.error('Error fetching device count:', error)
  55. return 0
  56. }
  57. }
  58. /** 初始化 */
  59. onMounted(async () => {
  60. if (!id) {
  61. message.warning('参数错误,产品不能为空!')
  62. delView(unref(currentRoute))
  63. return
  64. }
  65. await getProductData(id)
  66. // 查询设备数量
  67. if (product.value.id) {
  68. product.value.deviceCount = await getDeviceCount(product.value.id)
  69. console.log('Device count:', product.value.deviceCount)
  70. } else {
  71. console.error('Product ID is undefined')
  72. }
  73. })
  74. </script>