index.vue 8.9 KB

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