Authored by 周少峰

home

... ... @@ -20,28 +20,7 @@ const index = (req, res, next)=>{
}).catch(next);
};
// 个人中心-首页-喜欢的品牌
async function brands(req, res) {
let brandsData = await req.ctx(indexService).brands();
res.json({brands: brandsData, more: '/brands'});
}
// 新品上架
async function newArrive(req, res) {
let arrive = await req.ctx(indexService).newArrive();
res.json({newArrive: arrive});
}
// 推荐
async function recommend(req, res) {
let uid = req.user.uid;
let udid = req.user.uid + req.yoho.udid;
let channelNum = req.yoho.channelNum;
res.json({recommend: await req.ctx(indexService).recommend(uid, udid, channelNum)});
}
// 头像和左侧菜单我的消息
async function newsAvatar(req, res) {
... ... @@ -51,19 +30,24 @@ async function newsAvatar(req, res) {
res.json(result);
}
async function numbers(req, res) {
async function asyncData(req, res) {
let uid = req.user.uid;
let result = await req.ctx(indexService).numbers(uid);
let udid = req.user.uid + req.yoho.udid;
let channelNum = req.yoho.channelNum;
res.json(result);
let data = await Promise.props({
numbers: req.ctx(indexService).numbers(uid),
brands: req.ctx(indexService).brands(),
products: req.ctx(indexService).newArrive(),
rec: req.ctx(indexService).recommend(uid, udid, channelNum)
});
res.json(data);
}
module.exports = {
index,
brands,
newArrive,
recommend,
newsAvatar,
numbers
asyncData
};
... ...
... ... @@ -206,7 +206,7 @@ module.exports = class extends global.yoho.BaseModel {
arrive = JSON.parse(arrive);
}
return Promise.resolve(arrive);
return Promise.resolve({newArrive: arrive});
}
// 推荐数据
... ... @@ -225,7 +225,7 @@ module.exports = class extends global.yoho.BaseModel {
recommend = JSON.parse(recommend);
}
return Promise.resolve(recommend);
return Promise.resolve({recommend: recommend});
}
// 个人中心首页 异步获取品牌数据
... ... @@ -244,7 +244,7 @@ module.exports = class extends global.yoho.BaseModel {
brand = JSON.parse(brand);
}
return Promise.resolve(brand);
return Promise.resolve({brands: brand, more: '/brands'});
}
// 个人中心异步查询我的消息和头像
... ...
... ... @@ -64,11 +64,8 @@ const checkLogin = (req, res, next) => {
// 首页
router.get(['/index', '/'], tabsMiddleware.getCommonHeaderNew, indexController.index);
router.get('/index/brands', checkLogin, indexController.brands);
router.get('/index/newArrive', checkLogin, indexController.newArrive);
router.get('/index/recommend', checkLogin, indexController.recommend);
router.get('/index/newsAvatar', checkLogin, indexController.newsAvatar);
router.get('/index/numbers', checkLogin, indexController.numbers);
router.get('/index/async', checkLogin, indexController.asyncData);
// router.get(['/index', '/'], tabsMiddleware.getCommonHeader, indexController.index);
... ...
... ... @@ -58,7 +58,7 @@ module.exports = class extends global.yoho.BaseModel {
uid: uid
};
return this.get({data: param});
return this.get({data: param, param: {cache: true}});
}
};
... ...
... ... @@ -45,8 +45,8 @@ module.exports = {
// gray
// singleApi: 'http://single.gray.yohops.com/',
// api: 'http://api.gray.yohops.com/',
// service: 'http://api.gray.yohops.com/',
// api: 'http://apigray.yoho.cn/',
// service: 'http://apigray.yoho.cn/',
// platformApi: 'http://172.16.6.210:8088/',
// dev
... ...
... ... @@ -185,25 +185,31 @@ function pageChange(self, $ul, page, itemWith, curPage, num) {
}
});
// 待处理订单,未读消息,待分享商品数量
$.getJSON('//www.yohobuy.com/home/index/numbers', function(numbers) {
$.each(numbers, function(key, val) {
$('#' + key).html(val);
});
});
// 喜欢的品牌
$.getJSON('//www.yohobuy.com/home/index/brands', function(brands) {
$brandsBox.html(handlebars.compile($brandsTpl)(brands));
});
// 新品上架
$.getJSON('//www.yohobuy.com/home/index/newArrive', function(products) {
$newBox.html(handlebars.compile($newTpl)(products));
});
// 异步数据
$.getJSON('//www.yohobuy.com/home/index/async', function(data){
// 猜你喜欢
$.getJSON('//www.yohobuy.com/home/index/recommend', function(rec) {
$recommendBox.html(handlebars.compile($recommendTpl)(rec));
});
// 首页异步数据待处理订单,未读消息,待分享商品数量
if (data.numbers) {
$.each(data.numbers, function(key, val) {
$('#' + key).html(val);
});
}
// 喜欢的品牌
if (data.brands) {
$brandsBox.html(handlebars.compile($brandsTpl)(data.brands));
}
// 新品上架
if (data.products) {
$newBox.html(handlebars.compile($newTpl)(data.products));
}
// 推荐
if (data.rec) {
$recommendBox.html(handlebars.compile($recommendTpl)(data.rec));
}
})
}());
... ...