DeviceDetailsHeader.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div>
  3. <div class="flex items-start justify-between">
  4. <div>
  5. <el-col>
  6. <el-row>
  7. <span class="text-xl font-bold">{{ device.deviceName }}</span>
  8. </el-row>
  9. </el-col>
  10. </div>
  11. <div>
  12. <!-- 右上:按钮 -->
  13. <el-button
  14. @click="openForm('update', device.id)"
  15. v-hasPermi="['iot:device:update']"
  16. v-if="product.status === 0"
  17. >
  18. 编辑
  19. </el-button>
  20. </div>
  21. </div>
  22. </div>
  23. <ContentWrap class="mt-10px">
  24. <el-descriptions :column="5" direction="horizontal">
  25. <el-descriptions-item label="产品">
  26. <el-link @click="goToProductDetail(product.id)">{{ product.name }}</el-link>
  27. </el-descriptions-item>
  28. <el-descriptions-item label="ProductKey">
  29. {{ product.productKey }}
  30. <el-button @click="copyToClipboard(product.productKey)">复制</el-button>
  31. </el-descriptions-item>
  32. </el-descriptions>
  33. </ContentWrap>
  34. <!-- 表单弹窗:添加/修改 -->
  35. <DeviceForm ref="formRef" @success="emit('refresh')" />
  36. </template>
  37. <script setup lang="ts">
  38. import { ref } from 'vue'
  39. import DeviceForm from '@/views/iot/device/DeviceForm.vue'
  40. import { ProductVO } from '@/api/iot/product'
  41. import { DeviceVO } from '@/api/iot/device'
  42. import { useRouter } from 'vue-router'
  43. const message = useMessage()
  44. const router = useRouter()
  45. // 操作修改
  46. const formRef = ref()
  47. const openForm = (type: string, id?: number) => {
  48. formRef.value.open(type, id)
  49. }
  50. const { product, device } = defineProps<{ product: ProductVO; device: DeviceVO }>()
  51. const emit = defineEmits(['refresh'])
  52. /**
  53. * 将文本复制到剪贴板
  54. *
  55. * @param text 需要复制的文本
  56. */
  57. const copyToClipboard = (text: string) => {
  58. // TODO @haohao:可以考虑用 await 异步转同步哈
  59. navigator.clipboard.writeText(text).then(() => {
  60. message.success('复制成功')
  61. })
  62. }
  63. /**
  64. * 跳转到产品详情页面
  65. *
  66. * @param productId 产品 ID
  67. */
  68. const goToProductDetail = (productId: number) => {
  69. router.push({ name: 'IoTProductDetail', params: { id: productId } })
  70. }
  71. </script>