收藏
回答

企业号开发中H5页面使用wx.chooseImage接口,部分安卓手机偶出现页面刷新的问题如何解决?

问题描述:

机型:华为mate20X 系统版本:10.0.0.195 微信版本:7.0.13

用户启动人脸拍照,照片拍完后,点击完成按钮(‘完成’按钮需要点击多次),这时还未走入success和fail回调就会触发页面刷新,刷新后需要重新拍照,有时候拍一次可成功,多数情况需要多次重复操作拍照才能上传成功。

视频中出现的提示“二维码已失效”是因为用户点击完成后,又重新请求这个二维码地址了。

视频如下:

链接: https://pan.baidu.com/s/13ibMn89zGpr05pabf4chLQ 提取码: k6a7

代码如下:

 // 点击开始拍照
 document.querySelector('#tips').onclick = function (){
    //接口2:拍照或从手机相册中选图接口
    wx.chooseImage({
        count1,
        sizeType: ['compressed'],
        sourceType: ['camera'],
        successfunction (res{
            alert("chooseImage--success")
            // "开始拍摄"按钮隐藏
            $("#tips").css("display","none");
            $("#chooseImage1").css("display","none");
            var img1 = $('#chooseImage1');
            //返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
            var imgLocalId = res.localIds;
            if(!imgLocalId){
                fnPicInfo('',imgLocalId,'choose','fb',JSON.stringify(res));
            }
            $("#returnImg").attr('src',imgLocalId);
            $("#returnImgBox").css("display","block");
            // 屏幕高度
            var VisualHeight = document.documentElement.clientHeight;
            $(document).ready(function(){
                $("#returnImg").on("load",function(){
                    var returnImgHeight = $(this).height();
                    var marginHeight = (VisualHeight - returnImgHeight)/2;
                    $("#returnImgBox").css("margin-top",marginHeight);
                });
            });
            //拍照之后询问是否确认上传
            $("#isupload").css("display","block");
            //不上传或者重新选择
            $("#isupload_n").click(function(){
                $("#isupload").css("display","none");
                $("#tips").css("display","block");
                $("#tips").html("重新拍摄");
                $("#returnImgBox").css("display","none");
                $("#chooseImage1").css("display","block");
            });
            //确认上传
            $("#isupload_y").click(function(){
                $("#isupload").css("display","none");
                //在此处加一个加载进度条。。。。。。。
                $(".processwrap").css("display","block");
                //接口3:上传图片接口
                wx.uploadImage({
                    // 需要上传的图片的本地ID,由chooseImage接口获得
                    localId: imgLocalId[0], 
                    // 默认为1,显示进度提示
                    isShowProgressTips1, 
                    successfunction (res{
                        alert("uploadImage--success")
                        if(res.serverId.indexOf("wxLocalResource://")>=0){
                            mui.alert('',"照片上传失败,请重新拍照上传!",'');
                            return;
                        }
                        mediaId = res.serverId;
                        if(!mediaId){
                            nPicInfo(mediaId,imgLocalId,'upload','fb',JSON.stringify(res));
                        } 
                        img1.attr('src',imgLocalId);
                        mediaId1 = mediaId;
                        localId1 = imgLocalId;
                        var paramStrs = message.split("#");
                        //准备请求的参数:mediaId
                        var requestdata = {
                            "mediaId": mediaId,
                            "traceno": paramStrs[0],
                            "name": paramStrs[1],
                            "idnotype": paramStrs[2],
                            "idno": paramStrs[3],
                            traincode: paramStrs[4],
                            managecom: paramStrs[5]
                        }
                        //调用图片上传接口
                        post_mediaId(requestdata);
                    },
                    failfunction(re){
                        $(".processwrap").css("display","none");
                        wx.getNetworkType({
                            successfunction (res{
                                $('.hidden_word1').show();
                                newNet = res.networkType;
                                fnPicInfo('','','upload','fb',re);
                            }
                        });
                    }
                });
            });
        },
        failfunction(re){
            alert("chooseImage--fail");
            wx.getNetworkType({
                successfunction (res{
                    $('.hidden_word1').show();
                    newNet = res.networkType;
                    fnPicInfo('','','choose','fb',re);
                }
          });
        }
    });
};
最后一次编辑于  04-23
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签