Просмотр исходного кода

页面修改及网点组件化

zuypeng 1 год назад
Родитель
Сommit
36095bbca2

+ 174 - 0
src/components/station/index.vue

@@ -0,0 +1,174 @@
+<template>
+  <view class="station_item"
+        @click="handleNavStation(item)">
+    <view class="station_item-title">
+      <text class="font13">{{ item.stationName }}</text>
+    </view>
+
+    <view class="station_item-status">
+      <text class="station_item-status-text">{{ item.stationStatus == 'Normal' ? '营业中' : '暂停营业' }}</text>
+    </view>
+
+    <view class="station_item-content">
+      <view class="station_item-content-left">
+        <view class="station_item-content-left-label">
+          <view class="font12 station_item-content-left-label-left">
+            <text class="station_item-content-left-label-left_idle">空闲</text>
+            <text class="station_item-content-left-label-left_count">{{ item.parkingNum }}/{{ item.parkingNum }}</text>
+          </view>
+          <!--              <uv-tags size="small" class="station_item-content-left-label_tag" text="洗车机" plain shape="circle"></uv-tags>-->
+          <!--              <view class="station_item-content-left-label_func">{{ ['清洁', '泡沫', '吸尘', '消毒', '充电']?.join(" | ") }}</view>-->
+        </view>
+        <view class="station_item-content-left-position">
+          <uv-icon name="empty-address" size="20" color="#aaa"></uv-icon>
+          <text>{{ item.address }}</text>
+        </view>
+      </view>
+      <view class="station_item-content-right">
+        <uv-button circle type="primary" size="mini" plain @click.stop="handleNavMap(item)">{{ item.distance }}km</uv-button>
+        <!--            <uv-tags text="1222km" type="warning" plain size="mini"></uv-tags>-->
+      </view>
+    </view>
+
+    <view class="station_item-distance">
+      <uv-text type="primary" :text="item.parkingFee" size="12"></uv-text>
+    </view>
+  </view>
+</template>
+
+<script setup lang="ts" name="Station">
+import {onMounted, reactive, ref} from 'vue'
+
+const props = defineProps({
+  item: {
+    type: Object,
+    require: true
+  }
+})
+
+
+
+const handleNavMap = (station:any) => {
+  let location = JSON.parse(station.location)
+  uni.openLocation({
+    latitude: location.stationLat,
+    longitude: location.stationLng,
+    scale: 18,
+    name: station.stationName,
+    address: station.address,
+  });
+}
+
+const handleNavStation = (station: any) => {
+  getApp<any>().globalData.pageData = {station}
+  uni.navigateTo({
+    url: '/pages-wash/station/index?id='+station.id
+  })
+  console.log(station)
+}
+
+</script>
+
+<style scoped lang="scss">
+
+.station_item {
+  display: flex;
+  flex-direction: column;
+  border-radius: 10rpx;
+  margin-top: 20rpx;
+  padding: 15rpx;
+  background: #fafafa;
+  position: relative;
+
+  &-title {
+    display: inline-flex;
+    padding-left: 5px;
+  }
+
+  &-status {
+    position: absolute;
+    right: 6rpx;
+    top: 0;
+
+    &-text {
+      background: $uni-color-primary;
+      padding: 6rpx;
+      color: white;
+      font-size: 12px;
+      border-radius: 20rpx 6rpx;
+    }
+  }
+
+  &-content {
+    display: flex;
+    justify-content: space-between;
+    width: 100%;
+
+    &-left {
+      flex: 1;
+      display: flex;
+      flex-direction: column;
+      padding: 5rpx;
+
+      &-label {
+        padding: 4rpx 8rpx;
+        display: inline-flex;
+        margin-top: 8rpx;
+        //justify-content: space-between;
+
+        &-left {
+          //border: 1px solid $uni-color-primary;
+          border-radius: 4rpx;
+
+          &_idle {
+            background: $uni-color-primary;
+            padding: 6rpx;
+            color: white;
+            border-radius: 4rpx;
+          }
+
+          &_count {
+            //border-radius: 4rpx;
+            margin-left: 10px;
+            color: $uni-color-primary;
+            font-size: 13px;
+          }
+
+          &_tag {
+            width: 30rpx;
+          }
+
+        }
+
+
+        &_func {
+          padding-left: 50rpx;
+          font-size: 24rpx;
+          color: #aaa;
+        }
+      }
+
+      &-position {
+        display: inline-flex;
+        font-size: 24rpx;
+        margin-top: 8rpx;
+      }
+    }
+
+    &-right {
+      width: 120rpx;
+      display: flex;
+      flex-direction: column;
+      justify-content: center;
+      align-content: center;
+    }
+  }
+
+  &-distance {
+    font-size: 24rpx;
+    padding-left: 5px;
+    margin-top: 8rpx;
+  }
+}
+
+</style>

