Browse Source

Signed-off-by: liuboyan <632697560@qq.com>
1

liuboyan 4 years ago
parent
commit
d86d02e3ed
1 changed files with 26 additions and 21 deletions
  1. 26 21
      pages/login/index.vue

+ 26 - 21
pages/login/index.vue

@@ -41,6 +41,7 @@
 		data() {
 			return {
 				logo: API.getServerImg + 'logo.png',
+				code: '',
 				account: '',
 				password: '',
 				iconStyle: {
@@ -49,7 +50,20 @@
 				}
 			}
 		},
-		onLoad() {},
+		onShow() {
+			uni.login({
+				provider: 'weixin',
+				success: (res) => {
+					this.code = res.code
+				},
+				fail: () => {
+					this.$refs.uTips.show({
+						title: '微信登录授权失败',
+						type: 'warning',
+					})
+				}
+			})
+		},
 		methods: {
 			login() {
 				if (!this.account || !this.password) {
@@ -99,32 +113,23 @@
 					}
 				});
 			},
+			//  微信一键登录--获取手机号
 			getUserinfoWechat(data) {
-				uni.login({
-					provider: 'weixin',
-					success: (res) => {
-						let wxLoginData = {
-							code: res.code,
-							encryptedData: data.target.encryptedData,
-							iv: data.target.iv,
-						}
-						uni.setStorage({
-							key: 'wxLoginData',
-							data: wxLoginData
-						})
-						this.getUserInfo(wxLoginData)
-					},
-					fail: () => {
-						this.$refs.uTips.show({
-							title: '微信登录授权失败',
-							type: 'warning',
-						})
-					}
+				let wxLoginData = {
+					code: this.code,
+					encryptedData: data.target.encryptedData,
+					iv: data.target.iv,
+				}
+				uni.setStorage({
+					key: 'wxLoginData',
+					data: wxLoginData
 				})
+				this.getUserInfo(wxLoginData)
 			},
 			// 发请求获取个人数据
 			getUserInfo(wxLoginData) {
 				NET.request(API.wxLogin, wxLoginData, 'POST').then(res => {
+					debugger
 					uni.setStorage({
 						key: 'token',
 						data: res.data.token