Browse Source

fix: fix login status bug

qiang 3 years ago
parent
commit
452859bd9c

+ 5 - 6
pages/classification/classification.wxml

@@ -1,6 +1,5 @@
 <!-- 搜索框 -->
 <search></search>
-
 <!-- 分类索引 -->
 <view class="hmly-ification">
 	<!-- 左边部分 -->
@@ -8,7 +7,9 @@
 		scroll-top="{{VerticalNavTop}}">
 		<block wx:for="{{ificationTitle}}" wx:key="index">
 			<view class="hmly-left-title {{index === activeIndex ? 'hmly-active':''}}" data-index="{{index}}"
-				data-id="{{index}}" bindtap="change">{{item.title}}</view>
+				data-id="{{index}}" bindtap="change">
+				{{item.title}}
+			</view>
 		</block>
 	</scroll-view>
 
@@ -18,10 +19,8 @@
 		<view class="hmly-content-scroll-item" wx:for="{{ificationContent}}" wx:key="index" data-index="{{index}}"
 			id="main-id-{{index}}">
 			<view class="hmly-top">
-				<view class="hmly-content-title">
-					{{item.title}}
-					<text class="icon-right"></text>
-				</view>
+				{{item.title}}
+				<text class="icon-right"></text>
 			</view>
 			<view class="hmly-content">
 				<view class="hmly-content-text" wx:for="{{item.content}}" wx:key="index">

+ 4 - 0
pages/classification/classification.wxss

@@ -43,6 +43,10 @@
 	height: 40rpx;
 	padding: 20rpx 0rpx;
 	margin: 0rpx auto;
+	font-size: center;
+	display: flex;
+	justify-content: center;
+	align-items: center;
 }
 
 .hmly-content-title {

+ 24 - 22
pages/collection/collection.js

@@ -3,15 +3,15 @@ Page({
   data: {
     currentIndex:0,
     height:0,
+    login: false,
     content: [
       {text: "我的收藏"},
       {text: "我的已购"},
       {text: "收听历史"},
       {text: "我的礼包"}
-    ],
-    login: true
+    ]
   },
-  onLoad(options) {
+  onLoad() {
     const that = this;
     wx.getSystemInfo({
       success (res) {
@@ -20,32 +20,34 @@ Page({
         })
       }
     })
-    wx.getStorage({
-      key: 'login',
-      success(res){
-        if(res.data === 200){
+  },
+  onShow() {
+    const that = this
+    if (!that.login) {
+      wx.getStorage({
+        key: 'userinfo',
+        success(res){
           that.setData({
-            login: false,
+            login: res.data ? true : false,
           })
         }
-      }
-    })
+      })
+    }
   },
   // 点击获取头像和昵称
   bindGetUserInfo(e) {
     const that = this;
-    wx.getUserInfo({
-      success: function (res) {
-        app.globalData.userInfo = e.detail.userInfo;
-        wx.setStorage({
-          key: "login",
-          data: 200
-        })
-        that.setData({
-          login: false,
-        })
-      }
-    })
+		wx.getUserInfo({
+			success: function (res) {
+				wx.setStorage({
+					key: "userinfo",
+					data: JSON.stringify(res.userInfo)
+				})
+				that.setData({
+					login: true
+				})
+			}
+		})
   },
   checkItem(e) {
     const that = this;

+ 1 - 1
pages/collection/collection.wxml

@@ -1,5 +1,5 @@
 <!-- 若是没有登录就显示登录界面 -->
-<block wx:if="{{login}}">
+<block wx:if="{{!login}}">
 	<!-- logo -->
 	<view class="hmly-logo" hover-class="none" hover-stop-propagation="false">
 		<image class="hmly-logo-img" src="/image/logo.png" mode="widthFix" lazy-load="false"></image>

+ 30 - 34
pages/user/user.js

@@ -1,11 +1,6 @@
-// pages/user/user.js
 const app = getApp()
 let userInfo = app.globalData.userInfo;
 Page({
-
-	/**
-	 * 页面的初始数据
-	 */
 	data: {
 		timeout: [
 			{ text: "不开启" },
@@ -18,13 +13,13 @@ Page({
 			{ text: "30分钟后" },
 		],
 		activeIndex: 0,
-		login: true,
+		login: false,
 		avatarUrl: "",
 		nickName: ""
 	},
 
-	onLoad(options) {
-		var that = this;
+	onLoad() {
+		const that = this;
 		//获得设备信息
 		wx.getSystemInfo({
 			success(res) {
@@ -33,37 +28,38 @@ Page({
 				})
 			}
 		})
-		// 查看是否授权
-		wx.getStorage({
-			key: 'login',
-			success(res) {
-				if (res.data === 200) {
-					that.setData({
-						login: false
-					})
-				} else {
-					that.setData({
-						login: true
-					})
-				}
-			}
-		})
-
 	},
+	onShow() {
+    const that = this
+    if (!that.login) {
+      wx.getStorage({
+				key: 'userinfo',
+				success(res) {
+					if (res.data) {
+						const userinfo = JSON.parse(res.data)
+						that.setData({
+							login: true,
+							avatarUrl: userinfo.avatarUrl,
+							nickName: userinfo.nickName
+						})
+					}
+				}
+			})
+    }
+  },
 	// 获取用户的头像和昵称信息
 	bindGetUserInfo(e) {
-		var that = this;
+		const that = this;
 		wx.getUserInfo({
 			success: function (res) {
-				app.globalData.userInfo = e.detail.userInfo;
 				wx.setStorage({
-					key: "login",
-					data: 200
+					key: "userinfo",
+					data: JSON.stringify(res.userInfo)
 				})
 				that.setData({
-					login: false,
-					avatarUrl: e.detail.userInfo.avatarUrl,
-					nickName: e.detail.userInfo.nickName
+					login: true,
+					avatarUrl: res.userInfo.avatarUrl,
+					nickName: res.userInfo.nickName
 				})
 			}
 		})
@@ -79,19 +75,19 @@ Page({
 		});
 	},
 	openSwitch() {
-		var that = this;
+		const that = this;
 		that.setData({
 			show: true
 		})
 	},
 	close() {
-		var that = this;
+		const that = this;
 		that.setData({
 			show: false
 		})
 	},
 	chooseTimeOut(e) {
-		var that = this;
+		const that = this;
 		that.setData({
 			activeIndex: e.currentTarget.dataset.activeindex
 		})

+ 1 - 1
pages/user/user.wxml

@@ -1,5 +1,5 @@
 <!-- pages/user/user.wxml -->
-<block wx:if="{{login}}">
+<block wx:if="{{!login}}">
 	<!-- logo -->
 	<view class="hmly-logo">
 		<image class="hmly-logo-img" src="/image/logo.png" mode="widthFix"></image>