Browse Source

【修复】之前校园卡进入,如果是新用户,回到首页无法启动微卡登陆组件,从而无法授权。

程志平 4 years ago
parent
commit
2951c6b3ab
3 changed files with 51 additions and 40 deletions
  1. 25 21
      pages/index/index.vue
  2. 18 15
      pages/jiaofei/jiaofei.vue
  3. 8 4
      pages/reshui/reshui.vue

+ 25 - 21
pages/index/index.vue

@@ -31,17 +31,18 @@
 			return {
 			return {
 				ceshi: 'code',
 				ceshi: 'code',
 				huanjing: '部署环境', // 部署环境是key,用来获取环境
 				huanjing: '部署环境', // 部署环境是key,用来获取环境
-				visible: false,  // 是否授权可见
-				showLogin: true,  // 是否启动授权
-				appkey: '5AA49F3E4CACA380',  // 商户appkey
+				visible: false, // 是否授权可见
+				showLogin: true, // 是否启动授权
+				appkey: '5AA49F3E4CACA380', // 商户appkey
 				appid: 'wx2fc3f45732fae5d3', // 获取用户信息
 				appid: 'wx2fc3f45732fae5d3', // 获取用户信息
 				ocode: '1015730314', // 获取用户信息
 				ocode: '1015730314', // 获取用户信息
 				app_secret: '58D34C81D82B35179ED896C4362B0FC0', // 获取用户信息
 				app_secret: '58D34C81D82B35179ED896C4362B0FC0', // 获取用户信息
-				userinfo: '',  // 用户信息
-				showQR_code: false,  // 显示校园卡二维码
-				validation_failed: false,  // 验证失败
-				validation_times: 0,  // 授权次数
-				from: 0,  // 跳转参数
+				userinfo: '', // 用户信息
+				showQR_code: false, // 显示校园卡二维码
+				validation_failed: false, // 验证失败
+				validation_times: 0, // 授权次数
+				from: 0, // 跳转参数
+				execed_onload: false
 			}
 			}
 		},
 		},
 		onLoad(options) {
 		onLoad(options) {
@@ -51,8 +52,16 @@
 			}
 			}
 			// 是否是测试环境,查询数据接口中参数的值决定,方便以后测试
 			// 是否是测试环境,查询数据接口中参数的值决定,方便以后测试
 			this.isTestEnvironment()
 			this.isTestEnvironment()
-
+			// 检查是否存在用户信息
 			this.has_user_info()
 			this.has_user_info()
+
+			this.execed_onload = true
+		},
+		onShow() {
+			if (!this.execed_onload) {
+				// 检查是否存在用户信息
+				this.has_user_info()
+			}
 		},
 		},
 		methods: {
 		methods: {
 			/**
 			/**
@@ -91,15 +100,11 @@
 			 */
 			 */
 			has_user_info() {
 			has_user_info() {
 				try {
 				try {
-					this.userinfo = this.$store.state.userInfo
+					// console.log(111111);
 					const value = uni.getStorageSync('userinfo_storage_key');
 					const value = uni.getStorageSync('userinfo_storage_key');
 					if (value == '') {
 					if (value == '') {
-						if (typeof(this.userinfo) == 'undefined' || JSON.stringify(this.userinfo) == '{}') {
-							this.showLogin = true
-							this.visible = true
-						} else {
-							this.showLogin = false
-						}
+						this.showLogin = true
+						this.visible = true
 					} else {
 					} else {
 						this.showLogin = false
 						this.showLogin = false
 						this.userinfo = value
 						this.userinfo = value
@@ -124,7 +129,7 @@
 			 */
 			 */
 			reauthorization() {
 			reauthorization() {
 				this.validation_times = this.validation_times + 1
 				this.validation_times = this.validation_times + 1
-				
+
 				if (this.validation_times >= 2) {
 				if (this.validation_times >= 2) {
 					this.login_fail_callback()
 					this.login_fail_callback()
 				} else {
 				} else {
@@ -134,7 +139,7 @@
 							this.showLogin = false
 							this.showLogin = false
 							this.userinfo = {}
 							this.userinfo = {}
 						}, 30)
 						}, 30)
-								
+
 						setTimeout(() => {
 						setTimeout(() => {
 							this.showLogin = true
 							this.showLogin = true
 							this.visible = true
 							this.visible = true
@@ -216,7 +221,7 @@
 				const {
 				const {
 					wxcode = ""
 					wxcode = ""
 				} = detail
 				} = detail
-				
+
 				this.validation_failed = false
 				this.validation_failed = false
 				// 通过wxcode换取access_token
 				// 通过wxcode换取access_token
 				this.get_access_token(wxcode)
 				this.get_access_token(wxcode)
@@ -341,8 +346,7 @@
 					uni.showToast({
 					uni.showToast({
 						icon: 'success',
 						icon: 'success',
 						title: '授权失败:' + res.data.mess,
 						title: '授权失败:' + res.data.mess,
-						success: (res) => {
-						}
+						success: (res) => {}
 					})
 					})
 				}
 				}
 			}
 			}

+ 18 - 15
pages/jiaofei/jiaofei.vue

@@ -118,7 +118,7 @@
 								title: '学号为空,请进行授权',
 								title: '学号为空,请进行授权',
 								duration: 3000
 								duration: 3000
 							});
 							});
-							
+
 							return
 							return
 						}
 						}
 					}
 					}