+ 18 - 11
src/components/tab-bar/index.vue

@@ -1,22 +1,19 @@
 <template>
   <view class="tabbar">
-    <uv-tabbar value:bind="value" :fixed="true" @change="index=>value = index">
-      <uv-tabbar-item text="首页" icon="home" @tap.stop="handleTabbarClick('index')"></uv-tabbar-item>
-      <uv-tabbar-item text="优惠" icon="photo" @tap.stop="handleTabbarClick('coupon')"></uv-tabbar-item>
-      <uv-tabbar-item text="" icon="scan" :iconSize="40" @tap.stop="handleTabbarClick('map')" style="margin-top: -25px">
-        <template #text>
-
-        </template>
+    <uv-tabbar :value="value" :fixed="true" @change="index=>value = index">
+      <uv-tabbar-item text="网点" icon="home" @tap.stop="handleTabbarClick('index')"></uv-tabbar-item>
+<!--      <uv-tabbar-item text="优惠" icon="photo" @tap.stop="handleTabbarClick('coupon')"></uv-tabbar-item>-->
+      <uv-tabbar-item text="" icon="scan" :iconSize="40" @tap.stop="handleTabbarClick('map')" style="margin-top: -125px">
       </uv-tabbar-item>
-      <uv-tabbar-item text="订单" icon="play-right" @tap.stop="handleTabbarClick('order')"></uv-tabbar-item>
+<!--      <uv-tabbar-item text="订单" icon="play-right" @tap.stop="handleTabbarClick('order')"></uv-tabbar-item>-->
       <uv-tabbar-item text="我的" icon="account" @tap.stop="handleTabbarClick('user')"></uv-tabbar-item>
     </uv-tabbar>
   </view>
 
 </template>
 <script setup lang="ts" name="TabBar">
