农产品溯源地图

This commit is contained in:
13713575202 2025-04-30 15:32:56 +08:00
parent 28ea06f411
commit fa5993c982
3 changed files with 115 additions and 54 deletions

View File

@ -47,8 +47,6 @@ export default {
const option = reactive({}); const option = reactive({});
watchEffect(() => { watchEffect(() => {
regMap(props.name, props.geo);
console.info('watchEffect');
props.chartData && initCharts(); props.chartData && initCharts();
}); });
@ -66,8 +64,9 @@ export default {
if (props.option) { if (props.option) {
Object.assign(option, cloneDeep(props.option)); Object.assign(option, cloneDeep(props.option));
} }
setOptions(option);
setOptions(option);
regMap(props.name, props.geo);
onMapClick((data) => { onMapClick((data) => {
emit('click', data); emit('click', data);
}); });

View File

@ -1,15 +1,26 @@
<template> <template>
<section ref="chartRef" class="_container"></section> <div class="map-center-warp">
<div class="map-pos">
<custom-echart-maps height="100%" width="100%" :option="chartsData.option" :geo="geoData" :name="mapName" @click="mapClick" />
</div>
</div>
</template> </template>
<script setup> <script setup>
import { ref, onMounted } from 'vue'; import { isEmpty, getAssetsFile } from '@/utils';
import { useEcharts } from '@/hooks/useEcharts'; import { ref, reactive, onMounted, computed } from 'vue';
import { useRoute } from 'vue-router';
import geoJsonData from './china.json'; // ;
const route = useRoute();
const props = defineProps({
dialogTitle: {
type: String,
default: '首页',
},
});
const isShow = ref(false);
let geoData = geoJsonData;
let mapName = ref('china');
onMounted(() => loadMapChart());
const chartRef = ref(null);
const { setOptions, getInstance, startAutoPlay } = useEcharts(chartRef);
const chinaGeoCoordMap = ref({ const chinaGeoCoordMap = ref({
云南: [102.9199, 25.4663], 云南: [102.9199, 25.4663],
广东: [113.12244, 23.009505], 广东: [113.12244, 23.009505],
@ -24,7 +35,7 @@ const chinaDatas = ref([
[{ name: '四川', value: 1256 }], [{ name: '四川', value: 1256 }],
[{ name: '河北', value: 382 }], [{ name: '河北', value: 382 }],
]); ]);
function convertData(data) { const convertData = (data) => {
var res = []; var res = [];
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
var dataItem = data[i]; var dataItem = data[i];
@ -43,8 +54,8 @@ function convertData(data) {
} }
} }
return res; return res;
} };
function getSeries() { const getSeries = () => {
let list = []; let list = [];
[['云南', chinaDatas.value]].forEach(function (item, i) { [['云南', chinaDatas.value]].forEach(function (item, i) {
list.push( list.push(
@ -147,9 +158,10 @@ function getSeries() {
); );
}); });
return list; return list;
} };
async function loadMapChart() {
var option = { const chartsData = reactive({
option: {
title: { title: {
text: '地图统计图表', text: '地图统计图表',
subtext: '', subtext: '',
@ -177,7 +189,6 @@ async function loadMapChart() {
transitionDuration: 0, transitionDuration: 0,
extraCssText: 'z-index:100', extraCssText: 'z-index:100',
formatter: function (params, ticket, callback) { formatter: function (params, ticket, callback) {
console.log('params', params);
let val = 0; let val = 0;
if (typeof params.value == 'number') { if (typeof params.value == 'number') {
val = params.value; val = params.value;
@ -187,7 +198,6 @@ async function loadMapChart() {
// //
var res = ''; var res = '';
var name = params.name; var name = params.name;
res = "<span style='color:#fff;'>" + name + '</span><br/>数据:' + val; res = "<span style='color:#fff;'>" + name + '</span><br/>数据:' + val;
return res; return res;
}, },
@ -205,7 +215,7 @@ async function loadMapChart() {
}, },
}, },
geo: { geo: {
map: 'china', map: mapName.value,
zoom: 1.2, zoom: 1.2,
top: 250, top: 250,
label: { label: {
@ -226,40 +236,92 @@ async function loadMapChart() {
}, },
}, },
series: getSeries(), series: getSeries(),
}; },
// const { rows } = await selectRecord(this.baseId); });
// //
// // option.series[0].data = rows.map((item) => ({
// // name: item.queryCity,
// // value: [item.queryCoordinate.split(',')[0], item.queryCoordinate.split(',')[1], item.queryCount],
// // }));
// //
// let i = 956;
// rows.forEach((item) => {
// i += item.queryCount;
// });
// option.title.subtext = `${rows.length}${i}`;
option.title.subtext = `我们的产品走过了18个城市被客户查询了73812次`;
// this.$echarts.registerMap('china', { geoJSON: chinaMap });
// myChart.on('click', (params) => {
// if (params.name.includes('广')) {
// this.$emit('dataType', '2');
// } else if (params.name.includes('')) {
// this.$emit('dataType', '1');
// } else {
// this.$emit('dataType', '0');
// }
// });
console.log('option', option);
setOptions(option);
}
</script>
let currentMap = reactive({});
const mapClick = (data) => {
// if (props.markerData.length && props.markerData.length > 0) {
// if (data.seriesType == 'effectScatter') {
// isShow.value = true;
// currentMap = data;
// emit('mapclick', currentMap);
// }
// } else {
// isShow.value = true;
// currentMap = data;
// emit('mapclick', currentMap);
// }
};
const handleClose = () => {
isShow.value = false;
};
const emit = defineEmits(['mapclick']);
</script>
<style lang="scss" scoped> <style lang="scss" scoped>
._container { div {
padding: 40px; box-sizing: border-box;
}
::v-deep() {
.el-dialog {
background: url(iconUrl) no-repeat left top;
background-repeat: no-repeat;
background-size: cover;
border-radius: 8px !important;
min-height: 200px;
max-height: 500px;
overflow-y: auto;
background-size: 100% 100%;
padding: 16px;
margin-top: 15%;
}
.el-dialog__header {
margin-top: 10px;
text-align: left;
padding-left: 48px;
.el-dialog__title,
i {
color: #fff !important;
}
.el-dialog__headerbtn {
top: 8px !important;
}
}
.map-dialog-my-header {
margin-top: 4px;
display: inline-flex;
justify-content: space-between;
h4 {
font-weight: normal !important;
}
}
}
.map-center-warp {
width: 100%;
text-align: center;
position: relative;
height: 90%;
.map-img {
width: 80%;
height: 80%;
position: absolute;
bottom: 0;
left: 50%;
object-fit: contain;
transform: translateX(-50%);
max-width: 1000px;
max-height: 1000px;
}
.map-pos {
width: 100%; width: 100%;
height: 100%; height: 100%;
border: 1px solid red; position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
} }
</style> </style>

View File

@ -25,7 +25,7 @@
</div> </div>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<centerMap /> <traceMap></traceMap>
</el-col> </el-col>
<el-col :span="6" class="right-charts"> <el-col :span="6" class="right-charts">
<div class="right-charts-item"> <div class="right-charts-item">
@ -55,7 +55,7 @@
</template> </template>
<script setup> <script setup>
import { ref } from 'vue'; import { ref } from 'vue';
import centerMap from './components/centerMap.vue'; import traceMap from './components/traceMap.vue';
import codeNumCharts from './components/codeNumCharts.vue'; import codeNumCharts from './components/codeNumCharts.vue';
import mainPartCharts from './components/mainPartCharts.vue'; import mainPartCharts from './components/mainPartCharts.vue';
import principalTypeCharts from './components/principalTypeCharts.vue'; import principalTypeCharts from './components/principalTypeCharts.vue';