index.js
3 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const WXAPI = require("apifm-wxapi");
const AUTH = require("../../utils/auth");
Component({
options: {
addGlobalClass: true,
},
/**
* 组件的对外属性,是属性名到属性设置的映射表
*/
properties: {
title: String,
alarmText: String,
show: Boolean,
},
/**
* 组件的内部数据,和 properties 一同用于组件的模板渲染
*/
data: {},
// 组件数据字段监听器,用于监听 properties 和 data 的变化
observers: {},
lifetimes: {
attached() {},
detached() {
// 在组件实例被从页面节点树移除时执行
},
},
/**
* 组件的方法列表
*/
methods: {
close() {
this.triggerEvent("cancel");
},
async getPhoneNumber(e) {
if (e.detail.errMsg.includes("privacy permission is not authorized")) {
wx.showModal({
content: "请阅读并同意隐私条款以后才能继续本操作",
confirmText: "阅读协议",
cancelText: "取消",
success (res) {
if (res.confirm) {
wx.requirePrivacyAuthorize(); // 弹出用户隐私授权框
}
}
});
return;
}
if (!e.detail.errMsg) {
wx.showModal({
content: "getPhoneNumber异常",
showCancel: false
});
return;
}
if (e.detail.errMsg === "getPhoneNumber:fail user deny") {
return;
}
if (!e.detail.errMsg || e.detail.errMsg !== "getPhoneNumber:ok") {
wx.showModal({
content: e.detail.errMsg,
showCancel: false
});
return;
}
this._getPhoneNumber(e);
},
async _getPhoneNumber(e) {
let res;
const extConfigSync = wx.getExtConfigSync();
if (extConfigSync.subDomain) {
// 服务商模式
const code = await AUTH.wxaCode();
res = await WXAPI.wxappServiceBindMobile({
token: wx.getStorageSync("token"),
code,
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
});
} else {
res = await WXAPI.bindMobileWxappV2(wx.getStorageSync("token"), e.detail.code);
}
if (res.code === 0) {
wx.showToast({
title: "绑定成功"
});
this.data.mobile = res.data;
this.triggerEvent("ok", this.data);
} else {
wx.showModal({
content: res.msg,
showCancel: false
});
}
},
}
});