chooseImage 限制只能拍照模式下,点击没反应
https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.chooseImage.html
代码片段
shareInst.wx.chooseImage({
count: 1, // 默认9
sourceType: ['camera'],
success: function (resp) {
console.log("小程序", resp)
shareInst.wx.checkJsApi({
jsApiList: shareData.jsApiList,
success: function (jsApiRes) {
if (jsApiRes.checkResult.getLocalImgData) {
shareInst.wx.getLocalImgData({
localId: resp[0], // 图片的localID
success: function (res) {
var localData = res.localData; // localData是图片的base64数据,可以用img标签显示
if (localData.indexOf(";base64,") == -1) {//兼容处理,安卓获取的图片base64码没有前缀,而苹果有,base64前缀并不固定
localData = "data:image/jpeg;base64," + localData;//加上base64前缀
}
if (localData.indexOf("data:image/jgp;base64,") != -1) {//兼容处理,若是苹果手机,将前缀中的jgp替换成jpeg
localData = localData.replace("data:image/jgp;base64,", "data:image/jpeg;base64,");
}
_this.nimSendFileByUrl(localData);
}
});
} else {
if (resp.length) {
shareInst.app.$vux.loading.show({text: `正在发送...`});
}
console.log("resp[0]", resp);
let {localIds} = resp
console.log("resp[0]", localIds);
shareInst.wx.uploadImage({
localId: localIds[0], // 需要上传的图片的本地ID,由chooseImage接口获得
isShowProgressTips: 1, // 默认为1,显示进度提示
success: function (res) {
console.log("成功", res);
var serverId = res.serverId; // 返回图片的服务器端ID
let params = {wxCode: shareData.launchParams.wxCode, mediaId: serverId};
console.log("上传图片的id", params);
shareInst.Api.getMedia(params).then(mediaResp => {
if (mediaResp.code == 0 && mediaResp.result.length > 0) {
_this.nimSendFileByUrl(mediaResp.result);
} else {
shareInst.app.$vux.loading.hide();
}
});
},
fail: function (error) {
console.log("fail", error);
shareInst.app.$vux.loading.hide();
},
cancel: function (error) {
console.log("cancel", error);
shareInst.app.$vux.loading.hide();
}
});
}
}
});
},
fail: function (res) {
}
})
1 回复
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。