Authored by liangxs

model开发

@@ -6,39 +6,10 @@ @@ -6,39 +6,10 @@
6 6
7 'use strict'; 7 'use strict';
8 8
9 -const headerModel = require('../../../doraemon/models/header');  
10 -  
11 -// const channelModel = require('../models/index'); 9 +const channelModel = require('../models/index');
12 10
13 exports.boysIndex = (req, res) => { 11 exports.boysIndex = (req, res) => {
14 - headerModel.requestHeaderData()  
15 - .then(response => {  
16 - let data = headerModel.setHeaderData(response.data, 'boys');  
17 -  
18 - data.module = 'index';  
19 - data.page = 'index';  
20 - data.footerTop = true;  
21 -  
22 - res.render('boys', data);  
23 - })  
24 - .catch(() => {  
25 - res.render('error', {devEnv: true, pageErr: true});  
26 - });  
27 -};  
28 -  
29 -exports.girlsIndex = (req, res) => {  
30 - headerModel.requestHeaderData()  
31 - .then(response => {  
32 - let data = headerModel.setHeaderData(response.data, 'girls');  
33 -  
34 - data.module = 'index';  
35 - data.page = 'index';  
36 - data.footerTop = true;  
37 -  
38 - res.render('girls', data);  
39 - })  
40 - .catch(() => {  
41 - res.render('error', {devEnv: true, pageErr: true});  
42 - });  
43 - 12 + channelModel.getContent('boys').then(data => {
  13 + res.render('boys', data);
  14 + });
44 }; 15 };
@@ -5,31 +5,190 @@ @@ -5,31 +5,190 @@
5 */ 5 */
6 'use strict'; 6 'use strict';
7 7
8 -// const _ = require('lodash'); 8 +const _ = require('lodash');
9 9
10 const ServiceAPI = require(`${global.library}/api`).ServiceAPI; 10 const ServiceAPI = require(`${global.library}/api`).ServiceAPI;
11 const sign = require(`${global.library}/sign`); 11 const sign = require(`${global.library}/sign`);
12 12
13 const serviceApi = new ServiceAPI(); 13 const serviceApi = new ServiceAPI();
14 14
15 -/**  
16 - * 获取公共配置  
17 - * @param undefined  
18 - * @return {Object} 配置对象  
19 - */  
20 -// const commonConfig = () => ({  
21 -// title: 'girls'  
22 -// }); 15 +const headerModel = require('../../../doraemon/models/header');
23 16
24 -exports.getContent = () => {  
25 - let data = sign.apiSign({ 17 +// 创意生活
  18 +// const CODE_LIFESTYLE_CHANNEL_1 = '380c38155fd8beee10913a3f5b462da6';
  19 +
  20 +// const CODE_LIFESTYLE_CHANNEL_2 = '665f7c2fb9d037ee820766953ee34bf7';
  21 +
  22 +const channelMap = {
  23 + boys: {
  24 + code: '79372627eee75d73afe7f9bac91e5ce6',
  25 + gender: '1,3'
  26 + },
  27 + girls: {
  28 + code: '75215008957605c05e8cd375eac4f817',
  29 + gender: '2,3'
  30 + },
  31 + kids: {
  32 + code: 'd71f4b27f2a7229fbb31a4bc490a6f36',
  33 + gender: 'kids'
  34 + },
  35 + lifestyle: {
  36 + code: '8a341ca7eacc069ba80f02dec80eaf34',
  37 + gender: 'lifestyle'
  38 + }
  39 +};
  40 +
  41 +const getBannerList = data => {
  42 + let list = [];
  43 +
  44 + _.forEach(data, (bannerData) => {
  45 +
  46 + let obj = {};
  47 +
  48 + obj.href = bannerData.url;
  49 + obj.img = bannerData.src;
  50 + obj.name = bannerData.title;
  51 +
  52 + list.push(obj);
  53 + });
  54 +
  55 + return list;
  56 +};
  57 +
  58 +const getNewReportFloorData = data => {
  59 + let list = [];
  60 +
  61 + _.forEach(data, (item, index) => {
  62 + if (item.data.text === '最新速报') {
  63 + let obj = {};
  64 +
  65 + obj.href = data[index + 1].data[0].url;
  66 + obj.img = data[index + 1].data[0].src;
  67 +
  68 + list.push(obj);
  69 +
  70 + _.forEach(data[index + 2].data, (floorData) => {
  71 + let o = {};
  72 +
  73 + o.href = floorData.url;
  74 + o.img = floorData.src;
  75 +
  76 + list.push(o);
  77 + });
  78 +
  79 + obj.href = data[index + 3].data[0].url;
  80 + obj.img = data[index + 3].data[0].src;
  81 +
  82 + list.push(obj);
  83 + }
  84 + });
  85 +
  86 + return list;
  87 +};
  88 +
  89 +// 热门品类
  90 +const getHotGoodsFloorData = data => {
  91 + let list = [];
  92 +
  93 + _.forEach(data, (item) => {
  94 + if (item.template_intro === '热门品类') {
  95 + let object = {},
  96 + keyword = [],
  97 + category = [],
  98 + brands = [],
  99 + types = [];
  100 +
  101 + // product = [];
  102 + // console.log(item.data);
  103 + // console.log(item.data.menuNav);
  104 + // console.log(item.data.navs);
  105 + // return false;
  106 +
  107 + _.forEach(item.data.menuNav.list, (it) => {
  108 + let obj = {};
  109 +
  110 + obj.name = it.name;
  111 + obj.href = it.url;
  112 + category.push(obj);
  113 + });
  114 +
  115 + _.forEach(item.data.menuNav.blocks, (it) => {
  116 + let obj = {};
26 117
27 - /* eslint-disable */  
28 - client_type: 'web'  
29 - /* eslint-enable */ 118 + obj.name = it.title;
  119 + obj.href = it.url;
  120 + obj.img = it.img;
  121 + keyword.push(obj);
  122 + });
  123 +
  124 + _.forEach(item.data.imgs, (it, index) => {
  125 + let obj = {};
  126 +
  127 + obj.name = it.title;
  128 + obj.href = it.url;
  129 + obj.img = it.img;
  130 +
  131 + if (index < 2) {
  132 + brands.push(obj);
  133 + } else {
  134 + types.push(obj);
  135 + }
  136 + });
  137 +
  138 + object.keyword = keyword;
  139 + object.category = category;
  140 + object.brands = brands;
  141 + object.types = types;
  142 + list.push(object);
  143 + }
30 }); 144 });
31 145
32 - serviceApi.get('/operations/api/v5/resource/home', data).then(response => {  
33 - console.log(response); 146 + return list;
  147 +};
  148 +
  149 +const requestContent = (type) => {
  150 + let data = sign.apiSign({
  151 + /* eslint-disable */
  152 + client_type: 'web',
  153 + /* eslint-enable */
  154 + content_code: channelMap[type || 'boys'].code,
  155 + gender: channelMap[type || 'boys'].gender,
  156 + page: 1,
  157 + limit: 1000
  158 + });
  159 +
  160 + return serviceApi.get('/operations/api/v5/resource/home', data);
  161 +};
  162 +
  163 +
  164 +exports.getContent = (type) => {
  165 + return Promise.all([headerModel.requestHeaderData(), requestContent(type)]).then(res => {
  166 + let headerData = res[0].data,
  167 + contentData = res[1].data;
  168 +
  169 + let data = {};
  170 +
  171 +
  172 + data = headerModel.setHeaderData(headerData, 'boys');
  173 + data.module = 'channel';
  174 + data.page = 'boys';
  175 + data.footerTop = true;
  176 + data.channel = true;
  177 +
  178 + data.slide = {
  179 + list: getBannerList(contentData.list[0].data.big_image),
  180 + pagination: getBannerList(contentData.list[0].data.list)
  181 + };
  182 +
  183 + data.newReport = {
  184 + name: '最新速报',
  185 + list: getNewReportFloorData(contentData.list)
  186 + };
  187 +
  188 + data.recommend = {
  189 + tplrecommend: getHotGoodsFloorData(contentData.list)
  190 + };
  191 + console.log(data.newReport);
  192 + return data;
34 }); 193 });
35 }; 194 };
1 <div class="home-page yoho-page boys" data-page="boys"> 1 <div class="home-page yoho-page boys" data-page="boys">
2 - {{> commodity}} 2 + {{! 品类推荐}}
  3 + {{# recommend}}
  4 + {{> index/boy-recommend}}
  5 + {{/ recommend}}
3 </div> 6 </div>
4 <script>__custom = {"yopid":"index"};</script> 7 <script>__custom = {"yopid":"index"};</script>
5 8
  1 +{{# tplrecommend}}
  2 + <div class="tpl-recommend clearfix">
  3 + {{> index/floor-header}}
  4 + <div class="tpl-body clearfix">
  5 + <div class="tpl-nav">
  6 + <div class="tpl-keywords">
  7 + {{#each keyword}}
  8 + <a class="keywords{{@index}}" title="{{name}}" href="{{href}}" target= "_blank"><img class="lazy" data-original="{{img}}"/></a>
  9 + {{/each}}
  10 + </div>
  11 + <div class="tpl-category clearfix">
  12 + {{#each category}}
  13 + <a href="{{href}}" target= "_blank">{{name}}</a>
  14 + {{/each}}
  15 + </div>
  16 + </div>
  17 + <div class="tpl-brands imgopacity clearfix">
  18 + <ul>
  19 + {{#each brands}}
  20 + <li><a title="{{name}}" href="{{href}}" target= "_blank"><img class="lazy" data-original="{{img img 100 100}}"/></a></li>
  21 + {{/each}}
  22 + </ul>
  23 + </div>
  24 + <div class="tpl-types imgopacity clearfix">
  25 + <ul>
  26 + {{#each types}}
  27 + <li><a title="{{name}}" href="{{href}}" target= "_blank"><img class="lazy" data-original="{{img}}"/></a></li>
  28 + {{/each}}
  29 + </ul>
  30 + </div>
  31 + </div>
  32 + <div class="tpl-products imgopacity clearfix">
  33 + <ul>
  34 + {{#each products}}
  35 + <li><a href="{{href}}" title="{{name}}" target= "_blank"><img class="lazy" data-original="{{img}}"/></a></li>
  36 + {{/each}}
  37 + </ul>
  38 + </div>
  39 + </div>
  40 +{{/ tplrecommend}}
  41 +
  42 +
  1 +<div class="floor-header clearfix">
  2 + <h2 class="floor-title">{{name}}</h2>
  3 + {{#if navs}}
  4 + <ul class="header-navs">
  5 + {{# navs}}
  6 + <li data-classify="{{id}}">
  7 + <a target="_blank" href="{{href}}">{{name}}</a>
  8 + </li>
  9 + {{/ navs}}
  10 + </ul>
  11 + {{/if}}
  12 +</div>