factoryindex.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="page">
  3. <!-- 1. 顶部标题 -->
  4. <view class="header">
  5. <text class="title">盐都区闲置厂房分布</text>
  6. </view>
  7. <!-- 2. 轮播图 -->
  8. <swiper
  9. class="swiper"
  10. circular
  11. :indicator-dots="true"
  12. :autoplay="true"
  13. :interval="3000"
  14. :duration="800"
  15. >
  16. <swiper-item v-for="(item, index) in picture" :key="index">
  17. <image :src="item" class="swiper-item" mode="aspectFill" />
  18. </swiper-item>
  19. </swiper>
  20. <!-- 3. 地图 -->
  21. <view class="map-box">
  22. <canvas
  23. canvas-id="ydChart"
  24. id="ydChart"
  25. class="map-canvas"
  26. />
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import * as echarts from 'echarts'
  32. export default {
  33. data() {
  34. return {
  35. chart: null,
  36. /* 轮播图示例,换成你的真实图片即可 */
  37. picture:["https://ydwqfw.com.cn/yd_qycpfbH5/bg1.jpg",
  38. "https://ydwqfw.com.cn/yd_qycpfbH5/bg2.jpg",
  39. "https://ydwqfw.com.cn/yd_qycpfbH5/bg3.jpg",
  40. "https://ydwqfw.com.cn/yd_qycpfbH5/bg4.jpg"],
  41. }
  42. },
  43. async onReady() {
  44. const json = await this.loadGeoJSON()
  45. echarts.registerMap('yanduqu', json)
  46. let canvasNode
  47. // #ifdef H5
  48. canvasNode = document.getElementById('ydChart')
  49. // #endif
  50. // #ifndef H5
  51. canvasNode = await new Promise(resolve => {
  52. uni.createSelectorQuery()
  53. .in(this)
  54. .select('#ydChart')
  55. .node(res => resolve(res.node))
  56. .exec()
  57. })
  58. // #endif
  59. this.chart = echarts.init(canvasNode, null, {
  60. width : uni.getSystemInfoSync().windowWidth,
  61. height: uni.getSystemInfoSync().windowHeight * 0.6 // 地图占屏幕 50%
  62. })
  63. this.renderMap()
  64. },
  65. methods: {
  66. loadGeoJSON() {
  67. return new Promise((resolve, reject) => {
  68. uni.request({
  69. url: './static/yandu.json',
  70. method: 'GET',
  71. success: res => resolve(res.data),
  72. fail: reject
  73. })
  74. })
  75. },
  76. renderMap() {
  77. const option = {
  78. geo: [{
  79. map: 'yanduqu',
  80. roam: false,
  81. aspectScale: 1.2,
  82. zoom: 1.1,
  83. itemStyle: {
  84. areaColor: '#4ea397',
  85. borderColor: '#fff',
  86. borderWidth: 1
  87. },
  88. emphasis: {
  89. itemStyle: { areaColor: '#ffca28' }
  90. },
  91. // 关键:打开标签
  92. label: {
  93. show: true, // 默认显示名称
  94. color: '#fff', // 文字颜色
  95. fontSize: 14, // 字号
  96. fontWeight: 'bold',
  97. textBorderColor: 'rgba(85, 85, 255, 0.7)', // 描边让字更清晰
  98. textBorderWidth: 2
  99. }
  100. }],
  101. series: [{ type: 'map', geoIndex: 0, data: [] }]
  102. }
  103. this.chart.setOption(option)
  104. this.chart.on('click', params => {
  105. uni.navigateTo({
  106. url: `/pages/factoryBuildings/factoryBuildingsList?parkid=${params.name}`
  107. })
  108. })
  109. }
  110. }
  111. }
  112. </script>
  113. <style scoped>
  114. .page {
  115. display: flex;
  116. flex-direction: column;
  117. height: 100vh;
  118. background: #f5f5f5;
  119. }
  120. /* 顶部标题 */
  121. .header {
  122. padding: 20rpx 0;
  123. text-align: center;
  124. background: #fff;
  125. }
  126. .title {
  127. font-size: 36rpx;
  128. font-weight: bold;
  129. color: #333;
  130. }
  131. /* 轮播图 */
  132. .swiper {
  133. width: 100%;
  134. height: 300rpx;
  135. }
  136. .swiper-item {
  137. width: 100%;
  138. height: 100%;
  139. }
  140. /* 地图容器 */
  141. .map-box {
  142. flex: 1;
  143. width: 100%;
  144. }
  145. .map-canvas {
  146. width: 100%;
  147. height: 100%;
  148. }
  149. </style>