点击复制功能、拨打电话

效果图:

wxml

<view class="box">
    <image src="../../images/online/weixin.png" mode="widthFix" />
    <view class="tell">{{weixin}}</view>
    <view class="tip" data-weixin="{{weixin}}" catchtap="getWeixin">复制去加好友</view>
</view>
<view class="btns">
    <view class="tellBtn" catchtap="call" data-phone="{{phone}}">
        <image src="../../images/online/tell.png" mode="widthFix" />
        <text>电话咨询</text>
    </view>
    <view class="onlineBtn">
        <image src="../../images/online/msg.png" mode="widthFix" />
        <text>在线咨询</text>
    </view>
</view>

js

  data: {
    phone: "12345678", //咨询电话
    weixin: "15825996354", //微信号
  },
  // 拨打电话
  call: function (e) {
    let phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: phone,
      success() {
        console.log("接口调用成功的回调函数");
      },
      fail() {
        console.log("接口调用失败的回调函数");
      },
      complete() {
        console.log("接口调用结束的回调函数(调用成功、失败都会执行)");
      },
    });
  },
  // 复制微信号加好友
  getWeixin: function (e) {
    let weixin = e.currentTarget.dataset.weixin;
    wx.setClipboardData({
      data: weixin,
      success: function (res) {
        wx.showToast({
          title: "复制成功",
        });
        wx.getClipboardData({
          //微信提供的这个api是获取系统剪贴板的内容
          success: function (res) {
            console.log(res.data); // 已复制内容
            if (res.data == "") {
              wx.showToast({
                title: "暂未设置微信号",
              });
            }
          },
        });
      },
    });
  },

官网:剪贴板
参考:微信小程序----点击复制功能、拨打电话

posted @ 2021-05-30 23:23  星河几重  阅读(243)  评论(0编辑  收藏  举报