selectRegionPopup.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <popup v-model:show="showValue" round class="select-region-popup" z-index="10000" teleport="body">
  3. <div class="image-wrapper">
  4. <div class="map-container" ref="mapContainer"></div>
  5. </div>
  6. <div class="content">
  7. <div class="title">{{ title }}</div>
  8. <div class="sub-title">{{ subTitle }}</div>
  9. </div>
  10. <div class="actions">
  11. <div class="btn btn-ghost" @click="handleSkip">{{ t('跳过') }}</div>
  12. <div class="btn btn-primary" @click="handleConfirm">{{ t('去勾选') }}</div>
  13. </div>
  14. </popup>
  15. </template>
  16. <script setup>
  17. import { useI18n } from "@/i18n";
  18. const { t } = useI18n();
  19. import { Popup } from "vant";
  20. import { computed, ref, watch, onMounted, onBeforeUnmount, nextTick } from "vue";
  21. import DrawRegionMap from "@/views/old_mini/interactionList/map/drawRegionMap.js";
  22. const props = defineProps({
  23. show: {
  24. type: Boolean,
  25. default: false,
  26. },
  27. title: {
  28. type: String,
  29. default: "勾选 区域",
  30. },
  31. subTitle: {
  32. type: String,
  33. default: "精准匹配农情信息,高效管理分区",
  34. },
  35. /** 地图中心点,WKT POINT 格式 */
  36. centerPoint: {
  37. type: String,
  38. default: "POINT (113.6142086995688 23.585836479509055)",
  39. },
  40. });
  41. const emit = defineEmits(["update:show", "skip", "confirm"]);
  42. const mapContainer = ref(null);
  43. const drawRegionMap = new DrawRegionMap();
  44. const showValue = computed({
  45. get: () => props.show,
  46. set: (value) => emit("update:show", value),
  47. });
  48. const handleSkip = () => {
  49. emit("skip");
  50. emit("update:show", false);
  51. };
  52. const handleConfirm = () => {
  53. emit("confirm");
  54. emit("update:show", false);
  55. };
  56. const initMap = () => {
  57. if (!mapContainer.value) return;
  58. if (drawRegionMap.kmap) return;
  59. // 在弹窗中以只读模式展示地图(仅中心点,不回显地块)
  60. drawRegionMap.initMap(props.centerPoint, mapContainer.value, false, false, true);
  61. };
  62. const destroyMap = () => {
  63. if (drawRegionMap && drawRegionMap.kmap && drawRegionMap.destroyMap) {
  64. drawRegionMap.destroyMap();
  65. }
  66. };
  67. onMounted(() => {
  68. if (showValue.value) {
  69. nextTick(() => {
  70. initMap();
  71. });
  72. }
  73. });
  74. watch(
  75. () => showValue.value,
  76. (val) => {
  77. if (val) {
  78. nextTick(() => {
  79. destroyMap();
  80. initMap();
  81. });
  82. } else {
  83. destroyMap();
  84. }
  85. }
  86. );
  87. onBeforeUnmount(() => {
  88. destroyMap();
  89. });
  90. </script>
  91. <style scoped lang="scss">
  92. .select-region-popup {
  93. width: 100%;
  94. padding: 20px;
  95. .image-wrapper {
  96. width: 100%;
  97. background: #ffffff;
  98. }
  99. .map-container {
  100. width: 100%;
  101. height: 180px;
  102. border-radius: 8px;
  103. overflow: hidden;
  104. }
  105. .content {
  106. margin-top: 12px;
  107. text-align: center;
  108. .title {
  109. font-size: 22px;
  110. margin-bottom: 4px;
  111. }
  112. .sub-title {
  113. font-size: 20px;
  114. }
  115. }
  116. .actions {
  117. display: flex;
  118. justify-content: space-between;
  119. margin-top: 28px;
  120. gap: 10px;
  121. .btn {
  122. height: 40px;
  123. line-height: 40px;
  124. border-radius: 25px;
  125. text-align: center;
  126. }
  127. .btn-ghost {
  128. width: 110px;
  129. border: 1px solid rgba(153, 153, 153, 0.5);
  130. color: #666666;
  131. }
  132. .btn-primary {
  133. width: 162px;
  134. background: #2199f8;
  135. color: #ffffff;
  136. border: 1px solid #2199f8;
  137. }
  138. }
  139. }
  140. </style>