844a810d by simon

默认提交

1 parent d96bfccf
...@@ -5,6 +5,16 @@ Component({ ...@@ -5,6 +5,16 @@ Component({
5 innerText: { 5 innerText: {
6 type: String, 6 type: String,
7 value: 'default value', 7 value: 'default value',
8 },
9 // 用户拒绝授权后是否后退页面
10 cancelBack: {
11 type: Boolean,
12 value: false,
13 },
14 // 用户拒绝授权后描述
15 cancelDesc: {
16 type: String,
17 value: "同意授权才能获得更多体验哦~",
8 } 18 }
9 }, 19 },
10 data: { 20 data: {
...@@ -24,18 +34,38 @@ Component({ ...@@ -24,18 +34,38 @@ Component({
24 name: "_evt_hide_mask" 34 name: "_evt_hide_mask"
25 }); 35 });
26 }, 36 },
37
38 // 授权成功事件
27 authComplete() { 39 authComplete() {
28 this.triggerEvent('evtcomp', { 40 this.triggerEvent('evtcomp', {
29 name: "_evt_auth_complete" 41 name: "_evt_auth_complete"
30 }); 42 });
31 }, 43 },
44
45 // 点击暂不授权按钮
46 cancelAuth(e) {
47 this.hideMask();
48 // this.triggerEvent('evtcomp', {
49 // name: "_evt_auth_cancel"
50 // });
51 // if (this.properties.cancelBack) {
52 // wx.navigateBack({
53 // delta: 1
54 // });
55 // }
56 },
57
58 // 点击确认授权按钮
32 bindGetUserInfo(e) { 59 bindGetUserInfo(e) {
33 wx.showLoading(); 60 wx.showLoading();
34 this.getUserInfo(e.detail); 61 this.getUserInfo(e.detail);
35 }, 62 },
63
64 // 授权操作
36 getUserInfo(e) { 65 getUserInfo(e) {
37 let _this = this; 66 let _this = this;
38 // app.globalData.userInfo = e.userInfo; 67 if (e.encryptedData && e.iv) {
68 // 同意授权
39 app.post({ 69 app.post({
40 url: app.api.register, 70 url: app.api.register,
41 sid: false, 71 sid: false,
...@@ -54,6 +84,21 @@ Component({ ...@@ -54,6 +84,21 @@ Component({
54 _this.authComplete(); 84 _this.authComplete();
55 _this.initPage(); 85 _this.initPage();
56 }).catch((err) => {}) 86 }).catch((err) => {})
87 } else {
88 // 取消授权
89 if (_this.properties.cancelBack) {
90 wx.navigateBack({
91 delta: 1
92 });
93 } else {
94 if (_this.properties.cancelDesc) {
95 wx.showToast({
96 title: _this.properties.cancelDesc,
97 icon: "none"
98 })
99 }
100 }
101 }
57 }, 102 },
58 103
59 /** 104 /**
......
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
10 </view> 10 </view>
11 </view> 11 </view>
12 <view class="btn-wrap"> 12 <view class="btn-wrap">
13 <!-- <button class="btn gray" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">确认授权</button> --> 13 <button class="btn btn2" bindtap="cancelAuth">暂不授权</button>
14 <button class="btn btn2" bindtap="hideMask">暂不授权</button>
15 <button class="btn" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">确认授权</button> 14 <button class="btn" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">确认授权</button>
16 </view> 15 </view>
17 </view> 16 </view>
......