From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/views/iot/product/product/detail/index.vue | 76 ++++++++++++++++++++++++++++++++++++++
1 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/src/views/iot/product/product/detail/index.vue b/src/views/iot/product/product/detail/index.vue
new file mode 100644
index 0000000..0e996eb
--- /dev/null
+++ b/src/views/iot/product/product/detail/index.vue
@@ -0,0 +1,76 @@
+<template>
+ <ProductDetailsHeader :loading="loading" :product="product" @refresh="() => getProductData(id)" />
+ <el-col>
+ <el-tabs v-model="activeTab">
+ <el-tab-pane label="浜у搧淇℃伅" name="info">
+ <ProductDetailsInfo v-if="activeTab === 'info'" :product="product" />
+ </el-tab-pane>
+ <el-tab-pane label="鐗╂ā鍨嬶紙鍔熻兘瀹氫箟锛�" lazy name="thingModel">
+ <IoTProductThingModel ref="thingModelRef" />
+ </el-tab-pane>
+ </el-tabs>
+ </el-col>
+</template>
+<script lang="ts" setup>
+import { ProductApi, ProductVO } from '@/api/iot/product/product'
+import { DeviceApi } from '@/api/iot/device/device'
+import ProductDetailsHeader from './ProductDetailsHeader.vue'
+import ProductDetailsInfo from './ProductDetailsInfo.vue'
+import IoTProductThingModel from '@/views/iot/thingmodel/index.vue'
+import { useTagsViewStore } from '@/store/modules/tagsView'
+import { useRouter } from 'vue-router'
+import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
+
+defineOptions({ name: 'IoTProductDetail' })
+
+const { delView } = useTagsViewStore() // 瑙嗗浘鎿嶄綔
+const { currentRoute } = useRouter()
+
+const route = useRoute()
+const message = useMessage()
+const id = route.params.id // 缂栧彿
+const loading = ref(true) // 鍔犺浇涓�
+const product = ref<ProductVO>({} as ProductVO) // 璇︽儏
+const activeTab = ref('info') // 榛樿涓� info 鏍囩椤�
+
+provide(IOT_PROVIDE_KEY.PRODUCT, product) // 鎻愪緵浜у搧淇℃伅缁欎骇鍝佷俊鎭鎯呴〉鐨勬墍鏈夊瓙缁勪欢
+
+/** 鑾峰彇璇︽儏 */
+const getProductData = async (id: number) => {
+ loading.value = true
+ try {
+ product.value = await ProductApi.getProduct(id)
+ } finally {
+ loading.value = false
+ }
+}
+
+/** 鏌ヨ璁惧鏁伴噺 */
+const getDeviceCount = async (productId: number) => {
+ try {
+ return await DeviceApi.getDeviceCount(productId)
+ } catch (error) {
+ console.error('Error fetching device count:', error, 'productId:', productId)
+ return 0
+ }
+}
+
+/** 鍒濆鍖� */
+onMounted(async () => {
+ if (!id) {
+ message.warning('鍙傛暟閿欒锛屼骇鍝佷笉鑳戒负绌猴紒')
+ delView(unref(currentRoute))
+ return
+ }
+ await getProductData(id)
+ // 澶勭悊 tab 鍙傛暟
+ const { tab } = route.query
+ if (tab) {
+ activeTab.value = tab as string
+ }
+ // 鏌ヨ璁惧鏁伴噺
+ if (product.value.id) {
+ product.value.deviceCount = await getDeviceCount(product.value.id)
+ }
+})
+</script>
--
Gitblit v1.8.0