小程序电话相关使用
<-- html -->
<view>
<button bindtap="makeCall">呼叫用户</button>
<button bindtap="addPerson">添加联系人</button>
<button bindtap="choose">选择操作</button>
</view>
1、打电话
// js
methods: {
makeCall() {
wx.makePhoneCall({
phoneNumber: '888888888',
success: res => {
console.log(res)
},
fail: err => {
console.log(err)
}
})
}
}
效果图
2、添加联系人
// js
methods: {
addPerson() {
wx.addPhoneContact({
firstName: '姓名',
mobilePhoneNumber: '电话号码'
success: res => {
console.log(res)
},
fail: err => {
console.log(err)
}
})
}
}
效果图
3、选择操作
// js
methods: {
addPerson() {
wx.showActionSheet({
itemList: ['呼叫', '添加联系人'],
success: res => {
if (res.tapIndex === 0) {
wx.makePhoneCall({
phoneNumber: '888888888'
})
} else if (res.tapIndex === 1) {
wx.addPhoneContact({
firstName: '姓名',
mobilePhoneNumber: '电话号码'
})
}
},
fail: err => {
console.log(err)
}
})
}
}
// 此段代码中,res.tapIndex对应与itemList中被选择的元素
效果图