-import {ref} from 'vue'
-import {onLoad, onTabItemTap} from "@dcloudio/uni-app";
+import {onMounted, reactive, ref} from 'vue'
+import {onLoad, onShow, onTabItemTap} from "@dcloudio/uni-app";
 
 const props = defineProps({
   index: {
@@ -28,15 +25,25 @@ const value = ref(0)
 
 
 onLoad(() => {
+  console.log("tabbar onLoad", props.index, value.value)
+  value.value = props.index;
+})
+
+onShow(() => {
   console.log("tabbar onshow", props.index, value.value)
   value.value = props.index;
 })
 
+onMounted(()=>{
+  console.log("tabbar onMounted", props.index, value.value)
+  value.value = props.index;
+})
+
 const handleTabbarClick = (tab: string) => {
   uni.switchTab({
     url: `/pages/${tab}/index`,
     success: (e: any) => {
-      console.log("tabbar switch>>>>", e)
+      console.log("tabbar switch>>>>", tab,e)
     },
     fail: (e: any) => {
       console.error("swtich error >>>>>", JSON.stringify(e))

+ 7 - 1
src/manifest.json

@@ -6,10 +6,16 @@
     "versionCode" : "100",
     "transformPx" : false,
     "mp-weixin" : {
-        "appid" : "",
+        "appid" : "wxe466e6b630cc47ae",
         "setting" : {
             "urlCheck" : false
         },
+        "requiredPrivateInfos": ["getLocation"],
+        "permission": {
+            "scope.userLocation": {
+                "desc": "你的位置信息将用于获取附近洗车网点位置"
+            }
+        },
         "usingComponents" : true
     },
     "uniStatistics": {

+ 5 - 36
src/pages-wash/station/index.vue

@@ -4,39 +4,7 @@
 
     <view class="station-box">
       <view class=" station_wrapper">
-        <view class="station_item" >
-          <view class="station_item-title">
-            <text class="font13">{{ state.station.stationName }}</text>
-          </view>
-
-          <view class="station_item-status">
-            <text class="station_item-status-text">{{ state.station.stationStatus=='Normal'?'营业中':'暂停营业' }}</text>
-          </view>
-
-          <view class="station_item-content">
-            <view class="station_item-content-left">
-              <view class="station_item-content-left-label">
-                <view class="font12 station_item-content-left-label-left">
-                  <text class="station_item-content-left-label-left_idle">空闲</text>
-                  <text class="station_item-content-left-label-left_count">{{ state.station.parkingNum }}/{{ state.station.parkingNum }}</text>
-                </view>
-                <!--              <uv-tags size="small" class="station_item-content-left-label_tag" text="洗车机" plain shape="circle"></uv-tags>-->
-                <view class="station_item-content-left-label_func">{{ ['清洁', '泡沫', '吸尘', '消毒', '充电']?.join(" | ") }}</view>
-              </view>
-              <view class="station_item-content-left-position">
-                <uv-icon name="empty-address" size="20" color="#aaa"></uv-icon>
-                <text>{{ state.station.address }}</text>
-              </view>
-            </view>
-            <view class="station_item-content-right">
-              <uv-button circle type="primary" size="mini" plain @click="handleNavStation">去洗车</uv-button>
-            </view>
-          </view>
-
-          <view class="station_item-distance">
-            <uv-text type="primary" :text="state.station.parkingFee" size="12"></uv-text>
-          </view>
-        </view>
+        <WashStation :item=" state.station"></WashStation>
       </view>
     </view>
 
@@ -52,6 +20,7 @@
 import {onHide, onLoad, onShow} from "@dcloudio/uni-app";
 import {reactive, ref} from "vue";
 import {get} from "@/utils/https";
+import WashStation from "@/components/station/index.vue"
 
 const initState = () => ({
   deviceList: [] as any[],
@@ -81,7 +50,7 @@ const loadStationDeviceList = () => {
   if (!state.station.id) {
     return;
   }
-  get(`/wash-device/listWashDevice`, {stationId: state.station.id}).then((deviceList:any) => {
+  get(`/wash-device/listWashDevice`, {stationId: state.station.stationId}).then((deviceList:any) => {
     state.deviceList = deviceList;
   })
 }
@@ -97,12 +66,12 @@ const handleNavStation = () => {
 .page {
   min-height: 100vh;
   width: 100%;
-  padding: 20 rpx;
+  padding: 20rpx;
   background-color: #eee;
 }
 
 .block {
-  border-radius: 20 rpx;
+  border-radius: 20rpx;
   background: #fff;
 }
 .content_station {

+ 17 - 16
src/pages.json

@@ -120,43 +120,44 @@
     }
   ],
   "tabBar": {
-    "custom": false,
+    "custom": true,
     "color": "#7A7E83",
     "selectedColor": "#3cc51f",
     "borderStyle": "black",
     "backgroundColor": "#ffffff",
+    "fontSize": "12px",
+    "spacing": "5px",
+    "height": "60px",
     "list": [
       {
         "pagePath": "pages/index/index",
         "iconPath": "static/tabbar/1.png",
         "selectedIconPath": "static/tabbar/1-1.png",
-        "text": "首页"
-      },
-      {
-        "pagePath": "pages/coupon/index",
-        "iconPath": "static/tabbar/1.png",
-        "selectedIconPath": "static/tabbar/1-1.png",
-        "text": "优惠"
+        "text": "网点"
       },
+
       {
         "pagePath": "pages/map/index",
         "iconPath": "static/tabbar/2.png",
         "selectedIconPath": "static/tabbar/2.png",
-        "text": "地图"
-      },
-      {
-        "pagePath": "pages/order/index",
-        "iconPath": "static/tabbar/3.png",
-        "selectedIconPath": "static/tabbar/3-1.png",
-        "text": "订单"
+        "text": "扫码"
       },
+
       {
         "pagePath": "pages/user/index",
         "iconPath": "static/tabbar/4.png",
         "selectedIconPath": "static/tabbar/4-1.png",
         "text": "我的"
       }
-    ]
+    ],
+    "midButton": {
+      "width": "80rpx",
+      "height": "80rpx",
+      "text": "扫码",
+      "iconPath": "static/tabbar/1.png",
+      "selectedIconPath": "static/tabbar/1-1.png",
+      "iconWidth": "50rpx"
+    }
   },
   "globalStyle": {
     "navigationBarTextStyle": "black",

+ 77 - 159
src/pages/index/index.vue

@@ -37,13 +37,15 @@
 
     <!--    站点清单  start-->
     <view class="w100 content_station">
-      <view class="station_item" v-for="item in state.stationList" :key="item.id">
+      <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
+<!--      <view class="station_item" v-for="item in state.stationList" :key="item.id"
+            @click="handleNavStation(item)">
         <view class="station_item-title">
           <text class="font13">{{ item.stationName }}</text>
         </view>
 
         <view class="station_item-status">
-          <text class="station_item-status-text">{{ item.stationStatus=='Normal'?'营业中':'暂停营业' }}</text>
+          <text class="station_item-status-text">{{ item.stationStatus == 'Normal' ? '营业中' : '暂停营业' }}</text>
         </view>
 
         <view class="station_item-content">
@@ -53,8 +55,8 @@
                 <text class="station_item-content-left-label-left_idle">空闲</text>
                 <text class="station_item-content-left-label-left_count">{{ item.parkingNum }}/{{ item.parkingNum }}</text>
               </view>
-              <!--              <uv-tags size="small" class="station_item-content-left-label_tag" text="洗车机" plain shape="circle"></uv-tags>-->
-              <view class="station_item-content-left-label_func">{{ ['清洁', '泡沫', '吸尘', '消毒', '充电']?.join(" | ") }}</view>
+              &lt;!&ndash;              <uv-tags size="small" class="station_item-content-left-label_tag" text="洗车机" plain shape="circle"></uv-tags>&ndash;&gt;
+&lt;!&ndash;              <view class="station_item-content-left-label_func">{{ ['清洁', '泡沫', '吸尘', '消毒', '充电']?.join(" | ") }}</view>&ndash;&gt;
             </view>
             <view class="station_item-content-left-position">
               <uv-icon name="empty-address" size="20" color="#aaa"></uv-icon>
@@ -62,15 +64,15 @@
             </view>
           </view>
           <view class="station_item-content-right">
-            <uv-button circle type="primary" size="mini" plain @click="handleNavStation(item)">去洗车</uv-button>
-<!--            <uv-tags text="1222km" type="warning" plain size="mini"></uv-tags>-->
+            <uv-button circle type="primary" size="mini" plain @click.stop="handleNavMap(item)">{{  item.distance  }}km</uv-button>
+            &lt;!&ndash;            <uv-tags text="1222km" type="warning" plain size="mini"></uv-tags>&ndash;&gt;
           </view>
         </view>
 
         <view class="station_item-distance">
           <uv-text type="primary" :text="item.parkingFee" size="12"></uv-text>
         </view>
-      </view>
+      </view>-->
     </view>
     <!--    站点清单  end-->
 
@@ -85,7 +87,7 @@
         </view>-->
 
     <login-bar class="w100 text-center loginbar"></login-bar>
-    <!--    <tab-bar :index="0"></tab-bar>-->
+    <tab-bar :index="0"></tab-bar>
   </view>
 </template>
 
@@ -94,7 +96,9 @@ import {reactive, ref} from 'vue'
 import {onHide, onShow, onLoad} from "@dcloudio/uni-app";
 import TabBar from "@/components/tab-bar/index.vue";
 import LoginBar from "@/components/login-bar/index.vue";
-import {get,post} from "@/utils/https";
+import WashStation from "@/components/station/index.vue"
+import {get, post} from "@/utils/https";
+import {calcMapDistance} from "@/utils/common"
 
 const title = ref('Hello')
 const qrcode_ref = ref()
@@ -128,52 +132,25 @@ const initState = () => ({
     borderRadius: '40rpx',//圆角
   },
   notice: '中秋佳节,全场8折,快来洗车吧!',
-  stationList: [
-    {
-      id: 1,
-      name: '河源路洗车场2222',
-      status: 1,
-      total: 17,
-      idle: 2,
-      funs: ['清洁', '泡沫', '吸尘', '消毒', '充电'],
-      address: '深圳市宝安区河源路12345号',
-      tips: '半小时内免停车费,超时领取停车券免费',
-    },
-    {
-      id: 2,
-      name: '河源路洗车场2222',
-      status: 1,
-      total: 17,
-      idle: 2,
-      funs: ['清洁', '泡沫', '吸尘', '消毒', '充电'],
-      address: '深圳市宝安区河源路12345号',
-      tips: '半小时内免停车费,超时领取停车券免费',
-    },
-    {
-      id: 3,
-      name: '河源路洗车场2222',
-      status: 1,
-      total: 17,
-      idle: 2,
-      funs: ['清洁', '泡沫', '吸尘', '消毒', '充电'],
-      address: '深圳市宝安区河源路12345号',
-      tips: '半小时内免停车费,超时领取停车券免费',
-    }
-  ]
+  stationList: [],
+  location: {
+    latitude: 0,
+    longitude: 0,
+  }
 })
 
 const state = reactive(initState())
 
 onLoad((e: any) => {
-  let query = decodeURIComponent(e.q);
-  let scanTime =e.scancode_time;
-  console.log(query)
-  if(query){
+  let query = decodeURIComponent(e);
+  let scanTime = e.scancode_time;
+  console.log(e)
+/*  if (query) {
     uni.showToast({
-      title:query,
-      duration:5000
+      title: query,
+      duration: 5000
     })
-  }
+  }*/
 
 })
 
@@ -182,32 +159,73 @@ onShow(() => {
   if (!gd.token) {
     console.log(gd)
   }
-  loadWashStationList();
+  loadCurrentLocation();
+
+
 });
 
 onHide(() => {
   Object.assign(state, initState());
 })
 
+/**
+ * 获取当前的地理位置
+ */
+const loadCurrentLocation = () => {
+  uni.authorize({
+    scope: 'scope.userLocation',
+    success() {
+      uni.getLocation({
+        type: 'gcj02', //返回可以用于uni.openLocation的经纬度
+        success: res => {
+          state.location = {
+            latitude: res.latitude,
+            longitude: res.longitude
+          }
+          loadWashStationList();
+          console.log("loadCurrentLocation location", res)
+        }
+      });
+    },
+    fail(e) {
+      loadWashStationList();
+      console.log("authorize location fail", e)
+    }
+  })
+
+}
 
 const loadWashStationList = () => {
-  post(`/wash-station/listStation`,{pageSize:5}).then((res:any)=>{
+  post(`/wash-station/listStation`, {pageSize: 5}).then((res: any) => {
     console.log(res)
-    let {list,total} = res;
+    let {list, total} = res;
+    list.forEach((station: any) => {
+      if (station.location) {
+        let stationLocation = JSON.parse(station.location);
+        station.distance = calcMapDistance(state.location.latitude,state.location.longitude,stationLocation.stationLat,stationLocation.stationLng);
+      }
+    })
     state.stationList = list;
   })
 }
 
+const handleNavMap = (station:any) => {
+  let location = JSON.parse(station.location)
+  uni.openLocation({
+    latitude: location.stationLat,
+    longitude: location.stationLng,
+    scale: 18,
+    name: station.stationName,
+    address: station.address,
+  });
+}
+
 const handleNavStation = (station: any) => {
-  getApp<any>().globalData.pageData  = {station}
+  getApp<any>().globalData.pageData = {station}
   uni.navigateTo({
     url: '/pages-wash/station/index?id='+station.id
   })
-}
-const handleGotoGuide = () => {
-  uni.navigateTo({
-    url: '/pages/guide/index'
-  })
+  console.log(station)
 }
 
 </script>
@@ -226,7 +244,7 @@ const handleGotoGuide = () => {
 .logo {
   height: 200rpx;
   width: 200rpx;
-  margin: 200 rpx auto 50 rpx;
+  margin: 200rpx auto 50rpx;
 }
 
 .menu-content {
@@ -258,107 +276,7 @@ const handleGotoGuide = () => {
   text-align: center;
 }
 
-.station_item {
-  display: flex;
-  flex-direction: column;
-  border-radius: 10rpx;
-  margin-top: 20rpx;
-  padding: 15rpx;
-  background: #fafafa;
-  position: relative;
-
-  &-title {
-    display: inline-flex;
-    padding-left: 5px;
-  }
-
-  &-status {
-    position: absolute;
-    right: 6rpx;
-    top: 0;
-
-    &-text {
-      background: $uni-color-primary;
-      padding: 6rpx;
-      color: white;
-      font-size: 12px;
-      border-radius: 20rpx 6rpx;
-    }
-  }
-
-  &-content {
-    display: flex;
-    justify-content: space-between;
-    width: 100%;
-
-    &-left {
-      flex: 1;
-      display: flex;
-      flex-direction: column;
-      padding: 5rpx;
-
-      &-label {
-        padding: 4rpx 8rpx;
-        display: inline-flex;
-        margin-top: 8rpx;
-        //justify-content: space-between;
-
-        &-left {
-          //border: 1px solid $uni-color-primary;
-          border-radius: 4rpx;
-
-          &_idle {
-            background: $uni-color-primary;
-            padding: 6rpx;
-            color: white;
-            border-radius: 4rpx;
-          }
-
-          &_count {
-            //border-radius: 4rpx;
-            margin-left: 10px;
-            color: $uni-color-primary;
-            font-size: 13px;
-          }
-
-          &_tag {
-            width: 30rpx;
-          }
-
-        }
-
-
-        &_func {
-          padding-left: 50rpx;
-          font-size: 24rpx;
-          color: #aaa;
-        }
-      }
-
-      &-position {
-        display: inline-flex;
-        font-size: 24rpx;
-        margin-top: 8rpx;
-      }
-    }
-
-    &-right {
-      width: 120rpx;
-      display: flex;
-      flex-direction: column;
-      justify-content: center;
-      align-content: center;
-    }
-  }
-
-  &-distance {
-    font-size: 24rpx;
-    padding-left: 5px;
-    margin-top: 8rpx;
-  }
-}
-
-.loginbar{
+.loginbar {
   position: fixed;
   bottom: 20rpx;
 }

+ 35 - 14
src/pages/map/index.vue

@@ -61,7 +61,7 @@
     </view>
     <!--    站点清单  end-->
 <!--    <login-bar class="w100 text-center"></login-bar>-->
-<!--    <tab-bar :index="2"/>-->
+    <tab-bar :index="1"/>
   </view>
 </template>
 
@@ -121,6 +121,15 @@ onHide(() => {
   Object.assign(state, initState());
 })
 
+const fetchLocationPermission = ()=>{
+  uni.authorize({
+    scope: 'scope.userLocation',
+    success() {
+      uni.getLocation()
+    }
+  })
+}
+
 const handleMapRegionChange = (e: any) => {
   if (state.isIgnoreChangeLocation) {
     return;
@@ -154,21 +163,27 @@ const resetLocation = () => {
   //   return;
   // }
   console.log("reset location")
-  uni.getLocation({
-    type: 'gcj02', //返回可以用于uni.openLocation的经纬度
-    success: res=>{
-      const latitude = res.latitude;
-      const longitude = res.longitude;
-      console.log("reset location",res)
-      uni.openLocation({
-        latitude: latitude,
-        longitude: longitude,
-        success: function () {
-          console.log('success');
+  uni.authorize({
+    scope: 'scope.userLocation',
+    success() {
+      uni.getLocation({
+        type: 'gcj02', //返回可以用于uni.openLocation的经纬度
+        success: res=>{
+          const latitude = res.latitude;
+          const longitude = res.longitude;
+          console.log("reset location",res)
+          uni.openLocation({
+            latitude: latitude,
+            longitude: longitude,
+            success: function () {
+              console.log('success');
+            }
+          });
         }
       });
     }
-  });
+  })
+
   // eslint-disable-next-line promise/catch-or-return
   // fetchLocation().then((res: any) => {
   //   const { latitude, longitude } = res;
@@ -205,7 +220,13 @@ const handleSearchStation = (e: any) => {
 }
 
 const handleNavStation = (station: any) => {
-
+  uni.openLocation({
+    latitude:station.stationLat,
+    longitude:station.stationLng,
+    scale: 18,
+    name: station.stationName,
+    address:station.address,
+  });
 }
 </script>
 

+ 1 - 1
src/pages/user/index.vue

@@ -45,7 +45,7 @@
     </view>
   </block>
 <!--  <login-bar class="w100 text-center"></login-bar>-->
-<!--  <tab-bar :index="4"/>-->
+  <tab-bar :index="2"/>
 </template>
 
 <script setup lang="ts">

+ 20 - 1
src/utils/common.ts

@@ -32,4 +32,23 @@ export function throttle(fn: Function, wait: number) {
             timer = null
         }, delay)
     }
-}
+}
+
+//计算坐标距离
+export function calcMapDistance(lat1: number, lng1: number, lat2: number, lng2: number) {
+    let radLat1 = (lat1 * Math.PI) / 180.0;
+    let radLat2 = (lat2 * Math.PI) / 180.0;
+    let a = radLat1 - radLat2;
+    let b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
+    let s =
+        2 *
+        Math.asin(
+            Math.sqrt(
+                Math.pow(Math.sin(a / 2), 2) +
+                Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)
+            )
+        );
+    s = s * 6378.137; // EARTH_RADIUS;
+    s = Math.round(s * 10000) / 10000;
+    return s.toFixed(2);
+}

+ 3 - 3
src/utils/device.ts

@@ -1,8 +1,8 @@
-export function rpxToPx(rpx: number): number {
+export function rpxToPx(unirpx: number): number {
   if (getApp<any>().globalData.device) {
-    return (rpx * getApp<any>().globalData.device.windowWidth) / 750;
+    return (unirpx * getApp<any>().globalData.device.windowWidth) / 750;
   }
-  returnrpx;
+  return unirpx;
 }
 
 export function pxToRpx(px: number): number {

+ 3 - 2
src/utils/https.ts

@@ -13,7 +13,7 @@ console.log("env", e);
 isDevelopment = e === "develop" || e === "trial";
 // #endif
 
-const env: string = isDevelopment ? "dev" : "prd";
+let env: string = isDevelopment ? "dev" : "prd";
 const apis = {
     dev: {
         serverUrl: "http://localhost:8088/api",
@@ -25,13 +25,14 @@ const apis = {
     },
 };
 // @ts-ignore
+// @ts-ignore
 const cfg = {
     key: {
         token: 'wash.token'
     },
     env: env,
     api: {
-        serverUrl: apis[env].serverUrl,
+        serverUrl: apis[env]?.serverUrl,
         fileUrl: apis[env].fileUrl,
         uploadUrl: apis[env].serverUrl + "file/upload"
     }