wx.chooseImage({
success: function(res) {
var tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: 'http://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'file',
formData:{
'user': 'test'
},
success: function(res){
var data = res.data
//do something
}
})
}
})
var img_index = 0;//上传带第几张
var image_list1 = new Array();
//上传图片
var upload_img = function (that, file_name) {
that.setData({
hidden: false
});
wx.uploadFile({
url: '',
filePath: file_name,
name: 'file',
success: function (res) {
//此处判断是否上传成功
var obj = JSON.parse(res.data);
if (obj.ret_code == 1) {
//上传成功以后将上传成功的图片加入数组显示出来,这样可以避免没有上传成功的图片就不显示
var uploads = new Array();
var image_list = new Array();
//加入返回值
uploads = that.data.upload;
uploads.push(obj.data);
//加入图片
image_list = that.data.tempFilePaths;
image_list.push(file_name);
that.setData({
upload: uploads,
tempFilePaths: image_list
});
//上传成功一次img_index+1,下面再次调用upload_img上传图片就可以直接传image_list1[img_index],也就是下一张图片的链接
img_index = img_index + 1;
//这里需要作出判断图片是否上传完成,如果完成则取消缓冲框hidden
if (img_index < image_list1.length) {
upload_img(that, '' + image_list1[img_index]);
} else {
that.setData({
hidden: true
});
}
//刷新界面
that.update();
} else {
that.setData({
hidden: true
});
utils.show_toast(obj.msg);
}
},
fail: function (res) {
that.setData({
hidden: true
});
utils.show_toast('加入失败');
}
})
}
if (that.data.tempFilePaths.length < 9) {
wx.chooseImage({
count: 9 - that.data.tempFilePaths.length, // 最多可以选择的图片张数,默认9
sizeType: ['compressed'], // original 原图,compressed 压缩图,默认二者都有
sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
success: function (res) {
// success
img_index = 0;
image_list1=new Array();
//将选择的图片放入要上传的数组中
for (var i = 0; i < res.tempFilePaths.length; i++) {
console.log(i + ';' + res.tempFilePaths[i]);
image_list1.push(res.tempFilePaths[i]);
}
//最开始上传第一张图片
upload_img(that, '' + image_list1[img_index]);
},
fail: function () {
utils.show_toast('选取失败');
}
})
} else {
utils.show_toast('当前最多只能选择9张图片');
}
utils.show_toast(‘当前最多只能选择9张图片')
//弹窗
function show_toast(text) {
wx.showToast({
title: text,
icon: ‘success',
duration: 2000
});
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有