Authored by biao

update for render channel with data from Java API

1 const model = require('../models'); 1 const model = require('../models');
2 2
3 exports.index = (req, res) => { 3 exports.index = (req, res) => {
4 - res.display('index', Object.assign({  
5 - module: 'channel',  
6 - page: 'home'  
7 - }, model.getContent())); 4 + const channelType = req.path.substring(1) || 'men';
  5 +
  6 + model.getContent(channelType).then(result => {
  7 + res.display('index', Object.assign({
  8 + module: 'channel',
  9 + page: 'home'
  10 + }, result));
  11 + });
8 }; 12 };
  1 +/**
  2 + * 频道页
  3 + * @author: 赵彪<bill.zhao@yoho.cn>
  4 + * @date: 2016/7/26
  5 + */
  6 +'use strict';
  7 +
  8 +// const api = global.yoho.API;
  9 +const api = global.yoho.ServiceAPI;
  10 +
  11 +const channelMap = require('../../../config/channel-type').channelMap;
  12 +
  13 +const getChannelDataAsync = type => {
  14 + const data = {
  15 + client_type: 'web',
  16 + content_code: channelMap[type].code,
  17 + gender: channelMap[type].gender,
  18 + page: 1,
  19 + limit: 1000
  20 + };
  21 +
  22 + return api.get('operations/api/v5/resource/home', data, {
  23 + cache: true,
  24 + code: 200
  25 + });
  26 +};
  27 +
  28 +module.exports = {
  29 + getChannelDataAsync
  30 +};
