lilei 4 роки тому
батько
коміт
09a130cb01
1 змінених файлів з 32 додано та 12 видалено
  1. 32 12
      pages/userCenter/index.vue

+ 32 - 12
pages/userCenter/index.vue

@@ -3,16 +3,18 @@
 		<!-- 头部 -->
 		<view class="user-head" @click="toUserPage">
 			<view class="user-photo">
-				<open-data type="userAvatarUrl"></open-data>
+				<text v-if="hasLogin"><open-data type="userAvatarUrl"></open-data></text>
+				<u-image v-else src="/static/logo.png" width="100" height="100"></u-image>
 			</view>
 			<view class="user-info">
-				<open-data type="userNickName"></open-data>
+				<text v-if="hasLogin"><open-data type="userNickName"></open-data></text>
+				<u-button v-else size="mini" shape="circle" @click="toLoginPage">登录</u-button>
 			</view>
-			<view>
+			<view v-if="hasLogin">
 				<u-icon name="arrow-right" color="#fff"></u-icon>
 			</view>
 		</view>
-		<view class="my-ledou">
+		<view class="my-ledou" v-if="hasLogin">
 			<view class="user-jifen">
 				<view>我的乐豆:<text>345</text></view>
 				<u-image mode="scaleToFill" width="35rpx" height="35rpx" src="/static/ledou.png"></u-image>
@@ -34,7 +36,7 @@
 </template>
 
 <script>
-	import {logout} from '@/api/login.js'
+	import {logout, checkLogin } from '@/api/login.js'
 	export default {
 		data() {
 			return {
@@ -42,10 +44,15 @@
 					borderRadius:'100rpx',
 					fontSize:'30rpx',
 					background: '#01c9b2'
-				}
+				},
+				hasLogin: false
 			};
 		},
 		onShow() {
+			checkLogin().then(res => {
+				console.log(res)
+				this.hasLogin = res.status==200
+			})
 		},
 		onLoad() {
 		},
@@ -58,16 +65,24 @@
 					'/pages/agreement/agreement?fromPage=usercenter',
 					'/pages/userCenter/aboutUs'
 					]
-				uni.navigateTo({
-					url: pageUrl[index]
-				})
+				if(index<2&&this.hasLogin || index>=2){
+					uni.navigateTo({
+						url: pageUrl[index]
+					})
+				}else{
+					this.toLoginPage()
+				}	
 			},
 			//  跳转
 			toUserPage(){
 				//  未登录跳转登录,已登录跳转用户信息页
-				uni.navigateTo({
-					url: '/pages/userCenter/userInfo/userInfo'
-				})
+				if(this.hasLogin){
+					uni.navigateTo({
+						url: '/pages/userCenter/userInfo/userInfo'
+					})
+				}else{
+					this.toLoginPage()
+				}
 			},
 			//  乐豆明细
 			toLdPage(){
@@ -78,6 +93,11 @@
 			bindGetUserInfo(res){
 				console.log(res)
 			},
+			toLoginPage(){
+				uni.navigateTo({
+					url: '/pages/login/login'
+				})
+			}
 		}
 	}
 </script>