2025-02-28 20:47:07 +08:00
|
|
|
|
<template>
|
|
|
|
|
<a-layout>
|
|
|
|
|
<a-layout-sider :resize-directions="['right']">
|
|
|
|
|
<a-row>
|
2025-03-11 17:26:36 +08:00
|
|
|
|
<a-col
|
|
|
|
|
:span="24"
|
|
|
|
|
v-for="device in deviceList"
|
|
|
|
|
:key="device.id"
|
|
|
|
|
@click="selectDevice(device)"
|
|
|
|
|
>
|
2025-03-07 19:16:59 +08:00
|
|
|
|
{{ device.name }}
|
|
|
|
|
</a-col>
|
2025-02-28 20:47:07 +08:00
|
|
|
|
</a-row>
|
|
|
|
|
</a-layout-sider>
|
|
|
|
|
<a-layout-content>
|
|
|
|
|
<div id="container"></div>
|
|
|
|
|
</a-layout-content>
|
|
|
|
|
</a-layout>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2025-03-07 19:16:59 +08:00
|
|
|
|
import { onMounted, ref } from 'vue';
|
2025-02-28 20:47:07 +08:00
|
|
|
|
import AMapLoader from '@amap/amap-jsapi-loader';
|
|
|
|
|
import { DeviceRecord, queryDeviceList } from '@/api/device';
|
2025-03-11 17:26:36 +08:00
|
|
|
|
import '@amap/amap-jsapi-types';
|
2025-03-07 19:16:59 +08:00
|
|
|
|
import router from '@/router';
|
2025-03-11 17:26:36 +08:00
|
|
|
|
import { Message } from '@arco-design/web-vue';
|
2025-02-28 20:47:07 +08:00
|
|
|
|
|
|
|
|
|
let map: any = null;
|
|
|
|
|
const deviceList = ref<DeviceRecord[]>([]);
|
2025-03-07 19:16:59 +08:00
|
|
|
|
let selectDevice = (device: DeviceRecord) => {
|
|
|
|
|
console.log(device);
|
2025-03-11 17:26:36 +08:00
|
|
|
|
};
|
2025-03-07 19:16:59 +08:00
|
|
|
|
|
2025-03-02 17:53:03 +08:00
|
|
|
|
AMapLoader.load({
|
|
|
|
|
key: 'a4e80eed798a56451b226dcfca81b846', // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
|
|
|
version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
|
|
|
|
plugins: [], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
|
|
|
|
})
|
|
|
|
|
.then((AMap) => {
|
|
|
|
|
map = new AMap.Map('container', {
|
|
|
|
|
// 设置地图容器id
|
|
|
|
|
viewMode: '3D', // 是否为3D地图模式
|
|
|
|
|
zoom: 11, // 初始化地图级别
|
|
|
|
|
center: [116.397428, 39.90923], // 初始化地图中心点位置
|
|
|
|
|
});
|
2025-03-07 19:16:59 +08:00
|
|
|
|
|
|
|
|
|
selectDevice = (device: DeviceRecord) => {
|
|
|
|
|
if (device.longitude && device.latitude) {
|
|
|
|
|
const lngLat = [device.longitude, device.latitude];
|
|
|
|
|
const content = document.createElement('div');
|
|
|
|
|
content.className = 'custom-content-marker';
|
|
|
|
|
content.innerHTML = `
|
|
|
|
|
<img src="https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png" alt="标记点" />`;
|
|
|
|
|
|
|
|
|
|
// 创建标记点
|
|
|
|
|
const marker = new AMap.Marker({
|
|
|
|
|
position: lngLat,
|
|
|
|
|
content,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 将标记点添加到地图上
|
|
|
|
|
map.setCenter(lngLat);
|
2025-03-10 20:55:56 +08:00
|
|
|
|
map.setZoom(20);
|
2025-03-07 19:16:59 +08:00
|
|
|
|
map.add(marker);
|
|
|
|
|
|
|
|
|
|
const infoContent = [
|
|
|
|
|
`<br/><div style="width: 300px;margin-left: 20px;padding-bottom: 10px"><b>设备名称: ${device.name}</b>`,
|
|
|
|
|
`<span style="font-size: 16px; color: #333;">硬件版本: ${device.hardwareVersion}</span>`,
|
|
|
|
|
`<span style="font-size: 16px; color: #333;">固件版本: ${device.firmwareVersion}</span>`,
|
|
|
|
|
`<span style="font-size: 16px; color: #333;">所属产品: ${device.productName}</span>`,
|
|
|
|
|
`<a-button style="margin-left: 200px;color: #0960bd" onclick="handleViewDetail('${device.id}')">查看详情
|
2025-03-11 17:26:36 +08:00
|
|
|
|
</a-button></div>`,
|
|
|
|
|
];
|
2025-03-07 19:16:59 +08:00
|
|
|
|
|
2025-03-11 17:26:36 +08:00
|
|
|
|
window.handleViewDetail = (deviceId: number) => {
|
2025-03-07 19:16:59 +08:00
|
|
|
|
router.push({ name: 'deviceDetail', params: { id: deviceId } });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 初始化信息窗体
|
|
|
|
|
const infoWindow = new AMap.InfoWindow({
|
|
|
|
|
content: infoContent.join('<br>'),
|
|
|
|
|
offset: new AMap.Pixel(10, 10), // 调整信息窗体的偏移量
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 绑定标记点点击事件
|
|
|
|
|
marker.on('click', () => {
|
|
|
|
|
infoWindow.open(map, lngLat); // 打开信息窗体
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2025-03-11 17:26:36 +08:00
|
|
|
|
Message.error('设备缺少经纬度信息');
|
2025-03-07 19:16:59 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2025-03-02 17:53:03 +08:00
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
2025-03-11 17:26:36 +08:00
|
|
|
|
Message.error('加载地图失败');
|
2025-03-02 17:53:03 +08:00
|
|
|
|
console.log(e);
|
|
|
|
|
});
|
2025-02-28 20:47:07 +08:00
|
|
|
|
|
2025-03-07 19:16:59 +08:00
|
|
|
|
// 将依赖于 AMap 的代码放在 then 回调中
|
2025-03-02 17:53:03 +08:00
|
|
|
|
onMounted(() => {
|
2025-02-28 20:47:07 +08:00
|
|
|
|
// 获取设备列表
|
|
|
|
|
queryDeviceList({
|
|
|
|
|
current: 1,
|
|
|
|
|
size: 10,
|
|
|
|
|
})
|
|
|
|
|
.then((response) => {
|
|
|
|
|
deviceList.value = response.data.records;
|
|
|
|
|
})
|
2025-03-11 17:26:36 +08:00
|
|
|
|
.catch(() => {
|
|
|
|
|
Message.error('获取设备列表失败');
|
2025-02-28 20:47:07 +08:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-02 17:53:03 +08:00
|
|
|
|
// onUnmounted(() => {
|
|
|
|
|
// map?.destroy();
|
|
|
|
|
// });
|
2025-02-28 20:47:07 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
#container {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 800px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.custom-content-marker img {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|