Authored by liangxs

model开发

... ... @@ -6,39 +6,10 @@
'use strict';
const headerModel = require('../../../doraemon/models/header');
// const channelModel = require('../models/index');
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});
});
channelModel.getContent('boys').then(data => {
res.render('boys', data);
});
};
... ...
... ... @@ -5,31 +5,190 @@
*/
'use strict';
// const _ = require('lodash');
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'
// });
const headerModel = require('../../../doraemon/models/header');
exports.getContent = () => {
let data = sign.apiSign({
// 创意生活
// const CODE_LIFESTYLE_CHANNEL_1 = '380c38155fd8beee10913a3f5b462da6';
// const CODE_LIFESTYLE_CHANNEL_2 = '665f7c2fb9d037ee820766953ee34bf7';
const channelMap = {
boys: {
code: '79372627eee75d73afe7f9bac91e5ce6',
gender: '1,3'
},
girls: {
code: '75215008957605c05e8cd375eac4f817',
gender: '2,3'
},
kids: {
code: 'd71f4b27f2a7229fbb31a4bc490a6f36',
gender: 'kids'
},
lifestyle: {
code: '8a341ca7eacc069ba80f02dec80eaf34',
gender: 'lifestyle'
}
};
const getBannerList = data => {
let list = [];
_.forEach(data, (bannerData) => {
let obj = {};
obj.href = bannerData.url;
obj.img = bannerData.src;
obj.name = bannerData.title;
list.push(obj);
});
return list;
};
const getNewReportFloorData = data => {
let list = [];
_.forEach(data, (item, index) => {
if (item.data.text === '最新速报') {
let obj = {};
obj.href = data[index + 1].data[0].url;
obj.img = data[index + 1].data[0].src;
list.push(obj);
_.forEach(data[index + 2].data, (floorData) => {
let o = {};
o.href = floorData.url;
o.img = floorData.src;
list.push(o);
});
obj.href = data[index + 3].data[0].url;
obj.img = data[index + 3].data[0].src;
list.push(obj);
}
});
return list;
};
// 热门品类
const getHotGoodsFloorData = data => {
let list = [];
_.forEach(data, (item) => {
if (item.template_intro === '热门品类') {
let object = {},
keyword = [],
category = [],
brands = [],
types = [];
// product = [];
// console.log(item.data);
// console.log(item.data.menuNav);
// console.log(item.data.navs);
// return false;
_.forEach(item.data.menuNav.list, (it) => {
let obj = {};
obj.name = it.name;
obj.href = it.url;
category.push(obj);
});
_.forEach(item.data.menuNav.blocks, (it) => {
let obj = {};
/* eslint-disable */
client_type: 'web'
/* eslint-enable */
obj.name = it.title;
obj.href = it.url;
obj.img = it.img;
keyword.push(obj);
});
_.forEach(item.data.imgs, (it, index) => {
let obj = {};
obj.name = it.title;
obj.href = it.url;
obj.img = it.img;
if (index < 2) {
brands.push(obj);
} else {
types.push(obj);
}
});
object.keyword = keyword;
object.category = category;
object.brands = brands;
object.types = types;
list.push(object);
}
});
serviceApi.get('/operations/api/v5/resource/home', data).then(response => {
console.log(response);
return list;
};
const requestContent = (type) => {
let data = sign.apiSign({
/* eslint-disable */
client_type: 'web',
/* eslint-enable */
content_code: channelMap[type || 'boys'].code,
gender: channelMap[type || 'boys'].gender,
page: 1,
limit: 1000
});
return serviceApi.get('/operations/api/v5/resource/home', data);
};
exports.getContent = (type) => {
return Promise.all([headerModel.requestHeaderData(), requestContent(type)]).then(res => {
let headerData = res[0].data,
contentData = res[1].data;
let data = {};
data = headerModel.setHeaderData(headerData, 'boys');
data.module = 'channel';
data.page = 'boys';
data.footerTop = true;
data.channel = true;
data.slide = {
list: getBannerList(contentData.list[0].data.big_image),
pagination: getBannerList(contentData.list[0].data.list)
};
data.newReport = {
name: '最新速报',
list: getNewReportFloorData(contentData.list)
};
data.recommend = {
tplrecommend: getHotGoodsFloorData(contentData.list)
};
console.log(data.newReport);
return data;
});
};
... ...
<div class="home-page yoho-page boys" data-page="boys">
{{> commodity}}
{{! 品类推荐}}
{{# recommend}}
{{> index/boy-recommend}}
{{/ recommend}}
</div>
<script>__custom = {"yopid":"index"};</script>
... ...
{{# tplrecommend}}
<div class="tpl-recommend clearfix">
{{> index/floor-header}}
<div class="tpl-body clearfix">
<div class="tpl-nav">
<div class="tpl-keywords">
{{#each keyword}}
<a class="keywords{{@index}}" title="{{name}}" href="{{href}}" target= "_blank"><img class="lazy" data-original="{{img}}"/></a>
{{/each}}
</div>
<div class="tpl-category clearfix">
{{#each category}}
<a href="{{href}}" target= "_blank">{{name}}</a>
{{/each}}
</div>
</div>
<div class="tpl-brands imgopacity clearfix">
<ul>
{{#each brands}}
<li><a title="{{name}}" href="{{href}}" target= "_blank"><img class="lazy" data-original="{{img img 100 100}}"/></a></li>
{{/each}}
</ul>
</div>
<div class="tpl-types imgopacity clearfix">
<ul>
{{#each types}}
<li><a title="{{name}}" href="{{href}}" target= "_blank"><img class="lazy" data-original="{{img}}"/></a></li>
{{/each}}
</ul>
</div>
</div>
<div class="tpl-products imgopacity clearfix">
<ul>
{{#each products}}
<li><a href="{{href}}" title="{{name}}" target= "_blank"><img class="lazy" data-original="{{img}}"/></a></li>
{{/each}}
</ul>
</div>
</div>
{{/ tplrecommend}}
... ...
<div class="floor-header clearfix">
<h2 class="floor-title">{{name}}</h2>
{{#if navs}}
<ul class="header-navs">
{{# navs}}
<li data-classify="{{id}}">
<a target="_blank" href="{{href}}">{{name}}</a>
</li>
{{/ navs}}
</ul>
{{/if}}
</div>
\ No newline at end of file
... ...