<template> <!-- 监测法 --> <div class="water-analysis-page"> <el-table :key="isFlag" :data="tableData" max-height="500" v-loading="tableLoading" @row-click="clickModal" highlight-current-row ref="tableModal" > <el-table-column type="index" width="55" label="序号" /> <el-table-column :label="i.value" :prop="i.key" show-overflow-tooltip v-for="i in cloums"> <template #default="{ row }" v-if="i.key == 'isStandard'"> <el-tag round :type="row.isStandard === '' ? 'warning' : row.isStandard === '1' ? 'success' : 'error'"> {{ row.isStandard === '' ? '未填报' : row.isStandard === '1' ? '达标' : '未达标' }} </el-tag> </template> </el-table-column> </el-table> </div> </template> <script setup> import { waterLoggingCleanMonitor } from '@/api/spongePerformance/prevention'; const { proxy } = getCurrentInstance(); import { waterloggingPointList } from '@/api/sponeScreen/syntherticData.js'; import bus from '@/utils/mitt'; let isFlag = ref(1); const cloums = ref([ { value: '考核年份', key: 'year' }, { value: '消除个数', key: 'noFloodWaterLoggingPointNum' }, { value: '总数', key: 'waterLoggingPointNum' }, { value: '消除比例%', key: 'noFloodPercent' }, { value: '目标%', key: 'targetPercent' }, { value: '达标情况', key: 'isStandard' }, ]); const { params } = defineProps(['params']); const emits = defineEmits(); const tableModal = ref(null); const floodPointList = ref([]); const waterLoggingData = ref([]); const waterLoggingDataByType = ref([]); //动态组件 let dataForm = reactive({ tableData: '', tableDateTwo: '', tableLoading: true, }); let { date, tableData, tableDateTwo, tableLoading } = toRefs(dataForm); //获取列表数据 //搜索 const search = p => { dynamic_page_data_typeM(p); isFlag.value++; }; defineExpose({ search }); //删除 const dynamic_page_data_typeM = async id => { let { data } = await waterLoggingCleanMonitor(id); tableData.value = data; tableModal.value.setCurrentRow(tableData.value[0], true); //表格默认第一个高亮选中 tableLoading.value = false; addWaterLoggingByType(tableData.value[0].floodPointList); }; //地图添加消除与未消除内涝点 const addWaterLoggingByType = data => { let success_zishuiDate = []; let error_zishuiDate = []; if (data.length) { data.map(item => { item.color = '#d9001b'; item.isClear = false; }); error_zishuiDate = data; waterLoggingData.value.forEach(element => { data.forEach(item => { if (item.name != element.name) { success_zishuiDate.push(element); } }); }); waterLoggingDataByType.value = success_zishuiDate.concat(error_zishuiDate); } else waterLoggingDataByType.value = waterLoggingData.value; let waterLogjson = getWaterloggingGeojson(waterLoggingDataByType.value); if (!newfiberMapbox.map.getLayer('waterLoging')) { addWaterloggingLayer(waterLogjson, 'waterLoging'); } else { newfiberMapbox.map.getSource('waterLoging').setData(waterLogjson); } addwaterlogingPopup(waterLogjson); }; // 监测法表格点击 function clickModal(row) { floodPointList.value = row.floodPointList; // gis渲染点位 addWaterLoggingByType(floodPointList.value); } //获取25个内涝点 const getWaterlogging = async () => { let res = await waterloggingPointList(); if (res && res.code == 200) { waterLoggingData.value = res.data; waterLoggingData.value.forEach(element => { element.color = '#70b603'; element.isClear = true; }); } }; //内涝点geojson const getWaterloggingGeojson = data => { let features = []; data.forEach(element => { let feature = { type: 'Feature', geometry: { type: 'Point', coordinates: [Number(element.longitude), Number(element.latitude)], }, properties: element, }; features.push(feature); }); return { type: 'FeatureCollection', features: features, }; }; //地图渲染内涝点 const addWaterloggingLayer = (geojson, layerName) => { !!!newfiberMapbox.map.getSource(layerName) && newfiberMapbox.map.addSource(layerName, { type: 'geojson', data: geojson }); !!!newfiberMapbox.map.getLayer(layerName) && newfiberMapbox.map.addLayer({ id: layerName, type: 'circle', source: layerName, paint: { 'circle-color': ['get', 'color'], 'circle-radius': 7, }, }); }; //添加弹窗 const addwaterlogingPopup = geojson => { newfiberMapbox.popupService.popups.forEach(popup => { nextTick(() => { newfiberMapbox.removePopup(popup); }); }); geojson.features.forEach(feature => { let popupClass; let htmlText; !!feature.properties.isClear ? (popupClass = 'successPopup') : (popupClass = 'errorPopup'); !!feature.properties.isClear ? (htmlText = ` <div class=${popupClass}><div class='title'>${feature.properties.name}</div> <div class='part'>积水最大时长:${feature.properties.yearMaxHour}h</div> <div class='part'>最大积水深度:${feature.properties.yearMaxDepth}m</div> </div>`) : (htmlText = ` <div class=${popupClass}><div class='title'>${feature.properties.name}</div> <div class='part'>积水最大时长:${feature.properties.yearMaxHour}h</div> <div class='part'>最大积水深度:${feature.properties.yearMaxDepth}m</div> </div>`); return newfiberMapbox.addPopup( new mapboxL7.Popup({ title: '', html: htmlText, lngLat: { lng: feature.geometry.coordinates[0], lat: feature.geometry.coordinates[1], }, anchor: 'center', offsets: [0, 60], autoClose: false, }) ); }); }; onMounted(() => { dynamic_page_data_typeM(params); getWaterlogging(); newfiberMapbox.map.off('click'); newfiberMapbox.map.on('click', e => { let clickfeature = newfiberMapbox.map .queryRenderedFeatures([ [e.point.x - 10 / 2, e.point.y - 10 / 2], [e.point.x + 10 / 2, e.point.y + 10 / 2], ]) .filter(i => i.layer.id == 'waterLoging'); // console.log('clickfeature', '点击事件', clickfeature[0].properties.isFlood); bus.emit('waterLoginclickfeature', clickfeature[0].properties); }); }); onBeforeUnmount(() => { // console.log('newfiberMapbox', newfiberMapbox); if (!!!newfiberMapbox) return; !!newfiberMapbox.map.getLayer('waterLoging') && newfiberMapbox.map.removeLayer('waterLoging'); !!newfiberMapbox.map.getSource('waterLoging') && newfiberMapbox.map.removeSource('waterLoging'); newfiberMapbox.popupService.popups.forEach(popup => { nextTick(() => { newfiberMapbox.removePopup(popup); }); }); }); </script> <style lang="scss" scoped></style>