一、WXML
<view class="action-btn copy" bindtap="copyPhone" data-phone="{{user.mobile}}" data-name="{{user.name}}">
<text class="icon">复制</text>
</view>
<view class="action-btn call" bindtap="callPhone" data-phone="{{user.mobile}}">
<text class="icon">拨打</text>
</view>
<view class="action-btn save" bindtap="savePhone" data-name="{{user.name}}" data-phone="{{user.mobile}}">
<text class="icon">保存</text>
</view>二、JS
// 拨打电话
callPhone(e) {
const phone = e.currentTarget.dataset.phone;
wx.makePhoneCall({ phoneNumber: phone });
},
// 复制姓名/手机号
copyPhone(e) {
const name = e.currentTarget.dataset.name;
const phone = e.currentTarget.dataset.phone;
// 拼接复制内容:姓名 手机号
const copyText = `${name} ${phone}`;
wx.setClipboardData({
data: copyText,
success() {
wx.showToast({
title: '复制成功',
icon: 'success'
});
}
});
},
// 保存通讯录
savePhone(e) {
const name = e.currentTarget.dataset.name;
const phone = e.currentTarget.dataset.phone;
wx.addPhoneContact({
firstName: name,
mobilePhoneNumber: phone,
success() {
wx.showToast({ title: '保存成功', icon: 'success' });
},
fail() {
wx.showToast({ title: '保存失败', icon: 'none' });
}
});
}
生活的强者,不是指能搞定一切困难,也不是指没有恐惧,而是就算心里藏着无尽的疲惫和委屈,还是会认真地做好手头上的事情;就算自己被生活锤得心灰意冷,还是会尽心尽力地负起责任;就算发现现实与理想的差距有十万里,虽然鞭长莫及,却依然马不停蹄。