Detail.vue
7.34 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<template>
<div class="tabs-detail">
<div v-if="deviceDetail?.deviceInfo?.avatar">
<p>设备图片</p>
<Image :src="deviceDetail.deviceInfo.avatar" :width="200" />
</div>
<div>
<div class="flex" style="align-items: center">
<div>设备信息</div>
<Tooltip
title="复制或查看设备topic"
@click="openTopicModal"
placement="right"
v-if="deviceDetail.deviceType !== DeviceTypeEnum.SENSOR"
>
<QuestionCircleOutlined class="ml-2" style="font-size: 1rem" />
</Tooltip>
<BasicModal
@register="registerTopicModal"
centered
:footer="null"
title="设备Topic"
:canFullscreen="false"
:minHeight="50"
:height="50"
:useWrapper="false"
>
<div v-if="deviceDetail.deviceType === DeviceTypeEnum.GATEWAY" class="flex">
<div> 网关设备Topic : v1/gateway/telemetry </div>
<a-button
size="small"
class="ml-4"
@click="copyTopic('v1/gateway/telemetry')"
color="success"
>复制</a-button
>
</div>
<div v-if="deviceDetail.deviceType === DeviceTypeEnum.DIRECT_CONNECTION" class="flex">
<div> 直连设备Topic : v1/devices/me/telemetry </div>
<a-button
size="small"
class="ml-4"
@click="copyTopic('v1/devices/me/telemetry')"
color="success"
>复制</a-button
>
</div>
</BasicModal>
</div>
<Description @register="register" class="mt-4" :data="deviceDetail" />
</div>
<div class="mt-4">
<a-button type="primary" class="mr-4" @click="copyTbDeviceId">复制设备ID</a-button>
<a-button type="primary" class="mr-4" @click="copyDeviceToken">复制访问令牌</a-button>
<a-button type="primary" class="mr-4" @click="manageDeviceToken">管理设备凭证</a-button>
<ManageDeviceTokenModal @register="registerModal" />
</div>
<div class="mt-4">
<p>设备位置</p>
<div v-if="deviceDetail?.deviceInfo?.address">
<div ref="mapWrapRef" style="height: 550px; width: 100%"></div>
</div>
<Empty
v-if="!deviceDetail?.deviceInfo?.address"
:image="locationImage"
:imageStyle="{ display: 'flex', 'justify-content': 'center', height: '150px' }"
description="请添加设备地理位置"
/>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, unref, nextTick } from 'vue';
import { Empty, Image, Tooltip } from 'ant-design-vue';
import { descSchema } from '../../config/detail.config';
import { useAsyncScript } from '/@/hooks/web/useAsyncScript';
import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
import { useMessage } from '/@/hooks/web/useMessage';
import { BAI_DU_MAP_URL } from '/@/utils/fnUtils';
import { BasicModal, useModal } from '/@/components/Modal';
import ManageDeviceTokenModal from '../modal/ManageDeviceTokenModal.vue';
import { getDeviceToken } from '/@/api/device/deviceManager';
import { Description, useDescription } from '/@/components/Description';
import { QuestionCircleOutlined } from '@ant-design/icons-vue';
import { DeviceTypeEnum } from '/@/api/device/model/deviceModel';
import wz from '/@/assets/images/wz.png';
import { useAsyncQueue } from '../../../localtion/useAsyncQueue';
import locationImage from '/@/assets/icons/location.svg';
export default defineComponent({
components: {
Image,
Description,
ManageDeviceTokenModal,
QuestionCircleOutlined,
BasicModal,
Tooltip,
Empty,
},
props: {
deviceDetail: {
type: Object,
required: true,
},
},
emits: ['open-gateway-device'],
setup(props, { emit }) {
const [register] = useDescription({
layout: 'vertical',
schema: descSchema(emit),
column: 2,
});
// 地图
const mapWrapRef = ref<HTMLDivElement>();
const { executeFlag, setTask } = useAsyncQueue();
const { toPromise } = useAsyncScript({ src: BAI_DU_MAP_URL });
async function initMap(longitude: number, latitude: number, address: string) {
if (!(window as any).BMap) {
setTask(() => markerMap(longitude, latitude, address));
let interval: Nullable<NodeJS.Timer> = setInterval(() => {
if ((window as any).BMap) {
executeFlag.value = true;
clearInterval(interval!);
interval = null;
}
}, 300);
await toPromise();
return;
}
markerMap(longitude, latitude, address);
}
async function markerMap(longitude: number, latitude: number, address: string) {
await nextTick();
const wrapEl = unref(mapWrapRef);
const BMap = (window as any).BMap;
if (!wrapEl) return;
const map = new BMap.Map(wrapEl);
let myIcon = new BMap.Icon(wz, new BMap.Size(20, 30));
const point = new BMap.Point(Number(longitude), Number(latitude));
var content = `我在 ${address}`;
var label = new BMap.Label(content, {
// 创建文本标注
position: point,
offset: new BMap.Size(15, -35),
});
map.addOverlay(label); // 将标注添加到地图中
label.setStyle({
// 设置label的样式
color: '#000',
fontSize: '10px',
border: '1px solid #1E90FF',
});
let marker = new BMap.Marker(point, { icon: myIcon });
map.centerAndZoom(point, 15);
map.enableScrollWheelZoom(true);
map.addOverlay(marker);
}
const { createMessage } = useMessage();
const { clipboardRef } = useCopyToClipboard();
const copyTbDeviceId = () => {
clipboardRef.value = props.deviceDetail.tbDeviceId;
if (unref(clipboardRef)) {
createMessage.success('复制成功~');
}
};
const copyDeviceToken = async () => {
const token = await getDeviceToken(props.deviceDetail.tbDeviceId);
if (token.credentialsType === 'ACCESS_TOKEN') {
clipboardRef.value = token.credentialsId;
} else {
clipboardRef.value = token.credentialsValue;
}
createMessage.success('复制成功~');
};
const [registerModal, { openModal }] = useModal();
const manageDeviceToken = async () => {
const token = await getDeviceToken(props.deviceDetail.tbDeviceId);
openModal(true, token);
};
const copyTopic = (val) => {
const { isSuccessRef } = useCopyToClipboard(
JSON.parse(JSON.stringify(unref(val), null, 2))
);
unref(isSuccessRef);
createMessage.success('复制成功!');
};
const [registerTopicModal, { openModal: openTopicModal }] = useModal();
const remoteConnectiondGateway = () => {};
return {
mapWrapRef,
copyTbDeviceId,
copyDeviceToken,
initMap,
manageDeviceToken,
registerModal,
register,
openTopicModal,
registerTopicModal,
DeviceTypeEnum,
copyTopic,
remoteConnectiondGateway,
locationImage,
};
},
});
</script>
<style lang="less" scoped></style>