Authored by zhangxiaoru

guang

... ... @@ -187,9 +187,60 @@ const tag = (req, res, next) => {
}).catch(next);
};
/**
* 列表页(列表首页、标签列表页、作者列表页)动态数据,如:查看数,点赞数,评论数,是否点赞,是否回复
* @param req
* @param res
*/
const listDynamicData = (req, res) => {
let ids = req.query.ids;
let udid = req.sessionID;
let other = {};
let query = req.query.query,
type = req.query.type;
if (req.user.uid) {
other.uid = req.user.uid;
}
if (query) {
other.query = query;
}
if (type) {
other.type = type;
}
indexModel.getDynamicDataByIds(ids, udid, other).then(ret => {
res.send(ret);
});
};
/**
* 详情页动态数据,如:评论数,回复数,是否点赞,是否收藏
* @param req
* @param res
*/
const detailDynamicData = (req, res) => {
let id = req.query.id,
uid = req.user.uid,
udid = req.sessionID;
indexModel.getDynamicDataById(id, uid, udid).then((ret) => {
res.status(200).send(ret);
}).catch(() => {
res.status(400);
});
};
module.exports = {
editor,
pageData,
index,
tag
tag,
listDynamicData,
detailDynamicData
};
... ...
... ... @@ -9,6 +9,7 @@ const api = global.yoho.API;
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const guangProcess = require(`${global.utils}/guang-process`);
const _ = require('lodash');
/**
* [获取作者信息]
... ... @@ -65,12 +66,13 @@ const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, u
sort_id: sortId,
tag: tag,
author_id: authorId,
limit: limit
limit: 20
};
return serviceAPI.get('guang/api/v2/article/getList', param, {
cache: useCache
}).then((result) => {
console.log(result)
if (result && result.code === 200) {
return result;
} else {
... ... @@ -297,10 +299,60 @@ const getTagEditor = (param) => {
};
/**
* 获取制指定文章的动态信息
* @param ids
* @param udid
* @param other [Obejct] 包含uid,query,type等非必传参数
* @returns {Promise.<T>|*}
*/
const getDynamicDataByIds = (ids, udid, other) => {
let params = {
articleIds: ids,
udid: udid
};
if (other.uid) {
_.assign(params, {
uid: other.uid
});
}
if (other.query) {
_.assign(params, {
query: other.query
});
}
if (other.type) {
_.assign(params, {
type: other.type
});
}
return serviceAPI.get('guang/api/*/article/getSimpleArticleList', params, {cache: true});
};
/**
* 获取制指定文章的动态信息
* @param ids
* @returns {Promise.<T>|*}
*/
const getDynamicDataById = (id, uid, udid) => {
return serviceAPI.get('/gateway/guang/api/*/article/getArticlePraiseAndFavor', {
id: id,
uid: uid,
udid: udid
});
};
module.exports = {
getAuthor,
getArticleList,
getPageData,
getArticle,
getTagEditor
getTagEditor,
getDynamicDataByIds,
getDynamicDataById
};
... ...
... ... @@ -51,4 +51,7 @@ router.get('/plustar/brandinfo', plustar.getDetailData); // 祕
router.get('/rss', rss.index); // 订阅资讯
router.get('/info/listData', index.listDynamicData);
router.get('/info/detailData', index.detailDynamicData);
module.exports = router;
... ...
... ... @@ -25,6 +25,11 @@ module.exports = {
// service: 'http://service-test1.yohops.com:9999/',
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test1.yohops.com:9999/',
// favApi: 'http://192.168.102.31:8092/brower',
// api: 'http://192.168.102.205:8080/gateway/',
// service: 'http://192.168.102.205:8080/gateway/',
// search: 'http://192.168.102.216:8080/yohosearch/'
},
subDomains: {
host: '.m.yohobuy.com',
... ...
/**
* 动态获取页面数据
* @author liuchuanyang
* @date 2016/10/09
*/
var $ = require('yoho-jquery');
require('../common');
function getDynamicById(id) {
'use strict';
var param = {
id: id
};
// //guang.yohobuy.com/guang/info/detailData
return $.getJSON('/guang/info/detailData', param);
}
function renderData(data) {
'use strict';
if (data && data.code === 200 && data.data) {
$('.guang-detail-page .page-view').text(data.data.browseNum || 0);
}
}
function refreshData() {
'use strict';
var qs = window.queryString;
var id = qs.id;
getDynamicById(id).done(renderData);
}
refreshData();
... ...
... ... @@ -26,6 +26,7 @@ var setting = {
var $infos = $('#info-list');
require('../common');
require('./list-dynamic');
info.initInfosEvt($infos);
... ...
... ... @@ -22,6 +22,7 @@ var $infoList = $('#info-list'),
curType = $curNav.data('type');
require('../common');
require('./list-dynamic');
var state = {};
... ... @@ -49,8 +50,6 @@ info.initInfosEvt($infoList);
end: false
};
});
console.log(state);
}());
$nav.bind('contextmenu', function(e) {
return false;
... ...
... ... @@ -258,7 +258,7 @@ function loadMore($container, opt, url) {
delete opt.isTab;
},
error: function() {
console.log('error')
//console.log('error')
tip.show('网络断开连接了~');
searching = false;
delete opt.isTab;
... ...
... ... @@ -29,6 +29,7 @@ scrollToEl = document.querySelector('#wrapper .collocation-block');
require('../common');
require('../plugin/wx-share')();
require('./detail-dynamic');
/**
* 计算搭配的箭头的位置
... ...
/**
* 动态获取页面数据
* @author liuchuanyang
* @date 2016/10/09
*/
var $ = require('yoho-jquery');
var $msgs = $('#info-list');
require('../common');
function getDynamicByIds(ids) {
'use strict';
var data = {
ids: ids
};
var qs = window.queryString;
if (qs.query) {
// 标签列表
data.query = qs.query;
} else if (qs.type) {
// 逛首页type
data.type = qs.type;
} else if (!qs.author_id) {
// 非编辑页的情况下,为逛首页默认type=0
data.type = '0';
}
return $.ajax({
type: 'GET',
url: '/guang/info/listData',
data: data
});
}
function renderData(data) {
'use strict';
var i,
it,
$it;
var list;
if (data && data.code === 200 && (list = data.data.artList)) {
for (i = 0; i < list.length; i++) {
it = list[i];
if (it && it.articleId) {
$it = $('.guang-info[data-id=' + it.articleId + ']', $msgs);
// 浏览数目
$it.find('.page-view').text(it.views_num);
// 点赞状态
if (it.isPraise === 'Y') {
$it.find('.like-btn').addClass('liked');
} else {
$it.find('.like-btn').removeClass('liked');
}
// 点赞数目
$it.find('.like-count').text(it.praise_num);
// 评论数目
$it.find('.like-count').text(it.comment_num);
}
}
}
}
(function() {
'use strict';
var idArr = [];
$msgs.find('.guang-info').each(function() {
var id = $(this).data('id');
if (id) {
idArr.push(id);
}
});
getDynamicByIds(idArr.join(',')).then(renderData);
}());
... ...