/**
- 批量上传
- @param {Object} imgFiles 图片数组
-
@param {Object} callback 成功回调[successCount:上传成功图片数量;failureCount:上传失败图片数量]
*/
imgUpload : function(selectJob,callback){
BizJob.getSetting(selectJob);
imgFiles = [];
var assets = BizEvent.getAllTableData();
assets.G_PROBLEM_REC.forEach(function(record){
record.IMGS.forEach(function(img){
//filePath = Pictrue.getRealPath(img);
if(!_photoUploadObj[img]){
imgFiles.push(img);
console.log("imgFiles--one--:"+imgFiles)
}
});
});
console.log("imgFiles----:"+imgFiles);
if(imgFiles && imgFiles.length>0){
console.log("imgFiles长度---:"+imgFiles.length);
finish=0;
var total = imgFiles.length;
BizJob.showProgress(total);//mui.each(imgFiles,function(i,u){ for(var i in imgFiles){ photo = imgFiles[i]; console.log("Photo------:"+photo); console.log(1); BizJob.savePhoto(selectJob,Pictrue.getRealPath(photo),function(){ console.log("_photoUploadObj--2----:"+JSON.stringify(_photoUploadObj)); finish++; successCount++; BizJob.setProgress(finish,total); if(finish>=total){ setTimeout(function(){ BizJob.hideProgress(); if(callback) callback(successCount,failureCount); },500); } },function(){ finish++; failureCount++; BizJob.setProgress(finish,total); if(finish>=total){ setTimeout(function(){ BizJob.hideProgress(); if(callback) callback(successCount,failureCount); },500); } }); } }else{ if(callback) callback(0,0); }
},
/** - 同步验收单照片
- @param {Object} selectJob 工单照片
- @param {Function} _success 成功回调
- @param {Function} _failure 失败回调
*/
savePhoto : function(selectJob, path, _success,_failure){
var paramUrl = BizConfig.getUrl() + "/uploadPhoto?";
var token = Zhhy.DBHelper.getVal(BizConfig.TOKEN);
var task = plus.uploader.createUpload( paramUrl,
{ method:"POST",blocksize:204800,priority:100 },
function ( t, status ) {
// 上传完成
if ( status == 200 ) {
_photoUploadObj[photo] = 1;
console.log("_photoUploadObj-----:"+JSON.stringify(_photoUploadObj));
BizJob.setSetting(selectJob);
_success();
} else {
var msg = "上传工单照片失败" +status;
_failure(msg);
console.log("失败:"+status);
}
}
);
task.addFile(path, {key:".jpg"});
task.addData("JOB_ID", selectJob.ID);
task.addData("files", path);
task.addData("token", token);
task.start();
},
/** - 进度条
*/
showProgress : function(size){
ProgressUtil.showProgress({
content : "上传图片",
total : size
});
},
hideProgress : function(){
ProgressUtil.hideProgress();
},
setProgress : function(finish,total){
ProgressUtil.setProgress(finish);
},
/** - 获取基本设置数据
- photoStatus
*/
getSetting : function(selectJob){
_photoUploadObj = Zhhy.DBHelper.getVal("photoStatus"+selectJob.ID);
if(!_photoUploadObj){
_photoUploadObj = {};
}
},
/** - 保存基本设置数据
- json
*/
setSetting : function(selectJob){
Zhhy.DBHelper.setVal("photoStatus"+selectJob.ID, _photoUploadObj);
}
yaYY (作者)
以上代码添加多张照片,每上传一次只上传一张
2018-11-01 14:01
王者地带
task.addFile 需要循环添加,有多少个图片,循环几次,看下你的代码,你只写一次task.addFile,一次代表添加一个图片,
for(var i in imgFiles){
photo = imgFiles[i];
task.addFile(photo{key:"img"+i+""});
}
2018-11-01 14:51
yaYY (作者)
谢谢你已经解决了
2018-11-01 18:34