index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <DeviceDetailsHeader
  3. :loading="loading"
  4. :product="product"
  5. :device="device"
  6. @refresh="getDeviceData(id)"
  7. />
  8. <el-col>
  9. <el-tabs>
  10. <el-tab-pane label="设备信息">
  11. <DeviceDetailsInfo :product="product" :device="device" />
  12. </el-tab-pane>
  13. <el-tab-pane label="Topic 列表" />
  14. <el-tab-pane label="物模型数据" />
  15. <el-tab-pane label="子设备管理" />
  16. </el-tabs>
  17. </el-col>
  18. </template>
  19. <script lang="ts" setup>
  20. import { useTagsViewStore } from '@/store/modules/tagsView'
  21. import { DeviceApi, DeviceVO } from '@/api/iot/device'
  22. import { ProductApi, ProductVO } from '@/api/iot/product'
  23. import DeviceDetailsHeader from '@/views/iot/device/detail/DeviceDetailsHeader.vue'
  24. import DeviceDetailsInfo from '@/views/iot/device/detail/DeviceDetailsInfo.vue'
  25. defineOptions({ name: 'IoTDeviceDetail' })
  26. const route = useRoute()
  27. const message = useMessage()
  28. const id = route.params.id // 编号
  29. const loading = ref(true) // 加载中
  30. const product = ref<ProductVO>({} as ProductVO) // 产品详情
  31. const device = ref<DeviceVO>({} as DeviceVO) // 设备详情
  32. /** 获取设备详情 */
  33. const getDeviceData = async (id: number) => {
  34. loading.value = true
  35. try {
  36. device.value = await DeviceApi.getDevice(id)
  37. console.log(product.value)
  38. await getProductData(device.value.productId)
  39. } finally {
  40. loading.value = false
  41. }
  42. }
  43. /** 获取产品详情 */
  44. const getProductData = async (id: number) => {
  45. product.value = await ProductApi.getProduct(id)
  46. console.log(product.value)
  47. }
  48. /** 获取物模型 */
  49. /** 初始化 */
  50. const { delView } = useTagsViewStore() // 视图操作
  51. const { currentRoute } = useRouter() // 路由
  52. onMounted(async () => {
  53. if (!id) {
  54. message.warning('参数错误,产品不能为空!')
  55. delView(unref(currentRoute))
  56. return
  57. }
  58. await getDeviceData(id)
  59. })
  60. </script>