Authored by liuyue

Merge branch 'develop' of http://git.dev.yoho.cn/platform/yohobuy-shops-fe into develop

... ... @@ -32,7 +32,7 @@ var urlObj = {
// 逛
'guangGetAuthorList':'/guang/article/getAuthorList', // 逛-获取作者
'guangGetSortList':'/guang/article/getSortList', // 逛-获取作者
'guangGetSortList':'/ajax/guang/article/getSortList', // 逛-获取作者
'guangGetTagCategoryByStatus':'/guang/tagSort/getTagItems',
'guangCommentGetFilterItems':'/guang/comment/getItems', // 逛-评论列表-获取筛选条件
'guangPlusSatrChannel':'/guang/plustarcategory/getCategoryNames', // 逛-plus star 频道
... ...
... ... @@ -171,7 +171,7 @@ edit.prototype = {
},
'onComplete': function(response) {
if (response.status && response.code == 200) {
var _w = $(this).next().find('.fileinput-button-icon');
var _w = $(this).parent().find('.fileinput-button-icon');
var _img = $('img', _w).add('video', _w);
if (_img.length > 0) {
_img.attr("src", response.data);
... ...
... ... @@ -267,6 +267,17 @@ var util = {
setTimeout(function(){
$this.removeAttr("disabled");
},3000);
},
__joinImg:function(url) {
var urlArr = url.split('/');
var domain = 'static.yhbimg.com/brandLogo';
var num = urlArr[urlArr.length-1].substr(1,1);
var url = domain + url;
if(num == 1) {
return 'http://img11.' + url;
} else {
return 'http://img12.'+ url;
}
}
}
module.exports = util;
\ No newline at end of file
... ...
... ... @@ -41,17 +41,18 @@ function getHeader(req,res){
}
exports.uploadFile = function(req, res) {
var headers = getHeader(req,res);
exports.uploadFile = function (req, res) {
var headers = getHeader(req, res);
if (req.is("multipart/form-data")) {
console.log(req.body);
var url = [];
for (var key in req.body) {
url.push(key + "=" + req.body[key]);
}
req.body.file = fs.createReadStream(req.files[req.body.filename].path);
console.log("req.body",req.body);
//req.body.file = fs.createReadStream(req.files[req.body.filename].path);
if (req.body.__type == "batch-import") {
req.body.file = fs.createReadStream(req.files[req.body.filename].path);
request.post({
url: domain + '/batch/import?' + url.join("&"),
formData: req.body,
... ... @@ -63,31 +64,51 @@ exports.uploadFile = function(req, res) {
if (!error && httpResponse.statusCode == 200) {
var json = JSON.parse(body);
json.status = true;
// console.log(json);
res.json(json);
} else {
res.json(errBackMsg);
}
});
} else {
var files = req.files[req.body.filename];
//判断是单张传还是多张传
var flag = Object.prototype.toString.call(files) === '[object Array]';
//如果是单张,则数组化
if (!flag) {
files = [];
files.push(req.files[req.body.filename]);
}
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].name;
}
//如果是goodsimg(商品)的图片,灰度到老系统的上传地址
if (req.body.bucket === 'goodsimg') {
req.body.filename = req.files[req.body.filename].path;
//req.body.filename = req.files[req.body.filename].path;
request.post({
url: oldUploadUrl,
formData: {
fileData: req.body.file,
fileData: req.body.files,
project: req.body.bucket
}
}, function(error, resd, body) {
}, function (error, resd, body) {
if (!error && resd.statusCode == 200) {
var ret = JSON.parse(body);
if (ret.code === 200) {
var imgUrl = ret.data.imagesList[0];
//var imgUrl = ret.data.imagesList[0];
var imgs = ret.data.imagesList || [];
var datas = [];
for (var i = 0; i < imgs.length; i++) {
datas.push(joinimg(imgs[i]))
}
res.json({
code: 200,
data: joinimg(imgUrl),
data: datas[0],
datas:datas,
names: req.body.fileNames,
message: '上传成功',
status: true
});
... ... @@ -97,12 +118,12 @@ exports.uploadFile = function(req, res) {
res.json(errBackMsg);
});
} else {
req.body.file = fs.createReadStream(req.files[req.body.filename].path);
// delete req.body.files;
request.post({
url: domain + '/fileupload/upload',
formData: req.body
}, function optionalCallback(error, httpResponse, body) {
console.log(body);
if (!error && httpResponse.statusCode == 200) {
var json = JSON.parse(body);
json.status = true;
... ... @@ -119,7 +140,7 @@ exports.uploadFile = function(req, res) {
message: "请求类型错误"
});
}
}
};
/**
* 组合全路径的图片地址
... ... @@ -128,43 +149,60 @@ function joinimg(url) {
var urlArr = url.split('/');
var domain = 'static.yhbimg.com/goodsimg';
var num = urlArr[urlArr.length - 1].substr(1, 1);
var url = domain + url;
var url1 = domain + url;
if (num == 1) {
return 'http://img11.' + url;
return 'http://img11.' + url1;
} else {
return 'http://img12.' + url;
return 'http://img12.' + url1;
}
}
// exports.getSaveState=function(req,res){
// console.log("6666666");
// request.post({
// url: domain + '/product/queryBatchImportResult',
// formData: req.body
// }, function optionalCallback(error, httpResponse, body) {
// console.log(body);
// if (error) {
// return console.error('upload failed:', error);
// }
// if (!error && httpResponse.statusCode == 200) {
// var json = JSON.parse(body);
// json.status = true;
// // console.log(json);
// res.json(json);
// } else {
// res.json(errBackMsg);
// }
// });
// }
exports.ueditor = function(req, res) {
var headers = getHeader(req,res);
var headers = getHeader(req, res);
if (req.is("multipart/form-data")) {
req.body.file = fs.createReadStream(req.files.upfile.path);
req.body.bucket = "goodsimg";
req.body.bucket="goodsimg";
request.post({
url: domain + '/fileupload/upload',
formData: req.body
url: domain + '/fileupload/upload',
formData: req.body
}, function optionalCallback(error, httpResponse, body) {
// {"code":200,"data":"http://img12.static.yhbimg.com/goodsimg/2016/03/10/20/0258a569ab956e81339c7212bb23767c2d.jpg","message":"上传成功","status":true}
// {"originalName":"demo.jpg","name":"demo.jpg","url":"upload\/demo.jpg","size":"99697","type":".jpg","state":"SUCCESS"}
// {"originalName":"018da7232374448d10a565fdfe6211d078.jpg","name":"","url":"","type":".jpg","state":"SUCCESS"}
if (!error && httpResponse.statusCode == 200) {
var json = JSON.parse(body);
var result = {};
result.originalName = json.data.substring(json.data.lastIndexOf('/') + 1);
result.name = result.originalName;
result.url = json.data;
result.type = json.data.substring(json.data.lastIndexOf('.'));
result.state = json.message == "上传成功" ? "SUCCESS" : "FAIL";
var result={};
result.originalName=json.data.substring(json.data.lastIndexOf('/')+1);
result.name=result.originalName;
result.url=json.data;
result.type=json.data.substring(json.data.lastIndexOf('.'));
result.state=json.message=="上传成功"?"SUCCESS":"FAIL";
res.send(JSON.stringify(result));
} else {
res.send({
code: "500",
message: "接口异常"
});
}else{
res.send({code:"500",message:"接口异常"});
}
});
... ... @@ -177,7 +215,7 @@ exports.ueditor = function(req, res) {
}
exports.linkFile = function(req, res) {
request.get(domain + "/common/" + req.params.name + ".xlsx").pipe(res);
request.get(domain+"/common/"+req.params.name+".xlsx").pipe(res);
}
exports.downFile = function(req, res) {
... ... @@ -191,4 +229,8 @@ exports.downFile = function(req, res) {
json: true
};
request(options).pipe(res);
}
exports.getJSONFile=function(req,res){
console.log(searchDomain);
request.get("http://192.168.10.64:8080/yohosearch/brand/list.json").pipe(res);
}
\ No newline at end of file
... ...