guhongwei 2 tahun lalu
induk
melakukan
b1e2125a96
2 mengubah file dengan 70 tambahan dan 28 penghapusan
  1. 34 0
      App.vue
  2. 36 28
      pages/login/index.vue

+ 34 - 0
App.vue

@@ -1,5 +1,39 @@
 <script>
 	export default {
+		onLaunch: function() {
+			const that = this;
+			that.forceUpdate();
+		},
+		methods: {
+			// 强制更新
+			forceUpdate() {
+				const that = this;
+				let system = that.$config.system;
+				if (system.uniPlatform == 'mp-weixin') {
+					const updateManager = uni.getUpdateManager();
+					updateManager.onCheckForUpdate(function(res) {
+						// 请求完新版本信息的回调
+						console.log(res.hasUpdate);
+					});
+					updateManager.onUpdateReady(function(res) {
+						uni.showModal({
+							title: '更新提示',
+							content: '新版本已经准备好,是否重启应用?',
+							success(res) {
+								if (res.confirm) {
+									uni.clearStorage();
+									updateManager.applyUpdate();
+								}
+							}
+						});
+					});
+					updateManager.onUpdateFailed(function(res) {
+						console.log(res);
+						console.log('更新失败');
+					});
+				}
+			}
+		}
 	}
 </script>
 

+ 36 - 28
pages/login/index.vue

@@ -423,6 +423,7 @@
 				const that = this;
 				let system = that.system;
 				let agree = that.agree;
+				let openid = that.openid;
 				if (agree) {
 					if (system.uniPlatform == 'app') {
 						uni.showToast({
@@ -432,38 +433,46 @@
 						// todo:app端,微信一键登录
 					} else if (system.uniPlatform == 'mp-weixin') {
 						if (e == 'wx') {
-							const res = await that.$api(`/user/wxLogin`, 'POST', {
-								openid: that.openid
-							})
-							if (res.errcode == '0') {
-								uni.setStorage({
-									key: 'token',
-									data: res.data,
-									success: function() {
-										uni.navigateBack({
-											delta: 1
-										})
-									}
-								});
-							} else {
-								if (res.errcode == '-5') {
-									uni.showModal({
-										title: '提示',
-										content: '用户不存在,是否注册新账号?',
-										success: function(res) {
-											if (res.confirm) {
-												// 无账号,注册账号
-												that.wxCreate();
-											}
+							if (openid) {
+								const res = await that.$api(`/user/wxLogin`, 'POST', {
+									openid: openid
+								})
+								if (res.errcode == '0') {
+									uni.setStorage({
+										key: 'token',
+										data: res.data,
+										success: function() {
+											uni.navigateBack({
+												delta: 1
+											})
 										}
 									});
 								} else {
-									uni.showToast({
-										title: res.errmsg || '信息错误',
-										icon: 'none'
-									})
+									if (res.errcode == '-5') {
+										uni.showModal({
+											title: '提示',
+											content: '用户不存在,是否注册新账号?',
+											success: function(res) {
+												if (res.confirm) {
+													// 无账号,注册账号
+													that.wxCreate();
+												}
+											}
+										});
+									} else {
+										uni.showToast({
+											title: res.errmsg || '信息错误',
+											icon: 'none'
+										})
+									}
 								}
+							} else {
+								uni.showToast({
+									title: '缺少必要信息,暂无法登录!',
+									icon: 'none'
+								})
 							}
+
 						}
 					}
 				} else {
@@ -486,7 +495,6 @@
 							}],
 							name: res.userInfo.nickName,
 						}
-						console.log(parmas);
 						const arr = await that.$api(`/user`, 'POST', parmas);
 						if (arr.errcode == '0') {
 							that.$set(that, `user`, arr.data);