first commit
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
<script setup lang="ts">
|
||||
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
||||
import { onMounted, ref } from "vue";
|
||||
import { WebSocket } from "@/Service/Comm/TwWebSocket";
|
||||
import { Service } from "@/Service/Service"
|
||||
import { CNRiderOrderService } from '@/Service/CN/CNRiderOrderService'
|
||||
|
||||
let isios = ref(false)
|
||||
var socket = new WebSocket();
|
||||
|
||||
const currentLatitude = ref(0);
|
||||
const currentLongitude = ref(0);
|
||||
|
||||
let locationTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
|
||||
onLaunch(() => {
|
||||
isios.value = uni.getSystemInfoSync().platform != 'ios'//是否为ios
|
||||
//#ifdef APP-PLUS//app
|
||||
if (isios.value) {
|
||||
// getVersion()//更新
|
||||
}
|
||||
//#endif
|
||||
|
||||
//链接服务器
|
||||
uni.$on("ImCom", () => {
|
||||
socket.ConnectSocketInit();
|
||||
})
|
||||
uni.$on("ImComOff", function (data) {
|
||||
socket.CloseSocket(data);
|
||||
})
|
||||
startFetchingLocation();
|
||||
});
|
||||
onShow(() => {
|
||||
Service.SetStorageCache('isHede',false)
|
||||
//链接服务器
|
||||
if (Service.GetUserIsLogin()) {
|
||||
uni.$emit('ImCom')
|
||||
}
|
||||
|
||||
});
|
||||
onHide(() => {
|
||||
Service.SetStorageCache('isHede',true)
|
||||
});
|
||||
|
||||
|
||||
const startFetchingLocation = () => {
|
||||
// 安全检查:如果定时器已存在,先清除,防止重复启动
|
||||
if (locationTimer) {
|
||||
clearInterval(locationTimer);
|
||||
}
|
||||
|
||||
console.log("开始定时获取位置,间隔1分钟...");
|
||||
|
||||
// 1. 立即执行第一次获取
|
||||
getLocationNow();
|
||||
|
||||
// 2. 设置定时器,每 60000 毫秒 (1分钟) 执行一次
|
||||
locationTimer = setInterval(() => {
|
||||
getLocationNow();
|
||||
}, 60000);
|
||||
};
|
||||
|
||||
const getLocationNow = () => {
|
||||
console.log("正在获取当前经纬度...");
|
||||
|
||||
uni.getLocation({
|
||||
type: 'wgs84',
|
||||
isHighAccuracy: true,
|
||||
success: (res) => {
|
||||
console.log('成功获取到新位置:', res);
|
||||
|
||||
// 更新页面上的数据显示
|
||||
|
||||
console.log(res.latitude,res.longitude,'===')
|
||||
|
||||
if(Service.GetUserIsLogin()){
|
||||
CNRiderOrderService.UpdateRiderLocation(res.latitude,res.longitude).then(res=>{})
|
||||
}
|
||||
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('获取经纬度失败:', err);
|
||||
// (可选) 可以在这里添加失败提示
|
||||
// uni.showToast({ title: '获取位置失败', icon: 'none' });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 停止定时获取位置
|
||||
*/
|
||||
const stopFetchingLocation = () => {
|
||||
if (locationTimer) {
|
||||
clearInterval(locationTimer);
|
||||
locationTimer = null; // 清理 ID
|
||||
}
|
||||
};
|
||||
|
||||
const getUpData = () => {
|
||||
// #ifdef APP
|
||||
// plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
|
||||
// NvpMerchService.GetAppVersion().then(res=>{
|
||||
// console.log('wgtinfo.versionCode',wgtinfo.versionCode);
|
||||
// if (res.data.version > wgtinfo.versionCode) {
|
||||
// setTimeout(function() {
|
||||
// uni.navigateTo({
|
||||
// url: "/pages/upData/upData?info=" +
|
||||
// encodeURIComponent(
|
||||
// JSON.stringify(res.data))
|
||||
// })
|
||||
// }, 1000)
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// #endif
|
||||
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
@import "uview-plus/index.scss";
|
||||
@import "colorui/main.css";
|
||||
@import "colorui/icon.css";
|
||||
|
||||
page {
|
||||
--nav-mian: #1890FF; //全局颜色
|
||||
--nav-vice: #52C41A; //副颜色
|
||||
--nav-diluted: #FF4D4F; //次颜色
|
||||
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user