Эх сурвалжийг харах

fix: 距离超过1km时统一用km展示,保留一位小数

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
tanlie 1 сар өмнө
parent
commit
b9edc395cd

+ 5 - 1
wishing-tree-h5/src/views/MakeWishView.vue

@@ -6,7 +6,7 @@
       <div class="tree-info" v-if="tree">
         <p class="for-tree">🌳 {{ tree.name }}</p>
         <van-tag :type="isInRange ? 'success' : 'warning'" round>
-          {{ isInRange ? `距离 ${distance}m · 在范围内` : `距离 ${distance}m · 太远了` }}
+          {{ isInRange ? `距离 ${fmtDist(distance)} · 在范围内` : `距离 ${fmtDist(distance)} · 太远了` }}
         </van-tag>
       </div>
 
@@ -84,6 +84,10 @@ const tags = ref<string[]>([])
 const isPublic = ref(true)
 const submitting = ref(false)
 
+function fmtDist(m: number) {
+  return m >= 1000 ? (m / 1000).toFixed(1) + 'km' : m + 'm'
+}
+
 const distance = computed(() => {
   if (!tree.value || !locationStore.lng) return Infinity
   return Math.round(

+ 1 - 1
wishing-tree-h5/src/views/MapView.vue

@@ -163,7 +163,7 @@ async function loadTrees() {
   trees.forEach((tree: any) => {
     const isIn = tree.isInRange
     const color = isIn ? '#07c160' : '#ff976a'
-    const label = `${tree.name} ${tree.distance}m`
+    const label = `${tree.name} ${fmtDist(tree.distance)}`
 
     const content = `
       <div style="