Authored by ccbikai

增加资源位处理组件

@@ -4,10 +4,13 @@ @@ -4,10 +4,13 @@
4 * @date: 2016/05/09 4 * @date: 2016/05/09
5 */ 5 */
6 'use strict'; 6 'use strict';
  7 +const library = '../../../library';
  8 +const utils = '../../../utils';
7 const _ = require('lodash'); 9 const _ = require('lodash');
8 -const ServiceAPI = require(`${global.library}/api`).ServiceAPI;  
9 -const sign = require(`${global.library}/sign`);  
10 -const camelCase = require(`${global.library}/camel-case`); 10 +const ServiceAPI = require(`${library}/api`).ServiceAPI;
  11 +const sign = require(`${library}/sign`);
  12 +const camelCase = require(`${library}/camel-case`);
  13 +const resourcesProcess = require(`${utils}/resources-process`);
11 14
12 const api = new ServiceAPI(); 15 const api = new ServiceAPI();
13 16
@@ -91,43 +94,6 @@ const processSideBar = (list, choosed) => { @@ -91,43 +94,6 @@ const processSideBar = (list, choosed) => {
91 }; 94 };
92 95
93 /** 96 /**
94 - * 处理楼层数据  
95 - * @param {[array]} list  
96 - * @return {[array]}  
97 - */  
98 -const processFloor = (list) => {  
99 - const formatData = [];  
100 -  
101 - list = list || [];  
102 - list = camelCase(list);  
103 -  
104 - _.forEach(list, (floor) => {  
105 - floor[_.camelCase(floor.templateName)] = true;  
106 -  
107 - // 特殊资源位处理  
108 - // PLUS  
109 - if (floor.singleNameImage && floor.data) {  
110 - floor.data.title = {  
111 - title: floor.data.title  
112 - };  
113 - }  
114 -  
115 - // 潮流时装/经典裤裙/时尚靴履/潮人配饰/潮流上装  
116 - if (floor.recommendContentOne && floor.data) {  
117 - if (floor.data.bigImage && floor.data.bigImage.length > 1) {  
118 - floor.data.bigImage = {  
119 - bigList: floor.data.bigImage  
120 - };  
121 - }  
122 - }  
123 -  
124 - formatData.push(floor);  
125 - });  
126 -  
127 - return formatData;  
128 -};  
129 -  
130 -/**  
131 * 获取频道页面资源位 97 * 获取频道页面资源位
132 * @param {[object]} gender 98 * @param {[object]} gender
133 * @return {[type]} 99 * @return {[type]}
@@ -147,7 +113,7 @@ const getChannelResource = (params) => { @@ -147,7 +113,7 @@ const getChannelResource = (params) => {
147 113
148 return api.get('operations/api/v5/resource/home', sign.apiSign(params), 300).then(result => { 114 return api.get('operations/api/v5/resource/home', sign.apiSign(params), 300).then(result => {
149 if (result && result.code === 200) { 115 if (result && result.code === 200) {
150 - return processFloor(result.data.list); 116 + return resourcesProcess(result.data.list);
151 } else { 117 } else {
152 return result; 118 return result;
153 } 119 }
@@ -44,8 +44,6 @@ class Http { @@ -44,8 +44,6 @@ class Http {
44 return rp(options).then((result) => { 44 return rp(options).then((result) => {
45 let duration = timer.put('getApi');// 统计时间结束 45 let duration = timer.put('getApi');// 统计时间结束
46 46
47 - console.log(result);  
48 -  
49 // 数据校验 47 // 数据校验
50 if (!result) { 48 if (!result) {
51 log.error('error: 接口返回的数据结构错误,非 JSON'); 49 log.error('error: 接口返回的数据结构错误,非 JSON');
  1 +const _ = require('lodash');
  2 +const camelCase = require('../library/camel-case');
  3 +
  4 +/**
  5 + * 处理楼层数据
  6 + * @param {[array]} list
  7 + * @return {[array]}
  8 + */
  9 +module.exports = (list) => {
  10 + const formatData = [];
  11 +
  12 + list = list || [];
  13 + list = camelCase(list);
  14 +
  15 + _.forEach(list, (floor) => {
  16 + floor[_.camelCase(floor.templateName)] = true;
  17 +
  18 + // 特殊资源位处理
  19 + // PLUS
  20 + if (floor.singleNameImage && floor.data) {
  21 + floor.data.title = {
  22 + title: floor.data.title
  23 + };
  24 + }
  25 +
  26 + // 潮流时装/经典裤裙/时尚靴履/潮人配饰/潮流上装
  27 + if (floor.recommendContentOne && floor.data) {
  28 + if (floor.data.bigImage && floor.data.bigImage.length > 1) {
  29 + floor.data.bigImage = {
  30 + bigList: floor.data.bigImage
  31 + };
  32 + }
  33 + }
  34 +
  35 + formatData.push(floor);
  36 + });
  37 +
  38 + return formatData;
  39 +};