Authored by 于良

Native读取host、channel review by 草莓

@@ -24,10 +24,11 @@ import BrandStoreContainer from './containers/BrandStoreContainer'; @@ -24,10 +24,11 @@ import BrandStoreContainer from './containers/BrandStoreContainer';
24 24
25 import { 25 import {
26 setPlatform, 26 setPlatform,
  27 + setChannel,
  28 + setHost,
27 } from './reducers/app/appActions'; 29 } from './reducers/app/appActions';
28 30
29 import { 31 import {
30 - setScanType,  
31 setShopId, 32 setShopId,
32 } from './reducers/brandStore/brandStoreActions'; 33 } from './reducers/brandStore/brandStoreActions';
33 34
@@ -46,8 +47,11 @@ export default function native(platform) { @@ -46,8 +47,11 @@ export default function native(platform) {
46 render() { 47 render() {
47 const store = configureStore(getInitialState()); 48 const store = configureStore(getInitialState());
48 store.dispatch(setPlatform(platform)); 49 store.dispatch(setPlatform(platform));
49 - let storeId = this.props.storeId; 50 + let {storeId, host, channel} = this.props;
  51 + store.dispatch(setHost(host));
  52 + store.dispatch(setChannel(channel));
50 store.dispatch(setShopId(storeId)); 53 store.dispatch(setShopId(storeId));
  54 +
51 return ( 55 return (
52 <Provider store={store}> 56 <Provider store={store}>
53 <BrandStoreContainer /> 57 <BrandStoreContainer />
1 import keyMirror from 'key-mirror'; 1 import keyMirror from 'key-mirror';
2 2
3 export default keyMirror({ 3 export default keyMirror({
4 - SET_COLLECTION: null,  
5 - SET_STOREFILTER:null,  
6 - SEL_BRANDITEM:null,  
7 - SEL_COUPONITEM:null,  
8 SET_PLATFORM: null, 4 SET_PLATFORM: null,
  5 + SET_HOST: null,
  6 + SET_CHANNEL: null,
  7 +
  8 + SET_COLLECTION: null,
  9 + SET_STOREFILTER: null,
  10 + SEL_BRANDITEM: null,
  11 + SEL_COUPONITEM: null,
9 SET_SHOP_ID: null, 12 SET_SHOP_ID: null,
10 13
11 SHOP_INFO_SUCCESS: null, 14 SHOP_INFO_SUCCESS: null,
@@ -5,6 +5,7 @@ import ReactNative from 'react-native'; @@ -5,6 +5,7 @@ import ReactNative from 'react-native';
5 const { 5 const {
6 SET_PLATFORM, 6 SET_PLATFORM,
7 SET_CHANNEL, 7 SET_CHANNEL,
  8 + SET_HOST,
8 9
9 } = require('../../constants/actionTypes').default; 10 } = require('../../constants/actionTypes').default;
10 11
@@ -21,3 +22,10 @@ export function setChannel(channel) { @@ -21,3 +22,10 @@ export function setChannel(channel) {
21 payload: channel 22 payload: channel
22 }; 23 };
23 } 24 }
  25 +
  26 +export function setHost(host) {
  27 + return {
  28 + type: SET_HOST,
  29 + payload: host
  30 + };
  31 +}
@@ -5,6 +5,7 @@ import {Record, List, Map} from 'immutable'; @@ -5,6 +5,7 @@ import {Record, List, Map} from 'immutable';
5 let InitialState = Record({ 5 let InitialState = Record({
6 platform: 'ios', // ios, android 6 platform: 'ios', // ios, android
7 channel: 1, // 1 - boy, 2 - girl, 3 - kid, 4 - lifestyle, 5 - yoho 7 channel: 1, // 1 - boy, 2 - girl, 3 - kid, 4 - lifestyle, 5 - yoho
  8 + host: 'http://api.yoho.cn',
8 }); 9 });
9 10
10 export default InitialState; 11 export default InitialState;
@@ -5,6 +5,7 @@ import InitialState from './appInitialState'; @@ -5,6 +5,7 @@ import InitialState from './appInitialState';
5 const { 5 const {
6 SET_PLATFORM, 6 SET_PLATFORM,
7 SET_CHANNEL, 7 SET_CHANNEL,
  8 + SET_HOST,
8 } = require('../../constants/actionTypes').default; 9 } = require('../../constants/actionTypes').default;
9 10
10 const initialState = new InitialState; 11 const initialState = new InitialState;
@@ -17,6 +18,8 @@ export default function appReducer(state = initialState, action) { @@ -17,6 +18,8 @@ export default function appReducer(state = initialState, action) {
17 return state.set('platform', action.payload); 18 return state.set('platform', action.payload);
18 case SET_CHANNEL: 19 case SET_CHANNEL:
19 return state.set('channel', action.payload); 20 return state.set('channel', action.payload);
  21 + case SET_HOST:
  22 + return state.set('host', action.payload);
20 } 23 }
21 24
22 return state; 25 return state;
@@ -84,7 +84,7 @@ export function setStoreFilter(filter) { @@ -84,7 +84,7 @@ export function setStoreFilter(filter) {
84 export function setShopId(shopId) { 84 export function setShopId(shopId) {
85 return { 85 return {
86 type: SET_SHOP_ID, 86 type: SET_SHOP_ID,
87 - payload: 860, 87 + payload: shopId,
88 }; 88 };
89 } 89 }
90 90
@@ -122,7 +122,7 @@ export function getShopInfo() { @@ -122,7 +122,7 @@ export function getShopInfo() {
122 122
123 let fetchShopIntroInfo = (shopId, uid) => { 123 let fetchShopIntroInfo = (shopId, uid) => {
124 dispatch(shopInfoRequest()); 124 dispatch(shopInfoRequest());
125 - return new BrandStoreService().fetchShopInfo(shopId, uid) 125 + return new BrandStoreService(app.host).fetchShopInfo(shopId, uid)
126 .then(json => { 126 .then(json => {
127 dispatch(shopInfoSuccess(json)); 127 dispatch(shopInfoSuccess(json));
128 }) 128 })
@@ -175,7 +175,7 @@ export function getShopResources() { @@ -175,7 +175,7 @@ export function getShopResources() {
175 175
176 let fetchShopsResourcesInfo = (shopId) => { 176 let fetchShopsResourcesInfo = (shopId) => {
177 dispatch(shopResourceRequest()); 177 dispatch(shopResourceRequest());
178 - return new BrandStoreService().fetchShopResources(shopId) 178 + return new BrandStoreService(app.host).fetchShopResources(shopId)
179 .then(json => { 179 .then(json => {
180 let payload = parseShopResources(json, shopId); 180 let payload = parseShopResources(json, shopId);
181 dispatch(shopResourcesSuccess(payload)); 181 dispatch(shopResourcesSuccess(payload));
@@ -230,7 +230,7 @@ export function getShopCouponList() { @@ -230,7 +230,7 @@ export function getShopCouponList() {
230 230
231 let fetchShopCouponList = (shopId, uid) => { 231 let fetchShopCouponList = (shopId, uid) => {
232 dispatch(shopCouponListRequest()); 232 dispatch(shopCouponListRequest());
233 - return new BrandStoreService().fetchShopCouponList(shopId, uid) 233 + return new BrandStoreService(app.host).fetchShopCouponList(shopId, uid)
234 .then(json => { 234 .then(json => {
235 let payload = parseCouponList(json); 235 let payload = parseCouponList(json);
236 dispatch(shopCouponListSuccess(payload)); 236 dispatch(shopCouponListSuccess(payload));
@@ -307,7 +307,7 @@ export function getHotProduct() { @@ -307,7 +307,7 @@ export function getHotProduct() {
307 } 307 }
308 308
309 dispatch(hotProductRequest()); 309 dispatch(hotProductRequest());
310 - return new BrandStoreService().searchProductBySkn(productSkn) 310 + return new BrandStoreService(app.host).searchProductBySkn(productSkn)
311 .then(json => { 311 .then(json => {
312 _.forEach(json.product_list, (value, key) => { 312 _.forEach(json.product_list, (value, key) => {
313 json.product_list[key].is_soon_sold_out = 'N'; 313 json.product_list[key].is_soon_sold_out = 'N';
@@ -391,7 +391,7 @@ export function getProductList(reload=false) { @@ -391,7 +391,7 @@ export function getProductList(reload=false) {
391 let order = productList.order; 391 let order = productList.order;
392 let page = productList.currentPage + 1; 392 let page = productList.currentPage + 1;
393 let pageSize = productList.pageSize; 393 let pageSize = productList.pageSize;
394 - let channel = 1; 394 + let channel = app.channel;
395 395
396 let bSelectedFilterFactor,allFilterFactors; 396 let bSelectedFilterFactor,allFilterFactors;
397 allFilterFactors = filterFactors.toJS(); 397 allFilterFactors = filterFactors.toJS();
@@ -404,7 +404,7 @@ export function getProductList(reload=false) { @@ -404,7 +404,7 @@ export function getProductList(reload=false) {
404 } 404 }
405 } 405 }
406 dispatch(productListRequest()); 406 dispatch(productListRequest());
407 - return new BrandStoreService().productList(shopId, channel, order, page, pageSize, allFilterFactors) 407 + return new BrandStoreService(app.host).productList(shopId, channel, order, page, pageSize, allFilterFactors)
408 .then(json => { 408 .then(json => {
409 let payload = parseProductList(json); 409 let payload = parseProductList(json);
410 payload.endReached = payload.currentPage == payload.pageCount; 410 payload.endReached = payload.currentPage == payload.pageCount;
@@ -601,7 +601,7 @@ export function addFavorite() { @@ -601,7 +601,7 @@ export function addFavorite() {
601 601
602 ReactNative.NativeModules.YH_CommonHelper.uid() 602 ReactNative.NativeModules.YH_CommonHelper.uid()
603 .then(uid => { 603 .then(uid => {
604 - return new BrandStoreService().addFavorite(shopId, shopId, uid) 604 + return new BrandStoreService(app.host).addFavorite(shopId, shopId, uid)
605 .then(json => { 605 .then(json => {
606 console.log('收藏成功'); 606 console.log('收藏成功');
607 dispatch(addFavoriteSuccess()); 607 dispatch(addFavoriteSuccess());
@@ -614,7 +614,7 @@ export function addFavorite() { @@ -614,7 +614,7 @@ export function addFavorite() {
614 .catch(error => { 614 .catch(error => {
615 ReactNative.NativeModules.YH_CommonHelper.login() 615 ReactNative.NativeModules.YH_CommonHelper.login()
616 .then(uid => { 616 .then(uid => {
617 - return new BrandStoreService().addFavorite(shopId, shopId, uid) 617 + return new BrandStoreService(app.host).addFavorite(shopId, shopId, uid)
618 .then(json => { 618 .then(json => {
619 console.log('收藏成功'); 619 console.log('收藏成功');
620 dispatch(addFavoriteSuccess()); 620 dispatch(addFavoriteSuccess());
@@ -636,7 +636,7 @@ export function cancelFavorite() { @@ -636,7 +636,7 @@ export function cancelFavorite() {
636 636
637 ReactNative.NativeModules.YH_CommonHelper.uid() 637 ReactNative.NativeModules.YH_CommonHelper.uid()
638 .then(uid => { 638 .then(uid => {
639 - return new BrandStoreService().cancelFavorite(shopId, shopId, uid) 639 + return new BrandStoreService(app.host).cancelFavorite(shopId, shopId, uid)
640 .then(json => { 640 .then(json => {
641 console.log('取消收藏成功'); 641 console.log('取消收藏成功');
642 dispatch(cancelFavoriteSuccess()); 642 dispatch(cancelFavoriteSuccess());
@@ -658,13 +658,14 @@ export function getFavoriteState() { @@ -658,13 +658,14 @@ export function getFavoriteState() {
658 658
659 ReactNative.NativeModules.YH_CommonHelper.uid() 659 ReactNative.NativeModules.YH_CommonHelper.uid()
660 .then(uid => { 660 .then(uid => {
661 - return new BrandStoreService().isFavorite(shopId, uid) 661 + return new BrandStoreService(app.host).isFavorite(shopId, uid)
662 .then(json => { 662 .then(json => {
663 if (json) { 663 if (json) {
664 dispatch(addFavoriteSuccess()); 664 dispatch(addFavoriteSuccess());
665 } 665 }
666 }) 666 })
667 .catch(error => { 667 .catch(error => {
  668 +
668 }); 669 });
669 }) 670 })
670 .catch(error => { 671 .catch(error => {
@@ -4,8 +4,11 @@ import Request from '../../common/services/Request'; @@ -4,8 +4,11 @@ import Request from '../../common/services/Request';
4 4
5 export default class BrandStoreService { 5 export default class BrandStoreService {
6 6
7 - constructor () {  
8 - let baseURL = 'http://api-test3.yohops.com:9999'; 7 + constructor(host) {
  8 + let baseURL = 'http://api.yoho.cn';
  9 + if(host){
  10 + baseURL = host;
  11 + }
9 this.api = new Request(baseURL); 12 this.api = new Request(baseURL);
10 } 13 }
11 14
@@ -75,7 +78,7 @@ export default class BrandStoreService { @@ -75,7 +78,7 @@ export default class BrandStoreService {
75 }); 78 });
76 } 79 }
77 80
78 - async productList(shop_id, yh_channel=1, order='s_t_asc', page=1, limit=60, filterFactors, v=7) { 81 + async productList(shop_id, yh_channel=1, order='s_t_asc', page=1, limit=60, filterFactors={}, v=7) {
79 return await this.api.get({ 82 return await this.api.get({
80 url: '', 83 url: '',
81 body: { 84 body: {
@@ -119,6 +122,7 @@ export default class BrandStoreService { @@ -119,6 +122,7 @@ export default class BrandStoreService {
119 throw(error); 122 throw(error);
120 }); 123 });
121 } 124 }
  125 +
122 async cancelFavorite(id, fav_id,uid, type='brand', gender=1, v=7) { 126 async cancelFavorite(id, fav_id,uid, type='brand', gender=1, v=7) {
123 return await this.api.get({ 127 return await this.api.get({
124 url: '', 128 url: '',