美文网首页
页面授权模板

页面授权模板

作者: 秀萝卜 | 来源:发表于2020-03-05 23:53 被阅读0次

    页面授权


    shouquan.png
    <view class='authorisation_area'>
        <image class='logo' src='http://waliu.bailingkeji.com/waliuimg/logo.png' />
        <view class='auth_h1'>小程序申请获取以下权限</view>
        <view class='auth_p'>获取您的公开信息(昵称、头像等)</view>
        <button class='auth_btn' open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">同意</button>
        <view class='auth_a' bindtap='retunindex'>返回首页</view>
    </view>
    
    Page({
        data: {
            path: ''
        },
        retunindex() {
            wx.reLaunch({
                url: '../index/index',
            })
        },
        bindGetUserInfo: function (e) {
            var detail = e.detail;
            var errMsg = detail.errMsg; // 错误信息
            var msgContent = 'getUserInfo:ok';
            var unmsgContent = 'getUserInfo:fail auth deny';
            //用户拒绝授权
            if (errMsg == unmsgContent) {
                wx.switchTab({  //跳转到首页
                    url: '../index/index'
                });
                return;
            }
            if (errMsg != msgContent) {
                wx.showToast({
                    title: '获取信息失败,请重试',
                    icon: 'none',
                    duration: 2000
                })
                return false;
            }
    
            var encryptedData = detail.encryptedData;
            var iv = detail.iv;
    
            if (encryptedData == null || iv == null) {
                wx.showToast({
                    title: '获取信息失败,请重试',
                    icon: 'none',
                    duration: 2000
                })
                return false;
            }
            var pages = getCurrentPages()//获取加载页面
            var currenPage = pages[pages.length - 1];//获取当前页面,可以看我另一个文章getPageCurrent详解
            var paht = '..' + currenPage.__displayReporter.showReferpagepath.substring(5);//获取上页路径
            var length = paht.length;
            var url = paht.substring(0, length - 5);
            console.log(paht); //   ../aaa/aaa.html
            console.log(url); //    ../aaa/aaa
    
        },
    })
    page {
        background: #fff;
        padding-top: 180rpx;
    }
    
    .authorisation_area {
        width: 100%;
        padding: 0 40rpx;
        box-sizing: border-box;
    }
    
    .logo {
        width: 200rpx;
        height: 200rpx;
        border-radius: 50%;
        display: block;
        margin: 0rpx auto 0rpx;
        border: 1rpx solid #e5e5e5;
    }
    
    .auth_h1 {
        font-size: 32rpx;
        line-height: 52rpx;
        text-align: center;
        border-bottom: 1rpx solid #e5e5e5;
        padding: 30rpx 0;
    }
    
    .auth_p {
        font-size: 28rpx;
        line-height: 48rpx;
        text-align: center;
        color: #999;
        margin: 20rpx 0;
    }
    
    .ic_dot {
        width: 8rpx;
        height: 20rpx;
        display: inline-block;
        margin-right: 10rpx;
    }
    
    .auth_btn {
        width: 670rpx;
        height: 88rpx;
        line-height: 88rpx;
        font-size: 32rpx;
        color: #e5d5c8;
        background: #710002;
        text-align: center;
        border-radius: 10rpx;
        margin: 160rpx auto 0;
    }
    
    .auth_a {
        font-size: 32rpx;
        line-height: 52rpx;
        text-align: center;
        border-bottom: 1rpx solid #e5e5e5;
        width: 160rpx;
        margin: 20rpx auto;
        color: #999;
    }
    

    相关文章

      网友评论

          本文标题:页面授权模板

          本文链接:https://www.haomeiwen.com/subject/cpjdrhtx.html