|
|
|
|
@ -17,60 +17,45 @@ |
|
|
|
|
message: '', //报警信息通知 |
|
|
|
|
timer: null, |
|
|
|
|
reportLastTime: null, //报警信息最后一次时间 |
|
|
|
|
msgIds:[] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
onLaunch: function() { |
|
|
|
|
console.log('App Launch'); |
|
|
|
|
this.onKeep(); |
|
|
|
|
/********设置开机自动启动开始********/ |
|
|
|
|
// this.requestAndroidPermission().then(res => { |
|
|
|
|
// if (res == 0) { |
|
|
|
|
// let userInfo = uni.getStorageSync('mobileInfo') ? JSON.parse(uni.getStorageSync('mobileInfo')) : null; |
|
|
|
|
// if (userInfo && userInfo.employeeId != this.employeeId) { |
|
|
|
|
// this.employeeId = userInfo.employeeId; |
|
|
|
|
// } else { |
|
|
|
|
// uni.navigateTo({ |
|
|
|
|
// url: '/pages/setting/user' |
|
|
|
|
// }) |
|
|
|
|
// } |
|
|
|
|
// } else { |
|
|
|
|
// // uni.showModal({ |
|
|
|
|
// // title: '是否忽略电池优化', |
|
|
|
|
// // content: '忽略后才能在后台保持连接接收消息通知,请前往设置!', |
|
|
|
|
// // confirmText: '去设置', |
|
|
|
|
// // success: (res) => { |
|
|
|
|
// // if (res.confirm) { |
|
|
|
|
// // var main = plus.android.runtimeMainActivity(); |
|
|
|
|
// // var Intent = plus.android.importClass('android.content.Intent'); //导入插件 |
|
|
|
|
// // var Settings = plus.android.importClass('android.provider.Settings'); //导入插件 |
|
|
|
|
// // var intent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); //打开耗电详情 |
|
|
|
|
// // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
|
|
|
// // main.startActivity(intent); //执行 |
|
|
|
|
// // } |
|
|
|
|
// // } |
|
|
|
|
// // }); |
|
|
|
|
// } |
|
|
|
|
// }); |
|
|
|
|
/********设置开机自动启动结束********/ |
|
|
|
|
}, |
|
|
|
|
beforeDestroy() { |
|
|
|
|
console.log('销毁'); |
|
|
|
|
this.stop(); |
|
|
|
|
}, |
|
|
|
|
onShow: function() { |
|
|
|
|
//清除通知消息 |
|
|
|
|
this.msgIds.map(id => { |
|
|
|
|
console.log('取消通知', id) |
|
|
|
|
this.onCancelNotify(id); |
|
|
|
|
}) |
|
|
|
|
this.msgIds = []; |
|
|
|
|
console.log('App Show'); |
|
|
|
|
let userInfo = uni.getStorageSync('mobileInfo') ? JSON.parse(uni.getStorageSync('mobileInfo')) : null; |
|
|
|
|
if (userInfo && userInfo.employeeId != this.employeeId) { |
|
|
|
|
this.employeeId = userInfo.employeeId; |
|
|
|
|
this.getStatus(); |
|
|
|
|
// this.subStatus(); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
// uni.navigateTo({ |
|
|
|
|
// url: '/pages/setting/user' |
|
|
|
|
// }) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
onHide: function() { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
console.log('通知', new Date().getTime()) |
|
|
|
|
this.onShowNotify(); |
|
|
|
|
}, 1000) |
|
|
|
|
setTimeout(() => { |
|
|
|
|
console.log('通知', new Date().getTime()) |
|
|
|
|
this.onShowNotify(); |
|
|
|
|
}, 3000) |
|
|
|
|
console.log('App Hide', this.employeeId); |
|
|
|
|
if (this.employeeId) { |
|
|
|
|
// this.getStatus(); |
|
|
|
|
@ -131,7 +116,7 @@ |
|
|
|
|
subStatus(num) { |
|
|
|
|
//监听 websocket 连接状态 |
|
|
|
|
websocket.subStatus(res => { |
|
|
|
|
console.log("监听 websocket 连接状态"+num, res); |
|
|
|
|
console.log("监听 websocket 连接状态" + num, res); |
|
|
|
|
if (!res.websocketStatus) { |
|
|
|
|
this.stop(); |
|
|
|
|
this.timer && clearTimeout(this.timer); |
|
|
|
|
@ -159,11 +144,14 @@ |
|
|
|
|
//通用保活 |
|
|
|
|
keepAlive.onKeep({ |
|
|
|
|
title: "齐鲁医院报警通知", |
|
|
|
|
content: "保持运行", |
|
|
|
|
content: "保持运行中...", |
|
|
|
|
isRouge: true |
|
|
|
|
}, |
|
|
|
|
(res) => { |
|
|
|
|
console.log(res); |
|
|
|
|
console.log('onkeep', res); |
|
|
|
|
// if (res.ok) { |
|
|
|
|
// this.isIgnoringBattery(); |
|
|
|
|
// } |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
onAutoStart() { //去设置自启动、后台运行 |
|
|
|
|
@ -204,26 +192,26 @@ |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
onShowNotify() { //常驻通知保活 |
|
|
|
|
let id = new Date().getTime(); |
|
|
|
|
keepAlive.onShowNotify({ |
|
|
|
|
//channelId: "Ba-KeepAlive", |
|
|
|
|
//channelName: "Ba-KeepAlive", |
|
|
|
|
ID: new Date().getTime(), |
|
|
|
|
// channelId: "Ba-KeepAlive", |
|
|
|
|
// channelName: "Ba-KeepAlive", |
|
|
|
|
ID: id, |
|
|
|
|
title: "入侵报警信息", |
|
|
|
|
content: this.message, |
|
|
|
|
}, |
|
|
|
|
(res) => { |
|
|
|
|
console.log(res); |
|
|
|
|
this.msgIds.push(id); |
|
|
|
|
this.message = ''; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
onCancelNotify() { |
|
|
|
|
onCancelNotify(id) { |
|
|
|
|
//取消常驻通知保活 |
|
|
|
|
keepAlive.onCancelNotify({ |
|
|
|
|
//channelId: "Ba-KeepAlive", |
|
|
|
|
//channelName: "Ba-KeepAlive", |
|
|
|
|
//ID:99 |
|
|
|
|
//title: "测试", |
|
|
|
|
//content: "常驻通知描述", |
|
|
|
|
// channelId: "Ba-KeepAlive", |
|
|
|
|
// channelName: "Ba-KeepAlive", |
|
|
|
|
ID:id |
|
|
|
|
}, |
|
|
|
|
(res) => { |
|
|
|
|
console.log(res); |
|
|
|
|
|