uniapp一键登录

<template>
	<view class="cdj_ti">
		<view id="medialist" class="medialist" style="position: fixed;top:0;overflow: auto;height: calc(100pv);">
			<view id="media">
				<view><image :src="url+imgvip"></image></view>
				<view style="margin-top: -11rpx;"><image :src="url+imgvip"></image></view>
				<view style="margin-top: -11rpx;"><image :src="url+imgvip"></image></view>
				<view style="margin-top: -11rpx;"><image :src="url+imgvip"></image></view>
				<view style="margin-top: -11rpx;"><image :src="url+imgvip"></image></view>
				<view style="margin-top: -11rpx;"><image :src="url+imgvip"></image></view>
				<view style="margin-top: -11rpx;"><image :src="url+imgvip"></image></view>
				<view style="margin-top: -11rpx;"><image :src="url+imgvip"></image></view>
			</view>
		</view>
		<view style="width: 100%;display: flex;justify-content: center;margin-top: 200rpx;flex-wrap: wrap;">
			<image style="width:200rpx;height: 200rpx;" src="../../static/login.png"></image>
			<view style="width: 100%;text-align: center;margin-top: 30rpx;color: red;z-index: 100;">大 胆 说 喜 欢</view>
		</view>
		<view style="position: absolute;bottom: 500rpx;margin-left: 230rpx;">
			<view style="background-color: rgb(252, 60, 121);width: 200rpx;padding: 15rpx 60rpx 15rpx 60rpx;border-radius: 100rpx;">
				<view @click="dadelogin" style="margin-left: 19rpx;color: #ffffff;">开启opps</view>
			</view>
		</view>
	</view>
</template>

<script>
	import url from "../../http/url.js";
	export default {
		data() {
			return {
				url:'',
				imgvip:'',
				user: '',
				pwd:'',
				array:[],
				is:1,
				tongyi:2,
				autoStatus:true,
			}
		},
		onLoad(){
			
			this.isAutoLogin();
			
			uni.setStorageSync('tops',1);
			this.$http.http("get","/Index/Index/img",{}).then(req=>{
				this.imgvip = req.data.data.result[0].url;
			})
			// uni.redirectTo({
			// 	url: '/pages/login/login'
			// });
			this.url = url.urls;
			const user = uni.getStorageSync('user');
			if(user){
				let dade = {'phoen':user}
				this.$http.http("POST","/Admin/Login/indexLogin",dade).then(req=>{
					console.log(req.data.code)
					if(req.data.code == 200){
						uni.setStorageSync('tops', 1);
						uni.redirectTo({
							url: '/pages/tabBar/tabBar'
						});
					}
				})
			}
		},
		methods: {
			// 判断是否支持一键登陆
			isAutoLogin() {
				let _that = this
				uni.getProvider({ //获取可用的服务提供商
					service: 'oauth',
					success: function(res) {
						console.log(res.provider) // ['weixin', qq', 'univerify']
					}
				});
				uni.preLogin({ //预登录
					provider: 'univerify', //用手机号登录
					success() {
						_that.autoStatus = true
						// console.log('预登录成功')
					},

					fail(err) { //预登录失败
						_that.autoStatus = false
						// console.log('错误码:' + err.errCode)
						// console.log(err.errMsg)
					}
				})
			},
			dadelogin(){
				if(this.autoStatus == false){
					uni.redirectTo({
						url: '/pages/login/login'
					});
					return false;
				}
				if(this.tongyi == 2){
					this.logindade();
				}else{
					uni.showToast({
						icon :'none',
						title: '未同意<隐私协议>和<用户协议>1',
						duration: 2000
					});
				}
				
			},
			dadelogins(){
				if(this.tongyi == 1){
					this.tongyi = 2;
				}else{
					this.tongyi = 1;
				}
			},
			wenj(){
				let urlsa = url.urls+'/public/pdf/opps.pdf';
				//console.log(urlsa)
				uni.downloadFile({
				  url: urlsa,
				  success: function (res) {
				    var filePath = res.tempFilePath;
				    uni.openDocument({
				      filePath: filePath,
				      showMenu: true,
				      success: function (res) {
				        //console.log('打开文档成功');
				      }
				    });
				  }
				});
			},
			cdj_sta:function(){
				let data = {"user":this.user,"pwd":this.pwd};
				this.$http.http("POST","/Admin/Login/indexLogins",data).then(req=>{
					console.log(req.data.code)
					if(req.data.code == 200){
						uni.setStorageSync('user', req.data.data.user);
						uni.setStorageSync('token', req.data.data.token);
						uni.setStorageSync('shop_id', req.data.data.shop_id);
						uni.redirectTo({
							url: '/pages/tabBar/tabBar'
						});
					}else{
						uni.showToast({
							icon :'none',
							title: '账号或密码错误',
							duration: 2000
						});
					}
				})
			},
			//登录成功调用
			logins(data){
				//登录手机号
				let dade = {'phoen':data.result.data.phoneNumber}
				this.$http.http("POST","/Admin/Login/indexLogin",dade).then(req=>{
					uni.setStorageSync('user', req.data.data.user);
					uni.setStorageSync('token', req.data.data.token);
					uni.setStorageSync('shop_id', req.data.data.shop_id);
					uni.setStorageSync('tops', 1);
					if(req.data.data.login == 1){
						uni.redirectTo({
							url: '/pages/my/myUserInfo'
						});
					}else{
						uni.redirectTo({
							url: '/pages/tabBar/tabBar'
						});
					}
					
				})
			},
			
			logindade(){
				// uni.reLaunch({
				// 	url: '/pages/login/login',
				// });
				let _this = this;
				uni.preLogin({
					provider: 'univerify',
					success: () => {
						uni.login({
							provider: 'univerify',
							univerifyStyle: {
								"fullScreen": true, // 是否全屏显示,true表示全屏模式,false表示非全屏模式,默认值为false。
								"backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff  
								"phoneNum": {
									"color": "#000000", // 手机号文字颜色 默认值:#000000   
								},
								"slogan": {
									"color": "#8a8b90", //  slogan 字体颜色 默认值:#8a8b90  
								},
								"icon": {
									"path": "static/logo.png" // 自定义显示在授权框中的logo,仅支持本地图片 默认显示App logo   
								},
								"authButton": {
									"normalColor": "#3479f5", // 授权按钮正常状态背景颜色 默认值:#3479f5  
									"highlightColor": "#2861c5", // 授权按钮按下状态背景颜色 默认值:#2861c5(仅ios支持)  
									"disabledColor": "#73aaf5", // 授权按钮不可点击时背景颜色 默认值:#73aaf5(仅ios支持)  
									"textColor": "#ffffff", // 授权按钮文字颜色 默认值:#ffffff  
									"title": "本机号码一键登录" // 授权按钮文案 默认值:“本机号码一键登录”  
								},
								"otherLoginButton": {
									"visible": "false", // 是否显示其他登录按钮,默认值:true  
								},
								"otherLoginButton": {  
									"visible": true, // 是否显示其他登录按钮,默认值:true  
									"normalColor": "", // 其他登录按钮正常状态背景颜色 默认值:透明 
									"highlightColor": "", // 其他登录按钮按下状态背景颜色 默认值:透明 
									"textColor": "#656565", // 其他登录按钮文字颜色 默认值:#656565  
									"title": "其他登录方式", // 其他登录方式按钮文字 默认值:“其他登录方式”  
									"borderColor": "",  //边框颜色 默认值:透明(仅iOS支持)  
									"borderRadius": "0px" ,// 其他登录按钮圆角 默认值:"24px" (按钮高度的一半)
								},
							},
							success: (res) => {
								// console.log(res)
								uniCloud.callFunction({
									name: 'getPhoneNumber', // 你的云函数名称
									data: {
										access_token: res.authResult.access_token, // 客户端一键登录接口返回的access_token
										openid: res.authResult.openid // 客户端一键登录接口返回的openid
									}
								}).then(dataRes => {
									// console.log('云函数返回的参数3333', dataRes)1
									// console.log(dataRes)
									_this.logins(dataRes);
									
								}).catch(err => {
									// console.log('云函数报错', err)
								})
								uni.showToast({
									title: res.authResult,
									icon: "none"
								})
								uni.closeAuthView() //关闭一键登录弹出窗口
							},
							fail(res) {
								uni.reLaunch({
									url: '/pages/login/login',
								});
								uni.closeAuthView()
								// console.log('失败')
							},
						})
					},
					fail(res) {
						console.log('一键登录失败',res)
						if (res.errMsg != 'login:ok') {
							uni.redirectTo({
								url: '/pages/login/login'
							});
							uni.showToast({
								title: res.metadata.msg,
								icon: "none"
							})
						}
					}
				})
			},

			register(){
				this.logindade();
			}
			
		}
	}
