uni-app 第三方微信登录

<template>
	<view class="page page-fill">
		<!-- header start -->
		<view class="header">

			<view v-if="userLogin">
				<image :src="userphoto" class="face"></image>
			</view>
			<view v-else>
				<image src="../../static/userfalse.png" class="face"></image>
			</view>
			<view class="info-wapper" v-if="userLogin">
				<view class="nickname">{{nickname}}</view>
				<view class="nav-info">city: {{city}}</view>
			</view>
			<view class="info-wapper" v-else>
				<view class="regist-login" data-logintype="weixin" @click="appAuthLogin">微信登录</view>
			</view>

			<view class="set-wapper">
				<image src="../../static/setting.png" mode="" class="settings"></image>
			</view>
		</view>
		<!-- header end -->

		<view class="page-content">
			<!-- 服务 start -->
			<view class="service-wapper">
				<view class="service-item" @click="outLogin">
					<image src="../../static/daifukuan2.png" mode="widthFix" class="service-icon"></image>
					<text class="service-title">退出登录</text>
					<image src="../../static/come.png" mode="widthFix" class="service-come"></image>
				</view>
			</view>
			<!-- 服务 end -->
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userLogin: false,
				nickname: "",
				city: "",
				userphoto: ""
			}
		},
		onLoad() {
		},
		onShow() {
			let userInfo = uni.getStorageSync('userInfo');
			if (userInfo) {
				this.userLogin = true;
				this.nickname = userInfo.nickName;
				this.city = userInfo.city;
				this.userphoto = userInfo.avatarUrl;
			} else {
				this.userLogin = false;
			}
		},
		methods: {
			appAuthLogin(e) {
				//获取用户的登录类型
				var logintype = e.currentTarget.dataset.logintype;
				//授权登录
				uni.login({
					provider: logintype,
					success: (res) => {
						//授权成功后获取用户信息
						uni.getUserInfo({
							provider: logintype,
							success: (res) => {
								
								uni.showToast({
									title: "登录成功",
									success: (res) => {
										uni.switchTab({
											url: "../index/index"
										})
									}
								})
								
								var me = this;
								me.userLogin = true;
								uni.setStorageSync("userInfo", res.userInfo);
							}
						})
					}
				})

			},
			onPullDownRefresh() {
				//延迟加载,防止提示框出不来
				setTimeout(function() {
					uni.showToast({
						title: "数据加载成功",
					})
				}, 200)
				//导航条的加载动画,pages.json里如果不禁用的话
				uni.showNavigationBarLoading();
				//成功获取数据后结束下拉刷新
				uni.stopPullDownRefresh();
				//成功获取数据后隐藏加载动画
				uni.hideNavigationBarLoading();
			},
			//退出登录
			outLogin() {
				var me = this;
				uni.showModal({
					title: '退出登录',
					content: '确定要退出登录吗',
					success: function(res) {
						if (res.confirm) {
							me.userLogin = false;
							uni.removeStorageSync('userInfo');
							uni.showToast({
								title: "成功退出登录"
							})
						}
					}
				});

			}
		},


	}
</script>

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值