微信小程序(3)—— 添加联系人至通讯录

添加联系人至通讯录

我写的小功能是在点击联系人的时候,进行选择多种选择(拨打电话和添加联系人)。 该功能必须在手机上运行才能体验最终效果。

代码参考并分析

wxml:

<van-col span="8" class=footer_list2 data-id=4 catchtap=freeTell data-current="4" bindtap="chooseImg">
		<image class="icon" src="{
          
   {mine}}"></image>
		<view>咨询电话</view>
</van-col>

js:

freeTell: function(){
          
   
    var that=this;
 	// 提示呼叫号码还是将号码添加到手机通讯录
 	wx.showActionSheet({
          
   
  		itemList: [呼叫,添加联系人],
  		success:function(res){
          
   
  			if(res.tapIndex===0){
          
   
   			// 呼叫号码
  				 wx.makePhoneCall({
          
   
  			 	 phoneNumber: that.data.phoneNum,
   				})
 			 }else if(res.tapIndex==1){
          
   
  				 // 添加到手机通讯录
  				 wx.addPhoneContact({
          
   
  					 firstName: test,//联系人姓名
  					 mobilePhoneNumber: that.data.phoneNum,//联系人手机号
   				})
  			}
  		}
 	})
  }

知识点

  1. wx.showActionSheet(Object object) 显示操作菜单
  2. wx.makePhoneCall(Object object) 拨打电话
  3. wx.addPhoneContact(Object object) 添加手机通讯录联系人。用户可以选择将该表单以「新增联系人」或「添加到已有联系人」的方式,写入手机系统通讯录

详情查看

经验分享 程序员 微信小程序 职场和发展