Authored by xuhongyun

支持多文件上传

... ... @@ -130,7 +130,25 @@ module.exports={
result={code: "501",message: "用户失效,请重新登录"};
return callback(null, result);
}
req.body.files = [fs.createReadStream(req.files.upfile.path)];
var files = req.files.upfile;
console.log(req.files);
//判断是单张传还是多张传
var flag = Object.prototype.toString.call(files) === '[object Array]';
//如果是单张,则数组化
if (!flag) {
files = [];
files.push(req.files.upfile);
}
req.body.files = [];
req.body.fileNames = [];
for (var index = 0; index < files.length; index++) {
req.body.files[index] = fs.createReadStream(files[index].path);
req.body.fileNames[index] = files[index].filename;
}
// req.body.files = [fs.createReadStream(req.files.upfile.path)];
req.body.bucket="goodsimg";
request.post({
url: "http://upload.static.yohobuy.com",
... ... @@ -142,21 +160,27 @@ module.exports={
if (!error && httpResponse.statusCode == 200) {
var ret = JSON.parse(body);
if (ret.code === 200) {
var imgUrl = ret.data.imagesList[0];
imgUrl=Utils.joinImg(imgUrl);
result={};
result = [];
for (var i = 0; i < ret.data.imagesList.length; i++) {
var imgUrl = ret.data.imagesList[i];
var rest = {};
imgUrl = Utils.joinImg(imgUrl);
if(imgUrl){
result.originalName=Date.now();
result.name=Date.now();
result.url=imgUrl;
result.type=imgUrl.substring(imgUrl.lastIndexOf('.'));
result.state="SUCCESS";
rest.originalName = Date.now();
rest.name = Date.now();
rest.url = imgUrl;
rest.type = imgUrl.substring(imgUrl.lastIndexOf('.'));
rest.state = "SUCCESS";
}else{
result.state="FAIL";
rest.state = "FAIL";
}
result.push(rest);
}
}
return callback(null, result);
}
});
},
downExcel:function(req, callback){
... ...
... ... @@ -137,7 +137,7 @@ var $=require('jquery');
'<div class="edui-image-upload%%">' +
'<span class="edui-image-icon"></span>' +
'<form class="edui-image-form" method="post" enctype="multipart/form-data" target="up">' +
'<input style=\"filter: alpha(opacity=0);\" class="edui-image-file" type="file" hidefocus name="upfile" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"/>' +
'<input style=\"filter: alpha(opacity=0);\" class="edui-image-file" type="file" multiple hidefocus name="upfile" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"/>' +
'</form>' +
'</div>',
... ... @@ -182,9 +182,12 @@ var $=require('jquery');
uploadComplete: function(r){
var me = this;
try{
r=r.match(/\{.*\}/g)[0];
r=r.match(/\[.*\]/g)[0];
var json = eval('('+r+')');
Base.callback(me.editor, me.dialog, json.url, json.state);
for (var i = 0; i < json.length; i++) {
Base.callback(me.editor, me.dialog, json[i].url, json[i].state);
}
}catch (e){
var lang = me.editor.getLang('image');
Base.callback(me.editor, me.dialog, '', (lang && lang.uploadError) || 'Error!');
... ... @@ -193,7 +196,7 @@ var $=require('jquery');
submit: function (callback) {
var me = this,
input = $( '<input style="filter: alpha(opacity=0);" class="edui-image-file" type="file" hidefocus="" name="upfile" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp">'),
input = $( '<input style="filter: alpha(opacity=0);" class="edui-image-file" type="file" multiple hidefocus="" name="upfile" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp">'),
input = input[0];
$(me.dialog).delegate( ".edui-image-file", "change", function ( e ) {
... ... @@ -405,8 +408,13 @@ var $=require('jquery');
}
});
$(document).on("click",".edui-image-product .edui-product-content .edui-image-pic",function(){
$(".edui-image-product .edui-product-content .edui-image-pic").removeClass("active-product");
$(this).addClass("active-product");
if ($(this).hasClass("active-product")) {
$(this).removeClass("active-product");
}
else {
$(this).addClass("active-product");
}
});
}
}
... ...