You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
297 lines
8.7 KiB
297 lines
8.7 KiB
// app.js
|
|
import {getStaffbasicinfo} from "./utils/api";
|
|
import {getOwnedRolesOfStaffId} from "./utils/statisticsApi";
|
|
import {getLocation} from "./utils/util";
|
|
import api from './utils/request'
|
|
import {
|
|
wxGetSetting,
|
|
wxShowModal,
|
|
wxRequestPost,
|
|
wxOpenSetting,
|
|
wxAuthorize,
|
|
wxStartLocationUpdateBackground,
|
|
} from "./utils/promise-wx-api.js";
|
|
App({
|
|
onLaunch: function (options) {
|
|
//获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度)
|
|
//这个最初我是在组件中获取,但是出现了一个问题,当第一次进入小程序时导航栏会把
|
|
//页面内容盖住一部分,当打开调试重新进入时就没有问题,这个问题弄得我是莫名其妙
|
|
//虽然最后解决了,但是花费了不少时间
|
|
let code = [1011, 1017, 1025, 1047, 1124, 1001, 1038, 1041, 1089, 1090, 1104, 1131, 1187];
|
|
if (code.includes(options.scene)) {
|
|
console.log(options.scene);
|
|
this.globalData.share = true
|
|
} else {
|
|
this.globalData.share = false
|
|
}
|
|
const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
|
|
wx.getSystemInfo({
|
|
success: (res) => {
|
|
this.globalData.height = res.statusBarHeight
|
|
this.globalData.deviceInfo.statusHeight = res.statusBarHeight
|
|
this.globalData.deviceInfo.navigationHeight = menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2
|
|
}
|
|
})
|
|
wx.hideTabBar()
|
|
getStaffbasicinfo().then(res=>{
|
|
this.globalData.user = res.data
|
|
getOwnedRolesOfStaffId(res.data.id).then(res2 => {
|
|
this.globalData.roleList = res2.data
|
|
})
|
|
}).catch(err=>{
|
|
console.log(err);
|
|
wx.redirectTo({
|
|
url: '/pages/login/login',
|
|
})
|
|
})
|
|
},
|
|
globalData: {
|
|
userInfo: null,
|
|
selected: 0,
|
|
deviceInfo: {
|
|
statusHeight: 19,
|
|
navigationHeight: 40
|
|
},
|
|
user: {},
|
|
share: false,
|
|
questionnaireUrl: '',
|
|
roleList: [],
|
|
gridId:'',
|
|
patrol: {
|
|
gridId: "",
|
|
gridName: "",
|
|
status: "ini", //
|
|
staffPatrolRecId: "",
|
|
serialNum: 2,
|
|
lastLocalTime: "",
|
|
lastUploadTime: "",
|
|
carmDown: 30,
|
|
},
|
|
},
|
|
async startPatrol() {
|
|
console.log("开始巡查--------------- status");
|
|
const {
|
|
patrol: { status },
|
|
} = this.globalData;
|
|
|
|
if (status === "ing") {
|
|
return false;
|
|
}
|
|
console.log("开始巡查--------------- ing");
|
|
|
|
console.log("开始巡查--------------- gridId");
|
|
// if (!this.globalData.user.agencyId) {
|
|
// await this.getGridInfo();
|
|
// }
|
|
|
|
const { msg: msgL, data: dataL } = await getLocation(false);
|
|
console.log(msgL,'seee');
|
|
if (msgL !== "success") {
|
|
return wx.showToast({
|
|
title: "请允许获取位置权限",
|
|
duration: 2000,
|
|
icon: "none",
|
|
});
|
|
}
|
|
|
|
const res = await api.post(
|
|
"epmetuser/staffpatrol/startpatrol",
|
|
{
|
|
gridId: this.globalData.user.agencyId,
|
|
latitude: dataL.latitude,
|
|
longitude: dataL.longitude,
|
|
speed: 0,
|
|
serialNum: 1,
|
|
},
|
|
{
|
|
// isMock: true,
|
|
isQuiet: true,
|
|
}
|
|
);
|
|
|
|
if (res.code === 0) {
|
|
this.globalData.patrol.gridId = this.globalData.user.agencyId;
|
|
this.globalData.patrol.gridName = this.globalData.gridName;
|
|
this.globalData.patrol.serialNum = 2;
|
|
this.globalData.patrol.staffPatrolRecId = res.data.staffPatrolRecId;
|
|
this.globalData.patrol.carmDown = res.data.carmDown;
|
|
this.startPatrolMonitor();
|
|
}
|
|
},
|
|
// 获取最近一次登陆的网格信息
|
|
async getGridInfo() {
|
|
const { customerId } = this.globalData.user;
|
|
|
|
const res = await api.post(
|
|
"gov/mine/agency/getlatestgrid",
|
|
{ customerId },
|
|
{
|
|
// isMock: true,
|
|
isQuiet: false,
|
|
}
|
|
);
|
|
if (res.code !== 0) {
|
|
console.log(msg);
|
|
return false;
|
|
} else {
|
|
console.log("获取grid信息成功:",res.data);
|
|
if (data && data.gridId) {
|
|
this.globalData.gridAgencyId = res.data.agencyId;
|
|
this.globalData.user.agencyId = res.data.gridId;
|
|
this.globalData.gridName = res.data.gridName;
|
|
console.log("获取grid信息成功:--------------", this.globalData.user.agencyId);
|
|
} else {
|
|
this.globalData.gridAgencyId = "";
|
|
this.globalData.user.agencyId = "";
|
|
this.globalData.gridName = "";
|
|
}
|
|
return true;
|
|
}
|
|
},
|
|
async startPatrolMonitor() {
|
|
const { msg: msgA, data: dataA } = await wxAuthorize({
|
|
scope: "scope.userLocationBackground",
|
|
});
|
|
console.log("999999----------------------", msgA, dataA);
|
|
if (msgA !== "success") {
|
|
const { msg: msgS, data: dataS } = await wxGetSetting();
|
|
if (msgS !== "success") {
|
|
return "";
|
|
}
|
|
if (!dataS.authSetting["scope.userLocationBackground"]) {
|
|
const { msg: msgM, data: dataM } = await wxShowModal({
|
|
title: "请授权获取位置",
|
|
content: "选择“使用小程序期间和离开小程序后”",
|
|
});
|
|
if (msgM !== "success" || dataM.cancel) {
|
|
return console.log("用户取消授权");
|
|
}
|
|
const { msg: msgO, data: dataO } = await wxOpenSetting();
|
|
if (
|
|
msgO !== "success" ||
|
|
!dataS.authSetting["scope.userLocation"]
|
|
) {
|
|
console.log(dataS.authSetting);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log("---------------实时位置监听start: ");
|
|
await wxStartLocationUpdateBackground();
|
|
this.globalData.patrol.status = "ing";
|
|
this.globalData.patrol.lastLocalTime = new Date().getTime();
|
|
console.log("---------------实时位置监听start2: ");
|
|
|
|
wx.onLocationChange((res) => {
|
|
console.log("---------------实时位置监听ing: ", res);
|
|
this.recordPatrolPoint(res);
|
|
});
|
|
},
|
|
async recordPatrolPoint(res) {
|
|
this.globalData.patrol.lastLocalTime = new Date().getTime();
|
|
if (
|
|
this.globalData.patrol.lastLocalTime -
|
|
this.globalData.patrol.lastUploadTime <
|
|
this.globalData.patrol.carmDown * 1000
|
|
) {
|
|
return "还不到时候";
|
|
}
|
|
this.globalData.patrol.lastUploadTime = new Date().getTime();
|
|
|
|
const {
|
|
patrol: { staffPatrolRecId, serialNum },
|
|
} = this.globalData;
|
|
|
|
const data= await api.post(
|
|
"epmetuser/staffpatrol/uploaddetail",
|
|
{
|
|
staffPatrolRecId,
|
|
serialNum,
|
|
latitude: res.latitude,
|
|
longitude: res.longitude,
|
|
speed: res.speed,
|
|
accuracy: res.accuracy,
|
|
altitude: res.altitude,
|
|
verticalAccuracy: res.verticalAccuracy,
|
|
horizontalAccuracy: res.horizontalAccuracy,
|
|
},
|
|
{
|
|
// isMock: true,
|
|
isQuiet: true,
|
|
}
|
|
);
|
|
|
|
if (data.code === 0) {
|
|
this.globalData.patrol.serialNum += 1;
|
|
console.log("---------------实时位置监听point: ", this.globalData.patrol);
|
|
}
|
|
},
|
|
async closePatrol(patrolEndTime = "") {
|
|
const {
|
|
patrol: { status },
|
|
} = this.globalData;
|
|
|
|
if (status === "ini") {
|
|
return false;
|
|
}
|
|
|
|
const { msg: msgL, data: dataL } = await getLocation();
|
|
|
|
if (msgL !== "success") return false;
|
|
console.log("4444444444---------------------- closePatrol");
|
|
wx.stopLocationUpdate();
|
|
this.globalData.patrol.status = "end";
|
|
|
|
if (!patrolEndTime) {
|
|
patrolEndTime = dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss");
|
|
}
|
|
|
|
const {
|
|
patrol: { gridId, staffPatrolRecId, serialNum },
|
|
} = this.globalData;
|
|
|
|
wx.showLoading({
|
|
title: "提交中……",
|
|
});
|
|
const res = await api.post(
|
|
"epmetuser/staffpatrol/endpatrol",
|
|
{
|
|
gridId,
|
|
staffPatrolRecId,
|
|
serialNum,
|
|
latitude: dataL.latitude,
|
|
longitude: dataL.longitude,
|
|
speed: 0,
|
|
patrolEndTime,
|
|
},
|
|
{
|
|
// isMock: true,
|
|
// isQuiet: true,
|
|
}
|
|
);
|
|
wx.hideLoading();
|
|
|
|
if (res.code === 0) {
|
|
this.globalData.patrol = {
|
|
gridId: "",
|
|
gridName: "",
|
|
status: "ini", //
|
|
staffPatrolRecId: "",
|
|
serialNum: 1,
|
|
lastLocalTime: "",
|
|
lastUploadTime: "",
|
|
carmDown: 30,
|
|
};
|
|
wx.showToast({
|
|
title: "操作成功",
|
|
icon: "none",
|
|
duration: 2000,
|
|
});
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
},
|
|
|
|
})
|
|
|