</script>

<style>
	uni-image {
	    width: 750rpx;
	    height: 1300rpx;
	    display: inline-block;
	    overflow: hidden;
	    position: relative;
	}
	#media{
	    animation:rolling 30s infinite linear;
	}
	#media:hover{
	    animation-play-state:paused;
	}
	@keyframes rolling{
	    0%{
	        transform: translateY(0);
	    }
	    100%{
	        transform: translateY(-800rpx);
	    }
	}
	.cdj_ti{
		width:100%;
	}
	.cdj_login{
		width: 100%;
		font-size: 50rpx;
		margin-bottom: 50rpx;
		margin-left: 1%;
		text-align: center;
	}
	.cdj_display{
		display:flex;
		margin-bottom:30rpx;
	}
	.cdj_input{
		display: flex;
		width: 100%;
		border:1rpx solid #d8d8d8;
		padding:19rpx;
	}
	.cdj_text{
		width:100rpx;
		line-height: 80rpx;
	}
	.cdj_bottom{
		background-color: #48b4ff;
		padding:19rpx;
		border-radius:5rpx;
		color:#ffffff;
		text-align:center;
	}
	.cdj_img_logo{
		width: 300rpx;
		height: 300rpx;
		margin-top: -18%;
		margin-bottom: 15%;
		margin-left: 70rpx;
	}
	.cdj_logo{
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
	}
	.cdj_edition{
		position: absolute;
		bottom: 30rpx;
		width: 77%;
		color: #c3c3c3;
		text-align: center;
	}
	.dade_lijzhuc{
		text-align: center;
		margin-top: 39rpx;
		color: #9d9d9d;
		
	}
</style>

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大得369

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值