|
@@ -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
|
}; |