ccjgmwz 3 years ago
parent
commit
81748a60dd
3 changed files with 124 additions and 9 deletions
  1. 102 6
      App.vue
  2. 4 0
      common/appUpdate.js
  3. 18 3
      manifest.json

+ 102 - 6
App.vue

@@ -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,109 @@
 					}
 					}
 				}
 				}
 				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
-
+			//获取安卓版本号 
+			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
 			let type = uni.getSystemInfoSync().platform
 			console.log(type)
 			console.log(type)
-			if (type == "android") {
-				appUpdate()
-			}
+			
 			var that = this
 			var that = this
 			plus.push.getClientInfoAsync((info) => {
 			plus.push.getClientInfoAsync((info) => {
 				var name = 'clientId'
 				var name = 'clientId'
@@ -183,6 +276,9 @@
 
 
 		},
 		},
 		onShow: function() {
 		onShow: function() {
+			if (type == "android") {
+				appUpdate()
+			}
 			console.log('App Show')
 			console.log('App Show')
 		},
 		},
 		onHide: function() {
 		onHide: function() {

+ 4 - 0
common/appUpdate.js

@@ -51,6 +51,10 @@ export default function appUpdate() {
 						})
 						})
 					} else if (flag_hot) {
 					} else if (flag_hot) {
 						console.log("热更新") 
 						console.log("热更新") 
+						uni.showToast({
+							icon:'none',
+							title:'正在热更新'
+						})
 						uni.downloadFile({
 						uni.downloadFile({
 							url: res.data.data.wgtUrl,
 							url: res.data.data.wgtUrl,
 							success: (downloadResult) => {
 							success: (downloadResult) => {

+ 18 - 3
manifest.json

@@ -2,8 +2,8 @@
     "name" : "易粮易运",
     "name" : "易粮易运",
     "appid" : "__UNI__7297DA2",
     "appid" : "__UNI__7297DA2",
     "description" : "易粮易运——为天下粮食人服务的App",
     "description" : "易粮易运——为天下粮食人服务的App",
-    "versionName" : "1.1.77",
-    "versionCode" : 1177,
+    "versionName" : "1.2.1",
+    "versionCode" : 121,
     "transformPx" : false,
     "transformPx" : false,
     /* SDK配置 */
     /* SDK配置 */
     "quickapp" : {},
     "quickapp" : {},
@@ -197,6 +197,21 @@
         "statusbar" : {
         "statusbar" : {
             "immersed" : false
             "immersed" : false
         },
         },
-        "nativePlugins" : {}
+        "nativePlugins" : {
+            "service-keep-live" : {
+                "__plugin_info__" : {
+                    "name" : "【推荐】安卓保活插件 防杀  增强保活,黑屏防睡眠(测试黑屏传数据一天多没问题)",
+                    "description" : "如果你的应用希望能够一直在后台运行而不被系统自动杀死的话,可以尝试一下。群485147231(已满) 598812409",
+                    "platforms" : "Android",
+                    "url" : "https://ext.dcloud.net.cn/plugin?id=3422",
+                    "android_package_name" : "uni.UNI7297DA2",
+                    "ios_bundle_id" : "uni.UNI7297DA2",
+                    "isCloud" : true,
+                    "bought" : 1,
+                    "pid" : "3422",
+                    "parameters" : {}
+                }
+            }
+        }
     }
     }
 }
 }