Map.vue
3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!--
* @Description:
* @Author: huyue
* @Date: 2023-07-20 10:19:06
* @LastEditors: huyue
* @LastEditTime: 2023-07-26 16:26:03
-->
<template>
<div>
<div id="map" class="map"></div>
</div>
</template>
<script>
import utils from '../../utils/util'
import * as echarts from 'echarts'
import mapBg from '../../assets/images/map-bg.jpg'
export default {
name: 'Map',
props: {
storeDistrictList: Array
},
data() {
return {
myChart: ''
}
},
mounted() {
this.myChart = echarts.init(document.getElementById('map'))
this.chartBindEvent()
},
methods: {
getOptions(data) {
var option = {
tooltip: {
show: true,
borderWidth: 0,
padding: 0,
backgroundColor: '#051526',
formatter: function(params) {
var _html = `<div style="backdrop-filter: blur(4px);background-color: #051526;border: 2px solid;border-image: linear-gradient(90deg, #074989, #30DCFF, #074989) 1;padding: 10px;">
<div style="color: #fff;">${params.name}</div>
<div style="display:flex;"><div style="color: #c9c9c9">客单价:</div><div style="color: #fff;">¥${params.data ? utils.numAddSymbol(params.data.perCusTrans) : 0}</div></div>
<div style="display:flex;"><div style="color: #c9c9c9">转化率:</div><div style="color: #fff;">${params.data ? utils.numAddSymbol(params.data.conversionRate) : 0}%</div></div>
<div style="display:flex;"><div style="color: #c9c9c9">占比:</div><div style="color: #fff;">${params.data ? utils.numAddSymbol(params.data.rate) : 0}%</div></div>
</div>`
return _html
}
},
series: [{
type: 'map',
map: 'china',
data: data,
itemStyle: {
// areaColor: '#061422',
areaColor: {
image: mapBg,
repeat: 'repeat'
},
borderColor: '#65C6F8',
shadowBlur: 10,
shadowColor: 'rgba(61, 87, 255, 0.41)'
},
emphasis: {
label: {
color: '#fff'
},
itemStyle: {
areaColor: {
type: 'linear',
x: 0,
y: 0,
x2: 1,
y2: 0,
colorStops: [{
offset: 0, color: '#079FF1' // 0% 处的颜色
}, {
offset: 1, color: '#6578FF' // 100% 处的颜色
}],
global: false // 缺省为 false
}
},
select: {
areaColor: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [{
offset: 0, color: '#079FF1' // 0% 处的颜色
}, {
offset: 1, color: '#6578FF' // 100% 处的颜色
}],
global: false // 缺省为 false
}
}
}
}]
}
return option
},
drawMap(data) {
this.mapOption = this.getOptions(data)
this.myChart.setOption(this.mapOption)
},
chartBindEvent() {
// resize
window.addEventListener('resize', () => {
this.myChart.resize()
})
}
}
}
</script>
<style lang="scss">
.map {
width: 40.58vw;
height: 45.89vh;
}
</style>