add 获取 bannerresource 数据 显示 review by 红魔
Showing
7 changed files
with
259 additions
and
33 deletions
@@ -48,18 +48,28 @@ export default class Brand extends Component { | @@ -48,18 +48,28 @@ export default class Brand extends Component { | ||
48 | renderHeader(){ | 48 | renderHeader(){ |
49 | let data = this.props.reourceForBoy; | 49 | let data = this.props.reourceForBoy; |
50 | let brandFliter = this.props.brandFliter; | 50 | let brandFliter = this.props.brandFliter; |
51 | - let bannerForBoy = data.get('bannerForBoy'); | ||
52 | - let custom_brandsForBoy = data.get('custom_brandsForBoy'); | ||
53 | - let brandsTextForBoy = data.get('brandsTextForBoy'); | 51 | + let channelFliter = this.props.channelFliter; |
52 | + | ||
53 | + if (channelFliter == 0) { | ||
54 | + data = this.props.reourceForBoy; | ||
55 | + } else if (channelFliter == 1) { | ||
56 | + data = this.props.reourceForGirl; | ||
57 | + } else if (channelFliter == 2) { | ||
58 | + data = this.props.reourceForKid; | ||
59 | + } else if (channelFliter == 3) { | ||
60 | + data = this.props.reourceForLifeStyle; | ||
61 | + } | ||
62 | + | ||
63 | + let banner = data.get('banner'); | ||
64 | + let custom_brands = data.get('custom_brands'); | ||
65 | + let brandsText = data.get('brandsText'); | ||
54 | 66 | ||
55 | return ( | 67 | return ( |
56 | <View style={styles.header}> | 68 | <View style={styles.header}> |
57 | - <YH_SearchBar | ||
58 | - | ||
59 | - /> | ||
60 | - {bannerForBoy?<BrandSwiper resource={bannerForBoy} onPressSlideItem={this.props.onPressSlideItem}/>:null} | ||
61 | - {custom_brandsForBoy?<BannerReourceList resource={custom_brandsForBoy} onPressSlideItem={this.props.onPressSlideItem}/>:null} | ||
62 | - <BrandFliter dataSource={brandsTextForBoy} selectID={brandFliter} onPressFilter={this.props.onPressFilter}/> | 69 | + <YH_SearchBar/> |
70 | + {banner?<BrandSwiper resource={banner} onPressSlideItem={this.props.onPressSlideItem}/>:null} | ||
71 | + {custom_brands?<BannerReourceList resource={custom_brands} onPressSlideItem={this.props.onPressSlideItem}/>:null} | ||
72 | + {brandsText?<BrandFliter dataSource={brandsText} selectID={brandFliter} onPressFilter={this.props.onPressFilter}/>:null} | ||
63 | </View> | 73 | </View> |
64 | ); | 74 | ); |
65 | } | 75 | } |
@@ -94,6 +104,9 @@ export default class Brand extends Component { | @@ -94,6 +104,9 @@ export default class Brand extends Component { | ||
94 | brandListForKid, | 104 | brandListForKid, |
95 | brandListForLifeStyle, | 105 | brandListForLifeStyle, |
96 | reourceForBoy, | 106 | reourceForBoy, |
107 | + reourceForGirl, | ||
108 | + reourceForKid, | ||
109 | + reourceForLifeStyle, | ||
97 | } = this.props; | 110 | } = this.props; |
98 | 111 | ||
99 | let data; | 112 | let data; |
@@ -47,6 +47,18 @@ export default keyMirror({ | @@ -47,6 +47,18 @@ export default keyMirror({ | ||
47 | GETBRANDRESOURCE_FOR_BOY_SUCCESS: null, | 47 | GETBRANDRESOURCE_FOR_BOY_SUCCESS: null, |
48 | GETBRANDRESOURCE_FOR_BOY_FAILURE: null, | 48 | GETBRANDRESOURCE_FOR_BOY_FAILURE: null, |
49 | 49 | ||
50 | + GETBRANDRESOURCE_FOR_GIRL_REQUEST: null, | ||
51 | + GETBRANDRESOURCE_FOR_GIRL_SUCCESS: null, | ||
52 | + GETBRANDRESOURCE_FOR_GIRL_FAILURE: null, | ||
53 | + | ||
54 | + GETBRANDRESOURCE_FOR_KID_REQUEST: null, | ||
55 | + GETBRANDRESOURCE_FOR_KID_SUCCESS: null, | ||
56 | + GETBRANDRESOURCE_FOR_KID_FAILURE: null, | ||
57 | + | ||
58 | + GETBRANDRESOURCE_FOR_LIFESTYLE_REQUEST: null, | ||
59 | + GETBRANDRESOURCE_FOR_LIFESTYLE_SUCCESS: null, | ||
60 | + GETBRANDRESOURCE_FOR_LIFESTYLE_FAILURE: null, | ||
61 | + | ||
50 | SET_BRAND_FILTER: null, | 62 | SET_BRAND_FILTER: null, |
51 | SET_CHANNEL_FILTER: null, | 63 | SET_CHANNEL_FILTER: null, |
52 | 64 |
@@ -72,6 +72,7 @@ class BrandContainer extends Component { | @@ -72,6 +72,7 @@ class BrandContainer extends Component { | ||
72 | 72 | ||
73 | _onChannelPressFliter(value){ | 73 | _onChannelPressFliter(value){ |
74 | this.props.actions.getBrandList(value); | 74 | this.props.actions.getBrandList(value); |
75 | + this.props.actions.getBrandResource(value); | ||
75 | this.props.actions.setChannelFilter(value); | 76 | this.props.actions.setChannelFilter(value); |
76 | } | 77 | } |
77 | 78 | ||
@@ -84,6 +85,9 @@ class BrandContainer extends Component { | @@ -84,6 +85,9 @@ class BrandContainer extends Component { | ||
84 | brandListForKid, | 85 | brandListForKid, |
85 | brandListForLifeStyle, | 86 | brandListForLifeStyle, |
86 | reourceForBoy, | 87 | reourceForBoy, |
88 | + reourceForGirl, | ||
89 | + reourceForKid, | ||
90 | + reourceForLifeStyle, | ||
87 | } = this.props.brand; | 91 | } = this.props.brand; |
88 | return ( | 92 | return ( |
89 | <View style={styles.container}> | 93 | <View style={styles.container}> |
@@ -95,6 +99,9 @@ class BrandContainer extends Component { | @@ -95,6 +99,9 @@ class BrandContainer extends Component { | ||
95 | brandListForKid= {brandListForKid} | 99 | brandListForKid= {brandListForKid} |
96 | brandListForLifeStyle= {brandListForLifeStyle} | 100 | brandListForLifeStyle= {brandListForLifeStyle} |
97 | reourceForBoy= {reourceForBoy} | 101 | reourceForBoy= {reourceForBoy} |
102 | + reourceForGirl={reourceForGirl} | ||
103 | + reourceForKid={reourceForKid} | ||
104 | + reourceForLifeStyle={reourceForLifeStyle} | ||
98 | onPressFilter= {this._onPressFilter} | 105 | onPressFilter= {this._onPressFilter} |
99 | onPressSlideItem= {this._onPressSlideItem} | 106 | onPressSlideItem= {this._onPressSlideItem} |
100 | onChannelPressFliter={this._onChannelPressFliter} | 107 | onChannelPressFliter={this._onChannelPressFliter} |
@@ -29,6 +29,19 @@ const { | @@ -29,6 +29,19 @@ const { | ||
29 | GETBRANDRESOURCE_FOR_BOY_SUCCESS, | 29 | GETBRANDRESOURCE_FOR_BOY_SUCCESS, |
30 | GETBRANDRESOURCE_FOR_BOY_FAILURE, | 30 | GETBRANDRESOURCE_FOR_BOY_FAILURE, |
31 | 31 | ||
32 | + GETBRANDRESOURCE_FOR_GIRL_REQUEST, | ||
33 | + GETBRANDRESOURCE_FOR_GIRL_SUCCESS, | ||
34 | + GETBRANDRESOURCE_FOR_GIRL_FAILURE, | ||
35 | + | ||
36 | + GETBRANDRESOURCE_FOR_KID_REQUEST, | ||
37 | + GETBRANDRESOURCE_FOR_KID_SUCCESS, | ||
38 | + GETBRANDRESOURCE_FOR_KID_FAILURE, | ||
39 | + | ||
40 | + GETBRANDRESOURCE_FOR_LIFESTYLE_REQUEST, | ||
41 | + GETBRANDRESOURCE_FOR_LIFESTYLE_SUCCESS, | ||
42 | + GETBRANDRESOURCE_FOR_LIFESTYLE_FAILURE, | ||
43 | + | ||
44 | + | ||
32 | } = require('../../constants/actionTypes').default; | 45 | } = require('../../constants/actionTypes').default; |
33 | 46 | ||
34 | 47 | ||
@@ -184,47 +197,137 @@ export function getBrandResourceForBoyFailure(error) { | @@ -184,47 +197,137 @@ export function getBrandResourceForBoyFailure(error) { | ||
184 | } | 197 | } |
185 | } | 198 | } |
186 | 199 | ||
200 | +export function getBrandResourceForGirlRequest() { | ||
201 | + return { | ||
202 | + type: GETBRANDRESOURCE_FOR_GIRL_REQUEST, | ||
203 | + }; | ||
204 | +} | ||
205 | + | ||
206 | +export function getBrandResourceForGirlSuccess(json) { | ||
207 | + return { | ||
208 | + type: GETBRANDRESOURCE_FOR_GIRL_SUCCESS, | ||
209 | + payload: json | ||
210 | + } | ||
211 | +} | ||
212 | + | ||
213 | +export function getBrandResourceForGirlFailure(error) { | ||
214 | + return { | ||
215 | + type: GETBRANDRESOURCE_FOR_GIRL_FAILURE, | ||
216 | + payload: error | ||
217 | + } | ||
218 | +} | ||
219 | + | ||
220 | +export function getBrandResourceForKidRequest() { | ||
221 | + return { | ||
222 | + type: GETBRANDRESOURCE_FOR_KID_REQUEST, | ||
223 | + }; | ||
224 | +} | ||
225 | + | ||
226 | +export function getBrandResourceForKidSuccess(json) { | ||
227 | + return { | ||
228 | + type: GETBRANDRESOURCE_FOR_KID_SUCCESS, | ||
229 | + payload: json | ||
230 | + } | ||
231 | +} | ||
232 | + | ||
233 | +export function getBrandResourceForKidFailure(error) { | ||
234 | + return { | ||
235 | + type: GETBRANDRESOURCE_FOR_KID_FAILURE, | ||
236 | + payload: error | ||
237 | + } | ||
238 | +} | ||
239 | + | ||
240 | +export function getBrandResourceForLifeStyleRequest() { | ||
241 | + return { | ||
242 | + type: GETBRANDRESOURCE_FOR_LIFESTYLE_REQUEST, | ||
243 | + }; | ||
244 | +} | ||
245 | + | ||
246 | +export function getBrandResourceForLifeStyleSuccess(json) { | ||
247 | + return { | ||
248 | + type: GETBRANDRESOURCE_FOR_LIFESTYLE_SUCCESS, | ||
249 | + payload: json | ||
250 | + } | ||
251 | +} | ||
252 | + | ||
253 | +export function getBrandResourceForLifeStyleFailure(error) { | ||
254 | + return { | ||
255 | + type: GETBRANDRESOURCE_FOR_LIFESTYLE_FAILURE, | ||
256 | + payload: error | ||
257 | + } | ||
258 | +} | ||
259 | + | ||
187 | export function getBrandResource(channel) { | 260 | export function getBrandResource(channel) { |
188 | return (dispatch, getState) => { | 261 | return (dispatch, getState) => { |
189 | let {app, classify} = getState(); | 262 | let {app, classify} = getState(); |
190 | - dispatch(getBrandResourceForBoyRequest()); | ||
191 | - return new BrandService(app.serviceHost).getBrandResource() | 263 | + let content_code; |
264 | + if (channel == 0) { | ||
265 | + dispatch(getBrandResourceForBoyRequest()); | ||
266 | + content_code = 'ce6ac059493ec26241a8cbe0bfa1b17a'; | ||
267 | + }else if (channel == 1) { | ||
268 | + dispatch(getBrandResourceForGirlRequest()); | ||
269 | + content_code = 'dac99cdedc1f948e84c145aca561f7d2'; | ||
270 | + }else if (channel == 2) { | ||
271 | + dispatch(getBrandResourceForKidRequest()); | ||
272 | + content_code = '713784f93f52bb1a7b93916b2bb15510'; | ||
273 | + }else if (channel == 3) { | ||
274 | + dispatch(getBrandResourceForLifeStyleRequest()); | ||
275 | + content_code = 'f1aa914fd23cbcda71a87de6f5416c75'; | ||
276 | + } | ||
277 | + | ||
278 | + return new BrandService(app.serviceHost).getBrandResource(content_code) | ||
192 | .then(json => { | 279 | .then(json => { |
193 | let payload = parseResourceResources(json); | 280 | let payload = parseResourceResources(json); |
194 | - dispatch(getBrandResourceForBoySuccess(payload)); | 281 | + if (channel == 0) { |
282 | + dispatch(getBrandResourceForBoySuccess(payload)); | ||
283 | + }else if (channel == 1) { | ||
284 | + dispatch(getBrandResourceForGirlSuccess(payload)); | ||
285 | + }else if (channel == 2) { | ||
286 | + dispatch(getBrandResourceForKidSuccess(payload)); | ||
287 | + }else if (channel == 3) { | ||
288 | + dispatch(getBrandResourceForLifeStyleSuccess(payload)); | ||
289 | + } | ||
195 | }) | 290 | }) |
196 | .catch(error => { | 291 | .catch(error => { |
197 | - dispatch(getBrandResourceForBoyFailure(error)); | 292 | + if (channel == 0) { |
293 | + dispatch(getBrandResourceForBoyFailure(error)); | ||
294 | + }else if (channel == 1) { | ||
295 | + dispatch(getBrandResourceForGirlFailure(error)); | ||
296 | + }else if (channel == 2) { | ||
297 | + dispatch(getBrandResourceForKidFailure(error)); | ||
298 | + }else if (channel == 3) { | ||
299 | + dispatch(getBrandResourceForLifeStyleFailure(error)); | ||
300 | + } | ||
198 | }); | 301 | }); |
199 | }; | 302 | }; |
200 | } | 303 | } |
201 | 304 | ||
202 | export function parseResourceResources(json) { | 305 | export function parseResourceResources(json) { |
203 | 306 | ||
204 | - let bannerForBoy = []; | ||
205 | - let custom_brandsForBoy = []; | ||
206 | - let brandsTextForBoy = []; | 307 | + let banner = []; |
308 | + let custom_brands = []; | ||
309 | + let brandsText = []; | ||
207 | 310 | ||
208 | - brandsTextForBoy.push({key: 'default',name: '全部品牌'}); | 311 | + brandsText.push({key: 'default',name: '全部品牌'}); |
209 | 312 | ||
210 | for (var i = 0; i < json.length; i++) { | 313 | for (var i = 0; i < json.length; i++) { |
211 | if (json[i].template_name == 'focus') { | 314 | if (json[i].template_name == 'focus') { |
212 | - bannerForBoy = json[i]; | 315 | + banner = json[i]; |
213 | } | 316 | } |
214 | if (json[i].template_name == 'custom_brands') { | 317 | if (json[i].template_name == 'custom_brands') { |
215 | - custom_brandsForBoy = json[i]; | 318 | + custom_brands = json[i]; |
216 | } | 319 | } |
217 | if (json[i].template_name == 'text') { | 320 | if (json[i].template_name == 'text') { |
218 | let data = json[i].data; | 321 | let data = json[i].data; |
219 | let template_id = json[i].template_id; | 322 | let template_id = json[i].template_id; |
220 | let text = data.text; | 323 | let text = data.text; |
221 | - brandsTextForBoy.push({key: template_id,name: text}); | 324 | + brandsText.push({key: template_id,name: text}); |
222 | } | 325 | } |
223 | } | 326 | } |
224 | 327 | ||
225 | return { | 328 | return { |
226 | - bannerForBoy, | ||
227 | - custom_brandsForBoy, | ||
228 | - brandsTextForBoy, | 329 | + banner, |
330 | + custom_brands, | ||
331 | + brandsText, | ||
229 | }; | 332 | }; |
230 | } | 333 | } |
@@ -26,9 +26,24 @@ let InitialState = Record({ | @@ -26,9 +26,24 @@ let InitialState = Record({ | ||
26 | new_list: List(), | 26 | new_list: List(), |
27 | })), | 27 | })), |
28 | reourceForBoy: new (Record({ | 28 | reourceForBoy: new (Record({ |
29 | - bannerForBoy: Map(), | ||
30 | - custom_brandsForBoy: Map(), | ||
31 | - brandsTextForBoy: List(), | 29 | + banner: Map(), |
30 | + custom_brands: Map(), | ||
31 | + brandsText: List(), | ||
32 | + })), | ||
33 | + reourceForGirl: new (Record({ | ||
34 | + banner: Map(), | ||
35 | + custom_brands: Map(), | ||
36 | + brandsText: List(), | ||
37 | + })), | ||
38 | + reourceForKid: new (Record({ | ||
39 | + banner: Map(), | ||
40 | + custom_brands: Map(), | ||
41 | + brandsText: List(), | ||
42 | + })), | ||
43 | + reourceForLifeStyle: new (Record({ | ||
44 | + banner: Map(), | ||
45 | + custom_brands: Map(), | ||
46 | + brandsText: List(), | ||
32 | })), | 47 | })), |
33 | }); | 48 | }); |
34 | 49 |
@@ -29,6 +29,18 @@ const { | @@ -29,6 +29,18 @@ const { | ||
29 | GETBRANDRESOURCE_FOR_BOY_SUCCESS, | 29 | GETBRANDRESOURCE_FOR_BOY_SUCCESS, |
30 | GETBRANDRESOURCE_FOR_BOY_FAILURE, | 30 | GETBRANDRESOURCE_FOR_BOY_FAILURE, |
31 | 31 | ||
32 | + GETBRANDRESOURCE_FOR_GIRL_REQUEST, | ||
33 | + GETBRANDRESOURCE_FOR_GIRL_SUCCESS, | ||
34 | + GETBRANDRESOURCE_FOR_GIRL_FAILURE, | ||
35 | + | ||
36 | + GETBRANDRESOURCE_FOR_KID_REQUEST, | ||
37 | + GETBRANDRESOURCE_FOR_KID_SUCCESS, | ||
38 | + GETBRANDRESOURCE_FOR_KID_FAILURE, | ||
39 | + | ||
40 | + GETBRANDRESOURCE_FOR_LIFESTYLE_REQUEST, | ||
41 | + GETBRANDRESOURCE_FOR_LIFESTYLE_SUCCESS, | ||
42 | + GETBRANDRESOURCE_FOR_LIFESTYLE_FAILURE, | ||
43 | + | ||
32 | } = require('../../constants/actionTypes').default; | 44 | } = require('../../constants/actionTypes').default; |
33 | 45 | ||
34 | const initialState = new InitialState; | 46 | const initialState = new InitialState; |
@@ -134,19 +146,83 @@ export default function brandReducer(state=initialState, action) { | @@ -134,19 +146,83 @@ export default function brandReducer(state=initialState, action) { | ||
134 | case GETBRANDRESOURCE_FOR_BOY_SUCCESS: | 146 | case GETBRANDRESOURCE_FOR_BOY_SUCCESS: |
135 | { | 147 | { |
136 | let { | 148 | let { |
137 | - bannerForBoy, | ||
138 | - custom_brandsForBoy, | ||
139 | - brandsTextForBoy, | 149 | + banner, |
150 | + custom_brands, | ||
151 | + brandsText, | ||
140 | } = action.payload; | 152 | } = action.payload; |
141 | 153 | ||
142 | - return state.setIn(['reourceForBoy', 'bannerForBoy'], Immutable.fromJS(bannerForBoy)) | ||
143 | - .setIn(['reourceForBoy', 'custom_brandsForBoy'], Immutable.fromJS(custom_brandsForBoy)) | ||
144 | - .setIn(['reourceForBoy', 'brandsTextForBoy'], Immutable.fromJS(brandsTextForBoy)) | 154 | + return state.setIn(['reourceForBoy', 'banner'], Immutable.fromJS(banner)) |
155 | + .setIn(['reourceForBoy', 'custom_brands'], Immutable.fromJS(custom_brands)) | ||
156 | + .setIn(['reourceForBoy', 'brandsText'], Immutable.fromJS(brandsText)) | ||
145 | } | 157 | } |
146 | case GETBRANDRESOURCE_FOR_BOY_FAILURE: | 158 | case GETBRANDRESOURCE_FOR_BOY_FAILURE: |
147 | { | 159 | { |
148 | return state; | 160 | return state; |
149 | } | 161 | } |
162 | + | ||
163 | + case GETBRANDRESOURCE_FOR_GIRL_REQUEST: | ||
164 | + { | ||
165 | + return state; | ||
166 | + } | ||
167 | + case GETBRANDRESOURCE_FOR_GIRL_SUCCESS: | ||
168 | + { | ||
169 | + let { | ||
170 | + banner, | ||
171 | + custom_brands, | ||
172 | + brandsText, | ||
173 | + } = action.payload; | ||
174 | + | ||
175 | + return state.setIn(['reourceForGirl', 'banner'], Immutable.fromJS(banner)) | ||
176 | + .setIn(['reourceForGirl', 'custom_brands'], Immutable.fromJS(custom_brands)) | ||
177 | + .setIn(['reourceForGirl', 'brandsText'], Immutable.fromJS(brandsText)) | ||
178 | + } | ||
179 | + case GETBRANDRESOURCE_FOR_GIRL_FAILURE: | ||
180 | + { | ||
181 | + return state; | ||
182 | + } | ||
183 | + | ||
184 | + case GETBRANDRESOURCE_FOR_KID_REQUEST: | ||
185 | + { | ||
186 | + return state; | ||
187 | + } | ||
188 | + case GETBRANDRESOURCE_FOR_KID_SUCCESS: | ||
189 | + { | ||
190 | + let { | ||
191 | + banner, | ||
192 | + custom_brands, | ||
193 | + brandsText, | ||
194 | + } = action.payload; | ||
195 | + | ||
196 | + return state.setIn(['reourceForKid', 'banner'], Immutable.fromJS(banner)) | ||
197 | + .setIn(['reourceForKid', 'custom_brands'], Immutable.fromJS(custom_brands)) | ||
198 | + .setIn(['reourceForKid', 'brandsText'], Immutable.fromJS(brandsText)) | ||
199 | + } | ||
200 | + case GETBRANDRESOURCE_FOR_KID_FAILURE: | ||
201 | + { | ||
202 | + return state; | ||
203 | + } | ||
204 | + | ||
205 | + case GETBRANDRESOURCE_FOR_LIFESTYLE_REQUEST: | ||
206 | + { | ||
207 | + return state; | ||
208 | + } | ||
209 | + case GETBRANDRESOURCE_FOR_LIFESTYLE_SUCCESS: | ||
210 | + { | ||
211 | + let { | ||
212 | + banner, | ||
213 | + custom_brands, | ||
214 | + brandsText, | ||
215 | + } = action.payload; | ||
216 | + | ||
217 | + return state.setIn(['reourceForLifeStyle', 'banner'], Immutable.fromJS(banner)) | ||
218 | + .setIn(['reourceForLifeStyle', 'custom_brands'], Immutable.fromJS(custom_brands)) | ||
219 | + .setIn(['reourceForLifeStyle', 'brandsText'], Immutable.fromJS(brandsText)) | ||
220 | + } | ||
221 | + case GETBRANDRESOURCE_FOR_LIFESTYLE_FAILURE: | ||
222 | + { | ||
223 | + return state; | ||
224 | + } | ||
225 | + | ||
150 | } | 226 | } |
151 | 227 | ||
152 | return state; | 228 | return state; |
@@ -29,7 +29,7 @@ export default class BrandService { | @@ -29,7 +29,7 @@ export default class BrandService { | ||
29 | }); | 29 | }); |
30 | } | 30 | } |
31 | 31 | ||
32 | - async getBrandResource(content_code='ce6ac059493ec26241a8cbe0bfa1b17a',fromPage='iFP_Brand'){ | 32 | + async getBrandResource(content_code,fromPage='iFP_Brand'){ |
33 | return await this.api.post({ | 33 | return await this.api.post({ |
34 | url: '/operations/api/v5/resource/get', | 34 | url: '/operations/api/v5/resource/get', |
35 | body: { | 35 | body: { |
-
Please register or login to post a comment