小程序常用实用例子

拍照

// 选择照片

ChooseImage() {

wx.chooseImage({

count: 4, //默认9

sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有

sourceType: ['album'], //从相册选择

success: (res) => {

if (this.data.imgList.length != 0) {

this.setData({

imgList: this.data.imgList.concat(res.tempFilePaths)

})

} else {

this.setData({

imgList: res.tempFilePaths

})

}

}

});

},

页面

<view class="solids" bindtap="ChooseImage" wx:if="{{imgList.length<4}}">

<text class="cuIcon-cameraadd"></text>

</view>

照片预览

<view class="bg-img" wx:for="{{imgList}}" wx:key="index" bindtap="ViewImage" data-url="{{imgList[index]}}">

<image src='{{imgList[index]}}' mode='aspectFill'></image>

<view class="cu-tag bg-red" catchtap="DelImg" data-index="{{index}}">

<text class="cuIcon-close"></text>

</view>

</view>

// 预览照片

ViewImage(e) {

wx.previewImage({

urls: this.data.imgList,

current: e.currentTarget.dataset.url

});

},

// 打电话

CallPhone(e) {

console.log(e, e.currentTarget.dataset.phone)

let phoneNumber = e.currentTarget.dataset.phone

let showphone = e.currentTarget.dataset.showphone

wx.showModal({

title: '温馨提示',

content: `是否拨打${showphone}号码?`,

confirmText: '确定拨打',

confirmColor: '#0081ff',

cancelText: '取消',

cancelColor: '#acb5bd',

success: res => {

console.log(res)

if (res.confirm) {

wx.makePhoneCall({

phoneNumber: phoneNumber,

success: res => {

console.log(res)

},

fail: err => {

console.log(err)

}

})

}

},

fail: err => {

console.log(err)

}

})

},

相关推荐
土土哥V_araolin12 小时前
双迪大健康新零售系统开发要点
小程序·个人开发·零售
2501_9159090614 小时前
不用越狱就看不到 iOS App 内部文件?使用 Keymob 查看和导出应用数据目录
android·ios·小程序·https·uni-app·iphone·webview
CHU72903515 小时前
扭蛋机盲盒小程序前端功能设计及核心玩法介绍
前端·小程序
职豚求职小程序16 小时前
中华财险笔试测评题库小程序刷题职豚2026新
小程序
阿珊和她的猫16 小时前
小程序双线程架构:逻辑层与视图层的协同运作机制
小程序·架构
源码ym7k资源16 小时前
在线家政系统(APP+小程序)源码:为您提供专业的本地服务
小程序
2601_9520137616 小时前
家政服务小程序预约上门服务维修保洁上门服务在线派单技师入驻-ym7K
小程序
2501_9159214316 小时前
常用iOS性能测试工具大全及使用指南
android·测试工具·ios·小程序·uni-app·cocoa·iphone
一字白首17 小时前
小程序组件化进阶:从复用到通信的完整指南DAY04
前端·小程序·apache
是Winky啊17 小时前
【逆向+爬虫】获取小程序信息
小程序