• uniapp登录授权


    一、第一阶段(微信,QQ,微博)

    <template>
        <view class="content">
            <view class="box">
                <view class="item">
                    <image :src="qqimg" data-loginType="qq" mode="" @tap="auth" class="imagestyle"></image>
                    <view class="">
                        {{qqname}}
                    </view>
                </view>
                <view class="item">
                    <image :src="weixinimg" data-loginType="weixin" mode="" @tap="auth" class="imagestyle"></image>
                    <view class="">
                        {{weixinname}}
                    </view>
                </view>
                <view class="item">
                    <image :src="weiboimg" data-loginType="sinaweibo" mode="" @tap="auth" class="imagestyle"></image>
                    <view class="">
                        {{weiboname}}
                    </view>
                </view>
            </view>
            <view class="" @tap='goauthentication()'>
                指纹认证
            </view>
            <view class="" @tap='gooldauthentication()'>
                旧指纹认证
            </view>
            
            <view class="input">
                <input type="text" value="" @input="onChange" />
            </view>
        </view>
    </template>
    
    <script>
        export default {
            data() {
                return {
                    qqname: "qq_name",
                    weixinname: "weixin_name",
                    weiboname:'weibo_name',
                    qqimg: require('@/static/images/QQ.png'),
                    weixinimg: require('@/static/images/Weixin.png'),
                    weiboimg:require('@/static/images/Weibo.png')
                }
            },
            onLoad() {
    
            },
            methods: {
                
                // 获取数据
                onChange(){
                    uni.onKeyboardHeightChange(res => {
                      console.log(res.height)
                    })
                },
                
                
                // 跳转到指纹认证
                goauthentication:function(){
                    uni.navigateTo({
                        url:"/pages/authentication/authentication"
                    })
                },
                
                // 跳转到旧指纹认证
                gooldauthentication:function(){
                    uni.navigateTo({
                        url:"/pages/oldauthentication/oldauthentication"
                    })
                },
                
                auth(e) {
                    var that = this;
                    let loginType = e.currentTarget.dataset.logintype
                    console.log("loginType", loginType)
                    uni.login({
                        provider: loginType,
                        success(res) {
                            console.log(res)
                            // 登录成功后, 获取用户数据
                            uni.getUserInfo({
                                provider: loginType,
                                success(info) {
                                    var userInfo = info.userInfo
                                    console.log("userInfo", userInfo)
                                    var nickName = ""
                                    var avatarUrl = ""
                                    var openId = ""
                                    if (loginType == "weixin") {
                                        nickName = userInfo.nickName
                                        that.weixinname = nickName
                                        that.weixinimg = userInfo.avatarUrl
                                        avatarUrl = userInfo.avatarUrl
                                        openId = userInfo.openId
                                    } else if (loginType == "qq") {
                                        nickName = userInfo.nickname
                                        that.qqimg = userInfo.figureurl_qq
                                        that.qqname = nickName;
                                        avatarUrl = userInfo.figureurl_qq_2
                                        // qq返回了多个尺寸的头像, 按需选择
                                        openId = userInfo.openId
                                    } else if (loginType == "sinaweibo") {
                                        console.log("userInfo",userInfo)
                                        that.weiboname = userInfo.nickName
                                        that.weiboimg = userInfo.avatar_large
                                        nickName = userInfo.nickname
                                        avatarUrl = userInfo.avatar_large
                                        openId = userInfo.id
                                    }
                                }
                            })
                        }
                    })
                }
            }
        }
    </script>
    
    <style lang="scss">
        .content {
            .box {
                 100%;
                padding: 20rpx;
                box-sizing: border-box;
                display: flex;
    
                .item {
                     33.33%;
                    text-align: center;
                    border-right: 1rpx solid #C0C0C0;
    
                    .imagestyle {
                         50%;
                        height: 120rpx;
                    }
                }
            }
        }
    </style>
  • 相关阅读:
    C字符串和C++字符串
    Linux的用户态和内核态
    知乎问答:如何理解“In UNIX, everything is a file”?
    科普:并行计算、分布式计算、集群计算和云计算
    个人使用VIM的一些总结
    C语言回调函数学习
    Python的函数参数传递:传值?引用?
    ECMAScript 函数函数概述
    ECMAScript 函数arguments 对象
    ECMAScript 语句with 语句
  • 原文地址:https://www.cnblogs.com/dagongren/p/14025950.html
Copyright © 2020-2023  润新知