index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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">发布时间:{{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 :content="detailVO.content"></u-parse>
  10. </view>
  11. <view v-if="detailVO && detailVO.id && detailVO.latitude && detailVO.longitude" class="width-100 m-b-20"
  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. <detailBottom type="restaurant" :articleId.sync="detailVO.id" :liked.sync="detailVO.liked"
  17. :collected.sync="detailVO.collected" :views.sync="detailVO.views" :likeNum.sync="detailVO.likeNum"
  18. :collectNum.sync="detailVO.collectNum" @doRefresh="getDetail"></detailBottom>
  19. </view>
  20. </template>
  21. <script>
  22. import detailBottom from '@/pages/components/detailbottom.vue'
  23. export default {
  24. components: {
  25. detailBottom
  26. },
  27. data() {
  28. return {
  29. detailVO: {},
  30. //
  31. mapDom: null,
  32. }
  33. },
  34. onReady() {},
  35. methods: {
  36. createMap() {
  37. this.mapDom = uni.createMapContext("map", this);
  38. // 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
  39. this.mapDom.initMarkerCluster({
  40. enableDefaultStyle: false,
  41. zoomOnClick: true,
  42. gridSize: 60,
  43. complete(res) {
  44. console.log('initMarkerCluster', res)
  45. }
  46. });
  47. this.mapDom.on("markerClusterCreate", (e) => {
  48. console.log("markerClusterCreate", e);
  49. });
  50. },
  51. addMarkers(name, latitude, longitude) {
  52. const positions = [{
  53. latitude: latitude,
  54. longitude: longitude,
  55. name: name
  56. }]
  57. const markers = []
  58. positions.forEach((p, i) => {
  59. console.log(i)
  60. markers.push(
  61. Object.assign({}, {
  62. id: i + 1,
  63. // iconPath: img,
  64. // width: 50,
  65. // height: 50,
  66. joinCluster: true, // 指定了该参数才会参与聚合
  67. // label: {
  68. // // width: 50,
  69. // // height: 30,
  70. // borderWidth: 1,
  71. // borderRadius: 10,
  72. // padding: 5,
  73. // bgColor: '#ffffff',
  74. // content: p.name
  75. // }
  76. }, p)
  77. )
  78. })
  79. this.mapDom.addMarkers({
  80. markers,
  81. clear: false,
  82. complete(res) {
  83. console.log('addMarkers', res)
  84. }
  85. })
  86. },
  87. getDetail() {
  88. this.$u.api.getRestaurantDetail(this.detailVO.id).then(res => {
  89. if (res.data.content) {
  90. res.data.content = decodeURIComponent(res.data.content);
  91. }
  92. this.detailVO = res.data || {}
  93. if (this.detailVO && this.detailVO.id && this.detailVO.latitude && this.detailVO.longitude) {
  94. this.createMap();
  95. this.addMarkers(this.detailVO.name, res.data.latitude, res.data.longitude)
  96. }
  97. //
  98. uni.setNavigationBarTitle({
  99. title: res.data.name || ''
  100. })
  101. })
  102. }
  103. },
  104. onLoad(options) {
  105. this.detailVO.id = options.id || '';
  106. this.getDetail();
  107. },
  108. }
  109. </script>
  110. <style scoped lang="scss">
  111. .title {
  112. width: 100%;
  113. text-align: center;
  114. font-size: 25px;
  115. color: #65371b;
  116. margin-bottom: 20px;
  117. }
  118. .time {
  119. font-size: 14px;
  120. color: #787878;
  121. font-weight: 300;
  122. padding-bottom: 10px;
  123. }
  124. </style>