Map.vue
5.54 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!--
* @Description:
* @Author: huyue
* @Date: 2023-07-20 10:19:06
* @LastEditors: huyue
* @LastEditTime: 2023-08-23 16:15:25
-->
<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,
label: {
normal: {
color: '#ffffff'
},
emphasis: {
color: '#ffffff'
}
},
itemStyle: {
color: '#ffffff',
// areaColor: '#061422',
areaColor: {
image: mapBg,
repeat: 'repeat'
},
borderColor: '#65C6F8',
shadowBlur: 10,
shadowColor: 'rgba(61, 87, 255, 0.41)',
emphasis: {
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: {
itemStyle: {
// color: this.clickcolor, // 设置地图点击后的颜色
color: '#ffffff', // 设置地图点击后的颜色
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
}
}
},
}]
}
return option
},
drawMap(data) {
this.mapOption = this.getOptions(data)
this.myChart.setOption(this.mapOption)
this.selectEvent()
this.myChart.dispatchAction({
type: 'showTip',
seriesIndex: 0,
dataIndex: 0
})
// 取消高亮指定的数据图形
this.myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: 0
})
this.myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: 0
})
},
selectEvent() {
const myChart = this.myChart
this.myChart.on('click', function(e) {
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0
})
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: e.dataIndex
})
myChart.dispatchAction({
type: 'showTip',
seriesIndex: 1,
dataIndex: e.dataIndex
})
})
this.myChart.on('mousemove', function(e) {
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0
})
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: e.dataIndex
})
myChart.dispatchAction({
type: 'showTip',
seriesIndex: 1,
dataIndex: e.dataIndex
})
})
this.myChart.on('mouseout', function (e) {
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0
})
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: e.dataIndex
})
myChart.dispatchAction({
type: 'showTip',
seriesIndex: 1,
dataIndex: e.dataIndex
})
})
},
chartBindEvent() {
// resize
window.addEventListener('resize', () => {
this.myChart.resize()
})
}
}
}
</script>
<style lang="scss">
.map {
width: 40.58vw;
height: 45.89vh;
}
</style>