index.vue 2.1 KB

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