index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="layout-padding">
  3. <div class="layout-padding-auto layout-padding-view to-flex">
  4. <div ref="echartsMapRef" style="height: 100%;width: 100%;"></div>
  5. <div class="to-right">
  6. <h3>国内销售排名Top&nbsp;&nbsp;5</h3>
  7. <div class="item" v-for="(item,index) in topData" :key="index">
  8. {{item.name}}:&nbsp;&nbsp;{{item.value}}
  9. </div>
  10. </div>
  11. </div>
  12. </div>
  13. </template>
  14. <script setup lang="ts">
  15. import echartsMapList from "./mockData/mock.json"
  16. import {onMounted, ref} from "vue";
  17. import * as echarts from "echarts";
  18. import {allCity} from "/@/views/admin/visualization/digitalMap/mockData/allCity";
  19. import router from "/@/router";
  20. // 定义变量内容
  21. const echartsMapRef = ref<RefType>('')
  22. const mapData = allCity.sort((a, b) => {
  23. return b.value - a.value
  24. })
  25. const topData= mapData.slice(0, 5)
  26. // 注册中国地图
  27. echarts.registerMap('echartsMapList', echartsMapList)
  28. // 初始化
  29. // option配置
  30. const initEchartsMap = () => {
  31. const myChart = echarts.init(echartsMapRef.value)
  32. const option = {
  33. backgroundColor: 'transparent',
  34. title: {
  35. text: '国内销售数量',
  36. left: 'center',
  37. textStyle: {
  38. color: '#000'
  39. }
  40. },
  41. // layoutCenter: ['50%', '80%'],//位置
  42. // layoutSize:'130%',//大小
  43. tooltip: {
  44. trigger: 'item',
  45. formatter: (params) => params.name
  46. },
  47. visualMap: {
  48. min: 0,
  49. max: 50,
  50. text: ['High', 'Low'],
  51. realtime: false,
  52. calculable: true,
  53. inRange: {
  54. // color: ['lightskyblue', 'yellow', 'orangered']
  55. color: ['#aacff9','#75c7f6', '#33a9d6']
  56. }
  57. },
  58. series: [
  59. {
  60. name: '国内销售数量',
  61. type: 'map',
  62. map: 'echartsMapList',
  63. label: {
  64. show: true,
  65. fontSize:12,
  66. formatter:(params) => {
  67. if(params.value){
  68. return params.name+':'+params.value
  69. }
  70. return params.name+':0'
  71. },
  72. },
  73. top:'30%',
  74. roam:true,
  75. zoom:1.6,
  76. scaleLimit: {
  77. //滚轮缩放的极限控制
  78. min: 1, //缩放最小大小
  79. },
  80. data:mapData,
  81. }
  82. ]
  83. }
  84. myChart.setOption(option)
  85. myChart.on('georoam',(params) => {
  86. if('dy' in params|| 'dx' in params) return
  87. const myOption = myChart.getOption()
  88. const myZoom = myOption.series[0].zoom
  89. if(myZoom > 1.5){
  90. myOption.series[0].label.fontSize = 20
  91. }else if(myZoom > 1.1){
  92. myOption.series[0].label.fontSize = 12
  93. }else {
  94. myOption.series[0].label.fontSize = 10
  95. }
  96. delete myOption.series[0].top
  97. delete myOption.series[0].zoom
  98. myChart.setOption(myOption)
  99. })
  100. myChart.on('click', (e) => {
  101. router.push({path:`/admin/visualization/cityLevelMap/${e.data.code}/${e.data.name}`})
  102. });
  103. window.addEventListener('resize', () => {
  104. myChart.resize()
  105. })
  106. }
  107. onMounted(() => {
  108. initEchartsMap()
  109. })
  110. </script>
  111. <style scoped lang="scss">
  112. .to-flex {
  113. position: relative;
  114. .to-right {
  115. position: absolute;
  116. display: flex;
  117. flex-direction: column;
  118. justify-content: space-around;
  119. z-index: 999;
  120. bottom: 0;
  121. right: 0;
  122. width: 10%;
  123. max-width: 300px;
  124. height: 25%;
  125. background-color: rgba(0, 234, 255, 0.5);
  126. color: #000; /* 文本颜色为黑色 */
  127. h3 {
  128. text-align: center;
  129. font-size: 14px;
  130. }
  131. .item {
  132. text-align: center;
  133. font-size: 12px;
  134. }
  135. }
  136. }
  137. </style>