Authored by zhangxiaoru

star

... ... @@ -45,12 +45,12 @@ const _processPublicData = (req, title) => {
* @param {[object]} res
* @return {[type]}
*/
let index = (req, res, next) => {
exports.index = (req, res, next) => {
const pageHeadTab = _.cloneDeep(headTab);
pageHeadTab[0].cur = true;
starModel.getIndexData().then((result) => {
req.ctx(starModel).getIndexData().then((result) => {
md5Str = result.md5;
res.render('star/index', _.assign({
page: 'star',
... ... @@ -67,8 +67,8 @@ let index = (req, res, next) => {
}).catch(next);
};
let getIndexHtml = (req, res, next) => {
starModel.getIndexData().then((result) => {
exports.getIndexHtml = (req, res, next) => {
req.ctx(starModel).getIndexData().then((result) => {
if (md5Str !== result.md5) {
md5Str = result.md5;
... ... @@ -93,8 +93,8 @@ let getIndexHtml = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let special = (req, res, next) => {
starModel.getSpecialData().then((result) => {
exports.special = (req, res, next) => {
req.ctx(starModel).getSpecialData().then((result) => {
const pageHeadTab = _.cloneDeep(headTab);
pageHeadTab[1].cur = true;
... ... @@ -115,7 +115,7 @@ let special = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let collocation = (req, res) => {
exports.collocation = (req, res) => {
const pageHeadTab = _.cloneDeep(headTab);
pageHeadTab[2].cur = true;
... ... @@ -134,11 +134,11 @@ let collocation = (req, res) => {
* @param {[object]} res
* @return {[type]}
*/
let collocationList = (req, res, next) => {
exports.collocationList = (req, res, next) => {
let params = req.query;
let uid = req.user.uid || req.query.uid || req.cookies.guangStarUid || 0; // 客户端访问,不能使用 cookie
starModel.getCollocationListData(params, uid).then((result) => {
req.ctx(starModel).getCollocationListData(params, uid).then((result) => {
res.render('star/list', _.assign({
layout: false,
params: params,
... ... @@ -154,14 +154,14 @@ let collocationList = (req, res, next) => {
* @param {[type]} res [description]
* @return {[type]}
*/
let setFavorite = (req, res, next) => {
exports.setFavorite = (req, res, next) => {
let uid = req.user.uid || req.query.uid || req.cookies.guangStarUid || 0;
let params = {
articleId: req.body.articleId,
type: req.body.type
};
starModel.setFavorite(params, uid).then((result) => {
req.ctx(starModel).setFavorite(params, uid).then((result) => {
if (result.code === 400) {
if (req.body.pageType === '1') {
let urlEncode = '\/guang\/star\/collocation';
... ... @@ -185,7 +185,7 @@ let setFavorite = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let detail = (req, res) => {
exports.detail = (req, res) => {
res.render('star/detail', _.assign({
isStarDetailPage: true,
page: 'detail-list'
... ... @@ -198,11 +198,11 @@ let detail = (req, res) => {
* @param {[object]} res
* @return {[type]}
*/
let detailList = (req, res, next) => {
exports.detailList = (req, res, next) => {
let params = req.query;
let uid = req.user.uid || req.query.uid || req.cookies.guangStarUid || 0;
starModel.getDetailData(params, uid).then((result) => {
req.ctx(starModel).getDetailData(params, uid).then((result) => {
res.render('star/list', _.assign({
layout: false,
params: params,
... ... @@ -211,14 +211,3 @@ let detailList = (req, res, next) => {
}));
}).catch(next);
};
module.exports = {
index,
getIndexHtml,
special,
collocation,
collocationList,
setFavorite,
detail,
detailList
};
... ...
... ... @@ -15,258 +15,256 @@ const api = global.yoho.API;
const contentCode = contentCodeConfig.guang;
/**
* 获取资源位数据
* @param {[string]} page
* @return {[array]}
*/
const _getResources = (page) => {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode[page],
platform: 'iphone'
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return resourcesProcess(result.data);
} else {
logger.error('star class content resource return code no 200');
return [];
}
});
};
/**
* 星潮教室首页数据处理
* @param {[array]} dataList
* @return {[array]}
*/
const _processIndexData = (dataList) => {
const formatData = {
ads: [],
starAvatar: [],
articles: []
};
let list = dataList.data || {};
formatData.md5 = dataList.md5;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
// 首页资源位数据处理
if (list.ads) {
_.forEach(list.ads.data, (data) => {
formatData.ads.push({
src: data.src.replace('imageView/', 'imageView2/'),
url: data.url
});
/**
* 获取资源位数据
* @param {[string]} page
* @return {[array]}
*/
_getResources(page) {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode[page],
platform: 'iphone'
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return resourcesProcess(result.data);
} else {
logger.error('star class content resource return code no 200');
return [];
}
});
}
// 首页明星文章数据处理
if (list.list) {
_.forEach(list.list, (data, index) => {
const avatar = {
tags: []
};
/**
* 星潮教室首页数据处理
* @param {[array]} dataList
* @return {[array]}
*/
_processIndexData(dataList) {
const formatData = {
ads: [],
starAvatar: [],
articles: []
};
let list = dataList.data || {};
formatData.md5 = dataList.md5;
// 首页资源位数据处理
if (list.ads) {
_.forEach(list.ads.data, (data) => {
formatData.ads.push({
src: data.src.replace('imageView/', 'imageView2/'),
url: data.url
});
});
}
if (data.ext.tags.length > 1) {
avatar.isSwiper = true;
}
// 首页明星文章数据处理
if (list.list) {
_.forEach(list.list, (data, index) => {
const avatar = {
tags: []
};
_.forEach(data.ext.tags, (tags, i) => {
if (i >= 1) {
return;
if (data.ext.tags.length > 1) {
avatar.isSwiper = true;
}
avatar.tags.push({
avatarUrl: `/guang/star/detail?tag=${tags.tagName}&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${tags.tagName}"}}}`, // eslint-disable-line
cover: tags.cover ? (tags.cover + '?imageView2/2/w/104/h/104') : tags.cover,
tagName: tags.tagName
_.forEach(data.ext.tags, (tags, i) => {
if (i >= 1) {
return;
}
avatar.tags.push({
avatarUrl: `/guang/star/detail?tag=${tags.tagName}&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${tags.tagName}"}}}`, // eslint-disable-line
cover: tags.cover ? (tags.cover + '?imageView2/2/w/104/h/104') : tags.cover,
tagName: tags.tagName
});
});
});
if (formatData.articles.length > 30) {
return;
}
if (formatData.articles.length > 30) {
return;
}
formatData.articles.push(_.merge({
noLazy: index < 2,
id: data.id,
url: data.url,
title: data.title,
articeTxt: data.intro,
src: data.src,
publish_time: helpers.dateFormat('MM月DD日 hh:mm', data.publish_time),
views_num: data.views_num
}, avatar));
});
}
formatData.articles.push(_.merge({
noLazy: index < 2,
id: data.id,
url: data.url,
title: data.title,
articeTxt: data.intro,
src: data.src,
publish_time: helpers.dateFormat('MM月DD日 hh:mm', data.publish_time),
views_num: data.views_num
}, avatar));
});
}
// 首页明星头像数据处理
if (list.tags) {
_.forEach(list.tags, (data) => {
let url = `/guang/star/detail?tag=${data.tagName}&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${data.tagName}"}}}`; // eslint-disable-line
// 首页明星头像数据处理
if (list.tags) {
_.forEach(list.tags, (data) => {
let url = `/guang/star/detail?tag=${data.tagName}&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${data.tagName}"}}}`; // eslint-disable-line
formatData.starAvatar.push({
// noLazy: index < 6,
url: url,
cover: data.cover ? (data.cover +
'?imageView2/2/w/180/h/180/q/90').replace('http:', '') : data.cover.replace('http:', '')
formatData.starAvatar.push({
// noLazy: index < 6,
url: url,
cover: data.cover ? (data.cover +
'?imageView2/2/w/180/h/180/q/90').replace('http:', '') : data.cover.replace('http:', '')
});
});
});
}
}
return formatData;
};
return formatData;
}
/**
* 明星专题列表及星搭配数据处理
* @param {[array]} list
* @param {[boolean]} flag 明星专题列表需要转换下日期格式
* @return {[array]}
*/
const _processGuangData = (list, flag) => {
const formatData = [];
/**
* 明星专题列表及星搭配数据处理
* @param {[array]} list
* @param {[boolean]} flag 明星专题列表需要转换下日期格式
* @return {[array]}
*/
_processGuangData(list, flag) {
const formatData = [];
list = list || [];
list = list || [];
_.forEach(list, (data, key) => {
if (flag) {
data.publish_time = helpers.dateFormat('MM月DD日 hh:mm', data.publish_time);
}
_.forEach(list, (data, key) => {
if (flag) {
data.publish_time = helpers.dateFormat('MM月DD日 hh:mm', data.publish_time);
}
if (data.isFavor === 'N') {
data.isCollected = false;
} else {
data.isCollected = true;
}
if (data.isFavor === 'N') {
data.isCollected = false;
} else {
data.isCollected = true;
}
// data.src += '/q/80';
// data.src += '/q/80';
if (key < 2) {
data.islazy = true;
}
if (key < 2) {
data.islazy = true;
}
formatData.push(data);
});
formatData.push(data);
});
return formatData;
};
return formatData;
}
/**
* 星潮首页
*/
const getIndexData = () => {
return api.get('', {
method: 'app.starClass.index',
code: '8adc27fcf5676f356602889afcfd2a8e'
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return _processIndexData(result);
} else {
logger.error('star class content resource return code no 200');
return {};
}
});
};
/**
* 星潮首页
*/
getIndexData() {
return api.get('', {
method: 'app.starClass.index',
code: '8adc27fcf5676f356602889afcfd2a8e'
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return this._processIndexData(result);
} else {
logger.error('star class content resource return code no 200');
return {};
}
});
}
/**
* 明星专题
*/
const getDetailData = (params, uid) => {
return api.get('', {
method: 'app.starClass.lastTagArticle',
tag: params.tag,
page: params.page || 1,
size: 10,
uid: uid
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
if (params.page > result.data.totalPage) {
return '';
/**
* 明星专题
*/
getDetailData(params, uid) {
return api.get('', {
method: 'app.starClass.lastTagArticle',
tag: params.tag,
page: params.page || 1,
size: 10,
uid: uid
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
if (params.page > result.data.totalPage) {
return '';
} else {
return this._processGuangData(result.data.list, true);
}
} else {
return _processGuangData(result.data.list, true);
logger.error('api app.starClass.lastTagArticle code no 200');
return [];
}
} else {
logger.error('api app.starClass.lastTagArticle code no 200');
return [];
}
});
};
});
}
/**
* 星专题
*/
const getSpecialData = () => {
return _getResources('special').then((result) => {
/**
* 星专题
*/
getSpecialData() {
return this._getResources('special').then((result) => {
// 数据结构嵌套太深
_.forEach(result, (data, key) => {
_.map(data.data, (item) => {
if (!_.isObject(item)) {
return;
}
// 数据结构嵌套太深
_.forEach(result, (data, key) => {
_.map(data.data, (item) => {
if (!_.isObject(item)) {
return;
}
// item.src += '/q/80';
// item.src += '/q/80';
if (key < 4) {
item.islazy = true;
}
return item;
if (key < 4) {
item.islazy = true;
}
return item;
});
});
return result;
});
}
return result;
});
};
/**
* 星搭配
*/
getCollocationListData(params, uid) {
return serviceAPI.get('guang/api/v5/article/getStarClassroomArticleList', Object.assign({
limit: '20',
uid: uid
}, params), {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return this._processGuangData(result.data.list.artList);
} else {
logger.error('getStarClassroomArticleList code no 200');
return [];
}
});
}
/**
* 星搭配
*/
const getCollocationListData = (params, uid) => {
return serviceAPI.get('guang/api/v5/article/getStarClassroomArticleList', Object.assign({
limit: '20',
uid: uid
}, params), {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return _processGuangData(result.data.list.artList);
} else {
logger.error('getStarClassroomArticleList code no 200');
return [];
setFavorite(params, uid) {
if (!uid) {
return Promise.resolve({
code: 400,
message: '未登录'
});
}
});
};
const setFavorite = (params, uid) => {
if (!uid) {
return Promise.resolve({
code: 400,
message: '未登录'
return api.get('', {
method: params.type === 'del' ? 'app.sns.cancelFavorBackCount' : 'app.sns.setFavorBackCount',
client_type: 'h5',
article_id: params.articleId,
uid: uid
});
}
return api.get('', {
method: params.type === 'del' ? 'app.sns.cancelFavorBackCount' : 'app.sns.setFavorBackCount',
client_type: 'h5',
article_id: params.articleId,
uid: uid
});
};
module.exports = {
getIndexData,
getSpecialData,
getCollocationListData,
setFavorite,
getDetailData
};
... ...