index.vue 4.2 KB
<template>
	<view class="container"
		style="background-image: url('https://life.cloud.hjxbc.cn/sys/common/static/scott/pic/bg_me1_1692254734871.png');">
		<view class="page">
			<view class="user">
				<template v-if="isLogin && userAvatar">
					<image :src="userAvatar" class="icon"></image>
				</template>
				<view class="icon" @click="toLogin" v-else>
					<uni-icons type="person" size="50px" color="#6A59F2"></uni-icons>
				</view>
				<template v-if="isLogin">
					<view class="name" v-if="userName">{{userName}}</view>
					<view class="phone" v-if="userPhone">{{userPhone}}</view>
					<div class="information" @click="employeeEntry(1)">修改个人资料 ></div>
				</template>
				<teleport v-else>
					<view class="name" @click="toLogin" style="margin-bottom: 36rpx;">请登录</view>
				</teleport>
			</view>
			<view class="LogOut" v-if="isLogin" @click="logout">退出登录</view>
		</view>


		<authorization-modal ref="authorization" @loginEnd="onLoginEnd" @refuse="onRefuse" />
	</view>
</template>

<script>
	import authorizationModal from '@/components/authorization.vue'
	let timer = null
	export default {
		components: {
			authorizationModal
		},
		data() {
			return {
				isLogin: false,
				userName: '',
				userAvatar: '',
				userPhone: '',
			}
		},
		methods: {
			toLogin() {
				if (!this.isLogin) {
					uni.hideTabBar()
					this.$nextTick(() => {
						this.$refs.authorization.onOpenLogin()
					});
				}
			},
			logout() {
				let _this = this
				uni.showModal({
					title: '警告',
					content: '确定退出登录!',
					showCancel: true,
					success: function(res) {
						if (res.confirm) {
							wx.clearStorage()
							_this.onLoginEnd()
						}
					}
				});
			},
			employeeEntry(type) {
				if (this.isLogin) {
					if (type == 1) {
						uni.navigateTo({
							url: '/pages/myInformation/index',
						});
					}
				} else {
					uni.hideTabBar()
					this.$nextTick(() => {
						this.$refs.authorization.onOpenLogin()
					});
				}
			},
			onLoginEnd() {
				uni.showTabBar()
				uni.reLaunch({
					url: '/pages/home/index'
				})
			},
			onRefuse() {
				uni.showTabBar()
			},
		},
		onLoad() {
			const token = uni.getStorageSync('token');
			if (token) {
				this.isLogin = true
				this.userName = uni.getStorageSync('user_name')
				this.userAvatar = uni.getStorageSync('user_avatar')
				this.userPhone = uni.getStorageSync('user_phone')
			} else {
				this.isLogin = false
			}
		},
		onShow() {
			const token = uni.getStorageSync('token');
			if (token) {
				this.isLogin = true
				this.userName = uni.getStorageSync('user_name')
				this.userAvatar = uni.getStorageSync('user_avatar')
				this.userPhone = uni.getStorageSync('user_phone')
			} else {
				this.isLogin = false
			}
		},
		onHide() {
			if (timer) clearTimeout(timer)
			timer = null
		}
	}
</script>
<style>
	page {
		background-color: #F8F6F9;
	}
</style>
<style lang="scss" scoped>
	.container {
		width: 100%;
		height: 100vh;
		background-position: top center;
		background-repeat: no-repeat;
		background-color: #F8F8FA;
		background-size: cover;
		display: flex;
		align-items: center;
	}

	.page {
		width: 100%;
		box-sizing: border-box;
		padding: 0 85rpx;
	}

	.LogOut {
		background-color: #6A59F2;
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 40rpx;
		border: 1px solid #B5B8ED;
		box-sizing: border-box;
		font-size: 28rpx;
		color: #FFFFFF;
		font-weight: bold;
		text-align: center;
		margin-top: 60rpx;
	}

	.user {
		background-color: #ffffff;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		padding: 70rpx 30rpx;

		.icon {
			width: 160rpx;
			height: 160rpx;
			border-radius: 160rpx;
			border: 1px solid #6A59F2;
			text-align: center;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.name {
			font-size: 36rpx;
			color: #373737;
			margin: 20rpx 0 10rpx;
		}

		.phone {
			font-size: 28rpx;
			color: #373737;
			margin-bottom: 36rpx;
			opacity: 0.55;
		}

		.information {
			width: 300rpx;
			height: 60rpx;
			line-height: 60rpx;
			border-radius: 30rpx;
			border: 1px solid #B5B8ED;
			font-size: 28rpx;
			color: #6A59F2;
			text-align: center;
		}
	}
</style>