index.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <DeviceDetailsHeader
  3. :loading="loading"
  4. :product="product"
  5. :device="device"
  6. @refresh="getDeviceData(id)"
  7. />
  8. <el-col>
  9. <el-tabs v-model="activeTab">
  10. <el-tab-pane label="设备信息" name="info">
  11. <DeviceDetailsInfo v-if="activeTab === 'info'" :product="product" :device="device" />
  12. </el-tab-pane>
  13. <el-tab-pane label="Topic 列表" />
  14. <el-tab-pane label="物模型数据" name="model">
  15. <DeviceDetailsModel v-if="activeTab === 'model'" :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/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 = route.params.id // 编号
  33. const loading = ref(true) // 加载中
  34. const product = ref<ProductVO>({} as ProductVO) // 产品详情
  35. const device = ref<DeviceVO>({} as DeviceVO) // 设备详情
  36. const activeTab = ref('info') // 默认激活的标签页
  37. /** 获取设备详情 */
  38. const getDeviceData = async (id: number) => {
  39. loading.value = true
  40. try {
  41. device.value = await DeviceApi.getDevice(id)
  42. console.log(product.value)
  43. await getProductData(device.value.productId)
  44. } finally {
  45. loading.value = false
  46. }
  47. }
  48. /** 获取产品详情 */
  49. const getProductData = async (id: number) => {
  50. product.value = await ProductApi.getProduct(id)
  51. }
  52. /** 初始化 */
  53. const { delView } = useTagsViewStore() // 视图操作
  54. const { currentRoute } = useRouter() // 路由
  55. onMounted(async () => {
  56. if (!id) {
  57. message.warning('参数错误,产品不能为空!')
  58. delView(unref(currentRoute))
  59. return
  60. }
  61. await getDeviceData(id)
  62. })
  63. </script>