Browse Source

docs:首页模块

master
waibao2 2 months ago
parent
commit
0878c53809
  1. 80
      src/views/index.vue

80
src/views/index.vue

@ -4,13 +4,11 @@
<div id="mapContainer" class="map" style="height: calc(100vh - 50px);"> <div id="mapContainer" class="map" style="height: calc(100vh - 50px);">
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script setup name="Index"> <script setup name="Index">
import { onMounted, ref, reactive, nextTick } from "vue"; import { onMounted, ref, reactive, nextTick, onUnmounted } from "vue";
import _ from "lodash"; import _ from "lodash";
import L from 'leaflet' import L from 'leaflet'
import dayjs from 'dayjs' import dayjs from 'dayjs'
@ -19,7 +17,6 @@
const { proxy } = getCurrentInstance() const { proxy } = getCurrentInstance()
import qtGeojsonData from '@/assets/data/qingtian.json' import qtGeojsonData from '@/assets/data/qingtian.json'
const tdtKey = 'e0d855b509f09b891605c4dc5f29868b' const tdtKey = 'e0d855b509f09b891605c4dc5f29868b'
@ -84,7 +81,6 @@
const TownGov = [28.205423, 120.165288] // const TownGov = [28.205423, 120.165288] //
const initMap = () => { const initMap = () => {
// //
const defaultBase = '影像' const defaultBase = '影像'
tiandituMap = L.map('mapContainer', { tiandituMap = L.map('mapContainer', {
@ -153,6 +149,7 @@
// //
maskLayer.bringToFront(); maskLayer.bringToFront();
}; };
let MapData = [] let MapData = []
// //
const getIndexData = async () => { const getIndexData = async () => {
@ -162,7 +159,7 @@
if (res.code == 0) { if (res.code == 0) {
let rawData = res.data let rawData = res.data
rawData = _.filter(rawData, function (o) { rawData = _.filter(rawData, function (o) {
return !o.longitude == "" || !o.latitude == ''; return o.longitude !== "" && o.latitude !== "";
}); });
MapData = _.map(rawData, item => { MapData = _.map(rawData, item => {
item.position_xy = [item.latitude, item.longitude] item.position_xy = [item.latitude, item.longitude]
@ -178,12 +175,12 @@
addMarkers() addMarkers()
} }
} catch (error) { } catch (error) {
console.error(error)
} finally { } finally {
mapLoading.value = false mapLoading.value = false
} }
}; };
let dialogVisible = ref(false) // let dialogVisible = ref(false) //
let popupData = ref([]) let popupData = ref([])
let pinMarkers = []; // marker let pinMarkers = []; // marker
@ -191,6 +188,35 @@
let autoPlayInterval = null; // let autoPlayInterval = null; //
let isPaused = false; // let isPaused = false; //
let currentPopup = null; // let currentPopup = null; //
//
const showMarkerPopup = (e) => {
popupData.value = e.target.options;
const popupContent = `
<div style="color: white; padding: 10px; font-size: 14px;">
<h3 style="margin-top: 0;">${popupData.value.stnm}</h3>
<table class='dialog-table' style="width: 100%; border-collapse: collapse;">
${popupData.value.data ? popupData.value.data.map(row => `
<tr>
<td style="padding: 5px; width: 50%;">${row.name}${row.unit ? `${row.unit}` : ''}</td>
<td style="padding: 5px; width: 50%;">${row.value || row.latestValue || ''}</td>
</tr>
`).join('') : ''}
</table>
</div>
`;
// popup
if (currentPopup) {
tiandituMap.closePopup(currentPopup);
}
currentPopup = L.popup()
.setLatLng(e.target._latlng)
.setContent(popupContent)
.openOn(tiandituMap);
};
// //
const startAutoPlay = () => { const startAutoPlay = () => {
if (autoPlayInterval) { if (autoPlayInterval) {
@ -234,7 +260,7 @@
// //
pinMarkers.forEach(m => tiandituMap.removeLayer(m)); pinMarkers.forEach(m => tiandituMap.removeLayer(m));
pinMarkers = []; pinMarkers = [];
MapData.forEach(item => { MapData.forEach((item, index) => {
let marker; let marker;
const markerIcon = L.icon({ const markerIcon = L.icon({
iconUrl: item.icon || rain0, iconUrl: item.icon || rain0,
@ -265,6 +291,7 @@
}); });
marker.on('click', (e) => { marker.on('click', (e) => {
currentIndex = index; //
showMarkerPopup(e); showMarkerPopup(e);
}); });
pinMarkers.push(marker); pinMarkers.push(marker);
@ -280,7 +307,6 @@
firstMarker.fire('click'); firstMarker.fire('click');
} }
// //
/**************************** CodeGeeX Inline Diff ****************************/
startAutoPlay(); startAutoPlay();
} }
}, 1000); }, 1000);
@ -290,41 +316,19 @@
if (currentPopup) { if (currentPopup) {
tiandituMap.closePopup(currentPopup); tiandituMap.closePopup(currentPopup);
} }
// })
const showMarkerPopup = (e) => { }
/******************** 49ec4b3d-3bf0-41fc-a821-48f719365cbd ********************/
popupData.value = e.target.options;
const popupContent = `
<div style="color: white; padding: 10px; font-size: 14px;">
<h3 style="margin-top: 0;">${popupData.value.stnm}</h3>
<table class='dialog-table' style="width: 100%; border-collapse: collapse;">
${popupData.value.data.map(row => `
<tr>
<td style="padding: 5px; width: 50%;">${row.name}${row.unit ? `${row.unit}` : ''}</td>
<td style="padding: 5px; width: 50%;">${row.value || row.latestValue}</td>
</tr>
`).join('')}
</table>
</div>
`;
// popup
currentPopup = L.popup()
.setLatLng(e.target._latlng)
.setContent(popupContent)
.openOn(tiandituMap);
};
/*********************************************************** 弹窗 *****************************************/
onMounted(() => { onMounted(() => {
initMap() initMap()
}) })
// //
onUnmounted(() => { onUnmounted(() => {
if (autoPlayInterval) { if (autoPlayInterval) {
clearInterval(autoPlayInterval); clearInterval(autoPlayInterval);
} }
}); })
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@ -343,8 +347,6 @@
} }
} }
.el-table, .el-table,
.el-table__expanded-cell, .el-table__expanded-cell,
.el-table tr, .el-table tr,
@ -375,8 +377,6 @@
color: skyblue; color: skyblue;
} }
} }
} }
/* 隐藏popup的关闭按钮 */ /* 隐藏popup的关闭按钮 */

Loading…
Cancel
Save