MapBlock.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view class="position-relative radius-l overflow-hidden">
  3. <map
  4. id="map"
  5. mapId="map"
  6. class="w-100 height-400"
  7. :markers="mapLoader.content.value || []"
  8. :enable-zoom="false"
  9. :enable-scroll="false"
  10. :longitude="AppCofig.defaultLonLat[0]"
  11. :latitude="AppCofig.defaultLonLat[1]"
  12. :scale="15"
  13. @click="navTo(
  14. props.mapPage || '/pages/inhert/map/index',
  15. { tab: mapTab }
  16. )"
  17. />
  18. <scroll-view class="map-tags position-absolute" :scroll-x="true">
  19. <view class="tag-bar d-flex flex-row flex-nowrap">
  20. <view
  21. v-for="item in mapButtons" :key="item.id"
  22. :class="mapTab == item.id ? 'active' : ''"
  23. @click="mapTab=item.id"
  24. >
  25. <text :class="`iconfont ${item.icon}`" />
  26. {{ item.title }}
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </template>
  32. <script setup lang="ts">
  33. import { useSimpleDataLoader } from '@/common/composeabe/SimpleDataLoader';
  34. import { navTo } from '@/components/utils/PageAction';
  35. import { computed, getCurrentInstance, ref, watch } from 'vue';
  36. import { doLoadDynamicListData } from '../article/data/CommonCategoryDynamicData';
  37. import type { IHomeCommonCategoryBlockMapProps } from '../article/data/CommonCategoryDefine';
  38. import AppCofig from '@/common/config/AppCofig';
  39. import { waitTimeOut } from '@imengyu/imengyu-utils';
  40. const props = defineProps<IHomeCommonCategoryBlockMapProps>();
  41. const instance = getCurrentInstance();
  42. const mapCtx = uni.createMapContext('map', instance);
  43. const mapTab = ref(0);
  44. const mapButtons = computed(() => {
  45. return props.mapConfigItems
  46. .filter(item => item.visible !== false)
  47. .map((item, i) => ({
  48. ...item,
  49. id: i,
  50. }));
  51. })
  52. const mapLoader = useSimpleDataLoader(async () => {
  53. let list = (await doLoadDynamicListData(
  54. props.mapConfigItems[mapTab.value].data,
  55. 1, 6, '', [], []
  56. ))?.list || [];
  57. const res = list.map((p) => {
  58. return {
  59. title: p.title || p.name,
  60. id: p.id,
  61. longitude: Number(p.longitude),
  62. latitude: Number(p.latitude),
  63. iconPath: p.thumbnail,
  64. width: 40,
  65. height: 40,
  66. };
  67. });
  68. await waitTimeOut(200);
  69. mapCtx.includePoints({
  70. points: res.map(p => {
  71. if (!p.longitude || !p.latitude) {
  72. p.longitude = AppCofig.defaultLonLat[0];
  73. p.latitude = AppCofig.defaultLonLat[1];
  74. }
  75. return {
  76. latitude: p.latitude,
  77. longitude: p.longitude,
  78. }
  79. }),
  80. padding: [20, 20, 20, 20],
  81. });
  82. return res;
  83. }, true, undefined, true);
  84. watch(mapTab, () => mapLoader.loadData(undefined, true));
  85. </script>