Browse Source

调整启动

aleyds 3 years ago
parent
commit
0a1d87557a
4 changed files with 58 additions and 45 deletions
  1. 6 36
      App.vue
  2. 31 0
      utils/deviceUtils.js
  3. 16 0
      utils/pushUtils.js
  4. 5 9
      utils/update.js

+ 6 - 36
App.vue

@@ -1,47 +1,17 @@
 <script>
 	//#ifdef APP-PLUS
 	var alog = uni.requireNativePlugin("AndroidLog")
-	var device = uni.requireNativePlugin("DeviceInfo")
+	// var device = uni.requireNativePlugin("DeviceInfo")
 	import update from '@/utils/update.js';
+	import deviceUt from '@/utils/deviceUtils.js';
+	import pushreg from '@/utils/pushUtils.js';
 	//#endif
 	export default {
 		onLaunch: function() {
-			
 			//#ifdef APP-PLUS
-			
-			update(this);
-			//判断客户端类别
-			const _handlePush = function(message) {
-				//{"message":{"__UUID__":"androidPushMsg222631973","appid":"__UNI__29ECCC8","content":"{\"type\":2,\"jumpTo\":\"pages/login/login\"}","payload":{"jumpTo":"pages/login/login","type":2},"title":"智慧停车PDA"}}
-
-			};
-			// 
-			setTimeout(() => {
-				var pinf = plus.push.getClientInfo();
-				var cid = pinf.clientid; //客户端标识  
-				if (cid != null && cid != '' && cid != 'null') {
-					//注册设备
-					var deviceInfo = device.getDeviceInfo()
-					this.$u.api.deviceReg({
-							deviceNo: deviceInfo.deviceId,
-							pushCid: cid
-						})
-						.then(res => {
-							if (res.code == 200) {
-								plus.nativeUI.toast('设备注册成功');
-							} else {
-								plus.nativeUI.toast('设备注册失败');
-							}
-						}).catch(err => {
-							plus.nativeUI.toast('设备注册失败');
-						});
-					clearTimeout()
-				}
-			}, 400);
-			//监听系统通知栏消息点击事件  
-			plus.push.addEventListener('click', _handlePush, false);
-			//监听接收透传消息事件
-			plus.push.addEventListener('receive', _handlePush, false);
+			update(this); //软件更新
+			deviceUt.devicereg(this);  //设备注册
+			pushreg();  //推送注册
 			//#endif
 			//#ifdef H5
 			  this.$u.api.deviceReg({

+ 31 - 0
utils/deviceUtils.js

@@ -0,0 +1,31 @@
+
+// var alog = uni.requireNativePlugin("AndroidLog")
+// var apk = uni.requireNativePlugin("ApkPlug")
+var device = uni.requireNativePlugin("DeviceInfo")
+function devicereg(vue){	
+		setTimeout(() => {
+			var pinf = plus.push.getClientInfo();
+			var cid = pinf.clientid; //客户端标识  
+			if (cid) {
+				//注册设备
+				var deviceInfo = device.getDeviceInfo()
+				vue.$u.api.deviceReg({
+						deviceNo: deviceInfo.deviceId,
+						pushCid: cid
+					})
+					.then(res => {
+						if (res.code == 200) {
+							plus.nativeUI.toast('设备注册成功');
+						} else {
+							plus.nativeUI.toast('设备注册失败');
+						}
+					}).catch(err => {
+						plus.nativeUI.toast('设备注册失败');
+					});
+				clearTimeout()
+			}
+		}, 400);
+}
+export default {
+	devicereg
+}

+ 16 - 0
utils/pushUtils.js

@@ -0,0 +1,16 @@
+
+
+var alog = uni.requireNativePlugin("AndroidLog")
+const _handlePush = function(message) {
+				//{"message":{"__UUID__":"androidPushMsg222631973","appid":"__UNI__29ECCC8","content":"{\"type\":2,\"jumpTo\":\"pages/login/login\"}","payload":{"jumpTo":"pages/login/login","type":2},"title":"智慧停车PDA"}}
+				alog.info({msg: '接收到推送信息:' + JSON.stringify(message)});
+			};
+
+function pushreg(vue){	
+	     alog.info({msg: '推送注册'});
+		//监听系统通知栏消息点击事件
+		plus.push.addEventListener('click', _handlePush, false);
+		//监听接收透传消息事件
+		plus.push.addEventListener('receive', _handlePush, false);
+}
+export default pushreg

+ 5 - 9
utils/update.js

@@ -1,7 +1,7 @@
 
-var alog = uni.requireNativePlugin("AndroidLog")
-var apk = uni.requireNativePlugin("ApkPlug")
-function update(vue, callback){	
+// var alog = uni.requireNativePlugin("AndroidLog")
+// var apk = uni.requireNativePlugin("ApkPlug")
+function update(vue){	
 	plus.runtime.getProperty(plus.runtime.appid, function(wgtInfo){
 	  vue.$u.api.appveriosn({
 			appid: wgtInfo.appid,
@@ -12,20 +12,16 @@ function update(vue, callback){
 		.then(res => {
 			let data = res.data;
 			if(data.isUpload && data.wgtUrl){
-				// wgtUpdate(data)
 				updateExecute({
 					note: data.note,
 					downUrl: data.wgtUrl,
-					type: 1,
-					callback: callback
+					type: 1
 				});
 			}else if (data.isUpload && data.pkgUrl){
-				// pkgUpdate(data);
 				updateExecute({
 					note: data.note,
 					downUrl: data.pkgUrl,
-					type: 2,
-					callback: callback
+					type: 2
 				});
 			}else{
 				plus.nativeUI.toast('已经是最新版本');