Authored by biao

Merge branch 'feature/index-girls' into develop

... ... @@ -19,10 +19,19 @@ const cookieParser = require('cookie-parser');
const favicon = require('serve-favicon');
const session = require('express-session');
const memcached = require('connect-memcached');
const pkg = require('./package.json');
const app = express();
const MemcachedStore = memcached(session);
// 向模板注入变量
app.locals.devEnv = app.get('env') === 'development';
app.locals.version = pkg.version;
// 指定libray目录
global.library = path.resolve('./library');
app.set('view engine', '.hbs');
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
... ... @@ -46,6 +55,6 @@ app.use(session({
require('./dispatch')(app);
// listener
app.listen(6002, function() {
app.listen(config.port, function() {
console.log('yohobuy start');
});
... ...
/**
* girls controller
* @author: 赵彪<bill.zhao@yoho.cn>
* @date: 2016/05/16
*/
'use strict';
const headerModel = require('../../../doraemon/models/header');
// const channelModel = require('../models/index');
exports.boysIndex = (req, res) => {
headerModel.requestHeaderData()
.then(response => {
let data = headerModel.setHeaderData(response.data, 'boys');
data.module = 'index';
data.page = 'index';
data.footerTop = true;
res.render('boys', data);
})
.catch(() => {
res.render('error', {devEnv: true, pageErr: true});
});
};
exports.girlsIndex = (req, res) => {
headerModel.requestHeaderData()
.then(response => {
let data = headerModel.setHeaderData(response.data, 'girls');
data.module = 'index';
data.page = 'index';
data.footerTop = true;
res.render('girls', data);
})
.catch(() => {
res.render('error', {devEnv: true, pageErr: true});
});
};
... ...
/**
* sub app girls
* @author: biao<bill.zhao@yoho.cn>
* @date: 2016/05/16
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
var app = express();
// set view engin
var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
app.on('mount', function(parent) {
delete parent.locals.settings; // 不继承父 App 的设置
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: ['./views/partial', `${doraemon}/partial`],
helpers: 'helpers'
}));
// router
app.use(require('./router'));
module.exports = app;
... ...
/**
* girls model
* @author: 赵彪<bill.zhao@yoho.cn>
* @date: 2016/05/17
*/
'use strict';
// const _ = require('lodash');
const ServiceAPI = require(`${global.library}/api`).ServiceAPI;
const sign = require(`${global.library}/sign`);
const serviceApi = new ServiceAPI();
/**
* 获取公共配置
* @param undefined
* @return {Object} 配置对象
*/
// const commonConfig = () => ({
// title: 'girls'
// });
exports.getContent = () => {
let data = sign.apiSign({
/* eslint-disable */
client_type: 'web'
/* eslint-enable */
});
serviceApi.get('/operations/api/v5/resource/home', data).then(response => {
console.log(response);
});
};
... ...
/**
* router of sub app girls
* @author: biao<bill.zhao@yoho.cn>
* @date: 2016/05/16
*/
'use strict';
const router = require('express').Router(); // eslint-disable-line
const cRoot = './controllers';
// Your controller here
const channelController = require(`${cRoot}/index`);
router.get('/boys', channelController.boysIndex);
module.exports = router;
... ...
... ... @@ -9,18 +9,17 @@
const headerModel = require('../../../doraemon/models/header');
exports.index = (req, res) => {
headerModel.getHeaderData()
.then(function(response) {
let data = headerModel.getAllHeaderData(response.data, 'boy');
headerModel.requestHeaderData()
.then(response => {
let data = headerModel.setHeaderData(response.data, 'boys');
data.headerData.navbars[0].active = true;
data.module = 'index';
data.page = 'index';
data.footerTop = true;
res.render('index', data);
})
.catch(function() {
.catch(() => {
res.render('index', {devEnv: true, pageErr: true});
});
};
... ...
... ... @@ -10,6 +10,7 @@ const isProduction = process.env.NODE_ENV === 'production';
const isTest = process.env.NODE_ENV === 'test';
module.exports = {
port: 6002,
domains: {
api: 'http://192.168.102.205:8080/gateway',
service: 'http://testservice.yoho.cn:28077',
... ...
... ... @@ -12,5 +12,7 @@ module.exports = app => {
app.use(require('./apps/activity'));
// 业务模块
app.use('/', require('./apps/index'));
// 频道页
app.use('/', require('./apps/channel'));
};
... ...
... ... @@ -7,10 +7,9 @@
'use strict';
const _ = require('lodash');
const lRoot = '../../library/';
const ServiceAPI = require(`${lRoot}/api`).ServiceAPI;
const sign = require(`${lRoot}/sign`);
const ServiceAPI = require(`${global.library}/api`).ServiceAPI;
const sign = require(`${global.library}/sign`);
const serviceApi = new ServiceAPI();
... ... @@ -20,11 +19,22 @@ const serviceApi = new ServiceAPI();
* @return {Object} 配置对象
*/
const commonConfig = () => ({
title: 'home',
devEnv: true,
version: '0.0.1'
title: 'home'
});
const getChannelIndex = (type) => {
const channelMap = {
boys: 0,
girls: 1,
kids: 2,
lifestyle: 3
};
const index = channelMap[type];
return _.isNil(index) ? 0 : index;
};
/**
* 获取菜单
* @param undefined
... ... @@ -138,26 +148,7 @@ const getThirdNav = (data) => {
const getSubNav = (data, type) => {
let subNav = [];
let index;
switch (type) {
case 'boy':
index = 0;
break;
case 'girl':
index = 1;
break;
case 'kids':
index = 2;
break;
case 'lifestyle':
index = 3;
break;
default:
index = 0;
}
_.forEach(data[index].sub, function(item) {
_.forEach(data[getChannelIndex(type)].sub, function(item) {
let obj = {};
obj.link = item.sort_url;
... ... @@ -177,23 +168,28 @@ const getSubNav = (data, type) => {
};
/**
* 处理接口返回的数据
* @param {object} 接口返回的对象
* @param {String} 指定页面类型为boys,girls,kids,lifestyle
* @return {object} 头部数据
*/
exports.getAllHeaderData = function(resData, type) {
exports.setHeaderData = (resData, type) => {
let config = commonConfig();
let data = {
headerData: {
header: true,
type: type,
headType: type,
yohoGroup: getMenuData(),
navbars: getNavBar(resData),
subNav: getSubNav(resData, type)
}
};
data.headerData.navbars[getChannelIndex(type)].active = true;
return _.merge(config, data);
};
... ... @@ -202,11 +198,11 @@ exports.getAllHeaderData = function(resData, type) {
* @param undefined
* @return {promise}
*/
exports.getHeaderData = function() {
exports.requestHeaderData = () => {
let data = sign.apiSign({
/* eslint-disable */
client_type: 'web',
client_type: 'web'
/* eslint-enable */
});
... ...
{{# headerData}}
<div class="yoho-header {{headtype}}">
<div class="yoho-header {{headType}}">
<div class="tool-wrapper clearfix">
<div class="center-content">
<div class="yoho-group-map left">
... ...
... ... @@ -167,7 +167,7 @@ gulp.task('webpack-dev-server', () => {
new WebpackDevServer(webpack(devConfig), {
contentBase: '.',
publicPath: '//localhost:5002',
publicPath: '//localhost:5002/',
hot: true,
stats: {
colors: true
... ...