这个需求类似淘宝物流,网上查了很多 微信社区有个很帮助我 这里:https://developers./community/develop/doc/0002441c8440188e7e69bf08756400 感谢
正则匹配留言,找出电手机号码,结合wx.makePhoneCall// 下面这段比较繁琐var a = '15900000001一二15900000002三四15900000003五六15900000004', b = a.match(/(1\d{10})/g),c = a.split(/(?:1\d{10})/),list = [];for (var i in c){if (c[i] == '') {i == 0 && list.push({ type: 'phone', val: b[0] })} else {list.push({ type: 'text', val: c[i] })list.push({ type: 'phone', val: b[i] })}}// ===================================// 下面这段比较简洁一点 (推荐)var a = '15900000001一二15900000002三四15900000003五六15900000004', c = a.split(/(?:1\d{10})/),list = [];for (var i in c){var flag = c[i] != '' && /^(1\d{10})$/.test(c[i])c[i] != '' && list.push({ type: flag ? 'phone' : 'text', val: c[i] })}this.setData({list: list})console.log(list)//更简洁的更简洁一点的,只需splitvar a = '15900000001一二15900000002三四15900000003五六15900000004',c = a.split(/(1\d{10})/),list = []for (var i in c){var flag = c[i] != '' && /^(1\d{10})$/.test(c[i])c[i] != '' && list.push({ type: flag ? 'phone' : 'text', val: c[i] })}<view wx:for="{{list}}" wx:key bindtap="{{item.type=='phone'?'makePhoneCall':''}}" data-phone="{{item.type=='phone'?item.val:''}}">{{item.val}} </view>makePhoneCall: function (e) {wx.makePhoneCall({phoneNumber:e.currentTarget.dataset.phone})}
项目代码:<!-- 电话高亮 --><view class="wuliumessage"><text wx:for="{{item.Message}}" wx:key="index" wx:for-item="items" style="color:{{items.type=='phone'?'#61B8FD':''}}" catchtap="{{items.type=='phone'?'makePhoneCall':''}}" data-phone="{{items.type=='phone'?items.val:''}}">{{items.val}}</text></view>Paths.forEach((item, i) => {//识别字符串中包含的电话并切割let a = item.Message;var c = a.split(/(1\d{10})/);let list = [];for (var i in c) {var flag = c[i] != '' && /^(1\d{10})$/.test(c[i])c[i] != '' && list.push({ type: flag ? 'phone' : 'text', val: c[i] })}item.Message = list;})item的值是0:{Message: "您的快件代签收(本人),如有疑问请电联小哥【xxx,电话:133xxx1106】。疫情期间顺丰每日对网点消毒、小哥每日测温、配戴口罩,感谢您使用顺丰,期待再次为您服务。"Time: 1594782509Type: 300003}
如果觉得《微信小程序识别字符串中的手机号 手机号高亮显示 并且可以点击这个手机号 拨打电话?》对你有帮助,请点赞、收藏,并留下你的观点哦!