Kaynağa Gözat

🎨 优化创建村落时定位到原点问题

快乐的梦鱼 2 hafta önce
ebeveyn
işleme
5f8f13ad1f

+ 0 - 23
package-lock.json

@@ -12746,29 +12746,6 @@
         "typedarray-to-buffer": "^3.1.5"
       }
     },
-    "node_modules/ws": {
-      "version": "8.18.1",
-      "resolved": "https://registry.npmmirror.com/ws/-/ws-8.18.1.tgz",
-      "integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==",
-      "license": "MIT",
-      "optional": true,
-      "peer": true,
-      "engines": {
-        "node": ">=10.0.0"
-      },
-      "peerDependencies": {
-        "bufferutil": "^4.0.1",
-        "utf-8-validate": ">=5.0.2"
-      },
-      "peerDependenciesMeta": {
-        "bufferutil": {
-          "optional": true
-        },
-        "utf-8-validate": {
-          "optional": true
-        }
-      }
-    },
     "node_modules/xhr": {
       "version": "2.6.0",
       "resolved": "https://registry.npmmirror.com/xhr/-/xhr-2.6.0.tgz",

+ 4 - 7
src/pages/home/components/VillageMiniMap.vue

@@ -52,19 +52,20 @@
 </template>
 
 <script setup lang="ts">
-import { computed, getCurrentInstance } from 'vue';
+import { computed } from 'vue';
 import { useTheme } from '@/components/theme/ThemeDefine';
 import NoticeBar from '@/components/display/NoticeBar.vue';
 import type { MapMarker } from '@/types/Map';
 import ImagesUrls from '@/common/config/ImagesUrls';
 import FlexCol from '@/components/layout/FlexCol.vue';
 import Text from '@/components/basic/Text.vue';
+import { isValidLonLat, type LonLat } from '../composeabe/LonLat';
 
 const emit = defineEmits(['getedCurrentLonlat']);
 const props = withDefaults(defineProps<{
   markers?: MapMarker[];
   currentNoticeContent?: string;
-  lonlat?: { longitude: number, latitude: number } | undefined;
+  lonlat?: LonLat| undefined;
 }>(), {
   currentNoticeContent: '目前厦门市已被点亮一个社区,刚刚小亮贡献了10个光源,让湖里区点亮了一个社区',
   lonlat: () => ({
@@ -74,11 +75,7 @@ const props = withDefaults(defineProps<{
 });
 
 const isValidLonlat = computed(() => {
-  return (
-    props.lonlat && props.lonlat.longitude && props.lonlat.latitude &&
-    !isNaN(props.lonlat.longitude) && !isNaN(props.lonlat.latitude) &&
-    props.lonlat.longitude > -180 && props.lonlat.longitude < 180 && props.lonlat.latitude > -90 && props.lonlat.latitude < 90
-  );
+  return (!isValidLonLat(props.lonlat));
 });
 
 const themeContext = useTheme();

+ 14 - 0
src/pages/home/composeabe/LonLat.ts

@@ -0,0 +1,14 @@
+export interface LonLat {
+  longitude: number;
+  latitude: number;
+}
+
+export function isValidLonLat(lonLat: LonLat): boolean {
+  return (
+    lonLat.longitude !== undefined && lonLat.latitude !== undefined
+    && !(lonLat.longitude === lonLat.latitude && lonLat.latitude === 0)
+    && !isNaN(lonLat.longitude) && !isNaN(lonLat.latitude)
+    && lonLat.longitude >= 0 && lonLat.longitude <= 180
+    && lonLat.latitude >= 0 && lonLat.latitude <= 90
+  );
+}

+ 20 - 4
src/pages/home/light/create-village.vue

@@ -117,6 +117,7 @@ import BoxMid from '@/common/components/box/BoxMid.vue';
 import Touchable from '@/components/feedback/Touchable.vue';
 import Image from '@/components/basic/Image.vue';
 import { getCascaderItemByValue } from '@/components/form/CascaderUtils';
+import { isValidLonLat } from '../composeabe/LonLat';
 
 const mapCtx = uni.createMapContext('prevMap');
 
@@ -157,10 +158,25 @@ async function asyncLoadData(item: CascaderItem) {
 function handlePickEnd(values: CascaderItem[]) {
   if (values.length > 0) {
     selectedRegion.value = values[values.length - 1].data;
-    currentLonLat.value = {
-      longitude: Number(selectedRegion.value!.longitude),
-      latitude: Number(selectedRegion.value!.latitude),
-    };
+    let i = values.length - 1;
+    for (; i >= 0; i--) {
+      const lonlat = {
+        longitude: Number(values[i].data.longitude),
+        latitude: Number(values[i].data.latitude),
+      };
+      if (isValidLonLat(lonlat)) {
+        currentLonLat.value = lonlat;
+        console.log('currentLonLat.value', currentLonLat.value);
+        break;
+      }
+    }
+    if (i !== values.length - 1) {
+      alert({
+        title: '提示',
+        content: '您的家乡暂时没有经纬度信息,麻烦您拖动地图至您的家乡准确位置',
+        confirmText: '好',
+      })
+    }
     mapCtx.moveToLocation({
       longitude: Number(currentLonLat.value.longitude),
       latitude: Number(currentLonLat.value.latitude),