Files
energy_storage/web/src/components/Home/Map.vue

239 lines
5.4 KiB
Vue
Raw Normal View History

2025-09-01 16:58:54 +08:00
<template>
<div class="map">
2025-09-11 19:01:01 +08:00
<div ref="mapContent" class="mapContent">
<tdt-map
ref="tiandituMap"
:center="center"
:zoom="zoom"
@init="init"
map-style="black"
class="amap-box"
:mid="'amap-vue'"
>
<tdt-marker
v-for="marker in markers"
:position="[marker.lon, marker.lat]"
:key="marker.id"
:icon="marker.iconMap"
2025-09-11 19:01:01 +08:00
style="width: 20px;height: auto"
@click="clickArrayMarker(marker)"
:title="marker.name"
>
</tdt-marker>
</tdt-map>
2025-09-01 16:58:54 +08:00
</div>
<a-modal
class="modal"
ref="modal"
v-model:open="showCtrModal"
:destroy-on-close="true"
:get-container="() => $refs.mapContent"
:footer="null"
:title="testVal.name"
:mask="true"
>
2025-09-01 17:18:30 +08:00
<template #closeIcon>
<i class="iconfont icon-guanbi" style="font-size: 20px; cursor: pointer; color: #fff" />
2025-09-01 17:18:30 +08:00
</template>
2025-09-01 16:58:54 +08:00
<div class="modal-content">
<div class="home-modal">
2025-09-04 16:04:37 +08:00
<Modal :station-id="changeStationId"></Modal>
2025-09-01 16:58:54 +08:00
</div>
</div>
</a-modal>
</div>
</template>
2025-09-11 19:01:01 +08:00
2025-09-01 16:58:54 +08:00
<script>
import { getReq, postReq } from '@/request/api'
import Modal from '@/components/Home/Modal.vue'
import { loadTMap } from '@/utils/loadTMap'
2025-09-11 19:01:01 +08:00
import { gcj02ToWgs84, wgs84ToGcj02 } from '@/utils/gcj02ToWgs84'
import { TdtMap } from 'vue-tianditu'
2025-09-01 16:58:54 +08:00
export default {
name: 'Map',
components: { Modal, TdtMap },
2025-09-01 16:58:54 +08:00
data() {
return {
2025-09-12 11:43:32 +08:00
center: [113.5, 33.875], // 默认中心点(河南)
zoom: 10,
map: null,
currentMarker: {},
2025-09-01 16:58:54 +08:00
showCtrModal: false,
markers: [],
2025-09-01 16:58:54 +08:00
testVal: {
name: '场站211',
2025-09-05 09:26:14 +08:00
id: '2'
2025-09-03 13:53:00 +08:00
},
changeStationId: '',
targetKey: '98d875e39cf0ebab01e56a0f86c5ed44'
2025-09-01 16:58:54 +08:00
}
},
mounted() {
this.initMap()
},
2025-09-01 16:58:54 +08:00
methods: {
init(map) {
this.map = map
2025-09-11 19:01:01 +08:00
this.center= [110.404, 40.915]
this.getMarkList()
},
async getMarkList() {
2025-09-01 16:58:54 +08:00
try {
let query = {
2025-09-09 10:00:01 +08:00
role_id: localStorage.getItem('permission')[0].role_id
2025-09-03 13:53:00 +08:00
}
const res = await getReq('/queryStationList', query)
if (res.errcode === 0) {
this.markers = res.data.map((item) => {
return {
...item,
iconMap: !+item.status
? require('../../assets/home/homeIcon1.png')
: require('../../assets/home/homeIcon.png')
}
})
2025-09-01 16:58:54 +08:00
} else {
this.markers = []
2025-09-01 16:58:54 +08:00
throw res
}
} catch (error) {
2025-09-11 19:01:01 +08:00
console.log(error, 'eeeeeeeeeeeeeeee')
}
},
async initMap() {
try {
const [mapKey] = await Promise.all([this.getSysConfig('map-key')])
await loadTMap(mapKey)
2025-09-01 16:58:54 +08:00
} catch (err) {
console.error('天地图加载失败:', err)
2025-09-01 16:58:54 +08:00
}
},
2025-09-11 19:01:01 +08:00
// 备用定位方案
// setFallbackLocation() {
// const fallbackCoords = [116.404, 39.915] // 北京坐标
// this.center = fallbackCoords
// if (this.map) {
// this.map.setCenter(new T.LngLat(...fallbackCoords))
// }
// },
async getSysConfig() {
let sysConfig
try {
const query = {}
const res = await getReq('/', query)
if (res.errcode === 0) {
sysConfig = res.data.value
} else {
throw res
}
} catch (error) {
sysConfig = this.targetKey
}
return sysConfig
},
2025-09-11 19:01:01 +08:00
async clickArrayMarker(currentVal) {
this.changeStationId = currentVal.station_id
this.showCtrModal = true
2025-09-01 16:58:54 +08:00
}
}
}
</script>
2025-09-11 19:01:01 +08:00
2025-09-01 16:58:54 +08:00
<style scoped lang="scss">
2025-09-11 19:01:01 +08:00
/* 保持原有样式不变 */
2025-09-01 16:58:54 +08:00
.map {
width: 100%;
height: 100%;
.mapContent{
height:100%;
}
2025-09-01 16:58:54 +08:00
.icon1 {
width: 32px;
height: 80px;
background: url('../../assets/home/homeIcon1.png');
background-size: contain;
background-size: 100% 100%;
background-repeat: no-repeat;
}
.icon {
width: 32px;
height: 80px;
background: url('../../assets/home/homeIcon.png');
background-size: contain;
background-size: 100% 100%;
background-repeat: no-repeat;
}
:deep(.ant-modal-root .ant-modal-mask) {
background-color: #000 !important;
}
:deep(.modal.ant-modal) {
width: 68% !important;
height: 80% !important;
min-width: 1200px !important;
border: none;
padding: 20px;
background-image: url('../../assets/home/modal-bg.png');
background-size: 100% 100%;
background-position: center;
background-repeat: no-repeat;
& > div {
height: 100%;
}
.ant-modal-content {
height: 100%;
width: 96%;
margin: auto;
box-shadow: none;
background: transparent;
.ant-modal-close {
position: absolute;
right: 0;
top: 3px;
}
2025-09-01 16:58:54 +08:00
.ant-modal-body {
height: calc(100% - 45px);
color: #fff;
// padding: 10px;
div > span {
// margin-right: 10px;
}
}
.ant-modal-header {
height: 45px;
position: absolute;
top: -45px;
text-align: center;
width: 96%;
background: transparent;
div {
font-size: 32px;
color: #fff;
}
}
}
}
.modal-content {
height: calc(100% - 45px);
min-height: 700px;
}
.home-modal {
height: 100%;
}
:deep(.tdt-marker-icon){
height:auto!important;
}
2025-09-01 16:58:54 +08:00
}
2025-09-11 19:01:01 +08:00
</style>