index.js
2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* 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();
const headerModel = require('../../../doraemon/models/header');
// 创意生活
// 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 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);
};
// boys, girls, kids, lifestyle
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, type);
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)
};
return data;
});
};