zoukankan      html  css  js  c++  java
  • 小程序之获取用户信息取消授权处理

    简单概述一下效果:第一次点击了取消,之后点击的时候会一直出现获取权限弹框

    .wxml文件

    <button class='mark'  wx:if="{{canIUse}}"   open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo"></button>

    .js文件

    const app = getApp();
    Page({
        data: {
            canIUse: wx.canIUse('button.open-type.getUserInfo'),
            view: {
                height: null
            }
        },
        onLoad: function (options) {
            var that = this;
            wx.getSystemInfo({
                success: function (res) {
                    //   console.log(res);
                    wx.setStorageSync('viewHeight', res.windowHeight);
                    //设置高度,根据当前设备宽高满屏显示
                    that.setData({
                        view: {
                            height: res.windowHeight
                        }
                    })
                }
            });
            wx.login({
                success: function (res) {
                    if (res.code) {
                        wx.request({
                            url: app.globalData.url + 'index.php/api/Api/get_openid_api',
                            data: {
                                code: res.code
                            },
                            method: "GET",
                            success: function (response) {
                                if (response.data.status == 200) {
                                    wx.setStorageSync('openid', response.data.data.openid);
                                    wx.setStorageSync('uid', response.data.data.uid);
                                    that.setData({
                                        openid: response.data.data.openid
                                    })
                                } else {
                                    wx.showToast({
                                        title: '请求失败',
                                        icon: 'loading',
                                        duration: 1000
                                    })
                                }
                            }
                        })
                    } else {
                        console.log('获取用户登录态失败!' + res.errMsg);
                    }
                }
            })
        },
        wc_guide: function () {
            wx.navigateTo({
                url: '/pages/wc_guide/index',
            })
        },
        bindGetUserInfo: function (e) {
    
            console.log(e);
    
            var that = this;
    
            if (e.detail.userInfo) {
    
                var user_inf = e.detail.userInfo;
    
                wx.request({
                    url: app.globalData.url + 'index.php/api/Api/get_info',
                    data: {
    
                        uid: wx.getStorageSync('uid'),
                        avatar: user_inf.avatarUrl,
                        nickname: user_inf.nickName
    
                    },
                    success: function (res) {
    
                        that.setData({
                            canIUse: false
                        });
                    }
                });
    
            }
    
        }
    })
  • 相关阅读:
    [ZJOI2008]树的统计 树链剖分
    CF915E 动态开线段树
    Poj 2114 Boatherds(点分治)
    Poj 2599 Godfather(树的重心)
    Bzoj 2152: 聪聪可可(点分治)
    Cogs 1714. [POJ1741][男人八题]树上的点对(点分治)
    Cogs 329. K- 联赛(最大流)
    Cogs 731. [网络流24题] 最长递增子序列(最大流)
    Bzoj 2282: [Sdoi2011]消防(二分答案)
    Cogs 732. [网络流24题] 试题库(二分图)
  • 原文地址:https://www.cnblogs.com/wanan-01/p/9078093.html
Copyright © 2011-2022 走看看