From cfd85de890456173a9289da01ee5aff73103255e Mon Sep 17 00:00:00 2001 From: gcd Date: Mon, 31 Mar 2025 22:45:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 8 ++++++++ pages/index/index.vue | 40 ++++++++++++++++++++++++++++++++++++++-- utils/helpers.js | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index abfe46b..d6b3acb 100644 --- a/manifest.json +++ b/manifest.json @@ -51,6 +51,14 @@ /* 小程序特有相关 */ "mp-weixin" : { "appid" : "wx6172ec67683d31b9", + "requiredPrivateInfos" : [ + "getLocation" + ], + "permission" : { + "scope.userLocation" : { + "desc" : "计算接单距离、调用导航功能" + } + }, "setting" : { "urlCheck" : false }, diff --git a/pages/index/index.vue b/pages/index/index.vue index 8de724c..5cc954e 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -29,7 +29,8 @@ - 8.34公里 + 未知距离 + {{formatDistance(item.order_info.lat, item.order_info.lng)}} @@ -66,7 +67,7 @@ const toDetail = (id) => { } onLoad(() => { - getList() + init() }) const data = reactive({ @@ -99,6 +100,11 @@ const refreshStart = () => { return } + if (userLocation.lng === null || userLocation.lat === null) { + helpers.showToast('请授权位置权限') + return + } + refresh.interval = setInterval(() => { refresh.rotate_deg -= 12; }, 16); @@ -117,6 +123,36 @@ const refreshComplete = () => { }) } } + +const userLocation = reactive({ + lng: null, + lat: null, +}) + +//初始化 +const init = () => { + //获取师傅当前位置 + uni.getLocation({ + type: 'gcj02', + success(res) { + userLocation.lng = res.longitude + userLocation.lat = res.latitude + data.page = 1 + getList() + }, + fail(err) { + uni.showToast({ + title: '请授权位置权限', + icon: "error" + }) + } + }); +} + +const formatDistance = (lat, lng) => { + const res = helpers.getDistances(userLocation.lat, userLocation.lng, lat, lng); + return `${res.distance}${res.unit}`; +}