企业站点

This commit is contained in:
978184212@qq.com 2026-09-10 18:11:45 +08:00
parent 951dcbc568
commit 0ba08dcd55
1 changed files with 583 additions and 369 deletions

View File

@ -1,34 +1,70 @@
<template> <template>
<view class="container"> <view class="container">
<map id="map" ref="map" style="width: 100%; height: calc(100vh + 50rpx);" :scale="mapScale" :markers="markers" <map id="map" ref="map" style="width: 100%; height: calc(100vh + 50rpx);" :scale="mapScale"
:markers="filteredMarkers"
longitude="112.83100231396601" latitude="36.872032399813556" show-location show-compass show-scale longitude="112.83100231396601" latitude="36.872032399813556" show-location show-compass show-scale
@markertap="markertap"> @markertap="markertap">
</map> </map>
<view class="zdxq"> <view class="zdxq">
<view class="zdxqitem" @click="switch2Change('livestock')"> <view class="zdxqitem" :class="{ active: activeType === 'livestock' }" @click="switch2Change('livestock')">
<image src="../../static/zhandian_xuqin_dingwei.png" mode=""></image> <image src="../../static/zhandian_xuqin_dingwei.png" mode=""></image>
<view class="textss"> <view class="textss">
畜禽污染监测站 畜禽污染监测站
</view> </view>
</view> </view>
<view class="zdxqitem" @click="switch2Change('orient')"> <view class="zdxqitem" :class="{ active: activeType === 'orient' }" @click="switch2Change('orient')">
<image src="../../static/zhandian_nongtian_dingwei.png" mode=""></image> <image src="../../static/zhandian_nongtian_dingwei.png" mode=""></image>
<view class="textss"> <view class="textss">
农田污染监测站 农田污染监测站
</view> </view>
</view> </view>
<!-- <view class="zdxqitem" @click="switch2Change('watershed')"> <!-- 企业点位 -->
<image src="../../static/zhandian_xiaoliuyu_dingwei.png" mode=""></image> <view class="zdxqitem" :class="{ active: activeType === 'enterprise' }" @click="switch2Change('enterprise')">
<image src="../../static/qiyebzIcon.png" mode="" style="width: 40rpx; height: 40rpx;"></image>
<view class="textss"> <view class="textss">
小流域监测站 企业点位
</view>
</view>
</view>
<!-- 企业信息弹出框 -->
<view class="enterprise-popup" v-if="showEnterprisePopup" @click="closePopup">
<view class="popup-content" @click.stop>
<view class="popup-header">
<text class="popup-title">{{ currentEnterprise.entName || '企业信息' }}</text>
<text class="popup-close" @click="closePopup">×</text>
</view>
<view class="popup-body">
<view class="info-item">
<text class="label">企业简称</text>
<text class="value">{{ currentEnterprise.entShortName || '-' }}</text>
</view>
<view class="info-item">
<text class="label">负责人</text>
<text class="value">{{ currentEnterprise.entCharge || '-' }}</text>
</view>
<view class="info-item">
<text class="label">统一信用代码</text>
<text class="value">{{ currentEnterprise.entCredit || '-' }}</text>
</view>
<view class="info-item">
<text class="label">企业编号</text>
<text class="value">{{ currentEnterprise.entCode || '-' }}</text>
</view>
<view class="info-item">
<text class="label">企业简介</text>
<text class="value">{{ currentEnterprise.entIntro || '暂无简介' }}</text>
</view>
<view class="info-item">
<text class="label">联系电话</text>
<text class="value">{{ currentEnterprise.entPhone || '暂无' }}</text>
</view>
<view class="info-item">
<text class="label">创建时间</text>
<text class="value">{{ currentEnterprise.createTime || '-' }}</text>
</view> </view>
</view> </view>
<view class="zdxqitem" @click="switch2Change('soil')">
<image src="../../static/iconsheturangzs.png" mode=""></image>
<view class="textss">
长期定位监测点
</view> </view>
</view> -->
</view> </view>
</view> </view>
</template> </template>
@ -54,13 +90,28 @@
soilStationList: [], soilStationList: [],
allStationList: [], allStationList: [],
stationTwoList: [], stationTwoList: [],
mapCtx: null // mapCtx: null,
//
enterpriseList: [],
showEnterprisePopup: false,
currentEnterprise: {},
currentMarkerId: null,
maxMarkerId: 0,
// ''
activeType: ''
}; };
}, },
computed: {
// activeType marker
filteredMarkers() {
if (!this.activeType) {
return this.markers;
}
return this.markers.filter(item => item.stationType === this.activeType);
}
},
onLoad() {}, onLoad() {},
onReady() { onReady() {
// onReady
this.mapCtx = uni.createMapContext('map', this); this.mapCtx = uni.createMapContext('map', this);
}, },
onShow() { onShow() {
@ -75,7 +126,6 @@
}) })
}, },
methods: { methods: {
// kaihs
getList() { getList() {
this.markers = [] this.markers = []
this.stationList = [] this.stationList = []
@ -83,13 +133,16 @@
this.soilStationList = [] this.soilStationList = []
this.allStationList = [] this.allStationList = []
this.stationTwoList = [] this.stationTwoList = []
this.enterpriseList = []
this.maxMarkerId = 0
this.activeType = ''
uni.showLoading({ uni.showLoading({
title: '加载中' title: '加载中'
}); });
//
this.$http.get('/applet/survStationInfo/stationMap').then(res => { this.$http.get('/applet/survStationInfo/stationMap').then(res => {
//
this.stationList = [...res.data.data.stationInfo]; this.stationList = [...res.data.data.stationInfo];
this.cusLocationList = [...res.data.data.cusLocation]; this.cusLocationList = [...res.data.data.cusLocation];
this.soilStationList = [...res.data.data.deviceList]; this.soilStationList = [...res.data.data.deviceList];
@ -97,13 +150,16 @@
this.allStationList.push(...this.cusLocationList); this.allStationList.push(...this.cusLocationList);
this.allStationList.push(...this.soilStationList); this.allStationList.push(...this.soilStationList);
this.allStationList.forEach((item, index) => { this.allStationList.forEach((item, index) => {
item.id = index; item.id = index + 1;
}); });
this.issscd = false this.issscd = false
this.isssscd = false this.isssscd = false
this.isSoilShow = false this.isSoilShow = false
// id marker
this.maxMarkerId = this.allStationList.length + 1;
// //
this.enterpriseRender(); this.enterpriseRender();
this.stationRender(); this.stationRender();
@ -121,14 +177,97 @@
}); });
console.error('加载地图数据失败:', err); console.error('加载地图数据失败:', err);
}) })
//
this.$http.get('/applet/wxclient/getEntList').then(res => {
if (res.data.data && res.data.data.result) {
this.enterpriseList = res.data.data.result;
this.renderEnterpriseMarkers();
this.$nextTick(() => {
this.ensureAllMarkersVisible();
});
}
uni.hideLoading();
}).catch(err => {
uni.hideLoading();
uni.showToast({
title: '企业数据加载失败',
icon: 'none'
});
console.error('加载企业数据失败:', err);
})
}, },
//
renderEnterpriseMarkers() {
if (!this.enterpriseList || this.enterpriseList.length === 0) {
console.warn('企业列表为空');
return;
}
//
const validEnterpriseList = this.enterpriseList.filter((item) => {
const lat = Number(item.entLat);
const lng = Number(item.entLong);
return !isNaN(lat) && !isNaN(lng) && lat !== 0 && lng !== 0;
});
const invalidCount = this.enterpriseList.length - validEnterpriseList.length;
if (invalidCount > 0) {
console.log(`已过滤 ${invalidCount} 个缺少坐标的企业`);
}
validEnterpriseList.forEach((item) => {
const lat = Number(item.entLat);
const lng = Number(item.entLong);
const markerId = ++this.maxMarkerId;
let iconPath = '/static/qiyebzIcon.png';
if (item.entMapIcon) {
iconPath = this.baseUrl.replace(/\/$/, '') + '/' + item.entMapIcon.replace(/^\//, '');
}
const markerItem = {
id: markerId,
iconPath: iconPath,
latitude: lat,
longitude: lng,
width: 40,
height: 50,
stationType: 'enterprise',
stationName: item.entName,
entShortName: item.entShortName,
entCharge: item.entCharge,
entCredit: item.entCredit,
entCode: item.entCode,
entIntro: item.entIntro,
entPhone: item.entPhone,
createTime: item.createTime,
entId: item.id,
joinCluster: false,
zIndex: this.markersZIndex++,
enterpriseData: item,
callout: {
content: item.entName || '企业',
color: '#FFFFFF',
fontSize: 14,
borderRadius: 10,
bgColor: '#007AFF',
padding: 8,
display: 'ALWAYS'
}
};
this.markers.push(markerItem);
});
},
ensureAllMarkersVisible() { ensureAllMarkersVisible() {
//
if (!this.mapCtx) { if (!this.mapCtx) {
this.mapCtx = uni.createMapContext('map', this); this.mapCtx = uni.createMapContext('map', this);
} }
//
const validPoints = this.markers const validPoints = this.markers
.filter(item => { .filter(item => {
const lat = Number(item.latitude); const lat = Number(item.latitude);
@ -142,7 +281,6 @@
if (validPoints.length === 0) { if (validPoints.length === 0) {
console.warn('没有有效的坐标点'); console.warn('没有有效的坐标点');
// 使
if (this.center.latitude && this.center.longitude) { if (this.center.latitude && this.center.longitude) {
this.mapCtx.moveToLocation({ this.mapCtx.moveToLocation({
latitude: this.center.latitude, latitude: this.center.latitude,
@ -155,17 +293,15 @@
console.log('有效坐标点数量:', validPoints.length); console.log('有效坐标点数量:', validPoints.length);
// 1使 includePoints
try { try {
this.mapCtx.includePoints({ this.mapCtx.includePoints({
points: validPoints, points: validPoints,
padding: [120, 120, 120, 120], // padding: [120, 120, 120, 120],
success: () => { success: () => {
console.log('地图视野调整成功'); console.log('地图视野调整成功');
}, },
fail: (err) => { fail: (err) => {
console.error('includePoints失败:', err); console.error('includePoints失败:', err);
// 使
this.fallbackAdjustMap(validPoints); this.fallbackAdjustMap(validPoints);
} }
}); });
@ -174,7 +310,6 @@
this.fallbackAdjustMap(validPoints); this.fallbackAdjustMap(validPoints);
} }
// 2
setTimeout(() => { setTimeout(() => {
if (this.mapCtx) { if (this.mapCtx) {
try { try {
@ -188,7 +323,6 @@
} }
}, 500); }, 500);
// 3
setTimeout(() => { setTimeout(() => {
if (this.mapCtx) { if (this.mapCtx) {
try { try {
@ -202,11 +336,11 @@
} }
}, 1000); }, 1000);
}, },
fallbackAdjustMap(validPoints) { fallbackAdjustMap(validPoints) {
if (!validPoints || validPoints.length === 0) return; if (!validPoints || validPoints.length === 0) return;
try { try {
//
const lats = validPoints.map(p => p.latitude); const lats = validPoints.map(p => p.latitude);
const lngs = validPoints.map(p => p.longitude); const lngs = validPoints.map(p => p.longitude);
@ -215,11 +349,9 @@
const minLng = Math.min(...lngs); const minLng = Math.min(...lngs);
const maxLng = Math.max(...lngs); const maxLng = Math.max(...lngs);
//
const centerLat = (minLat + maxLat) / 2; const centerLat = (minLat + maxLat) / 2;
const centerLng = (minLng + maxLng) / 2; const centerLng = (minLng + maxLng) / 2;
//
const latDiff = maxLat - minLat; const latDiff = maxLat - minLat;
const lngDiff = maxLng - minLng; const lngDiff = maxLng - minLng;
const maxDiff = Math.max(latDiff, lngDiff); const maxDiff = Math.max(latDiff, lngDiff);
@ -234,7 +366,6 @@
console.log('备用方案 - 中心点:', centerLat, centerLng, '缩放:', scale); console.log('备用方案 - 中心点:', centerLat, centerLng, '缩放:', scale);
//
this.mapCtx.moveToLocation({ this.mapCtx.moveToLocation({
latitude: centerLat, latitude: centerLat,
longitude: centerLng, longitude: centerLng,
@ -244,13 +375,13 @@
console.error('备用方案失败:', e); console.error('备用方案失败:', e);
} }
}, },
enterpriseRender() { enterpriseRender() {
for (let i = 0; i < this.cusLocationList.length; i++) { for (let i = 0; i < this.cusLocationList.length; i++) {
const item = this.cusLocationList[i]; const item = this.cusLocationList[i];
const lat = Number(item.stationLatitude); const lat = Number(item.stationLatitude);
const lng = Number(item.stationLongitude); const lng = Number(item.stationLongitude);
//
if (isNaN(lat) || isNaN(lng) || lat === 0 || lng === 0) { if (isNaN(lat) || isNaN(lng) || lat === 0 || lng === 0) {
console.warn('企业点位坐标无效:', item.stationName, lat, lng); console.warn('企业点位坐标无效:', item.stationName, lat, lng);
continue; continue;
@ -285,7 +416,6 @@
const lat = Number(item.stationLatitude); const lat = Number(item.stationLatitude);
const lng = Number(item.stationLongitude); const lng = Number(item.stationLongitude);
//
if (isNaN(lat) || isNaN(lng) || lat === 0 || lng === 0) { if (isNaN(lat) || isNaN(lng) || lat === 0 || lng === 0) {
console.warn('站房点位坐标无效:', item.stationName, lat, lng); console.warn('站房点位坐标无效:', item.stationName, lat, lng);
continue; continue;
@ -319,7 +449,6 @@
const lat = Number(item.latitude); const lat = Number(item.latitude);
const lng = Number(item.longitude); const lng = Number(item.longitude);
//
if (isNaN(lat) || isNaN(lng) || lat === 0 || lng === 0) { if (isNaN(lat) || isNaN(lng) || lat === 0 || lng === 0) {
console.warn('监测点位坐标无效:', item.name, lat, lng); console.warn('监测点位坐标无效:', item.name, lat, lng);
return; return;
@ -366,10 +495,35 @@
this.markers.push(markerItem); this.markers.push(markerItem);
}); });
}, },
markertap(e) { markertap(e) {
const index = e.detail.markerId const index = e.detail.markerId;
const marker = this.markers.find(m => m.id === index); const marker = this.markers.find(m => Number(m.id) === Number(index));
if (marker) {
if (!marker) {
console.warn('未找到对应的marker, ID:', index);
return;
}
// ->
if (marker.stationType === 'enterprise') {
this.currentEnterprise = marker.enterpriseData || {
entName: marker.stationName || '企业名称',
entShortName: marker.entShortName || '',
entCharge: marker.entCharge || '',
entCredit: marker.entCredit || '',
entCode: marker.entCode || '',
entIntro: marker.entIntro || '暂无简介',
entPhone: marker.entPhone || '暂无',
createTime: marker.createTime || ''
};
this.currentMarkerId = marker.id;
this.showEnterprisePopup = true;
return;
}
//
if (['orient', 'livestock'].includes(marker.stationType)) { if (['orient', 'livestock'].includes(marker.stationType)) {
uni.navigateTo({ uni.navigateTo({
url: `/packDetail/pages/Site/detail?item=${encodeURIComponent(JSON.stringify(marker))}` url: `/packDetail/pages/Site/detail?item=${encodeURIComponent(JSON.stringify(marker))}`
@ -379,80 +533,63 @@
url: `/packDetail/pages/vidio/soilindex` url: `/packDetail/pages/vidio/soilindex`
}) })
} }
}
}, },
switch2Change(name) { //
//
let that = this;
if (name === that.lastTap) {
that.adjustMapToFitAllMarkers();
that.lastTap = '';
} else {
//
that.adjustMapToRegion(name);
that.lastTap = name;
} //
closePopup() {
this.showEnterprisePopup = false;
this.currentEnterprise = {};
this.currentMarkerId = null;
}, },
// setFitView
adjustMapToFitAllMarkers() { //
if (this.mapCtx && this.markers.length > 0) { switch2Change(name) {
this.mapCtx.includePoints({ if (this.activeType === name) {
points: this.markers.map(item => ({ //
latitude: item.latitude, this.activeType = '';
longitude: item.longitude } else {
})), //
padding: [60, 60, 60, 60] // this.activeType = name;
});
} }
// marker
this.$nextTick(() => {
this.adjustMapToVisibleMarkers();
});
}, },
adjustMapToRegion(regionName) {
// // marker
//stationType: "orient" adjustMapToVisibleMarkers() {
//stationType: "livestock" const list = this.filteredMarkers;
//stationType: "watershed" if (!list || list.length === 0) {
let that = this; return;
let points = [];
let markers = [];
if (regionName === 'orient' || regionName === 'livestock' || regionName === 'watershed') {
//
markers = this.markers.filter(item => item.stationType === regionName);
} else if (regionName === 'soil') {
//
markers = this.markers.filter(item => item.type === 'soil' || item.deviceType === 'soil');
} }
console.log(this.markers)
if (markers.length > 0) { const points = list
points = markers.map(item => { .filter(item => {
item.zIndex = (that.markersZIndex++); const lat = Number(item.latitude);
return { const lng = Number(item.longitude);
latitude: Number(item.latitude || item.stationLatitude), return !isNaN(lat) && !isNaN(lng) && lat !== 0 && lng !== 0;
longitude: Number(item.longitude || item.stationLongitude) })
} .map(item => ({
}); latitude: Number(item.latitude),
} longitude: Number(item.longitude)
if (points.length > 0 && this.mapCtx) { }));
if (points.length === 0 || !this.mapCtx) return;
this.mapCtx.includePoints({ this.mapCtx.includePoints({
points: points, points: points,
padding: [80, 110, 80, 110] // padding: [100, 100, 100, 100]
}); });
} else if (points.length === 0) {
//
// uni.showToast({
// title: `${regionName}`,
// icon: 'none'
// });
} }
},
} }
} }
</script> </script>
<style lang="scss"> <style lang="scss">
/* 样式保持不变 */
.bgimg { .bgimg {
position: fixed; position: fixed;
// z-index: -99;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
@ -466,7 +603,6 @@
font-size: 24rpx; font-size: 24rpx;
text-shadow: 1rpx 2rpx 0rpx #0D1934; text-shadow: 1rpx 2rpx 0rpx #0D1934;
font-weight: bold; font-weight: bold;
// background-image: url('@/static/zhandian_icon_nongtian_title.png');
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 100%; background-size: 100%;
display: flex; display: flex;
@ -481,7 +617,6 @@
font-size: 24rpx; font-size: 24rpx;
text-shadow: 1rpx 2rpx 0rpx #0D1934; text-shadow: 1rpx 2rpx 0rpx #0D1934;
font-weight: bold; font-weight: bold;
// background-image: url('@/static/zhandian_icon_xuqin_title.png');
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 100%; background-size: 100%;
display: flex; display: flex;
@ -511,6 +646,14 @@
border-radius: 6rpx; border-radius: 6rpx;
margin-bottom: 10rpx; margin-bottom: 10rpx;
position: relative; position: relative;
transition: all 0.2s ease;
}
/* 选中高亮 */
.zdxqitem.active {
background: rgba(0, 122, 255, 0.75);
border-color: #007AFF;
box-shadow: 0 0 12rpx rgba(0, 122, 255, 0.6);
} }
.crildon { .crildon {
@ -555,4 +698,75 @@
display: flex; display: flex;
align-items: center; align-items: center;
} }
/* 企业信息弹窗样式 */
.enterprise-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
}
.popup-content {
width: 600rpx;
max-height: 70vh;
background: #FFFFFF;
border-radius: 20rpx;
overflow: hidden;
display: flex;
flex-direction: column;
}
.popup-header {
padding: 30rpx 30rpx 20rpx;
border-bottom: 1px solid #eee;
display: flex;
justify-content: space-between;
align-items: center;
}
.popup-title {
font-size: 34rpx;
font-weight: bold;
color: #333;
flex: 1;
}
.popup-close {
font-size: 48rpx;
color: #999;
padding: 0 10rpx;
cursor: pointer;
}
.popup-body {
padding: 20rpx 30rpx;
overflow-y: auto;
flex: 1;
}
.info-item {
display: flex;
padding: 12rpx 0;
font-size: 28rpx;
border-bottom: 1px solid #f5f5f5;
}
.info-item .label {
color: #666;
width: 160rpx;
flex-shrink: 0;
}
.info-item .value {
color: #333;
flex: 1;
word-break: break-all;
}
</style> </style>