Authored by zhangxiaoru

plustarNew

... ... @@ -144,8 +144,47 @@ const index = (req, res, next) => {
}).catch(next);
};
/**
* 逛标签页
* @param req
* @param res
* @param next
*/
const tag = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '逛标签页'
});
let responseData = {
pageHeader: headerData,
module: 'guang',
page: 'index-editor',
title: '逛标签页',
pageFooter: true
};
let param = {
tag: req.query.tag,
isApp: req.query.app_version || req.query.appVersion || false,
gender: req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || '1,3',
uid: req.user.uid,
udid: req.user.udid,
type: req.query.type || 0
};
if (param.isApp === false) {
responseData.pageHeader.navTitle = param.tag;
}
indexModel.getTagEditor(param).then(result => {
res.render('index/list', Object.assign(responseData, result));
}).catch(next);
};
module.exports = {
editor,
pageData,
index
index,
tag
};
... ...
... ... @@ -65,6 +65,7 @@ const _pageArticleContent = (articleContent, isApp, gender) => {
skns.push(goods.id);
arr[goods.id] = goods.src;
});
// 通过SKN获取商品信息
productDetailModel.productInfoBySkns(skns).then((product) => {
if (product.data.product_list) {
... ... @@ -149,10 +150,11 @@ const _pageArticleContent = (articleContent, isApp, gender) => {
} else {
resolve(contents);
}
}
};
joinContentFunc(0, articleContent.length);
});
}
};
/**
* [处理品牌数据]
* @param {[array]} getBrand [品牌原数据]
... ... @@ -163,7 +165,8 @@ const _relatedBrand = (getBrand) => {
brand.thumb = brand.thumb.replace('http://', '//');
});
return relatedBrand;
}
};
/**
* [处理标签数据]
* @param {[array]} tags [标签原数据]
... ... @@ -180,7 +183,8 @@ const _relatedTag = (tags, isApp) => {
relatedTag.push(value);
});
return relatedTag;
}
};
/**
* [处理相关文章数据]
* @param {[array]} getOtherArticle [相关文章原数据]
... ... @@ -198,7 +202,8 @@ const _relatedInfo = (getOtherArticle, isApp) => {
relatedInfo.push(value);
});
return relatedInfo;
}
};
/**
* [处理分享内容]
* @param {[int]} id [资讯id]
... ... @@ -217,7 +222,8 @@ const _shareInfo = (id, getArticle) => {
shareInfo.shareImg = helpers.image(getArticle.cover_image, 640, 320);
}
return shareInfo;
}
};
/**
* [逛资讯详情页]
*/
... ... @@ -278,12 +284,13 @@ const index = (req, res, next) => {
pageView: detail.getArticle.pageViews,
content: []
};
if (detail.getArticleContent) {
//生成内容部分
// 生成内容部分
return _pageArticleContent(detail.getArticleContent, isApp, gender).then((contents) => {
guang.detail.content = contents;
// 相关品牌
if (detail.getBrand && detail.getBrand.length) {
guang.relatedBrand = _relatedBrand(detail.getBrand);
... ... @@ -326,6 +333,7 @@ const index = (req, res, next) => {
}
}).catch(next);
};
/**
* [逛mini内容页]
*/
... ... @@ -360,12 +368,13 @@ const mini = (req, res, next) => {
pageView: detail.getArticle.pageViews,
content: []
};
if (detail.getArticleContent) {
//生成内容部分
// 生成内容部分
return _pageArticleContent(detail.getArticleContent, isApp, gender).then((contents) => {
guang.detail.content = contents;
// 相关品牌
if (detail.getBrand && detail.getBrand.length) {
guang.relatedBrand = _relatedBrand(detail.getBrand);
... ... @@ -421,16 +430,17 @@ const foryoho = (req, res, next) => {
data.brand = detail.getBrand;
if (detail.getArticleContent) {
//生成内容部分
// 生成内容部分
return _pageArticleContent(detail.getArticleContent, isApp, gender).then((contents) => {
data.content = contents;
//内容中的相关推荐和悬浮商品移到data层级
// 内容中的相关推荐和悬浮商品移到data层级
let relatedRecoIndex = data.content.findIndex((cont) => {
return typeof cont.relatedReco !== 'undefined';
})
});
let collocationIndex = data.content.findIndex((cont) => {
return typeof cont.collocation !== 'undefined';
})
});
if (relatedRecoIndex > 0) {
data.goods = data.content[relatedRecoIndex].relatedReco;
data.content.splice(relatedRecoIndex, 1);
... ... @@ -448,7 +458,7 @@ const foryoho = (req, res, next) => {
}
}).catch(next);
}
};
module.exports = {
index,
... ...
... ... @@ -13,20 +13,20 @@ const helpers = global.yoho.helpers;
* [订阅逛最新的资讯]
*/
const index = (req, res, next) => {
let gender = req.query.gender || '1,2,3',
items = [];
let gender = req.query.gender || '1,2,3',
items = [];
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
return rssModel.getRssArticle(gender).then((result) => {
return res.render('rss/index', {
layout: false,
time: '',
items: result
})
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
return rssModel.getRssArticle(gender).then((result) => {
return res.render('rss/index', {
layout: false,
time: (new Date()).toUTCString(),
items: result
});
});
}
};
module.exports = {
index
}
\ No newline at end of file
index
};
... ...
... ... @@ -160,8 +160,8 @@ const _article = (param) => {
*/
const getArticle = (param) => {
let page = param.page ? param.page : 1;
Object.assign(param, { page: page });
return api.all([
... ... @@ -182,7 +182,7 @@ const getArticle = (param) => {
let indexTmp = 0;
if (result[0] && result[0].data && result[0].data) {
if (result[0] && result[0].data) {
indexTmp = 0;
... ... @@ -196,16 +196,16 @@ const getArticle = (param) => {
build.push({
typeId: val.id,
type: val.name,
focus: (val.id == type)
focus: (val.id === type)
});
inf.push({
show: (val.id == type),
show: (val.id === type),
typeId: type,
info: []
});
if ((val.id == type)) {
if ((val.id === type)) {
curIndex = indexTmp;
}
... ... @@ -219,7 +219,7 @@ const getArticle = (param) => {
}
if (result[1].data.list.adlist && result[1].data) {
if (result && result[1] && result[1].data && result[1].data.list) {
let swp = [];
... ... @@ -237,7 +237,7 @@ const getArticle = (param) => {
}
if (result[1].data.list.artList && result[1].data) {
if (result && result[1] && result[1].data && result[1].data.list) {
let inf = [];
... ... @@ -251,7 +251,44 @@ const getArticle = (param) => {
}
// console.log(resu);
return resu;
});
};
const getTagEditor = (param) => {
let page = param.page ? param.page : 1;
Object.assign(param, { page: page });
return api.all([
_article(param)
]).then(result => {
let resu = {
guang: {
tag: param.tag,
gender: param.gender,
isApp: param.isApp ? 1 : 0,
guangList: true
}
};
if (result && result[0] && result[0].data && result[0].data.list) {
let inf = [];
let infoList = result[0].data.list.artList;
infoList.forEach(val => {
inf.push(guangProcess.formatArticle(val, true, false, true));
});
resu.guang.infos = inf;
}
return resu;
... ... @@ -263,5 +300,6 @@ module.exports = {
getAuthor,
getArticleList,
getPageData,
getArticle
getArticle,
getTagEditor
};
... ...
... ... @@ -18,9 +18,9 @@ const helpers = global.yoho.helpers;
* @return {[array]}
*/
const getRssArticle = (gender) => {
let result = [],
article = {},
articlePromise;
let result = [],
article = {},
articlePromise;
switch (gender) {
case '1,3':
... ... @@ -35,60 +35,60 @@ const getRssArticle = (gender) => {
}
return articlePromise.then((article) => {
// 内容列表
if (article.data.list.artList) {
let build = {};
if (article.data.list.artList) {
let build = {};
let artListFunc = (i, len, resolve) => {
if (i < len) {
let value = article.data.list.artList[i];
if (typeof value.id !== 'undefined') {
build = guangProcess.formatArticle(value, false, false, true);
build.author.name = build.author.name || '';
return _genIntro(value.id).then((intro) => {
build.intro = intro;
result.push(build);
artListFunc(++i, len, resolve);
let artListFunc = (i, len, resolve) => {
if (i < len) {
let value = article.data.list.artList[i];
if (typeof value.id !== 'undefined') {
build = guangProcess.formatArticle(value, false, false, true);
build.author.name = build.author.name || '';
return _genIntro(value.id).then((intro) => {
build.intro = intro;
result.push(build);
artListFunc(++i, len, resolve);
});
}
} else {
resolve(result);
resolve(result);
}
}
return new Promise((resolve) => {
artListFunc(0, article.data.list.artList.length, resolve);
})
};
return new Promise((resolve) => {
artListFunc(0, article.data.list.artList.length, resolve);
});
}
});
}
};
/**
* [构建信息内容]
* @param {[int]} id [资讯id]
* @return {[string]}
* @return {[string]}
*/
const _genIntro = (id) => {
let result = '';
let result = '';
return infoModel.intro(id).then((resData) => {
if (resData.data) {
resData.data.forEach((value) => {
if (value.text) { //文字
result += htmlProcess.removeHtml(htmlProcess.escapeToHtml(value.text.data.text)) + '<br/>';
} else if (value.singleImage) {// 单张图
result += `<img src="${helpers.image(value.singleImage.data[0].src, 640, 640)}"/><br/>`;
return infoModel.intro(id).then((resData) => {
if (resData.data) {
resData.data.forEach((value) => {
if (value.text) { // 文字
result += htmlProcess.removeHtml(htmlProcess.escapeToHtml(value.text.data.text)) + '<br/>';
} else if (value.singleImage) { // 单张图
result += `<img src="${helpers.image(value.singleImage.data[0].src, 640, 640)}"/><br/>`;
} else if (value.smallPic && value.smallPic.data) { // 多张小图
value.smallPic.data.forEach((small) => {
result += `<img src="${helpers.image(small.src, 315, 420)}"/>`;
})
result += '<br/>';
value.smallPic.data.forEach((small) => {
result += `<img src="${helpers.image(small.src, 315, 420)}"/>`;
});
result += '<br/>';
}
})
return result;
});
return result;
}
});
}
};
module.exports = {
getRssArticle
}
\ No newline at end of file
getRssArticle
};
... ...
... ... @@ -31,6 +31,7 @@ router.post('/star/setFavorite', star.setFavorite); // 收藏文章
router.get('/plusstar', plusstar.index); // 潮流优选
router.get('/plusstar/resources-template', plusstar.resourcesTemplate); // 潮流优选首页-资源位
router.get('/', index.index); // 逛首页
router.get('/index/tags', index.tag); // 逛标签页
router.get('/author/list', index.editor); // 编辑简介
... ... @@ -45,6 +46,6 @@ router.get('/info/foryoho', info.foryoho); // 逛foryoho内容页
router.get('/plustar', plustar.getListData); // 国际优选列表页
router.get('/plustar/brandinfo', plustar.getDetailData); // 国际优选详情页
router.get('/rss', rss.index); //订阅资讯
router.get('/rss', rss.index); // 订阅资讯
module.exports = router;
... ...
... ... @@ -260,7 +260,7 @@ const formatProduct = (productData, showTags, showNew, showSale, width, height,
if (showPoint) {
if (result.price) {
result.price += '.00'
result.price += '.00';
}
if (result.salePrice) {
result.salePrice += '.00';
... ... @@ -284,11 +284,12 @@ const formatProduct = (productData, showTags, showNew, showSale, width, height,
is_new: showNew && productData.is_new === 'Y', // 新品
is_discount: showSale && productData.is_discount === 'Y', // 在售
is_limited: productData.is_limited && productData.is_limited === 'Y', // 限量
is_yohood: productData.is_yohood && productData.is_yohood === 'Y', //YOHOOD
midYear: productData.midear && productData.midear === 'Y', //年中
yearEnd: productData.yearnd && productData.yearnd === 'Y', //年末
is_yohood: productData.is_yohood && productData.is_yohood === 'Y', // YOHOOD
midYear: productData.midear && productData.midear === 'Y', // 年中
yearEnd: productData.yearnd && productData.yearnd === 'Y', // 年末
is_advance: productData.is_advance && productData.is_advance === 'Y' // 再到着
};
// 打折与即将售完组合显示打折
if (result.is_soon_sold_out && result.tags.is_discount) {
result.tags.is_new = false;
... ...
... ... @@ -4,36 +4,36 @@
'use strict';
const _htmlMap = {'<':'&lt;','>':'&gt;','&':'&amp;','"':'&quot;'};
const _EscapeMap = {'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};
const _htmlMap = {'<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;'};
const _EscapeMap = {'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"'};
/**
* [移除html标签]
*/
const removeHtml = (str) => {
return str.replace(/<[^>]+>/g, '');
}
return str.replace(/<[^>]+>/g, '');
};
/**
* [html转为转义]
*/
const htmlToEscape = (html) => {
return html.replace(/[<>&"]/g, (e) => {
return _htmlMap[e];
})
}
return html.replace(/[<>&"]/g, (e) => {
return _htmlMap[e];
});
};
/**
* [转义符转为html]
*/
const escapeToHtml = (str) => {
return str.replace(/&(lt|gt|nbsp|amp|quot);/g, (match, e) => {
return _EscapeMap[e];
})
}
return str.replace(/&(lt|gt|nbsp|amp|quot);/g, (match, e) => {
return _EscapeMap[e];
});
};
module.exports = {
removeHtml,
htmlToEscape,
escapeToHtml
}
\ No newline at end of file
removeHtml,
htmlToEscape,
escapeToHtml
};
... ...