Authored by yyq

上传图片路径不一致问题解决

... ... @@ -25,6 +25,24 @@ const returnAddress = {
phone: '17714194699'
};
/**
* 获取原图片路径
* @function _getForceSourceUrl
* @param { String } url 图片路径
* @return { String } 原图片路径
*/
const _getForceSourceUrl = (url) => {
const str = ['?imageView', '?imageMogr2'];
_.forEach(str, value => {
url = _.split(url, value, 1)[0];
});
url.replace('http:', '');
return url;
};
/**
* 获取用户退换货列表
* @function getUserReturn
... ... @@ -356,6 +374,14 @@ const _setRefundDetailData = (data) => {
let goods = [];
_.forEach(data.goods_list, value => {
let evidence;
if (!_.isEmpty(value.evidence_images)) {
evidence = [];
_.forEach(value.evidence_images, img => {
evidence.push(_getForceSourceUrl(img));
});
}
goods.push({
img: value.goods_image,
name: value.product_name,
... ... @@ -365,7 +391,7 @@ const _setRefundDetailData = (data) => {
reason: value.reason_name || '--',
price: value.sales_price,
remark: value.remark,
evidence: value.evidence_images
evidence: evidence
});
});
... ...
... ... @@ -140,9 +140,9 @@
<dd>
<label>照片凭证:</label>
{{# evidence}}
<div class="evidence-img">
<img class="lazy" data-original="{{image . 70 90}}">
</div>
<a href="{{this}}" class="evidence-img" target="_blank">
<img class="lazy" data-original="{{this}}">
</a>
{{/ evidence}}
</dd>
{{/if}}
... ...
... ... @@ -10,16 +10,16 @@ const request = require('request');
const fs = require('fs');
// 获取图片绝对地址
const getImgHost = (url) => {
let domain = 'static.yhbimg.com/goodsimg',
const getImgHost = (url, bucket) => {
let domain = `static.yhbimg.com/${bucket}`,
urlArr = url.split('/'),
num = urlArr[urlArr.length - 1].substr(1, 1),
url1 = domain + url;
if (num === '1') {
return 'http://img11.' + url1;
return `http://img11.${url1}`;
} else {
return 'http://img12.' + url1;
return `http://img12.${url1}`;
}
};
... ... @@ -45,41 +45,35 @@ const uploadImg = (req, res) => {
req.body.fileNames[fileIndex] = files[fileIndex].name;
}
if (req.body.bucket === 'goodsimg') {
request.post({
url: 'http://upload.static.yohobuy.com',
formData: {
fileData: req.body.files,
project: req.body.bucket
},
json: true
}, (error, httpResponse, rebody) => {
if (!error && httpResponse.statusCode === 200) {
imgs = rebody.data.imagesList || [];
datas = [];
request.post({
url: 'http://upload.static.yohobuy.com',
formData: {
fileData: req.body.files,
project: req.body.bucket
},
json: true
}, (error, httpResponse, rebody) => {
console.log(httpResponse);
if (!error && httpResponse.statusCode === 200) {
imgs = rebody.data.imagesList || [];
datas = [];
// 生成图片绝对地址
for (i = 0; i < imgs.length; i++) {
datas.push(getImgHost(imgs[i]));
}
// 生成图片绝对地址
for (i = 0; i < imgs.length; i++) {
datas.push(getImgHost(imgs[i], req.body.bucket));
}
}
res.json({
code: 200,
data: datas[0],
datas: datas,
imgs: imgs,
names: req.body.fileNames,
message: '上传成功',
status: true
});
});
} else {
res.json({
code: 500,
message: '上传图片失败, 请稍后重试!'
code: 200,
data: datas[0],
datas: datas,
imgs: imgs,
names: req.body.fileNames,
message: '上传成功',
status: true
});
}
});
} else {
res.json({
code: 401,
... ...
... ... @@ -6,7 +6,7 @@ var tpl = '<div style="width: 0px; height: 0px; overflow: hidden;">' +
'<form id="yoho-upload" method="post" enctype="multipart/form-data" ' +
'action="/common/uploadImg" target="ajaxUpload">' +
'<input type="file" name="filename" class="file-name" />' +
'<input type="hidden" name="bucket" value="goodsimg" />' +
'<input type="hidden" name="bucket" value="evidenceImages" />' +
'</form>' +
'</div>';
... ...
... ... @@ -197,10 +197,15 @@
.evidence-img {
width: 70px;
height: 90px;
height: 70px;
display: inline-block;
vertical-align: top;
}
.evidence-img > img {
width: 100%;
height: 100%;
}
}
}
}
... ...