61 lines
1.0 KiB
JavaScript
61 lines
1.0 KiB
JavaScript
var upObj = null;
|
|
wx.ready(function() {
|
|
// 5 图片接口
|
|
// 5.1 拍照、本地选图
|
|
var images = {
|
|
localId : [],
|
|
serverId : [],
|
|
uploadIds : [],
|
|
};
|
|
|
|
document.querySelector("#chooseImage").onclick = function() {
|
|
$(".photo").empty();
|
|
wx.chooseImage({
|
|
success : function(res) {
|
|
images = {
|
|
localId : res.localIds,
|
|
serverId : [],
|
|
uploadIds : [],
|
|
};
|
|
|
|
if (images.localId.length == 0) {
|
|
alert('请先拍取照片');
|
|
return;
|
|
}
|
|
if (images.localId.length > 4) {
|
|
alert('最多允许上传四张,请重新选择');
|
|
images.localId = [];
|
|
return;
|
|
}
|
|
|
|
upload(0);
|
|
}
|
|
});
|
|
};
|
|
|
|
function upload(i) {
|
|
localIdMes = images.localId[i];
|
|
|
|
wx.uploadImage({
|
|
localId : localIdMes,
|
|
success : function(res) {
|
|
showImage(res.serverId, i);
|
|
i++;
|
|
setTimeout(function() {
|
|
|
|
if (i < images.localId.length) {
|
|
upload(i);
|
|
}
|
|
}, 500)
|
|
},
|
|
fail : function(res) {
|
|
alert(JSON.stringify(res));
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
wx.error(function(res) {
|
|
alert(res.errMsg);
|
|
});
|