zoukankan      html  css  js  c++  java
  • 微信web开发的上传图片js接口

    $('.chooseImage').click(function(){
                wx.chooseImage({
                    count: pic_num, // 默认9,大于9也是显示9
                    sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有 'original', 
                    success: function (res) {
                        images.localId = res.localIds;
                        alert('已选择 ' + res.localIds.length + ' 张图片');
                        var img_data = "";
                        $.each(images.localId, function(i, v)
                        {
                            img_data += "<img class='wimg-item' src='"+v+"'>";
                        });
                        $("#image_content .chooseImage").before(img_data);
                        $("#uploadImage").click();
                    }
                });
            });
    
    
            document.querySelector('#uploadImage').onclick = function () {
                if (images.localId.length == 0) {
                    alert('请先使用 chooseImage 接口选择图片');
                    return;
                }
                var i = 0, length = images.localId.length;
                images.serverId = images.serverId || [];
                function upload() {
                    wx.uploadImage({
                        localId: images.localId[i],
                        isShowProgressTips: i == 0 ? 1:0,// 第一张图显示进度,避免出现一会弹出一个进度等待
                        success: function (res) {
                            i++;
                            $('#ask_submit').html('正在上传 '+i+'/'+length);
                            if(i>=length)
                            {
                                $('#ask_submit').html('确定');
                                // alert('已上传:' + i + '/' + length);
                            }
    
                            images.serverId.push(res.serverId);
                            if (i < length && i <= pic_num) {
                                upload();
                            }
                        },
                        fail: function (res) {
                            alert('~><~ 图片上传失败,请稍后再试...');
                            //alert(JSON.stringify(res));
                        }
                    });
                }
                upload();
            };
        });
  • 相关阅读:
    Codeforces 877 C. Slava and tanks
    Codeforces 877 D. Olya and Energy Drinks
    2017 10.25 NOIP模拟赛
    2017 国庆湖南 Day1
    UVA 12113 Overlapping Squares
    学大伟业 国庆Day2
    51nod 1629 B君的圆锥
    51nod 1381 硬币游戏
    [JSOI2010]满汉全席
    学大伟业 2017 国庆 Day1
  • 原文地址:https://www.cnblogs.com/firstForEver/p/4886132.html
Copyright © 2011-2022 走看看