|
@@ -8,7 +8,7 @@
|
|
import * as config from '@/config'
|
|
import * as config from '@/config'
|
|
import appUpdate from 'common/appUpdate.js'
|
|
import appUpdate from 'common/appUpdate.js'
|
|
import app_push from './components/APPPush/app_push.js'
|
|
import app_push from './components/APPPush/app_push.js'
|
|
-
|
|
|
|
|
|
+ const pushLive = uni.requireNativePlugin('service-keep-live');
|
|
export default {
|
|
export default {
|
|
methods: {
|
|
methods: {
|
|
...mapMutations(['login']),
|
|
...mapMutations(['login']),
|
|
@@ -83,16 +83,112 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return _haveRoles
|
|
return _haveRoles
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ goStartService() {
|
|
|
|
+ let obj = {
|
|
|
|
+ title: "易粮易运",
|
|
|
|
+ content: "正在后台运行",
|
|
|
|
+ mode: 1, //0是省点模式 1流氓模式
|
|
|
|
+ isShow:false //true显示通知栏,false隐藏通知栏
|
|
|
|
+ }
|
|
|
|
+ pushLive.startService(obj, function(res) {
|
|
|
|
+ console.log(res)
|
|
|
|
+ });
|
|
|
|
+ //判断是否加入白名单
|
|
|
|
+ pushLive.isIgnoringBatteryOptimizations(function(res) {
|
|
|
|
+ console.log(res);
|
|
|
|
+ let flag = res.flag;
|
|
|
|
+ if (flag == false) {
|
|
|
|
+ //提示 如果为了提高黑屏传点效果可以使用第二种申请加入白名单方式
|
|
|
|
+ //第一种申请加入白名单 只设置电量优化
|
|
|
|
+ pushLive.requestIgnoreBatteryOptimizations(function(res) {
|
|
|
|
+ console.log(res)
|
|
|
|
+ });
|
|
|
|
+ //第二种 申请加入白名单,设置后台无限制,自启动(无需设置),设置电量优化
|
|
|
|
+ // pushLive.gotoBackstage_WhiteList_autStart()
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ //设置定时任务触发时间 单位秒 60秒
|
|
|
|
+ //如果在设置后台运行的情况下,黑屏不发送数据,请使用setInterval代替
|
|
|
|
+ pushLive.setJobTime(60, function(res) {
|
|
|
|
+ console.log(res)
|
|
|
|
+ });
|
|
|
|
+ //设置黑屏唤醒屏幕 单位分钟 10分钟
|
|
|
|
+ pushLive.setWakeScreen(5)
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ //判断应用是否添加在白名单之中
|
|
|
|
+ isIgnoringBattery() {
|
|
|
|
+ pushLive.isIgnoringBatteryOptimizations(function(res) {
|
|
|
|
+ console.log(res);
|
|
|
|
+ let flag = res.flag;
|
|
|
|
+ if (flag == false) {
|
|
|
|
+ pushLive.requestIgnoreBatteryOptimizations(function(res) {
|
|
|
|
+ console.log(res)
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ //申请加入白名单
|
|
|
|
+ requestIgnoreBattery() {
|
|
|
|
+ pushLive.requestIgnoreBatteryOptimizations(function(res) {
|
|
|
|
+ console.log(res)
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ //设置app自启动
|
|
|
|
+ whiteListSetting() {
|
|
|
|
+ pushLive.gotoWhiteListSetting()
|
|
|
|
+ },
|
|
|
|
+ stopService() {
|
|
|
|
+ pushLive.closeService(function(res) {
|
|
|
|
+ console.log(res)
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ gotoBackstageWhiteListAutStart() {
|
|
|
|
+ pushLive.gotoBackstage_WhiteList_autStart()
|
|
|
|
+ },
|
|
|
|
+ addLocation() {
|
|
|
|
+ let dst = setInterval(function() {
|
|
|
|
+ uni.request({
|
|
|
|
+ header: {
|
|
|
|
+ 'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
+ },
|
|
|
|
+ url: 'http://123.*******/location',
|
|
|
|
+ data: {
|
|
|
|
+ longitude: 114.1598,
|
|
|
|
+ latitude: 32.145380,
|
|
|
|
+ user_id: 1812
|
|
|
|
+ },
|
|
|
|
+ method: 'POST',
|
|
|
|
+ success: (res) => {
|
|
|
|
+ console.log(res)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }, 1000 * 60)
|
|
|
|
+ },
|
|
},
|
|
},
|
|
onLaunch: function() {
|
|
onLaunch: function() {
|
|
// #ifdef APP-PLUS
|
|
// #ifdef APP-PLUS
|
|
-
|
|
|
|
- let type = uni.getSystemInfoSync().platform
|
|
|
|
- console.log(type)
|
|
|
|
if (type == "android") {
|
|
if (type == "android") {
|
|
appUpdate()
|
|
appUpdate()
|
|
}
|
|
}
|
|
|
|
+ //获取安卓版本号
|
|
|
|
+ pushLive.checkAndroidVersion(function(res) {
|
|
|
|
+ console.log(res)
|
|
|
|
+ })
|
|
|
|
+ //注意:开启服务之后,配置后台运行,白名单,自启动,即可实现长时间保活,黑屏传数据
|
|
|
|
+ this.goStartService();
|
|
|
|
+ // !!!如果在设置后台运行的情况下,黑屏不发送数据,请使用setInterval代替 定时任务回调
|
|
|
|
+ var globalEvent = uni.requireNativePlugin('globalEvent');
|
|
|
|
+ globalEvent.addEventListener('doJobEvent', function() {
|
|
|
|
+ console.log("---------")
|
|
|
|
+ /* uni.request({}) */
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ let type = uni.getSystemInfoSync().platform
|
|
|
|
+ console.log(type)
|
|
|
|
+
|
|
var that = this
|
|
var that = this
|
|
plus.push.getClientInfoAsync((info) => {
|
|
plus.push.getClientInfoAsync((info) => {
|
|
var name = 'clientId'
|
|
var name = 'clientId'
|
|
@@ -183,6 +279,7 @@
|
|
|
|
|
|
},
|
|
},
|
|
onShow: function() {
|
|
onShow: function() {
|
|
|
|
+
|
|
console.log('App Show')
|
|
console.log('App Show')
|
|
},
|
|
},
|
|
onHide: function() {
|
|
onHide: function() {
|