index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="page-view f-30 p-40 flex-dir-column flex-x-center">
  3. <view class="title">{{detailVO.name}}</view>
  4. <view class="time" v-if="detailVO.createTime">发布时间:{{detailVO.createTime?detailVO.createTime.substring(0,10) : ''}}</view>
  5. <view v-if="detailVO.videos" class="width-100">
  6. <video class="width-100" :src="detailVO.videos"></video>
  7. </view>
  8. <view class="col-info-d t-c m-b-30">
  9. <u-parse style="text-align: left;" :content="detailVO.content"></u-parse>
  10. </view>
  11. <view v-if="detailVO && detailVO.id && detailVO.latitude && detailVO.longitude" class="width-100 m-b-10"
  12. style="height: 250px;">
  13. <map id="map" class="width-100 height-100" :show-location="true" :latitude="detailVO.latitude"
  14. :longitude="detailVO.longitude"></map>
  15. </view>
  16. <view v-if="detailVO.address" class="time">{{detailVO.address || ''}}</view>
  17. <view @click="toMapAPP" class="to-map-btn">导航前往</view>
  18. <detailBottom type="restaurant" :articleId.sync="detailVO.id" :liked.sync="detailVO.liked"
  19. :collected.sync="detailVO.collected" :views.sync="detailVO.views" :likeNum.sync="detailVO.likeNum"
  20. :collectNum.sync="detailVO.collectNum" @doRefresh="getDetail"></detailBottom>
  21. </view>
  22. </template>
  23. <script>
  24. import detailBottom from '@/pages/components/detailbottom.vue'
  25. export default {
  26. components: {
  27. detailBottom
  28. },
  29. data() {
  30. return {
  31. detailVO: {},
  32. //
  33. mapDom: null,
  34. }
  35. },
  36. onReady() {},
  37. methods: {
  38. createMap() {
  39. this.mapDom = uni.createMapContext("map", this);
  40. // 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
  41. this.mapDom.initMarkerCluster({
  42. enableDefaultStyle: false,
  43. zoomOnClick: true,
  44. gridSize: 60,
  45. complete(res) {
  46. console.log('initMarkerCluster', res)
  47. }
  48. });
  49. this.mapDom.on("markerClusterCreate", (e) => {
  50. console.log("markerClusterCreate", e);
  51. });
  52. },
  53. addMarkers(name, latitude, longitude) {
  54. const positions = [{
  55. latitude: latitude,
  56. longitude: longitude,
  57. name: name
  58. }]
  59. const markers = []
  60. positions.forEach((p, i) => {
  61. console.log(i)
  62. markers.push(
  63. Object.assign({}, {
  64. id: i + 1,
  65. // iconPath: img,
  66. // width: 50,
  67. // height: 50,
  68. joinCluster: true, // 指定了该参数才会参与聚合
  69. // label: {
  70. // // width: 50,
  71. // // height: 30,
  72. // borderWidth: 1,
  73. // borderRadius: 10,
  74. // padding: 5,
  75. // bgColor: '#ffffff',
  76. // content: p.name
  77. // }
  78. }, p)
  79. )
  80. })
  81. this.mapDom.addMarkers({
  82. markers,
  83. clear: false,
  84. complete(res) {
  85. console.log('addMarkers', res)
  86. }
  87. })
  88. },
  89. toMapAPP(e = {}) {
  90. const latitude = Number(this.detailVO.latitude)
  91. const longitude = Number(this.detailVO.longitude)
  92. uni.openLocation({
  93. latitude: latitude,
  94. longitude: longitude,
  95. name: this.detailVO.address,
  96. scale: 12,
  97. success() {
  98. console.log('success')
  99. }
  100. })
  101. },
  102. getDetail() {
  103. this.$u.api.getRestaurantDetail(this.detailVO.id).then(res => {
  104. if (res.data.content) {
  105. res.data.content = decodeURIComponent(res.data.content);
  106. }
  107. this.detailVO = res.data || {}
  108. if (this.detailVO && this.detailVO.id && this.detailVO.latitude && this.detailVO.longitude) {
  109. this.createMap();
  110. this.addMarkers(this.detailVO.name, res.data.latitude, res.data.longitude)
  111. }
  112. //
  113. uni.setNavigationBarTitle({
  114. title: res.data.name || ''
  115. })
  116. })
  117. }
  118. },
  119. onLoad(options) {
  120. this.detailVO.id = options.id || '';
  121. this.getDetail();
  122. },
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. .title {
  127. width: 100%;
  128. text-align: center;
  129. font-size: 25px;
  130. color: #65371b;
  131. margin-bottom: 20px;
  132. }
  133. .time {
  134. font-size: 14px;
  135. color: #787878;
  136. font-weight: 300;
  137. padding-bottom: 10px;
  138. }
  139. .to-map-btn {
  140. text-align: center;
  141. width: 80%;
  142. padding: 5px;
  143. margin: auto;
  144. background-color: #3c9cff;
  145. color: white;
  146. letter-spacing: 2px;
  147. border-radius: 4rpx;
  148. margin-bottom: 30px;
  149. }
  150. </style>