Authored by biao

update for header model

... ... @@ -2,4 +2,6 @@ node_modules/
dist/
npm-debug.log
public/css/*
public/bundle/*
\ No newline at end of file
public/bundle/*
*.swp
... ...
var headerModel = require('../../../doraemon/models/HeaderModel');
function getHeaderData(cb) {
headerModel.getHeaderData(function(err, data) {
if (err) {
cb(err);
return;
}
cb(null, data);
});
}
exports.getHeaderData = getHeaderData;
... ...
... ... @@ -8,82 +8,12 @@
const router = require('express').Router();
const cRoot = './controllers';
const homeDataController = require(cRoot);
// Your controller here
router.get('/', function(req, res) {
res.render('index', {
title: 'home',
devEnv: true,
version: '0.0.1',
headerData: {
header: true,
type: 'boy',
yohoGroup: [
{
link: 'http://www.yoho.cn',
cn: '集团官网',
en: 'YOHO!'
},
{
link: 'http://www.yohoboys.com',
cn: '男生潮流',
en: 'YOHO!BOYS'
},
{
link: 'http://www.yohogirls.com',
cn: '女生潮流',
en: 'YOHO!GIRLS'
},
{
link: 'http://www.yohoshow.com',
cn: '物趣分享',
en: 'YOHO!SHOW'
},
{
link: 'http://www.yohood.cn',
cn: '潮流嘉年华',
en: 'YO\'HOOD'
}
],
navbars: [
{
active: true,
link: 'http://www.yohobuy.com/',
cn: '男生',
en: 'BOYS'
},
{
link: 'http://new.yohobuy.com/woman',
cn: '女生',
en: 'GIRLS'
}
],
subNav: [
{
link: '#',
name: '新品到着'
},
{
link: '#',
name: '品牌一览'
},
{
link: '#',
name: '服饰',
thirdNav: []
},
{
link: '#',
name: '鞋履',
thirdNav: []
},
{
link: '#',
name: '逛',
isNew: true
},
]
}
homeDataController.getHeaderData(function(err, data) {
res.render('index', data);
});
});
module.exports = router;
... ...
var rp = require('request-promise');
var _ = require('lodash');
function getConfig() {
return {
title: 'home',
devEnv: true,
version: '0.0.1'
}
}
function getMenuData() {
return [
{
link: 'http://www.yoho.cn',
cn: '集团官网',
en: 'YOHO!'
},
{
link: 'http://www.yohoboys.com',
cn: '男生潮流',
en: 'YOHO!BOYS'
},
{
link: 'http://www.yohogirls.com',
cn: '女生潮流',
en: 'YOHO!GIRLS'
},
{
link: 'http://www.yohoshow.com',
cn: '物趣分享',
en: 'YOHO!SHOW'
},
{
link: 'http://www.yohood.cn',
cn: '潮流嘉年华',
en: 'YO\'HOOD'
}
];
}
function getNavBar(data) {
var navBars = [];
_.forEach(data, function(item) {
var obj = {};
obj.link = item.sort_url;
obj.cn = item.sort_name;
obj.en = item.sort_name_en;
navBars.push(obj);
});
return navBars;
}
function getSubNav(data) {
var subNav = [];
_.forEach(data, function(item) {
var obj = {};
obj.link = item.sort_url;
obj.name = item.sort_name;
obj.isHot = item.is_hot === 'Y' ? true : false;
obj.isNew = item.is_new === 'Y' ? true : false;
subNav.push(obj);
});
return subNav;
}
function getAllHeaderData(resData) {
var config = getConfig();
var data = {
headerData: {
header: true,
type: 'boy',
yohoGroup: getMenuData(),
navbars: getNavBar(resData),
subNav: getSubNav(resData)
}
};
return _.merge(config, data);
}
exports.getHeaderData = function(done) {
var opt = {
uri: 'http://testservice.yoho.cn:28077/operations/api/v6/category/getCategory',
qs: {
app_version: '3.8.2',
client_type: 'web',
os_version: 'yohobuy:h5',
screen_size: '720x1280',
v: '7',
client_secret: 'f47f9d46f09d930496dee2a9082ff041'
},
headers: {
'content-type': 'application/json;charset=UTF-8'
}
};
rp(opt)
.then(function(res) {
var response = JSON.parse(res);
var data = getAllHeaderData(response.data);
done(null, data);
})
.catch(function(err) {
done(err);
});
}
... ...