@@ -140,7 +140,7 @@
 						}
 						}
 					}
 					}
 				}
 				}
-				
+
 				// 初始化参数
 				// 初始化参数
 				this.$store.state.building.add_class = 0;
 				this.$store.state.building.add_class = 0;
 
 
@@ -215,20 +215,23 @@
 
 
 					// console.log('获得openid', res);
 					// console.log('获得openid', res);
 					if (res.data.mess == '返回成功') {
 					if (res.data.mess == '返回成功') {
-						// 栋宿舍号
-						this.dorm_number = res.data.info[0].build + res.data.info[0].dom
-						// 校区
-						this.compus = res.data.info[0].campus
-						// 填充校区宿舍号
-						if (typeof(this.dorm_number.split('栋')[1]) == 'undefined') {
-							this.roomSelect = this.compus + ''
-						} else {
-							this.roomSelect = this.compus + this.dorm_number.split('栋')[1]
+						if (!(this.$store.state.building.roomSelect && typeof(this.$store.state.building.roomSelect) !=
+							'undefined')) {
+							// 栋宿舍号
+							this.dorm_number = res.data.info[0].build + res.data.info[0].dom
+							// 校区
+							this.compus = res.data.info[0].campus
+							// 填充校区宿舍号
+							if (typeof(this.dorm_number.split('栋')[1]) == 'undefined') {
+								this.roomSelect = this.compus + ''
+							} else {
+								this.roomSelect = this.compus + this.dorm_number.split('栋')[1]
+							}
+							// 存储选择
+							this.$store.state.building.roomSelect = this.roomSelect
+							// 样式
+							this.add_class = 1
 						}
 						}
-						// 存储选择
-						this.$store.state.building.roomSelect = this.roomSelect
-						// 样式
-						this.add_class = 1
 
 
 						// 请求选定的月份消费记录
 						// 请求选定的月份消费记录
 						this.getDianLiang()
 						this.getDianLiang()

+ 8 - 4
pages/reshui/reshui.vue

@@ -172,7 +172,7 @@
 								title: '学号为空,请进行授权',
 								title: '学号为空,请进行授权',
 								duration: 3000
 								duration: 3000
 							});
 							});
-							
+
 							return
 							return
 						}
 						}
 					}
 					}
@@ -202,7 +202,7 @@
 			getCode(options, param) {
 			getCode(options, param) {
 				uni.login({
 				uni.login({
 					success: (res) => {
 					success: (res) => {
-						// console.log('reshui', res);
+						// console.log('getCode', res);
 						if (res.code) {
 						if (res.code) {
 							// 请求服务器,获得openid
 							// 请求服务器,获得openid
 							this.getOpenId(options, res.code, param)
 							this.getOpenId(options, res.code, param)
@@ -231,7 +231,7 @@
 					}
 					}
 				})
 				})
 
 
-				// console.log(res);
+				// console.log('getOpenId', res);
 				if (res.data.mess == '返回成功') {
 				if (res.data.mess == '返回成功') {
 					// 判断存储的stu_number与返回的stu_number是否一致
 					// 判断存储的stu_number与返回的stu_number是否一致
 					let cardNumber = res.data.info[0].card_number
 					let cardNumber = res.data.info[0].card_number
@@ -324,7 +324,7 @@
 						}
 						}
 					});
 					});
 
 
-					// console.log(res);
+					console.log(res);
 					if (res.data.mess == '返回成功') {
 					if (res.data.mess == '返回成功') {
 						this.xiaofei_items = []
 						this.xiaofei_items = []
 						// 消费记录
 						// 消费记录
@@ -341,6 +341,10 @@
 									this.changeDate = false
 									this.changeDate = false
 								}
 								}
 							})
 							})
+
+							if (res.data.mess == '本月无消费记录') {
+								this.xiaofei_items = []
+							}
 						}
 						}
 					}
 					}
 				} else {
 				} else {