index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <div
  3. style="width: 100%; height: 100%"
  4. class="bs-design-wrap bs-bar"
  5. >
  6. <el-button class="button" v-if="this.level=='province'&&config.customize.down" @click="jumpTo(config)" type='text' > 返回上一级</el-button>
  7. <div
  8. :id="`chart${config.code}`"
  9. style="width: 100%; height: 100%"
  10. />
  11. </div>
  12. </template>
  13. <script>
  14. import 'insert-css'
  15. import * as echarts from 'echarts'
  16. import {nameMap} from './json/mapData.js'
  17. import commonMixins from 'data-room-ui/js/mixins/commonMixins.js'
  18. import paramsMixins from 'data-room-ui/js/mixins/paramsMixins'
  19. import linkageMixins from 'data-room-ui/js/mixins/linkageMixins'
  20. export default {
  21. name: 'MapCharts',
  22. mixins: [paramsMixins, commonMixins, linkageMixins],
  23. props: {
  24. id: {
  25. type: String,
  26. default: ''
  27. },
  28. config: {
  29. type: Object,
  30. default: () => ({})
  31. }
  32. },
  33. data () {
  34. return {
  35. charts: null,
  36. hasData: false,
  37. level:'',
  38. option:{}
  39. }
  40. },
  41. computed: {
  42. Data () {
  43. return JSON.parse(JSON.stringify(this.config))
  44. }
  45. },
  46. watch: {
  47. Data: {
  48. handler (newVal, oldVal) {
  49. if (newVal.w !== oldVal.w || newVal.h !== oldVal.h) {
  50. this.$nextTick(() => {
  51. this.charts.resize()
  52. })
  53. }
  54. },
  55. deep: true
  56. }
  57. },
  58. mounted () {
  59. this.chartInit()
  60. },
  61. beforeDestroy () {
  62. this.charts?.clear()
  63. },
  64. methods: {
  65. chartInit () {
  66. const config = this.config
  67. // key和code相等,说明是一进来刷新,调用list接口
  68. if (this.config.code === this.config.key || this.isPreview) {
  69. // 改变数据
  70. this.changeDataByCode(config).then((res) => {
  71. // 改变样式
  72. // config = this.changeStyle(res)
  73. this.newChart(config)
  74. }).catch(() => {})
  75. } else {
  76. // 否则说明是更新,这里的更新只指更新数据(改变样式时是直接调取changeStyle方法),因为更新数据会改变key,调用chart接口
  77. this.changeData(config).then((res) => {
  78. // 初始化图表
  79. this.newChart(res)
  80. })
  81. }
  82. },
  83. dataFormatting (config, data) {
  84. config.option = {
  85. ...config.option,
  86. data: data?.data
  87. }
  88. return config
  89. },
  90. async jumpTo(config){
  91. this.level='country'
  92. const mapUrl =`${window.BS_CONFIG?.httpConfigs?.baseURL}/static/chinaMap/country/中华人民共和国.json`
  93. const map = await this.$dataRoomAxios.get(decodeURI(mapUrl), {}, true)
  94. this.option.geo.map = '中华人民共和国';
  95. this.changeData({...config,customize:{...config.customize,level:'country',scope:'中国'}})
  96. echarts.registerMap('中华人民共和国', map);
  97. this.charts.setOption(this.option, true);
  98. },
  99. async newChart (config) {
  100. this.charts = echarts.init(
  101. document.getElementById(`chart${this.config.code}`)
  102. )
  103. this.level=config.customize.level
  104. const lines_coord = []
  105. let fromCoord=[]
  106. let coord=[]
  107. const mapUrl =config.customize.level==='world'?`${window.BS_CONFIG?.httpConfigs?.baseURL}/static/worldMap/world.json`:`${window.BS_CONFIG?.httpConfigs?.baseURL}/static/chinaMap/${config.customize.level}/${config.customize.dataMap}`
  108. this.$dataRoomAxios.get(decodeURI(mapUrl), {}, true).then(res=>{
  109. this.config.option.data.forEach(val => {
  110. lines_coord.push({value:val.value,msg:{...val}, coords:[[val.lat1,val.lng1],[val.lat2,val.lng2]]})
  111. if(val.type==='move_in'){
  112. coord.push({name:val.from,value:[val.lat1,val.lng1,val.value],msg:{...val}})
  113. fromCoord.push({name:val.to,value:[val.lat2,val.lng2,val.value],msg:{...val}})
  114. }else{
  115. coord.push({name:val.to,value:[val.lat2,val.lng2,val.value],msg:{...val}})
  116. fromCoord.push({name:val.from,value:[val.lat1,val.lng1,val.value],msg:{...val}})
  117. }
  118. })
  119. echarts.registerMap(config.customize.scope, res)
  120. this.option = {
  121. nameMap:config.customize.level=='world'?nameMap:'',
  122. // graphic: [
  123. // ],
  124. geo: {
  125. map: config.customize.scope,
  126. zlevel: 10,
  127. show:true,
  128. layoutCenter: ['50%', '50%'],
  129. roam: true,
  130. layoutSize: "100%",
  131. zoom: 1,
  132. label: {
  133. // 通常状态下的样式
  134. normal: {
  135. show: config.customize.mapName,
  136. textStyle: {
  137. color: '#fff'
  138. }
  139. },
  140. // 鼠标放上去的样式
  141. emphasis: {
  142. textStyle: {
  143. color: '#fff'
  144. }
  145. }
  146. },
  147. // 地图区域的样式设置
  148. itemStyle: {
  149. normal: {
  150. borderColor: config.customize.mapLineColor,
  151. borderWidth: 1,
  152. areaColor: config.customize.areaColor,
  153. shadowColor: 'fffff',
  154. shadowOffsetX: -2,
  155. shadowOffsetY: 2,
  156. shadowBlur: 10
  157. },
  158. // 鼠标放上去高亮的样式
  159. emphasis: {
  160. areaColor: '#389BB7',
  161. borderWidth: 0
  162. }
  163. }
  164. },
  165. tooltip: {
  166. backgroundColor: config.customize.tooltipBackgroundColor,
  167. borderColor: config.customize.borderColor,
  168. show: true,
  169. textStyle: {
  170. color: config.customize.fontColor,
  171. },
  172. },
  173. series: [
  174. {
  175. type:'effectScatter',
  176. coordinateSystem: 'geo',
  177. zlevel: 15,
  178. symbolSize:8,
  179. rippleEffect: {
  180. period: 4, brushType: 'stroke', scale: 4
  181. },
  182. tooltip: {
  183. trigger: 'item',
  184. formatter(params) {
  185. const a= eval(config.customize.scatterFormatter)
  186. return a
  187. },
  188. },
  189. itemStyle:{
  190. color:config.customize.scatterColor,
  191. opacity:1
  192. },
  193. data:coord
  194. },
  195. {
  196. type:'effectScatter',
  197. coordinateSystem: 'geo',
  198. zlevel: 15,
  199. symbolSize:12,
  200. tooltip: {
  201. trigger: 'item',
  202. formatter(params) {
  203. const a= eval(config.customize.scatterFormatter)
  204. return a
  205. },
  206. },
  207. rippleEffect: {
  208. period: 6, brushType: 'stroke', scale: 8
  209. },
  210. itemStyle:{
  211. color:config.customize.scatterCenterColor,
  212. opacity:1
  213. },
  214. data:fromCoord
  215. },
  216. {
  217. type:'lines',
  218. coordinateSystem:'geo',
  219. zlevel: 15,
  220. tooltip: {
  221. trigger: 'item',
  222. formatter(params) {
  223. const a= eval(config.customize.lineFormatter)
  224. return a
  225. },
  226. },
  227. effect: {
  228. show: true, period: 5, trailLength: 0, symbol: config.customize.symbol, color:config.customize.symbolColor,symbolSize: config.customize.symbolSize,
  229. },
  230. lineStyle: {
  231. normal: {color: function(value){
  232. return '#ffffff'
  233. },width: 2, opacity: 0.6, curveness: 0.2 }
  234. },
  235. data:lines_coord
  236. }
  237. ]
  238. }
  239. if (config.customize.visual) {
  240. this.option.visualMap = {
  241. show: false,
  242. min: config.customize.range[0],
  243. max: config.customize.range[1],
  244. seriesIndex: [0,2],
  245. inRange: {
  246. color: config.customize.rangeColor
  247. }
  248. }
  249. }
  250. this.charts.setOption(this.option)
  251. this.charts.on('click', async(params)=> {
  252. if(params.name=='') return
  253. if(config.customize.down===false||this.level==='province') return
  254. this.level='province'
  255. const mapUrl =`${window.BS_CONFIG?.httpConfigs?.baseURL}/static/chinaMap/province/${params.name}.json`
  256. const map = await this.$dataRoomAxios.get(decodeURI(mapUrl), {}, true)
  257. this.changeData({...config,customize:{...config.customize,level:'province',scope:params.name}})
  258. this.option.geo.map = params.name
  259. echarts.registerMap(params.name, map);
  260. this.charts.setOption(this.option, true);
  261. });
  262. })
  263. }
  264. }
  265. }
  266. </script>
  267. <style lang="scss" scoped>
  268. @import '../../assets/style/echartStyle';
  269. .light-theme {
  270. background-color: #ffffff;
  271. color: #000000;
  272. }
  273. .auto-theme {
  274. background-color: rgba(0, 0, 0, 0);
  275. }
  276. .bs-design-wrap{
  277. position: relative;
  278. .button{
  279. position: absolute;
  280. z-index: 999;
  281. }
  282. }
  283. </style>