1 -const getContent = () => {  
2 - const content = { 1 +/**
  2 + * 频道页 model
  3 + * @author: 赵彪<bill.zhao@yoho.cn>
  4 + * @date: 2016/07/26
  5 + */
  6 +'use strict';
  7 +
  8 +const channelApi = require('./channel-api');
  9 +const camelCase = global.yoho.camelCase;
  10 +const _ = require('lodash');
  11 +
  12 +/**
  13 + * 获取slider楼层数据
  14 + * @param {Object} d 接口返回的楼层数据
  15 + * @return {Object} 处理之后的数据
  16 + */
  17 +const _getSliderData = d => {
  18 +
  19 + return {
  20 + slider: d
  21 + };
  22 +};
  23 +
  24 +/**
  25 + * 获取BrandsAd楼层数据
  26 + * @param {Object} d 接口返回的楼层数据
  27 + * @return {Object} 处理之后的数据
  28 + */
  29 +const _getBrandAdFloor = d => {
  30 +
  31 + _.forEach(d, data => {
  32 + data.btnText = 'shop now';
  33 + });
  34 +
  35 + return {
  36 + brandsAd: d
  37 + };
  38 +};
  39 +
  40 +/**
  41 + * 获取new arrivals楼层数据
  42 + * @param {Object} d 接口返回的楼层数据
  43 + * @return {Object} 处理之后的数据
  44 + */
  45 +const _getNewArrivals = d => {
  46 + _.forEach(d, (data, index) => {
  47 + if (index === 0 || index === d.length - 1) {
  48 + data.smallImg = true;
  49 + }
  50 +
  51 + if (index % 2 === 0) {
  52 + data.even = true;
  53 + }
  54 + });
  55 +
  56 + return {
  57 + floorZh: '新品抢鲜看',
  58 + floorEn: 'NEW ARRIVALS',
  59 + newArrivals: d
  60 + };
  61 +};
  62 +
  63 +/**
  64 + * 获取classic brands楼层数据
  65 + * @param {Object} d 接口返回的楼层数据
  66 + * @return {Object} 处理之后的数据
  67 + */
  68 +const _getClassicBrands = d => {
  69 + let brands = [];
  70 + let subArr;
  71 + let i = 0;
  72 +
  73 + _.forEach(d, (data, index) => {
  74 + if (index === 0 || index === 1 || index === 6 || index === 7) {
  75 + brands.push({
  76 + big: [d[index]]
  77 + });
  78 + } else if ((index > 1 && index < 6 || index > 7 && index < 12) && index % 2 === 0) {
  79 + if (i < 4) {
  80 + subArr = d.slice(index, index + 2);
  81 + brands[i].small = subArr;
  82 + i += 1;
  83 + }
  84 + }
  85 + });
  86 +
  87 + _.forEach(brands, (data, index) => {
  88 + if (index < 2) {
  89 + data.bottomSpace = true;
  90 + }
  91 +
  92 + if (index === 1 || index === 3) {
  93 + data.right = true;
  94 + }
  95 + });
  96 +
  97 + return {
  98 + floorZh: '经典品牌',
  99 + floorEn: 'CLASSIC BRANDS',
  100 + classicBrands: brands
  101 + };
  102 +};
  103 +
  104 +/**
  105 + * 获取潮流标志楼层数据
  106 + * @param {Object} d 接口返回的楼层数据
  107 + * @return {Object} 处理之后的数据
  108 + */
  109 +const _getStyleIcon = d => {
  110 + _.forEach(d, data => {
  111 + data.btnText = '去看看';
  112 + });
  113 +
  114 + return {
  115 + floorZh: '潮流标志',
  116 + floorEn: 'STYLE ICON',
  117 + styleIcon: d
  118 + };
  119 +};
  120 +
  121 +/**
  122 + * 获取咨询楼层数据
  123 + * @param {Object} d 接口返回的楼层数据
  124 + * @return {Object} 处理之后的数据
  125 + */
  126 +const _getEditorial = d => {
  127 + console.log(d);
  128 + return {
  129 + floorZh: '资讯',
  130 + floorEn: 'EDITORIAL',
  131 + editorial: d
  132 + };
  133 +};
  134 +
  135 +
  136 +const floorMap = {
  137 + slider: _getSliderData,
  138 + 标题: _getBrandAdFloor,
  139 + 新品抢先看: _getNewArrivals,
  140 + CLASSIC: _getClassicBrands,
  141 + 潮流标识: _getStyleIcon,
  142 + EDITORIAL: _getEditorial
  143 +};
  144 +
  145 +/**
  146 + * 获取floorMap中对应的key
  147 + * @param {String} d 含有key的字符串
  148 + * @return {String} 得到的key值
  149 + */
  150 +const _getKey = d => {
  151 + let k = d.split(' ')[0];
  152 +
  153 + return k;
  154 +};
  155 +
  156 +/**
  157 + * 判断title类型是否为对象
  158 + * @param {Object} t title
  159 + * @return {Boolen}
  160 + */
  161 +const _isObjectTitle = t => {
  162 + return _.isObject(t);
  163 +};
  164 +
  165 +/**
  166 + * 判断是否为Banner焦点图楼层
  167 + * @param {Object} d 楼层数据
  168 + * @return {Boolen}
  169 + */
  170 +const _isBannerFloor = d => {
  171 + return d.templateName === 'focus' && d.templateIntro === '焦点图';
  172 +};
  173 +
  174 +/**
  175 + * 获取用于渲染模板的数据
  176 + * @param {Object} d 接口返回的数据
  177 + * @return {Array} 模板数据数组
  178 + */
  179 +const _processFloorData = d => {
  180 + let floorList = [];
  181 +
  182 + _.forEach(d, data => {
  183 + let floorTitle;
  184 + let floorData;
  185 +
  186 + // 处理banner
  187 + if (_isBannerFloor(data)) {
  188 + floorData = floorMap.slider(data.data);
  189 +
  190 + // 判断标题类型
  191 + } else if (_isObjectTitle(data.data.title)) {
  192 + floorTitle = _getKey(data.data.title.title);
  193 + floorData = floorMap[floorTitle](data.data.list);
  194 + } else {
  195 + floorTitle = _getKey(data.data.title);
  196 + floorData = floorMap[floorTitle](data.data.list);
  197 + }
  198 +
  199 + floorList.push(floorData);
  200 + });
  201 +
  202 + return floorList;
  203 +};
  204 +
  205 +const getContent = type => {
  206 + return channelApi.getChannelDataAsync(type).then(result => {
  207 + const l = camelCase(result.data.list);
  208 + const floor = {
  209 + content: _processFloorData(l)
  210 + };
  211 +
  212 + return floor;
  213 + });
  214 +
3 /* eslint-disable */ 215 /* eslint-disable */
  216 + const content = {
4 content: [ 217 content: [
5 { 218 {
6 slider: [ 219 slider: [
@@ -250,7 +463,7 @@ const getContent = () => { @@ -250,7 +463,7 @@ const getContent = () => {
250 }; 463 };
251 /* eslint-enable */ 464 /* eslint-enable */
252 465
253 - return content; 466 + // return content;
254 }; 467 };
255 468
256 module.exports = { 469 module.exports = {
1 <div class="ad-banner"> 1 <div class="ad-banner">
2 {{#adBanner}} 2 {{#adBanner}}
3 - <a href="{{link}}"> 3 + <a href="{{url}}">
4 <img class="lazy-img" data-original="{{image img 1150 160}}" alt=""> 4 <img class="lazy-img" data-original="{{image img 1150 160}}" alt="">
5 </a> 5 </a>
6 {{/adBanner}} 6 {{/adBanner}}
1 <div class="ad-container clearfix"> 1 <div class="ad-container clearfix">
2 {{# brandsAd}} 2 {{# brandsAd}}
3 <div class="ad {{#if @first}}first{{/if}}"> 3 <div class="ad {{#if @first}}first{{/if}}">
4 - <img class="lazy-img" data-original="{{image img 240 240}}" alt=""> 4 + <img class="lazy-img" data-original="{{image src 240 240}}" alt="">
5 {{> brand-text-box}} 5 {{> brand-text-box}}
6 </div> 6 </div>
7 {{/ brandsAd}} 7 {{/ brandsAd}}
1 {{# classicBrands}} 1 {{# classicBrands}}
2 <div class="brand-img-box {{#if right}}right{{/if}} {{#if bottomSpace}}mb10{{/if}}"> 2 <div class="brand-img-box {{#if right}}right{{/if}} {{#if bottomSpace}}mb10{{/if}}">
3 - <a href="{{link}}"> 3 + <a href="{{url}}">
4 {{# big}} 4 {{# big}}
5 - <img class="big-img lazy-img" data-original="{{image img 556 333}}" alt="big-img"> 5 + <img class="big-img lazy-img" data-original="{{image src 556 333}}" alt="big-img">
6 {{/ big}} 6 {{/ big}}
7 {{# small}} 7 {{# small}}
8 - <img class="small-img lazy-img {{#if @first}}first{{/if}}" data-original="{{image img 283 283}}" alt="big-img"> 8 + <img class="small-img lazy-img {{#if @first}}first{{/if}}" data-original="{{image src 283 283}}" alt="big-img">
9 {{/ small}} 9 {{/ small}}
10 </a> 10 </a>
11 </div> 11 </div>
1 <div class="brand-text-box"> 1 <div class="brand-text-box">
2 - <h4>{{name}}</h4>  
3 - <p>{{des}}</p>  
4 - <button>{{btnText}}</button> 2 + <h4>{{productName}}</h4>
  3 + <p>{{productDesc}}</p>
  4 + <a href="{{url}}">
  5 + <button>{{btnText}}</button>
  6 + </a>
5 </div> 7 </div>
@@ -4,15 +4,15 @@ @@ -4,15 +4,15 @@
4 {{# editorial}} 4 {{# editorial}}
5 <div class="news left"> 5 <div class="news left">
6 {{# big}} 6 {{# big}}
7 - <a href="{{link}}">  
8 - <img class="lazy-img" data-original="{{image img 395 495}}" alt=""> 7 + <a href="{{url}}">
  8 + <img class="lazy-img" data-original="{{image src 395 495}}" alt="">
9 </a> 9 </a>
10 {{/ big}} 10 {{/ big}}
11 </div> 11 </div>
12 <div class="news right"> 12 <div class="news right">
13 {{# small}} 13 {{# small}}
14 - <a href="{{link}}">  
15 - <img class="lazy-img {{#if bottomSpace}}bottom-space{{/if}} {{#if rightSpace}}right-space{{/if}}" data-original="{{image img 360 240}}" alt=""> 14 + <a href="{{url}}">
  15 + <img class="lazy-img {{#if bottomSpace}}bottom-space{{/if}} {{#if rightSpace}}right-space{{/if}}" data-original="{{image src 360 240}}" alt="">
16 </a> 16 </a>
17 {{/ small}} 17 {{/ small}}
18 </div> 18 </div>
@@ -4,22 +4,22 @@ @@ -4,22 +4,22 @@
4 {{# newArrivals}} 4 {{# newArrivals}}
5 <div class="arrival-item {{#if smallImg}}small-img{{/if}} {{#if @last}}last{{^}}normal{{/if}}"> 5 <div class="arrival-item {{#if smallImg}}small-img{{/if}} {{#if @last}}last{{^}}normal{{/if}}">
6 {{#if even}} 6 {{#if even}}
7 - <a href="{{link}}">  
8 - <img class="lazy-img" data-original="{{#if smallImg}}{{image img 223 490}}{{^}}{{image img 325 490}}{{/if}}" alt=""> 7 + <a href="{{url}}">
  8 + <img class="lazy-img" data-original="{{#if smallImg}}{{image src 223 490}}{{^}}{{image src 325 490}}{{/if}}" alt="">
9 </a> 9 </a>
10 <div class="brand-name"> 10 <div class="brand-name">
11 - <a href="{{link}}"> 11 + <a href="{{url}}">
12 <span class="bottom">{{name}}</span> 12 <span class="bottom">{{name}}</span>
13 </a> 13 </a>
14 </div> 14 </div>
15 {{^}} 15 {{^}}
16 <div class="brand-name"> 16 <div class="brand-name">
17 - <a href="{{link}}"> 17 + <a href="{{url}}">
18 <span class="top">{{name}}</span> 18 <span class="top">{{name}}</span>
19 </a> 19 </a>
20 </div> 20 </div>
21 - <a href="{{link}}">  
22 - <img class="lazy-img" data-original="{{#if smallImg}}{{image img 223 490}}{{^}}{{image img 325 490}}{{/if}}" alt=""> 21 + <a href="{{url}}">
  22 + <img class="lazy-img" data-original="{{#if smallImg}}{{image src 223 490}}{{^}}{{image src 325 490}}{{/if}}" alt="">
23 </a> 23 </a>
24 {{/if}} 24 {{/if}}
25 </div> 25 </div>
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 {{# slider}} 4 {{# slider}}
5 <li style="{{#if bgColor}}background:{{bgColor}}{{/if}}"> 5 <li style="{{#if bgColor}}background:{{bgColor}}{{/if}}">
6 <a href="{{url}}" target= "_blank"> 6 <a href="{{url}}" target= "_blank">
7 - <img class="lazy" data-original="{{image img 1920 645}}" alt=""> 7 + <img class="lazy" data-original="{{image src 1920 645}}" alt="">
8 </a> 8 </a>
9 {{# tips}} 9 {{# tips}}
10 <div class="slide-tips"> 10 <div class="slide-tips">
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 {{# pagination}} 23 {{# pagination}}
24 <li> 24 <li>
25 <a href="{{url}}" target="_blank"></a> 25 <a href="{{url}}" target="_blank"></a>
26 - <img src="{{image img 138 54}}" alt=""> 26 + <img src="{{image src 138 54}}" alt="">
27 </li> 27 </li>
28 {{/ pagination}} 28 {{/ pagination}}
29 </ul> 29 </ul>
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <div class="smooth-card-container"> 3 <div class="smooth-card-container">
4 {{# styleIcon}} 4 {{# styleIcon}}
5 <div class="card {{#if @first}}active{{/if}} {{#if @last}}last{{/if}}"> 5 <div class="card {{#if @first}}active{{/if}} {{#if @last}}last{{/if}}">
6 - <img class="img lazy-img" data-original="{{image img 221 320}}" /> 6 + <img class="img lazy-img" data-original="{{image src 221 320}}" />
7 {{> brand-text-box}} 7 {{> brand-text-box}}
8 </div> 8 </div>
9 {{/ styleIcon}} 9 {{/ styleIcon}}
  1 +/**
  2 + * 共用的map数据常量定义
  3 + * @author: 赵彪<bill.zhao@yoho.cn>
  4 + * @date: 2016/07/26
  5 + */
  6 +
  7 +'use strict';
  8 +
  9 +const channelMap = {
  10 + men: {
  11 + code: '39c103615558890846e56749af040228',
  12 + gender: '1,3'
  13 + },
  14 + women: {
  15 + code: '527079e6c46d0f125eb46b835968971b',
  16 + gender: '2,3'
  17 + },
  18 + lifestyle: {
  19 + code: '94b5ed607b6d565ffc29c2c04be121dc',
  20 + gender: ''
  21 + }
  22 +};
  23 +
  24 +const meCode = '02889429674251b93f2add429008e1f8';
  25 +
  26 +
  27 +module.exports = {
  28 + channelMap,
  29 + meCode
  30 +};
@@ -29,10 +29,12 @@ @@ -29,10 +29,12 @@
29 29
30 &.top { 30 &.top {
31 line-height: 30px; 31 line-height: 30px;
  32 + position: static !important;
32 } 33 }
33 34
34 &.bottom { 35 &.bottom {
35 line-height: 56px; 36 line-height: 56px;
  37 + position: static !important;
36 } 38 }
37 } 39 }
38 } 40 }