1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
| // Componet/Componet.js
| let app = getApp();
| Component({
| /**
| * 组件的属性列表
| */
| properties: {
|
| // 是否显示用户授权
| showAuth: {
| type: Boolean
| }
| },
| /**
| * 组件的初始数据
| */
| data: {
| canIUse: wx.canIUse('button.open-type.getUserInfo'),
| isShow: false,
| wxIcon: app.globalData.imgUrl + '/images/wx_login.png'
|
| },
|
| ready: function() {
| this.setData({
| isShow: this.properties.showAuth || false
| })
| },
| /**
| * 组件的方法列表
| */
| methods: {
| bindGetUserInfo: function(e) {
| var that = this;
| if (e.detail.userInfo) {
| //用户按了允许授权按钮
| // 获取到用户的信息了,打印到控制台上看下
| console.log("用户的信息如下:");
| console.log(e.detail.userInfo);
| //授权成功后,通过改变 isHide 的值,让实现页面显示出来,把授权页面隐藏起来
| that.setData({
| isShow: false
| });
| // that.triggerEvent('onSetData', { showTele: true});
| that.triggerEvent('onSetLoadingData', {
| showAuth: false
| });
|
| wx.setStorageSync('#userAuthorization#', 'user' + Date.now());
| wx.setStorageSync('#userInfo#', e.detail.userInfo);
|
| } else {
| console.log('点击取消');
| that.triggerEvent('onSetData', {
| showAuth: false
| });
|
|
| //用户按了拒绝按钮
| // wx.showModal({
| // title: '警告',
| // content: '您点击了拒绝授权,将无法进入小程序,请授权之后再进入!',
| // showCancel: false,
| // confirmText: '返回授权',
| // success: function (res) {
| // // 用户没有授权成功,不需要改变 isHide 的值
| // if (res.confirm) {
| // console.log('用户点击了“返回授权”');
| // }
| // }
| // });
| }
| }
| }
| })
|
|