feat: 定期更新用户位置

This commit is contained in:
gcd 2025-04-23 00:04:14 +08:00
parent def8b7026f
commit e8812b9a1b
3 changed files with 36 additions and 4 deletions

32
App.vue
View File

@ -1,6 +1,7 @@
<script setup>
import {onLaunch, onShow, onHide} from '@dcloudio/uni-app'
import {reactive, provide, inject} from 'vue'
import api from "./api/api";
//
const globalData = reactive({
@ -12,16 +13,41 @@ const globalData = reactive({
provide('globalData', globalData)
onLaunch(() => {
// console.log('App Launch')
initSysInfo()
setInterval(() => {
updateUserLocation()
}, 60 * 1000)
})
onShow(() => {
// console.log('App Show')
updateUserLocation()
})
onHide(() => {
// console.log('App Hide')
updateUserLocation()
})
/**
* 更新用户位置
*/
const updateUserLocation = () => {
let token = uni.getStorageSync('token')
//
if (!token) {
return
}
uni.getLocation({
type: 'gcj02',
success(res) {
let data = {longitude: res.longitude, latitude: res.latitude}
api.updateUserLocation(data).then(() => {
}).catch(() => {})
},
fail() {
}
});
}
const initSysInfo = () => {
//
let statusBar = uni.getWindowInfo().statusBarHeight

View File

@ -109,6 +109,12 @@ class Api {
let url = `${config.host}/worker/order_dispatch/saveWorkerRemark`;
return fetch.request('postFrom', url, data, true)
}
// 保存师傅备注
static updateUserLocation(data) {
let url = `${config.host}/worker/worker/updateWorkerLocation`;
return fetch.request('postFrom', url, data, true)
}
}
export default Api

View File

@ -3,7 +3,7 @@ let accountInfo = wx.getAccountInfoSync();
let envVersion = accountInfo.miniProgram.envVersion
//手动指定版本
envVersion = 'trial'
// envVersion = 'trial'
let hosts = {
"develop": 'http://wanyu.test',