瑶都万能墙
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
3.1 KiB

  1. <template>
  2. <view class="map-card">
  3. <!-- 地图区域 -->
  4. <view class="map-container">
  5. <map
  6. :latitude="latitude"
  7. :longitude="longitude"
  8. :markers="markers"
  9. :show-location="false"
  10. :enable-zoom="false"
  11. :enable-scroll="false"
  12. :enable-rotate="false"
  13. :enable-overlooking="false"
  14. :enable-traffic="false"
  15. class="map"
  16. @tap="onMapTap"
  17. ></map>
  18. </view>
  19. <!-- 地址信息区域 -->
  20. <view class="address-container">
  21. <view class="address-name">{{ addressName }}</view>
  22. <view class="address-detail" v-if="addressDetail">{{ addressDetail }}</view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'MapCard',
  29. props: {
  30. // 纬度
  31. latitude: {
  32. type: [Number, String],
  33. required: true,
  34. default: 39.908823
  35. },
  36. // 经度
  37. longitude: {
  38. type: [Number, String],
  39. required: true,
  40. default: 116.397470
  41. },
  42. // 地址名称
  43. addressName: {
  44. type: String,
  45. required: true,
  46. default: '位置信息'
  47. },
  48. // 地址详情(可选)
  49. addressDetail: {
  50. type: String,
  51. default: ''
  52. },
  53. // 地图高度
  54. mapHeight: {
  55. type: [Number, String],
  56. default: 300
  57. },
  58. // 是否可点击
  59. clickable: {
  60. type: Boolean,
  61. default: true
  62. }
  63. },
  64. computed: {
  65. // 地图标记点
  66. markers() {
  67. return [{
  68. id: 1,
  69. latitude: Number(this.latitude),
  70. longitude: Number(this.longitude),
  71. iconPath: '/static/image/location-marker.svg',
  72. width: 30,
  73. height: 30,
  74. callout: {
  75. content: this.addressName,
  76. color: '#333333',
  77. fontSize: 12,
  78. borderRadius: 4,
  79. bgColor: '#ffffff',
  80. padding: 8,
  81. display: 'ALWAYS'
  82. }
  83. }]
  84. }
  85. },
  86. methods: {
  87. // 地图点击事件
  88. onMapTap() {
  89. if (this.clickable) {
  90. this.$emit('mapClick', {
  91. latitude: this.latitude,
  92. longitude: this.longitude,
  93. addressName: this.addressName
  94. });
  95. // 打开地图导航
  96. this.openLocation();
  97. }
  98. },
  99. // 打开地图导航
  100. openLocation() {
  101. uni.openLocation({
  102. latitude: Number(this.latitude),
  103. longitude: Number(this.longitude),
  104. name: this.addressName,
  105. address: this.addressDetail || this.addressName,
  106. success: () => {
  107. console.log('打开地图成功');
  108. },
  109. fail: (err) => {
  110. console.error('打开地图失败:', err);
  111. uni.showToast({
  112. title: '打开地图失败',
  113. icon: 'none'
  114. });
  115. }
  116. });
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .map-card {
  123. background: $uni-bg-color;
  124. border-radius: $uni-border-radius-lg;
  125. overflow: hidden;
  126. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  127. margin: $uni-spacing-row-base;
  128. }
  129. .map-container {
  130. position: relative;
  131. height: 300rpx;
  132. .map {
  133. width: 100%;
  134. height: 100%;
  135. }
  136. }
  137. .address-container {
  138. padding: $uni-spacing-row-lg $uni-spacing-row-base;
  139. background: $uni-bg-color;
  140. .address-name {
  141. font-size: $uni-font-size-lg;
  142. color: $uni-text-color;
  143. font-weight: 500;
  144. margin-bottom: $uni-spacing-col-sm;
  145. line-height: 1.4;
  146. }
  147. .address-detail {
  148. font-size: $uni-font-size-sm;
  149. color: $uni-text-color-grey;
  150. line-height: 1.4;
  151. }
  152. }
  153. // 点击态效果
  154. .map-card:active {
  155. background: $uni-bg-color-hover;
  156. }
  157. </style>