先弹出操作菜单,选择拍照还是从相册选择。根据用户选择进行相应操作。如图所示
代码如下:
browse:function(){
let that = this;
wx.showActionSheet({
itemList: ['从相册中选择', '拍照'],
itemColor: "#00ff20",
success: function(res) {
if (!res.cancel) {
if (res.tapIndex == 0) {
that.chooseWxImage('album');
} else if (res.tapIndex == 1) {
that.chooseWxImage('camera');
}
}
}
})
},
/*打开相册、相机 */
chooseWxImage: function(type) {
let that = this;
wx.chooseImage({
count: that.data.countIndex,
sizeType: ['original', 'compressed'],
sourceType: [type],
success: function(res) {
// 选择图片后的完成确认操作
that.setData({
aimgurl: res.tempFilePaths
});
console.log(that.data.aimgurl);
}
})
}