效果展示:左边为安卓系统展示,右边为ios系统展示
代码:
toPhone(){
uni.makePhoneCall({
phoneNumber: "10086", //要拨打的手机号
success: (res) => {
// console.log("调用成功")
},
fail: (res) => {
// console.log('调用失败!')
}
})
},
api解析:uni.makePhoneCall(OBJECT) 拨打电话
OBJECT 参数说明:
参数名类型必填说明phoneNumberString是需要拨打的电话号码successFunction否接口调用成功的回调failFunction否接口调用失败的回调函数completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)
uniapp官方文档链接:https://uniapp.dcloud.net.cn/api/system/phone.html#makephonecall
拓展:点击弹出电话号码列表,选择其中一个电话号进行拨打
效果展示:
代码:
toPhone() {
const phoneList = ["10086","10010","10000"]
uni.showActionSheet({
itemList: phoneList, //电话列表
success: function(res) {
if (res.tapIndex !== undefined) {
uni.makePhoneCall({
phoneNumber: phoneList[res.tapIndex],
success: function() {
//console.log('拨打电话成功');
},
fail: function() {
//console.log('拨打电话失败');
}
});
}
}
});
}
api解析:uni.showActionSheet(OBJECT) 从底部向上弹出操作菜单
OBJECT参数说明:
参数类型必填说明平台差异说明titleString否菜单标题App、H5、支付宝小程序、钉钉小程序、微信小程序 3.4.5+(仅真机有效)alertTextString否警示文案(同菜单标题)微信小程序(仅真机有效)itemListArray
popover 值说明(仅App生效):
值类型说明topNumber指示区域坐标,使用原生 navigationBar 时一般需要加上 navigationBar 的高度leftNumber指示区域坐标widthNumber指示区域宽度heightNumber指示区域高度
success返回参数说明:
参数类型说明tapIndexNumber用户点击的按钮,从上到下的顺序,从0开始
uniapp官方文档链接: https://uniapp.dcloud.net.cn/api/ui/prompt.html#showactionsheet