gaoluyang
2026-06-24 712aa51536236d43e87273e4ce45ac5691dffad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<script lang="ts" setup>
import type { IotDeviceApi } from '#/api/iot/device/device';
import type { IotProductApi } from '#/api/iot/product/product';
 
import { useRouter } from 'vue-router';
 
import { useVbenModal } from '..\..\..\..\..\..\packages\effects\common-ui\src';
 
import { Button, Card, Descriptions, message } from 'ant-design-vue';
 
import DeviceForm from '../../modules/form.vue';
 
interface Props {
  product: IotProductApi.Product;
  device: IotDeviceApi.Device;
  loading?: boolean;
}
 
withDefaults(defineProps<Props>(), {
  loading: false,
});
 
const emit = defineEmits<{
  refresh: [];
}>();
 
const router = useRouter();
 
const [FormModal, formModalApi] = useVbenModal({
  connectedComponent: DeviceForm,
  destroyOnClose: true,
});
 
/** 复制到剪贴板 */
async function copyToClipboard(text: string | undefined) {
  if (!text) return;
  try {
    await navigator.clipboard.writeText(text);
    message.success('复制成功');
  } catch {
    message.error('复制失败');
  }
}
 
/** 跳转到产品详情页面 */
function goToProductDetail(productId: number | undefined) {
  if (productId) {
    router.push({ name: 'IoTProductDetail', params: { id: productId } });
  }
}
 
/** 打开编辑表单 */
function openEditForm(row: IotDeviceApi.Device) {
  formModalApi.setData(row).open();
}
</script>
<template>
  <div class="mb-4">
    <FormModal @success="emit('refresh')" />
 
    <div class="flex items-start justify-between">
      <div>
        <h2 class="text-xl font-bold">{{ device.deviceName }}</h2>
      </div>
      <div class="flex gap-2">
        <Button
          v-if="product.status === 0"
          v-access:code="['iot:device:update']"
          @click="openEditForm(device)"
        >
          编辑
        </Button>
      </div>
    </div>
 
    <Card class="mt-4">
      <Descriptions :column="2">
        <Descriptions.Item label="产品">
          <a
            class="cursor-pointer text-blue-600"
            @click="goToProductDetail(product.id)"
          >
            {{ product.name }}
          </a>
        </Descriptions.Item>
        <Descriptions.Item label="ProductKey">
          {{ product.productKey }}
          <Button
            class="ml-2"
            size="small"
            @click="copyToClipboard(product.productKey)"
          >
            复制
          </Button>
        </Descriptions.Item>
      </Descriptions>
    </Card>
  </div>
</template>