<template>
	<view class="page page-fill"> 
		<!-- 判断是否登录更改头像 -->
		<view class="header">
			<view v-if="userIsLogin">
				<image src="../../static/icos/108x108.png" class="face" ></image>
			</view>
			<view v-else>
				<image src="../../static/icos/default-face.png" class="face"></image>
			</view>
			
			<!-- 判断是否登录显示用户名 -->
			<view class="info-wapper" v-if="userIsLogin">
				<view class="nickname">
					{{res.usernameCn}}
				</view>
				<view class="nav-info">{{res.username}}</view>
			</view>
			
			<view v-else>
				<navigator url="../login/login">
					<view class="nickname regist-login">
						登录
					</view>
				</navigator>
			</view>	
		</view>
		
		<view class="info-wapper"  v-if="userIsLogin">
			<view class="footer-wapper">
				<view class="footer-words" style="margin-top: 10upx;" @click="logout">
					退出登录
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userIsLogin:false,
				res : {}
			}
		},
		onLoad() {
			 var res=uni.getStorageSync(
			 	'token'
			 )
			if(res == null ||res == "" || res == undefined){
				uni.navigateBack({
					delta:100
				})
			}
		},
		onShow() {
			var res=uni.getStorageSync(
			 	'token'
			 )
			if(res!=""&&res!=null&&res!=undefined){
				this.userIsLogin=true
				this.res =res
			}else{
				this.userIsLogin=false
				this.res={}
			}
		},
		methods: {
			//退出登录
			logout(){
				uni.clearStorageSync()
				 uni.navigateTo({
				 	url:"../login/login"
				 })
			}
		}
	}
</script>

<style>
	@import url("me.css");
</style>
