PhoneNumber.js
1.88 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
/*
* @Description:
* @Author: huyue
* @Date: 2022-12-09 13:58:15
* @LastEditors: huyue
* @LastEditTime: 2022-12-13 10:36:15
*/
// components/Login/Login.js
import { ssoApi } from "../../api/api";
import { componentsMixin } from "../../mixins/index";
Component({
behaviors: [componentsMixin],
/**
* 组件的属性列表
*/
properties: {
isHidden: {
type: Boolean,
value: false
},
phoneText: {
type: String,
value: '了解更多案例'
},
isImage: {
type: Boolean,
value: false
},
showIcon: {
type: Boolean,
value: true
},
/**
* type: 场景类型: 1.首页,整行;2.详情中的查看更多和申请合作切换;3.透明的(暂无);
*/
type: {
type: Number,
value: 1
},
hasPhoneNumber: {
type: Boolean,
}
},
observers: {
'hasPhoneNumber'(val) {
console.log(val)
}
},
/**
* 组件的初始数据
*/
data: {
},
/**
* 组件的方法列表
*/
methods: {
// 获取手机号
getPhoneNumber({detail}) {
if ( detail.errMsg && detail.errMsg.indexOf('user deny') !== -1 ) {
wx.hideLoading()
return;
}
wx.$util.showLoading('正在授权...')
delete detail.errMsg;
if (detail.iv && detail.encryptedData) {
ssoApi.authUserPhone(detail).then(({ data, code, message }) => {
wx.hideLoading()
if (code==0) {
wx.$util.setUserInfo(data);
// 其他操作
this.triggerEvent("updatePhoneNumber", data.phone);
} else {
wx.showToast({
title: message,
icon: 'none',
duration: 2000
})
}
});
}
},
jump() {
this.triggerEvent('toApplication')
},
forward() {
this.triggerEvent('toForward')
}
},
});