|
|
|
|
@ -12,52 +12,76 @@ |
|
|
|
|
}, |
|
|
|
|
data() { |
|
|
|
|
return { |
|
|
|
|
heartBeatEate: 60, //单位秒 |
|
|
|
|
heartBeatEate: 10, //单位秒 |
|
|
|
|
employeeId: '', |
|
|
|
|
message: '', //报警信息通知 |
|
|
|
|
timer: null, |
|
|
|
|
reportLastTime: null,//报警信息最后一次时间 |
|
|
|
|
reportLastTime: null, //报警信息最后一次时间 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
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; |
|
|
|
|
// this.getStatus(); |
|
|
|
|
} 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('销毁'); |
|
|
|
|
weboscket.stop(); |
|
|
|
|
this.stop(); |
|
|
|
|
}, |
|
|
|
|
onShow: function() { |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
if (keepAlive) { |
|
|
|
|
console.log('清除消息'); |
|
|
|
|
this.onCancelNotify(); |
|
|
|
|
this.getStatus(); |
|
|
|
|
this.subStatus(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
onHide: function() { |
|
|
|
|
console.log('App Hide'); |
|
|
|
|
if(this.employeeId) { |
|
|
|
|
console.log('App Hide', this.employeeId); |
|
|
|
|
if (this.employeeId) { |
|
|
|
|
this.sendMsg(); |
|
|
|
|
this.getStatus(); |
|
|
|
|
this.receiveMsg(); |
|
|
|
|
this.getStatus(1); |
|
|
|
|
this.subStatus(); |
|
|
|
|
} else { |
|
|
|
|
let userInfo = uni.getStorageSync('mobileInfo') ? JSON.parse(uni.getStorageSync('mobileInfo')) : null; |
|
|
|
|
if (userInfo && userInfo.employeeId != this.employeeId) { |
|
|
|
|
this.employeeId = userInfo.employeeId; |
|
|
|
|
this.sendMsg(); |
|
|
|
|
this.getStatus(); |
|
|
|
|
this.receiveMsg(); |
|
|
|
|
this.subStatus(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
@ -76,7 +100,7 @@ |
|
|
|
|
stop() { |
|
|
|
|
//停止服务 |
|
|
|
|
websocket.stop(res => { |
|
|
|
|
console.log('关闭websocket',res); |
|
|
|
|
console.log('关闭websocket', res); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
receiveMsg() { |
|
|
|
|
@ -85,9 +109,10 @@ |
|
|
|
|
console.log(res); |
|
|
|
|
if (res.ok && res.msg != '连接成功' && res.msg != 'header' && res.msg.indexOf('拒绝') < 0) { |
|
|
|
|
let obj = JSON.parse(res.msg); |
|
|
|
|
if(this.reportLastTime != obj.reportTime) { |
|
|
|
|
if (this.reportLastTime != obj.reportTime) { |
|
|
|
|
this.reportLastTime = obj.reportTime; |
|
|
|
|
this.message = obj.buildId + '号楼' + obj.floorNo + '层' + dateFormat(new Date(obj.reportTime)) + '发生报警:' + obj |
|
|
|
|
this.message = obj.buildId + '号楼' + obj.floorNo + '层' + dateFormat(new Date(obj.reportTime)) + |
|
|
|
|
'发生报警:' + obj |
|
|
|
|
.content; |
|
|
|
|
this.onShowNotify(); |
|
|
|
|
} |
|
|
|
|
@ -106,7 +131,13 @@ |
|
|
|
|
console.log('监听状态') |
|
|
|
|
websocket.subStatus(res => { |
|
|
|
|
console.log("监听 websocket 连接状态", res); |
|
|
|
|
if (!res.serviceStatus && !res.websocketStatus) { |
|
|
|
|
keepAlive.onShowNotify({ |
|
|
|
|
ID: new Date().getTime(), |
|
|
|
|
title: "监听 websocket 连接状态", |
|
|
|
|
content: res.serviceStatus + ' - ' + res.websocketStatus, |
|
|
|
|
}, |
|
|
|
|
(res) => {}); |
|
|
|
|
if (res.serviceStatus && !res.websocketStatus) { |
|
|
|
|
this.stop(); |
|
|
|
|
this.timer && clearTimeout(this.timer); |
|
|
|
|
this.timer = setTimeout(() => { |
|
|
|
|
@ -119,11 +150,8 @@ |
|
|
|
|
//获取 websocket 服务开启状态 |
|
|
|
|
websocket.getStatus(res => { |
|
|
|
|
console.log("websocket开启状态", res); |
|
|
|
|
if (res.data.serviceStatus) { |
|
|
|
|
if(type == 1) { |
|
|
|
|
this.subStatus(); |
|
|
|
|
} |
|
|
|
|
}else if(!res.data.serviceStatus && !res.data.websocketStatus){ |
|
|
|
|
if (!res.data.websocketStatus) { |
|
|
|
|
this.stop(); |
|
|
|
|
this.timer && clearTimeout(this.timer); |
|
|
|
|
this.timer = setTimeout(() => { |
|
|
|
|
this.start(); |
|
|
|
|
@ -135,10 +163,9 @@ |
|
|
|
|
onKeep() { |
|
|
|
|
//通用保活 |
|
|
|
|
keepAlive.onKeep({ |
|
|
|
|
//channelId: "Ba-KeepAlive", |
|
|
|
|
//channelName: "Ba-KeepAlive", |
|
|
|
|
// title: "测试", |
|
|
|
|
// content: "常驻通知描述", |
|
|
|
|
title: "齐鲁医院报警通知", |
|
|
|
|
content: "保持通知", |
|
|
|
|
isRouge: true |
|
|
|
|
}, |
|
|
|
|
(res) => { |
|
|
|
|
console.log(res); |
|
|
|
|
@ -211,7 +238,7 @@ |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
plus.android.requestPermissions( |
|
|
|
|
[ |
|
|
|
|
"android.permission.RECEIVE_BOOT_COMPLETED", |
|
|
|
|
"android.permission.RECEIVE_BOOT_COMPLETED", //开机自启权限 |
|
|
|
|
"android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS", //忽略电池优化 |
|
|
|
|
], |
|
|
|
|
(resultObj) => { |
|
|
|
|
@ -232,16 +259,6 @@ |
|
|
|
|
result = -1; |
|
|
|
|
} |
|
|
|
|
resolve(result); |
|
|
|
|
//若所需权限被拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限 |
|
|
|
|
if (result == -1) { |
|
|
|
|
reject("授权失败:" + JSON.stringify(resultObj.deniedAlways)); |
|
|
|
|
if (resultObj.deniedAlways.indexOf('android.permission.RECEIVE_BOOT_COMPLETED') > -1) { |
|
|
|
|
this.onAutoStart(); |
|
|
|
|
} else if (resultObj.deniedAlways.indexOf( |
|
|
|
|
'android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS') > -1) { |
|
|
|
|
this.requestIgnoreBattery(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
(error) => { |
|
|
|
|
console.log('申请权限错误:' + error.code + " = " + error.message); |
|
|
|
|
|