Authored by 于良

Native读取host、channel review by 草莓

... ... @@ -24,10 +24,11 @@ import BrandStoreContainer from './containers/BrandStoreContainer';
import {
setPlatform,
setChannel,
setHost,
} from './reducers/app/appActions';
import {
setScanType,
setShopId,
} from './reducers/brandStore/brandStoreActions';
... ... @@ -46,8 +47,11 @@ export default function native(platform) {
render() {
const store = configureStore(getInitialState());
store.dispatch(setPlatform(platform));
let storeId = this.props.storeId;
let {storeId, host, channel} = this.props;
store.dispatch(setHost(host));
store.dispatch(setChannel(channel));
store.dispatch(setShopId(storeId));
return (
<Provider store={store}>
<BrandStoreContainer />
... ...
import keyMirror from 'key-mirror';
export default keyMirror({
SET_COLLECTION: null,
SET_STOREFILTER:null,
SEL_BRANDITEM:null,
SEL_COUPONITEM:null,
SET_PLATFORM: null,
SET_HOST: null,
SET_CHANNEL: null,
SET_COLLECTION: null,
SET_STOREFILTER: null,
SEL_BRANDITEM: null,
SEL_COUPONITEM: null,
SET_SHOP_ID: null,
SHOP_INFO_SUCCESS: null,
... ...
... ... @@ -5,6 +5,7 @@ import ReactNative from 'react-native';
const {
SET_PLATFORM,
SET_CHANNEL,
SET_HOST,
} = require('../../constants/actionTypes').default;
... ... @@ -21,3 +22,10 @@ export function setChannel(channel) {
payload: channel
};
}
export function setHost(host) {
return {
type: SET_HOST,
payload: host
};
}
... ...
... ... @@ -5,6 +5,7 @@ import {Record, List, Map} from 'immutable';
let InitialState = Record({
platform: 'ios', // ios, android
channel: 1, // 1 - boy, 2 - girl, 3 - kid, 4 - lifestyle, 5 - yoho
host: 'http://api.yoho.cn',
});
export default InitialState;
... ...
... ... @@ -5,6 +5,7 @@ import InitialState from './appInitialState';
const {
SET_PLATFORM,
SET_CHANNEL,
SET_HOST,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -17,6 +18,8 @@ export default function appReducer(state = initialState, action) {
return state.set('platform', action.payload);
case SET_CHANNEL:
return state.set('channel', action.payload);
case SET_HOST:
return state.set('host', action.payload);
}
return state;
... ...
... ... @@ -84,7 +84,7 @@ export function setStoreFilter(filter) {
export function setShopId(shopId) {
return {
type: SET_SHOP_ID,
payload: 860,
payload: shopId,
};
}
... ... @@ -122,7 +122,7 @@ export function getShopInfo() {
let fetchShopIntroInfo = (shopId, uid) => {
dispatch(shopInfoRequest());
return new BrandStoreService().fetchShopInfo(shopId, uid)
return new BrandStoreService(app.host).fetchShopInfo(shopId, uid)
.then(json => {
dispatch(shopInfoSuccess(json));
})
... ... @@ -175,7 +175,7 @@ export function getShopResources() {
let fetchShopsResourcesInfo = (shopId) => {
dispatch(shopResourceRequest());
return new BrandStoreService().fetchShopResources(shopId)
return new BrandStoreService(app.host).fetchShopResources(shopId)
.then(json => {
let payload = parseShopResources(json, shopId);
dispatch(shopResourcesSuccess(payload));
... ... @@ -230,7 +230,7 @@ export function getShopCouponList() {
let fetchShopCouponList = (shopId, uid) => {
dispatch(shopCouponListRequest());
return new BrandStoreService().fetchShopCouponList(shopId, uid)
return new BrandStoreService(app.host).fetchShopCouponList(shopId, uid)
.then(json => {
let payload = parseCouponList(json);
dispatch(shopCouponListSuccess(payload));
... ... @@ -307,7 +307,7 @@ export function getHotProduct() {
}
dispatch(hotProductRequest());
return new BrandStoreService().searchProductBySkn(productSkn)
return new BrandStoreService(app.host).searchProductBySkn(productSkn)
.then(json => {
_.forEach(json.product_list, (value, key) => {
json.product_list[key].is_soon_sold_out = 'N';
... ... @@ -391,7 +391,7 @@ export function getProductList(reload=false) {
let order = productList.order;
let page = productList.currentPage + 1;
let pageSize = productList.pageSize;
let channel = 1;
let channel = app.channel;
let bSelectedFilterFactor,allFilterFactors;
allFilterFactors = filterFactors.toJS();
... ... @@ -404,7 +404,7 @@ export function getProductList(reload=false) {
}
}
dispatch(productListRequest());
return new BrandStoreService().productList(shopId, channel, order, page, pageSize, allFilterFactors)
return new BrandStoreService(app.host).productList(shopId, channel, order, page, pageSize, allFilterFactors)
.then(json => {
let payload = parseProductList(json);
payload.endReached = payload.currentPage == payload.pageCount;
... ... @@ -601,7 +601,7 @@ export function addFavorite() {
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
return new BrandStoreService().addFavorite(shopId, shopId, uid)
return new BrandStoreService(app.host).addFavorite(shopId, shopId, uid)
.then(json => {
console.log('收藏成功');
dispatch(addFavoriteSuccess());
... ... @@ -614,7 +614,7 @@ export function addFavorite() {
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
return new BrandStoreService().addFavorite(shopId, shopId, uid)
return new BrandStoreService(app.host).addFavorite(shopId, shopId, uid)
.then(json => {
console.log('收藏成功');
dispatch(addFavoriteSuccess());
... ... @@ -636,7 +636,7 @@ export function cancelFavorite() {
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
return new BrandStoreService().cancelFavorite(shopId, shopId, uid)
return new BrandStoreService(app.host).cancelFavorite(shopId, shopId, uid)
.then(json => {
console.log('取消收藏成功');
dispatch(cancelFavoriteSuccess());
... ... @@ -658,13 +658,14 @@ export function getFavoriteState() {
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
return new BrandStoreService().isFavorite(shopId, uid)
return new BrandStoreService(app.host).isFavorite(shopId, uid)
.then(json => {
if (json) {
dispatch(addFavoriteSuccess());
}
})
.catch(error => {
});
})
.catch(error => {
... ...
... ... @@ -4,8 +4,11 @@ import Request from '../../common/services/Request';
export default class BrandStoreService {
constructor () {
let baseURL = 'http://api-test3.yohops.com:9999';
constructor(host) {
let baseURL = 'http://api.yoho.cn';
if(host){
baseURL = host;
}
this.api = new Request(baseURL);
}
... ... @@ -75,7 +78,7 @@ export default class BrandStoreService {
});
}
async productList(shop_id, yh_channel=1, order='s_t_asc', page=1, limit=60, filterFactors, v=7) {
async productList(shop_id, yh_channel=1, order='s_t_asc', page=1, limit=60, filterFactors={}, v=7) {
return await this.api.get({
url: '',
body: {
... ... @@ -119,6 +122,7 @@ export default class BrandStoreService {
throw(error);
});
}
async cancelFavorite(id, fav_id,uid, type='brand', gender=1, v=7) {
return await this.api.get({
url: '',
... ...