Authored by zhangxiaoru

editorial

... ... @@ -16,7 +16,7 @@ const index = (req, res, next) => {
// let gender = req.query.brand || 1;
editorialModel.getIndexData(type, pageNum, limit).then((result) => {
console.log();
res.display('index', {
module: 'editorial',
page: 'index',
... ... @@ -26,7 +26,7 @@ const index = (req, res, next) => {
{
link: '/editorial?type=0',
pathTitle: '首页',
name: 'MEN首页'
name: 'MEN首页'
},
{
pathTitle: '资讯',
... ... @@ -34,7 +34,7 @@ const index = (req, res, next) => {
}
],
msgTypes: result.msgTypes,
msg: result.msg.list.artList,
msg: result.msg.tabs,
paginationOpts: {
page: pageNum, // current page: http://host/?page=2
limit: 20, // per_page records' number
... ... @@ -58,12 +58,13 @@ const index = (req, res, next) => {
const list = (req, res) => {
let pageNum = req.query.page || 1;
let limit = req.query.limit || 20;
let tag = req.params.tag || '暗黑';
let authorId = req.params.authorId || 0;
let tag = req.query.query;
let authorId = req.query.authorId;
// let curChannel = getChannelData(req.channel, req.query.query);
editorialModel.getListData(pageNum, limit, tag, authorId).then((result) => {
res.display('list', {
module: 'editorial',
page: 'list',
... ... @@ -85,8 +86,8 @@ const list = (req, res) => {
name: req.query.query
}
],
pathTitle: req.query.query,
msg: result.list.artList,
pathTitle: req.query.query || result.authorName,
msg: result.tabs,
paginationOpts: {
page: pageNum, // current page: http://host/?page=2
limit: 20, // per_page records' number
... ... @@ -103,7 +104,7 @@ const list = (req, res) => {
};
const detail = (req, res, next) => {
let id = req.params.id || 52571;
let id = req.params.id;
editorialModel.getDetailData(id).then((result) => {
res.display('detail', {
... ... @@ -128,7 +129,7 @@ const detail = (req, res, next) => {
}
],
header: result.head,
content: result.content,
content: result.content.contents,
tags: result.tags,
userInfo: result.head,
comment: result.comment,
... ... @@ -137,56 +138,10 @@ const detail = (req, res, next) => {
nextChapter: '来来来,让我们好好聊聊',
lastChapter: '除了黑白灰'
},
// content: {
// goods: [
// {
// img: 'http://placehold.it/274x366',
// link: '',
// name: 'Fred Perry Bomber jacket',
// price: '1015.00'
// }
// ]
// },
// relatedGoods: {
// relatedTitle: '推荐搭配',
// goods: [
// {
// img: 'http://placehold.it/274x366',
// link: '',
// name: 'Fred Perry Bomber jacket',
// price: '1015.00'
// }
//
// ]
// }
// },
// brands: [
// {
// url: 'http://placehold.it/274x366',
// thumb: 'wed',
// name: 'Fred Perry'
// },
// {
// url: 'http://placehold.it/274x366',
// thumb: 'wed',
// name: 'Fred Perry'
// },
// {
// url: 'http://placehold.it/274x366',
// thumb: 'wed',
// name: 'Fred Perry'
// },
// {
// url: 'http://placehold.it/274x366',
// thumb: 'wed',
// name: 'Fred Perry'
// }
// ],
share: {
shareImg: 'hjchsk',
shareDesc: 'wjhdfwe',
weixinUrl: 'www.baidu.com'
shareImg: result.content.shareImg,
shareDesc: result.head.title,
weixinUrl: req.originalUrl
}
... ... @@ -202,7 +157,7 @@ const detail = (req, res, next) => {
let setCollect = (req, res, next) => {
let uid = req.user.uid;
let id = req.params.id || 52571;
let id = req.params.id;
editorialModel.setCollect(id, uid).then((result) => {
res.json(result);
... ... @@ -211,7 +166,7 @@ let setCollect = (req, res, next) => {
let cancelCollect = (req, res, next) => {
let uid = req.user.uid;
let id = req.params.id || 52571;
let id = req.params.id;
editorialModel.setCollect(id, uid).then((result) => {
res.json(result);
... ... @@ -221,7 +176,7 @@ let cancelCollect = (req, res, next) => {
// 点赞
let setPraise = (req, res, next) => {
let udid = req.user.uid;
let id = req.params.id || 52571;
let id = req.params.id;
editorialModel.setPraise(id, udid).then((result) => {
res.json(result);
... ... @@ -230,7 +185,7 @@ let setPraise = (req, res, next) => {
let cancelPraise = (req, res, next) => {
let udid = req.user.uid;
let id = req.params.id || 52571;
let id = req.params.id;
editorialModel.cancelPraise(id, udid).then((result) => {
res.json(result);
... ... @@ -239,7 +194,7 @@ let cancelPraise = (req, res, next) => {
let addComment = (req, res, next) => {
let uid = req.user.uid;
let id = req.params.id || 52571;
let id = req.params.id;
let content = req.body.content;
editorialModel.setCollect(id, uid, content).then((result) => {
... ...
... ... @@ -33,7 +33,17 @@ const _processListData = (list) => {
list = list || [];
list = camelCase(list);
_.forEach(list.list.artList, (data) => {
let listData = {
tabs: []
};
_.forEach(list.list.artList, (data, index) => {
if (index === 0) {
listData = _.assign(listData, {
authorName: data.author.name
});
}
data.publishTime = data.publishTime.replace(/年|月/g, '/');
data.publishTime = data.publishTime.replace(/日/g, '');
... ... @@ -44,8 +54,9 @@ const _processListData = (list) => {
}
});
return list;
listData.tabs = list.list.artList;
return listData;
};
const _getResources = (type) => {
... ... @@ -87,12 +98,20 @@ const getIndexData = (type, pageNum, limit) => {
};
const getListData = (pageNum, limit, tag, authorId) => {
return serviceAPI.get('guang/api/*/article/getList', {
let param = {
page: pageNum,
limit: limit,
tag: tag,
author_id: authorId
}).then((result) => {
limit: limit
};
if (tag) {
param.tag = tag;
}
if (authorId) {
param.author_id = authorId;
}
return serviceAPI.get('guang/api/*/article/getList', param).then((result) => {
if (result && result.code === 200) {
return _processListData(result.data);
} else {
... ... @@ -103,7 +122,6 @@ const getListData = (pageNum, limit, tag, authorId) => {
};
// 详情页
const _getAuthorData = (id) => {
return serviceAPI.get('/guang/service/*/author/getAuthor', {
... ... @@ -150,14 +168,15 @@ const _processHeadData = (list) => {
time: data.publishTime,
isLike: data.isPraise,
isFavor: data.isFavor,
likeNum: data.praiseNum
likeNum: data.praiseNum,
};
}
if (index === 1) {
newData.headData = _.assign(newData.headData, {
authorId: data.authorId
authorId: data.authorId,
authorUrl: `/editorial/list/?authorId=${data.authorId}`
});
_.forEach(data.tags, function(value) {
... ... @@ -185,7 +204,6 @@ const _processHeadData = (list) => {
let data = yield _getAuthorData(id);
newData.headData = _.assign(newData.headData, {
authorUrl: data.url,
avatar: data.avatar,
name: data.name
});
... ... @@ -194,65 +212,36 @@ const _processHeadData = (list) => {
})();
};
// const _getGoodsSort = (skn) => {
// return api.get('', {
// product_skn: 51137901,
// method: 'h5.product.data'
// }).then((result) => {
// if (result && result.code === 200) {
// console.log(result)
// return result;
// } else {
// logger.error('数据返回 code 不是 200');
// return {};
// }
// });
// };
const _processContentData = (list) => {
list = list || [];
list = camelCase(list);
_.forEach(list, function(data) {
if (data.text) {
data.text.data.text = data.text.data.text.replace(/<.*?>/ig, '');
}
// if (data.goods) {
// console.log(data.goods)
// _.forEach(data.goods, function(data, index) {
let contentData = {
contents: []
};
// console.log(index)
// _.forEach(data, function(value) {
// // console.log(value)
// // // _getGoodsSort(value.id);
_.forEach(list, function(value) {
// });
// });
// }
if (value.singleImage) {
_.forEach(value.singleImage.data, function(data, index) {
if (index === 0) {
contentData = _.assign(contentData, {
shareImg: data.src
})
}
});
return false;
}
});
return list;
};
// // const _processCommentsData = (list) => {
// // list = list || [];
// // list = camelCase(list);
// // //let commentNum = list.list.length;
// // console.log(list)
// // }
contentData.contents = list;
return contentData;
}
// // head数据
// head数据
const _getHeadData = (id) => {
return serviceAPI.get('/guang/api/*/article/getArticleBaseInfo', {
id: id
... ... @@ -316,7 +305,7 @@ const _getRelateBrand = (id) => {
if (result && result.code === 200) {
return camelCase(result.data);
} else {
logger.error('相关文章数据返回 code 不是 200');
logger.error('相关品牌返回 code 不是 200');
return {};
}
});
... ...
... ... @@ -37,12 +37,12 @@
{{# text}}
<div class="article-text block">
{{# data}}
<p>{{text}}</p>
<p>{{{text}}}</p>
{{/ data}}
</div>
{{/ text}}
{{# goodsGroup}}
{{!-- {{# goodsGroup}}
<div class="related-reco">
<div class="article-title">
<div class="title-line"></div>
... ... @@ -71,7 +71,7 @@
{{/ goods}}
</div>
</div>
{{/ relatedGoods}}
{{/ relatedGoods}} --}}
{{/ content}}
{{#if brands}}
... ... @@ -122,7 +122,7 @@
<div class="article-tag">
<i class="tag-icon iconfont">&#xe648;</i>
<ul>
<ul id="tags">
{{# tags}}
<li>
<a href="{{url}}" target="_blank">{{name}}</a>
... ...
... ... @@ -85,34 +85,41 @@ $('#collect-btn').click(function() {
id: articleId
}
}).then(function(data) {
if (data.code === 200) {
new _alert('收藏成功').show();
$this.toggleClass('collected');
} else {
new _alert(data.message).show();
}
switch (data.code) {
// case 401:
// // 防止从已有col的页面再次进行跳转后出错的情况
// if (/\?col=(1|0)/.test(location.href)) {
// hrefUrl = location.href.replace(/\?col=(1|0)/, '?col=' + col);
// } else {
// hrefUrl = location.href + '?col=' + col;
// }
// location.href = '//www.yohobuy.com/signin.html?refer=' + encodeURI(hrefUrl);
// break;
case 400:
new _alert(data.message).show();
break;
case 200:
if (/\?col=(1|0)/.test(location.href)) {
// 如果页面url中含有col,为了防止页面刷新时收藏或者取消收藏会根据col来的问题,进行页面跳转拿掉参数
location.href = location.href.replace(/\?col=(1|0)/, '');
} else {
$this.toggleClass('collected');
}
break;
default:
break;
}
// switch (data.code) {
// // case 401:
// // // 防止从已有col的页面再次进行跳转后出错的情况
// // if (/\?col=(1|0)/.test(location.href)) {
// // hrefUrl = location.href.replace(/\?col=(1|0)/, '?col=' + col);
// // } else {
// // hrefUrl = location.href + '?col=' + col;
// // }
// // location.href = '//www.yohobuy.com/signin.html?refer=' + encodeURI(hrefUrl);
// // break;
// case 400:
// new _alert(data.message).show();
// break;
// case 200:
// if (/\?col=(1|0)/.test(location.href)) {
// // 如果页面url中含有col,为了防止页面刷新时收藏或者取消收藏会根据col来的问题,进行页面跳转拿掉参数
// location.href = location.href.replace(/\?col=(1|0)/, '');
// } else {
// $this.toggleClass('collected');
// }
// break;
// default:
// break;
// }
collecting = false;
});
}).bind('mouseenter mouseleave', function() {
... ... @@ -148,28 +155,16 @@ function comment() {
},
type: 'post',
success: function(data) {
switch (data.code) {
// case 401:
// locating = true;
// location.href = '//www.yohobuy.com/signin.html?refer=' +
// window.escape(location.href + '#comment-info');
// break;
case 400:
new _alert(data.message).show();
break;
case 200:
if (data.data) {
$commentList.html(data.data.content);
$commentNum.html(data.data.count);
showComment();
// clear comment-text
$('#comment-info').val('').keyup();
}
break;
default:
break;
if (data.code === 200) {
$commentList.html(data.data.content);
$commentNum.html(data.data.count);
showComment();
// clear comment-text
$('#comment-info').val('').keyup();
} else {
new _alert(data.message).show();
}
commenting = false;
}
... ... @@ -212,3 +207,7 @@ $('#comment-info').keyup(function() {
// init
$('#comment-info').trigger('keyup');
if (($('#tags').find('li').length) === 0) {
$('.article-tag').hide();
}
... ...
... ... @@ -48,15 +48,6 @@ $('.editorial-index-page').on('click', '.like-icon', function() {
new _alert(data.message).show();
}
// if (data.code === 200) {
// if (data.data * 1 === 0) {
// $this.next('b').addClass('num-0').children('.num').html('0'); // 隐藏数字显示
// } else {
// console.log(data.data)
// $this.next('b').removeClass('num-0').children('.num').html(data.data);
// }
// }
// prising = false;
});
}).on('mouseenter mouseleave', '.like-icon', function() {
$(this).closest('.like').toggleClass('hover');
... ...
... ... @@ -31,9 +31,7 @@ $('.editorial-list-page').on('click', '.like-icon', function() {
if (data.code === 200) {
$this.toggleClass('liked');
$this.next('b').removeClass('num-0').children('.num').html(data.data);
}
if (data.code === 500) {
}else {
new _alert(data.message).show();
}
... ...
... ... @@ -3,6 +3,7 @@
height: 50px;
line-height: 50px;
color: #666;
overflow: hidden;
a {
text-decoration: none;
... ...
... ... @@ -218,9 +218,7 @@
i {
opacity: 1;
}
span {
display: none;
}
.cancel-collect {
display: inline;
}
... ...