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();
            };
        });
  • 相关阅读:
    Redis的发布订阅
    Redis的事务
    Redis的持久化下
    Redis的持久化上
    Redis数据类型之Redis有序集合Zset(sorted set
    Redis数据类型之Redis哈希(Hash)
    Redis数据类型之Redis集合(Set)
    LeetCode#53-最大子序和
    LeetCode#442-数组中的重复数据
    LeetCode#1014-最佳观光组合
  • 原文地址:https://www.cnblogs.com/firstForEver/p/4886132.html
Copyright © 2011-2022 走看看