|
@@ -1,11 +1,18 @@
|
|
|
const APP = getApp();
|
|
|
-let mapContext; //地图对象
|
|
|
+//地图对象
|
|
|
+let mapContext;
|
|
|
//定时刷新位置信息对象
|
|
|
-let clockRefresh = null;
|
|
|
+let locationInterval = null;
|
|
|
//持续定位定时任务对象
|
|
|
-let continueRefresh = null;
|
|
|
+let freqInterval = null;
|
|
|
+//倒计时定时任务对象
|
|
|
+let countDownInterval = null;
|
|
|
+
|
|
|
Page({
|
|
|
data: {
|
|
|
+ schedule: 0,
|
|
|
+ circle: false,
|
|
|
+ loading: false,
|
|
|
stateInfo: null, //设备状态信息
|
|
|
markers: [], //地图标记
|
|
|
},
|
|
@@ -24,7 +31,7 @@ Page({
|
|
|
return;
|
|
|
}
|
|
|
//请求设备位置
|
|
|
- this.getLatestState(APP.globalData.openNum);
|
|
|
+ this.getLatestLocation(APP.globalData.openNum);
|
|
|
//开启定时任务-定时刷新位置信息
|
|
|
this.intervalRefresh(APP.globalData.openNum);
|
|
|
//开启定时任务-高频定位模式
|
|
@@ -34,10 +41,10 @@ Page({
|
|
|
// 监听页面隐藏
|
|
|
onHide: function () {
|
|
|
//清除定时
|
|
|
- clearInterval(clockRefresh);
|
|
|
- clearInterval(continueRefresh);
|
|
|
- clockRefresh = null;
|
|
|
- continueRefresh = null;
|
|
|
+ clearInterval(locationInterval);
|
|
|
+ clearInterval(freqInterval);
|
|
|
+ locationInterval = null;
|
|
|
+ freqInterval = null;
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -46,29 +53,36 @@ Page({
|
|
|
intervalRefresh: function (openNum) {
|
|
|
console.log("启动定时刷新位置")
|
|
|
const that = this;
|
|
|
- if (clockRefresh != null) return;
|
|
|
- clockRefresh = setInterval(function () {
|
|
|
- that.getLatestStateInterval(openNum);
|
|
|
- }, 15000)
|
|
|
+ if (locationInterval == null) {//不为空说明已经被初始化,则不做处理
|
|
|
+ that.countDown(14);
|
|
|
+ locationInterval = setInterval(function () {
|
|
|
+ APP.Get(APP.Url.getLatestLocation, { openNum: openNum }, false).then(res => {
|
|
|
+ that.countDown(14);
|
|
|
+ that.updateStateInfo(res.data);
|
|
|
+ })
|
|
|
+ }, 15000)
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * 定时设置持续定位
|
|
|
+ * 定时开启高频定位
|
|
|
*/
|
|
|
intervalSetContinue: function (openNum) {
|
|
|
console.log("启动持续定位")
|
|
|
const that = this;
|
|
|
- if (continueRefresh != null) return;
|
|
|
- that.setContinue(openNum);
|
|
|
- continueRefresh = setInterval(function () {
|
|
|
- that.setContinue(openNum);
|
|
|
- }, 240000)
|
|
|
+ if (freqInterval == null) {
|
|
|
+ that.startHighFreq(openNum)
|
|
|
+ freqInterval = setInterval(function () {
|
|
|
+ that.startHighFreq(openNum);
|
|
|
+ }, 240000)
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * 设置持续定位
|
|
|
+ * 开启高频定位
|
|
|
*/
|
|
|
- setContinue: function (openNum) {
|
|
|
+ startHighFreq: function (openNum) {
|
|
|
const params = {
|
|
|
openNum: openNum,
|
|
|
highFreq: 1
|
|
@@ -80,43 +94,31 @@ Page({
|
|
|
/**
|
|
|
* 获取设备位置
|
|
|
*/
|
|
|
- getLatestState: function (openNum) {
|
|
|
+ getLatestLocation(openNum) {
|
|
|
const that = this;
|
|
|
const params = {
|
|
|
openNum: openNum
|
|
|
}
|
|
|
- APP.Get(APP.Url.getLatestState, params, false).then(res => {
|
|
|
- const stateInfo = res.data;
|
|
|
- if (stateInfo == null) {
|
|
|
+ APP.Get(APP.Url.getLatestLocation, params, false).then(res => {
|
|
|
+ const detail = res.data;
|
|
|
+ if (detail == null) {
|
|
|
APP.Modal.tips("该设备还没有上传位置信息");
|
|
|
return;
|
|
|
}
|
|
|
//首次加载聚焦中心为当前位置
|
|
|
mapContext.moveToLocation({
|
|
|
- latitude: parseFloat(stateInfo.latGcj), //纬度
|
|
|
- longitude: parseFloat(stateInfo.lonGcj), //经度
|
|
|
+ latitude: detail.latGcj, //纬度
|
|
|
+ longitude: detail.lonGcj, //经度
|
|
|
})
|
|
|
- that.setStateInfo(stateInfo);
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取设备位置
|
|
|
- * 定时器
|
|
|
- */
|
|
|
- getLatestStateInterval: function (openNum) {
|
|
|
- const params = {
|
|
|
- openNum: openNum
|
|
|
- }
|
|
|
- APP.Get(APP.Url.getLatestState, params, false).then(res => {
|
|
|
- this.setStateInfo(res.data);
|
|
|
+ //更新位置数据
|
|
|
+ that.updateStateInfo(detail);
|
|
|
})
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 设置位置等状态信息
|
|
|
*/
|
|
|
- setStateInfo: function (stateInfo) {
|
|
|
+ updateStateInfo(stateInfo) {
|
|
|
if (stateInfo == null) return;
|
|
|
//定位时间
|
|
|
stateInfo.uploadTimeFormat = this.formatTime(stateInfo.uploadTime)
|
|
@@ -144,4 +146,69 @@ Page({
|
|
|
if (diff < 31104000) return parseInt(diff / 86400) + "天前";
|
|
|
return "1年前";
|
|
|
},
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 倒计时
|
|
|
+ */
|
|
|
+ countDown(second) {
|
|
|
+ const that = this;
|
|
|
+ if (countDownInterval == null) {
|
|
|
+ //系数
|
|
|
+ let factor = 100 / second;
|
|
|
+ //初始化步数
|
|
|
+ let step = 1;
|
|
|
+ //初始化进度条进度
|
|
|
+ this.setData({
|
|
|
+ schedule: 0,
|
|
|
+ circle: true,
|
|
|
+ loading: false
|
|
|
+ })
|
|
|
+
|
|
|
+ //定时器
|
|
|
+ countDownInterval = setInterval(() => {
|
|
|
+ //如果到达指定步数,则关闭定时
|
|
|
+ if (step >= second) {
|
|
|
+ clearInterval(countDownInterval);
|
|
|
+ countDownInterval = null;
|
|
|
+ this.setData({
|
|
|
+ schedule: 0,
|
|
|
+ circle: false,
|
|
|
+ loading: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ //进度条增加
|
|
|
+ that.setData({
|
|
|
+ schedule: factor * step
|
|
|
+ })
|
|
|
+ //步数增加
|
|
|
+ step = step + 1;
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新
|
|
|
+ */
|
|
|
+ refresh() {
|
|
|
+ wx.showLoading({
|
|
|
+ title: '正在刷新',
|
|
|
+ })
|
|
|
+ setTimeout(function () {
|
|
|
+ wx.hideLoading();
|
|
|
+ APP.Modal.tips("刷新成功");
|
|
|
+ }, 600)
|
|
|
+ },
|
|
|
+
|
|
|
+ call() {
|
|
|
+ APP.Modal.tips("功能暂未开通");
|
|
|
+ },
|
|
|
+
|
|
|
+ openMapApp() {
|
|
|
+ const params = {
|
|
|
+ longitude: this.data.stateInfo.lonGcj,
|
|
|
+ latitude: this.data.stateInfo.latGcj,
|
|
|
+ destination: "手机所在位置"
|
|
|
+ }
|
|
|
+ mapContext.openMapApp(params);
|
|
|
+ }
|
|
|
})
|