Authored by shangjf

首页接口业务逻辑 review by 于良

... ... @@ -57,6 +57,8 @@ export default class Banner extends React.Component {
let height = this.props.height;
let data = this.props.data.toArray();
height = Math.floor(height);
width = Math.floor(width);
return (
<Swiper
style={styles.banner}
... ...
... ... @@ -28,6 +28,7 @@ export default class Home extends Component {
this._onEndReached = this._onEndReached.bind(this);
this._renderFooter = this._renderFooter.bind(this);
this.trigggePullToRefresh = this.trigggePullToRefresh.bind(this);
this._floorCellRender = this._floorCellRender.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
... ... @@ -35,15 +36,11 @@ export default class Home extends Component {
});
}
componentDidMount() {
this.trigggePullToRefresh();
}
componentWillReceiveProps(nextProps) {
if (nextProps.data.ptr) {
this.listView && this.listView.scrollTo({x: 0, y: 0, animated: false, });
}
}
// componentWillReceiveProps(nextProps) {
// if (nextProps.data.ptr) {
// this.listView && this.listView.scrollTo({x: 0, y: 0, animated: false, });
// }
// }
trigggePullToRefresh() {
if (Platform.OS === 'ios') {
... ... @@ -56,13 +53,34 @@ export default class Home extends Component {
}
_renderRow(rowData, sectionID, rowID) {
switch (sectionID) {
case 'floor': {
return this._floorCellRender(rowData);
}
break;
case 'favorite': {
return null;
}
break;
default:
{
return null;
}
break;
}
return null;
}
_floorCellRender(rowData) {
let template_name = rowData.get('template_name');
switch (template_name) {
case 'focus': {
let data = rowData.get('data');
let bannerHeight = 155 * width / 320;
return (
<Focus
data={rowData}
data={data}
width={width}
height={bannerHeight}
onPress={this.props.onPressBanner}
... ... @@ -70,13 +88,13 @@ export default class Home extends Component {
);
}
break;
case 'appIconList': {
case 'app_icon_list': {
return (
<AppIconList/>
)
}
break;
case 'appHotBrands':{
case 'app_hot_brands':{
return (
<AppHotBrands/>
)
... ... @@ -89,12 +107,10 @@ export default class Home extends Component {
}
break;
default:
{
return null;
}
break;
}
return null;
}
_onEndReached() {
... ... @@ -107,29 +123,28 @@ export default class Home extends Component {
render() {
let {list, ptr, isFetching, endReached, showLoginTip, cachedList} = this.props.data;
let focus = Immutable.fromJS(
[
{
'src':'http://images.haiwainet.cn/2017/0207/20170207033215693.jpg'
},
{
'src':'http://images.haiwainet.cn/2017/0207/20170207033215693.jpg'
},
{
'src':'http://images.haiwainet.cn/2017/0207/20170207033215693.jpg'
},
]
);
let channel = this.props.channel;
let data = this.props.data.boy;
if (channel == 1) {
data = this.props.data.boy;
}else if (channel == 2) {
data = this.props.data.girl;
}else if (channel == 3) {
data = this.props.data.kid;
}else if (channel == 4) {
data = this.props.data.lifeStyle;
}
let {list, isFetching, isFirstLoad, favorite} = data;
let floorList = list.toArray();
let favoriteList = favorite.toJS().list;
let dataSource = {
'focus':[focus],
'appIconList':[1],
'appHotBrands':[1],
'trendsetterCollocation':[1],
};
floor: floorList,
favorite: favoriteList
}
let isPullToRefresh = ptr && isFetching;
let isLoadingMore = false;
let isPullToRefresh = isFetching;
return (
<View style={styles.container}>
... ... @@ -141,7 +156,7 @@ export default class Home extends Component {
dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
renderRow={this._renderRow}
enableEmptySections={true}
enablePullToRefresh={false}
enablePullToRefresh={true}
isOnPullToRefresh={isPullToRefresh}
onRefreshData={() => {
this.props.onRefresh && this.props.onRefresh();
... ...
... ... @@ -6,7 +6,36 @@ export default keyMirror({
SET_HOST: null,
SET_SERVICE_HOST: null,
SET_CHANNEL: null,
HOME_BOY_FLOOR_REQUEST: null,
HOME_BOY_FLOOR_SUCCESS: null,
HOME_BOY_FLOOR_FAILURE: null,
HOME_GIRL_FLOOR_REQUEST: null,
HOME_GIRL_FLOOR_SUCCESS: null,
HOME_GIRL_FLOOR_FAILURE: null,
HOME_KIDS_FLOOR_REQUEST: null,
HOME_KIDS_FLOOR_SUCCESS: null,
HOME_KIDS_FLOOR_FAILURE: null,
HOME_LIFESTYLE_FLOOR_REQUEST: null,
HOME_LIFESTYLE_FLOOR_SUCCESS: null,
HOME_LIFESTYLE_FLOOR_FAILURE: null,
HOME_BOY_FAVORITE_REQUEST: null,
HOME_BOY_FAVORITE_SUCCESS: null,
HOME_BOY_FAVORITE_FAILURE: null,
HOME_GIRL_FAVORITE_REQUEST: null,
HOME_GIRL_FAVORITE_SUCCESS: null,
HOME_GIRL_FAVORITE_FAILURE: null,
HOME_KIDS_FAVORITE_REQUEST: null,
HOME_KIDS_FAVORITE_SUCCESS: null,
HOME_KIDS_FAVORITE_FAILURE: null,
HOME_LIFESTYLE_FAVORITE_REQUEST: null,
HOME_LIFESTYLE_FAVORITE_SUCCESS: null,
HOME_LIFESTYLE_FAVORITE_FAILURE: null,
});
... ...
... ... @@ -16,12 +16,13 @@ import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as homeActions from '../reducers/home/homeActions';
import * as appActions from '../reducers/app/appActions';
import Home from '../components/home/Home';
const actions = [
homeActions,
appActions
];
function mapStateToProps(state) {
... ... @@ -53,13 +54,18 @@ class HomeContainer extends Component {
this.subscription = NativeAppEventEmitter.addListener(
'ChannelDidChangeEvent',
(reminder) => {
this.props.actions.setChannel(reminder.channel);
this.home && this.home.trigggePullToRefresh();
}
);
}
componentDidMount() {
ReactNative.NativeModules.YH_CommonHelper.currentChannel()
.then(result =>{
this.props.actions.setChannel(result[0]);
this.home && this.home.trigggePullToRefresh();
})
}
componentWillUnmount() {
... ... @@ -68,7 +74,7 @@ class HomeContainer extends Component {
_onRefresh() {
InteractionManager.runAfterInteractions(() => {
this.props.actions.fetchFloor();
});
}
... ... @@ -79,7 +85,7 @@ class HomeContainer extends Component {
}
render() {
let {home} = this.props;
let {app, home} = this.props;
return (
<View style={styles.container}>
<Home
... ... @@ -89,6 +95,7 @@ class HomeContainer extends Component {
data={home}
onRefresh={this._onRefresh}
onEndReached={this._onEndReached}
channel={app.channel}
/>
</View>
);
... ...
... ... @@ -5,6 +5,394 @@ import HomeService from '../../services/HomeService';
import store from 'react-native-simple-store';
const {
SET_CHANNEL,
HOME_BOY_FLOOR_REQUEST,
HOME_BOY_FLOOR_SUCCESS,
HOME_BOY_FLOOR_FAILURE,
HOME_GIRL_FLOOR_REQUEST,
HOME_GIRL_FLOOR_SUCCESS,
HOME_GIRL_FLOOR_FAILURE,
HOME_KIDS_FLOOR_REQUEST,
HOME_KIDS_FLOOR_SUCCESS,
HOME_KIDS_FLOOR_FAILURE,
HOME_LIFESTYLE_FLOOR_REQUEST,
HOME_LIFESTYLE_FLOOR_SUCCESS,
HOME_LIFESTYLE_FLOOR_FAILURE,
HOME_BOY_FAVORITE_REQUEST,
HOME_BOY_FAVORITE_SUCCESS,
HOME_BOY_FAVORITE_FAILURE,
HOME_GIRL_FAVORITE_REQUEST,
HOME_GIRL_FAVORITE_SUCCESS,
HOME_GIRL_FAVORITE_FAILURE,
HOME_KIDS_FAVORITE_REQUEST,
HOME_KIDS_FAVORITE_SUCCESS,
HOME_KIDS_FAVORITE_FAILURE,
HOME_LIFESTYLE_FAVORITE_REQUEST,
HOME_LIFESTYLE_FAVORITE_SUCCESS,
HOME_LIFESTYLE_FAVORITE_FAILURE,
} = require('../../constants/actionTypes').default;
export function fetchFloor() {
return (dispatch, getState) => {
let {app, home} = getState();
let channel = app.channel;
if ((channel == 1 && home.boy.isFetching)||
(channel == 2 && home.girl.isFetching)||
(channel == 3 && home.kid.isFetching)||
(channel == 4 && home.lifeStyle.isFetching)) {
return;
}
if (channel == 1) {
dispatch(fetchBoyFloor());
}else if (channel == 2) {
dispatch(fetchGirlFloor());
}else if (channel == 3) {
dispatch(fetchKidsFloor());
}else if (channel == 4) {
dispatch(fetchLifeStyleFloor());
}
let fetchFloorRequest = (sourcePage, contentCode, gender, new_device) => {
return new HomeService(app.serviceHost).fetchHomeFloorRequest(contentCode, channel, gender, sourcePage, new_device)
.then(json => {
let payload = parseHomeFloor(json)
console.log(payload);
if (channel == 1) {
dispatch(fetchBoyFloorSuccess(payload));
}else if (channel == 2) {
dispatch(fetchGirlFloorSuccess(payload));
}else if (channel == 3) {
dispatch(fetchKidsFloorSuccess(payload));
}else if (channel == 4) {
dispatch(fetchLifeStyleFloorSuccess(payload));
}
// 请求商品列表
dispatch(fetchHomeFavoriteList(channel, gender, contentCode, sourcePage));
})
.catch(error => {
if (channel == 1) {
dispatch(fetchBoyFloorFailure(error));
}else if (channel == 2) {
dispatch(fetchGirlFloorFailure(error));
}else if (channel == 3) {
dispatch(fetchKidsFloorFailure(error));
}else if (channel == 4) {
dispatch(fetchLifeStyleFloorFailure(error));
}
});
}
let sourcePage = '';
let contentCode = '';
let gender = '';
let new_device = '';
Promise.all([
ReactNative.NativeModules.YH_CommonHelper.sourcePage('YH_HomeViewController'),
ReactNative.NativeModules.YH_CommonHelper.isNewDevice(),
ReactNative.NativeModules.YH_CommonHelper.currentHomeContentCode(),
ReactNative.NativeModules.YH_CommonHelper.currentGender(),
]).then(result => {
sourcePage = result[0];
new_device = result[1];
contentCode = result[2];
gender = result[3];
fetchFloorRequest(sourcePage, contentCode, gender, new_device);
})
.catch(error => {
fetchFloorRequest(sourcePage, contentCode, gender, new_device);
});
}
}
function fetchHomeFavoriteList(channel, gender, contentCode, fromPage) {
return (dispatch, getState) => {
if (channel == 1 || channel == 2) {
dispatch(fetchBoyGirlFavoriteList(contentCode, gender, fromPage));
}else if (channel == 3) {
dispatch(fetchKidsFavoriteList(fromPage));
}else if (channel == 4) {
dispatch(fetchLifeStyleFavoriteList(fromPage));
}
}
}
export function fetchBoyGirlFavoriteList(contentCode, gender, page, fromPage) {
return (dispatch, getState) => {
let {app, home} = getState();
let channel = app.channel;
let data = home.boy;
if (channel == 1) {
dispatch(fetchBoyFavorite());
}else if (channel == 2) {
data = home.girl;
dispatch(fetchGirlFavorite());
}
let page = data.favorite.get('currentPage') + 1;
return new HomeService(app.host).fetchHomeFavoriteData(channel, contentCode, gender, fromPage, page)
.then(json =>{
let payload = parseHomeFavorite(json);
//商品列表最多分四页
payload.endReached = (payload.currentPage > 4) || (payload.currentPage == payload.pageCount);
if (channel == 1) {
dispatch(fetchBoyFavoriteSuccess(payload));
}else if (channel == 2) {
dispatch(fetchGirlFavoriteSuccess(payload));
}
})
.catch(error =>{
if (channel == 1) {
dispatch(fetchBoyFavoriteFailure(error));
}else if (channel == 2) {
dispatch(fetchGirlFavoriteFailure(error));
}
});
}
}
export function fetchKidsFavoriteList(page, fromPage) {
return (dispatch, getState) => {
let {app, home} = getState();
let data = home.kid;
let page = data.favorite.get('currentPage') + 1;
dispatch(fetchKidsFavorite());
return new HomeService(app.host).fetchHomeKidFavoriteData(fromPage, page)
.then(json =>{
dispatch(fetchKidsFavoriteSuccess(json));
})
.catch(error =>{
dispatch(fetchKidsFavoriteFailure(error));
});
}
}
function fetchLifeStyleFavoriteList(fromPage) {
return (dispatch, getState) => {
let {app, home} = getState();
let data = home.lifeStyle;
let page = data.get('currentPage') + 1;
dispatch(fetchLifeStyleFavorite());
return new HomeService(app.host).fetchHomeHotNewData(fromPage, page)
.then(json =>{
dispatch(fetchLifeStyleFavoriteSuccess(json));
})
.catch(error =>{
dispatch(fetchLifeStyleFavoriteFailure(error));
});
}
}
function parseHomeFloor(json) {
let list = json && json.list ? json.list : [];
let content_code = json && json.content_code ? json.content_code : '';
return {
list,
content_code,
};
}
function parseHomeFavorite(json) {
let currentPage = json && json.page ? json.page : 1;
let pageCount = json && json.page_total ? json.page_total : 0;
let total = json && json.total ? json.total : 0;
let list = json && json.list ? json.list : [];
return {
currentPage,
pageCount,
total,
list
}
}
/******** 首页楼层 *********/
// 开始请求
export function fetchBoyFloor(channel) {
return {
type: HOME_BOY_FLOOR_REQUEST,
};
}
export function fetchGirlFloor(channel) {
return {
type: HOME_GIRL_FLOOR_REQUEST,
};
}
export function fetchKidsFloor(channel) {
return {
type: HOME_KIDS_FLOOR_REQUEST,
};
}
export function fetchLifeStyleFloor(channel) {
return {
type: HOME_LIFESTYLE_FLOOR_REQUEST,
};
}
// 请求成功
export function fetchBoyFloorSuccess(json) {
return {
type: HOME_BOY_FLOOR_SUCCESS,
payload: json
};
}
export function fetchGirlFloorSuccess(json) {
return {
type: HOME_GIRL_FLOOR_SUCCESS,
payload: json
};
}
export function fetchKidsFloorSuccess(json) {
return {
type: HOME_KIDS_FLOOR_SUCCESS,
payload: json
};
}
export function fetchLifeStyleFloorSuccess(json) {
return {
type: HOME_LIFESTYLE_FLOOR_SUCCESS,
payload: json
};
}
// 请求失败
export function fetchBoyFloorFailure(error, channel) {
return {
type: HOME_BOY_FLOOR_FAILURE,
payload: error
};
}
export function fetchGirlFloorFailure(error, channel) {
return {
type: HOME_GIRL_FLOOR_FAILURE,
payload: error
};
}
export function fetchKidsFloorFailure(error, channel) {
return {
type: HOME_KIDS_FLOOR_FAILURE,
payload: error
};
}
export function fetchLifeStyleFloorFailure(error, channel) {
return {
type: HOME_LIFESTYLE_FLOOR_FAILURE,
payload: error
};
}
/******** 首页猜你喜欢商品列表*********/
//开始请求
export function fetchBoyFavorite() {
return {
type: HOME_BOY_FAVORITE_REQUEST,
};
}
export function fetchGirlFavorite() {
return {
type: HOME_GIRL_FAVORITE_REQUEST,
};
}
export function fetchKidsFavorite() {
return {
type: HOME_KIDS_FAVORITE_REQUEST,
};
}
export function fetchLifeStyleFavorite() {
return {
type: HOME_LIFESTYLE_FAVORITE_REQUEST,
};
}
// 请求成功
export function fetchBoyFavoriteSuccess(json) {
return {
type: HOME_BOY_FAVORITE_SUCCESS,
payload: json
};
}
export function fetchGirlFavoriteSuccess(json) {
return {
type: HOME_GIRL_FAVORITE_SUCCESS,
payload: json
};
}
export function fetchKidsFavoriteSuccess(json) {
return {
type: HOME_KIDS_FAVORITE_SUCCESS,
payload: json
};
}
export function fetchLifeStyleFavoriteSuccess(json) {
return {
type: HOME_LIFESTYLE_FAVORITE_SUCCESS,
payload: json
};
}
// 请求失败
export function fetchBoyFavoriteFailure(error) {
return {
type: HOME_BOY_FAVORITE_FAILURE,
payload: error
};
}
export function fetchGirlFavoriteFailure(error) {
return {
type: HOME_GIRL_FAVORITE_FAILURE,
payload: error
};
}
export function fetchKidsFavoriteFailure(error) {
return {
type: HOME_KIDS_FAVORITE_FAILURE,
payload: error
};
}
export function fetchLifeStyleFavoriteFailure(error) {
return {
type: HOME_LIFESTYLE_FAVORITE_FAILURE,
payload: error
};
}
... ...
'use strict';
import {Record, List, Map} from 'immutable';
import Immutable, {Record, List, Map} from 'immutable';
let templet = new Record({
ptr: false, // 是否下拉刷新
let favorite = Immutable.fromJS({
isFetching: false,
currentPage: 0,
pageCount: 0,
pageSize: 50,
endReached: false,
list: List(),
});
let templet = new (Record({
isFetching: false,
isFirstLoad: true,
error: null,
list: List(),
md5:'',
favorite: favorite, //男, 女,潮童频道 猜你喜欢列表
content_code: '',
}));
let lifeStyle = new (Record({
isFetching: false,
isFirstLoad: true,
error: null,
cachedList: List(),
list: List(),
currentPage: 0,
pageCount: 0,
pageSize: 10,
total: 0,
endReached: false,
sourceType: 0, // 0 - 默认,1 - 全球购,2 - 奥莱
md5:'',
favoriteList: List(),
});
isListFetching: false,
hotList: List(), //创意生活频道 人气单品商品列表
newList: List(), //创意生活频道 新品到着商品列表
content_code: '',
}));
let InitialState = Record({
boy: templet,
girl: templet,
kid: templet,
lifeStyle: templet,
lifeStyle: lifeStyle,
});
export default InitialState;
... ...
... ... @@ -4,7 +4,37 @@ import InitialState from './homeInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_CHANNEL,
HOME_BOY_FLOOR_REQUEST,
HOME_BOY_FLOOR_SUCCESS,
HOME_BOY_FLOOR_FAILURE,
HOME_GIRL_FLOOR_REQUEST,
HOME_GIRL_FLOOR_SUCCESS,
HOME_GIRL_FLOOR_FAILURE,
HOME_KIDS_FLOOR_REQUEST,
HOME_KIDS_FLOOR_SUCCESS,
HOME_KIDS_FLOOR_FAILURE,
HOME_LIFESTYLE_FLOOR_REQUEST,
HOME_LIFESTYLE_FLOOR_SUCCESS,
HOME_LIFESTYLE_FLOOR_FAILURE,
HOME_BOY_FAVORITE_REQUEST,
HOME_BOY_FAVORITE_SUCCESS,
HOME_BOY_FAVORITE_FAILURE,
HOME_GIRL_FAVORITE_REQUEST,
HOME_GIRL_FAVORITE_SUCCESS,
HOME_GIRL_FAVORITE_FAILURE,
HOME_KIDS_FAVORITE_REQUEST,
HOME_KIDS_FAVORITE_SUCCESS,
HOME_KIDS_FAVORITE_FAILURE,
HOME_LIFESTYLE_FAVORITE_REQUEST,
HOME_LIFESTYLE_FAVORITE_SUCCESS,
HOME_LIFESTYLE_FAVORITE_FAILURE,
} = require('../../constants/actionTypes').default;
... ... @@ -12,8 +42,105 @@ const initialState = new InitialState;
export default function homeReducer(state=initialState, action) {
switch(action.type) {
case HOME_BOY_FLOOR_REQUEST:{
return state.setIn(['boy', 'isFetching'], true);
}
case HOME_GIRL_FLOOR_REQUEST:{
return state.setIn(['girl', 'isFetching'], true)
.setIn(['girl', 'isFirstLoad'], false);
}
case HOME_KIDS_FLOOR_REQUEST:{
return state.setIn(['kid', 'isFetching'], true)
.setIn(['kid', 'isFirstLoad'], false);
}
case HOME_LIFESTYLE_FLOOR_REQUEST:{
return state.setIn(['lifeStyle', 'isFetching'], true)
.setIn(['lifeStyle', 'isFirstLoad'], false);
}
case HOME_BOY_FLOOR_SUCCESS:{
return state.setIn(['boy', 'isFetching'], false)
.setIn(['boy', 'list'], Immutable.fromJS(action.payload.list))
.setIn(['boy', 'content_code'], Immutable.fromJS(action.payload.content_code))
.setIn(['boy', 'error'], null)
.setIn(['boy', 'isFirstLoad'], false);
}
case HOME_GIRL_FLOOR_SUCCESS:{
return state.setIn(['girl', 'isFetching'], false)
.setIn(['girl', 'list'], Immutable.fromJS(action.payload.list))
.setIn(['girl', 'content_code'], Immutable.fromJS(action.payload.content_code))
.setIn(['girl', 'error'], null)
.setIn(['girl', 'isFirstLoad'], false);
}
case HOME_KIDS_FLOOR_SUCCESS:{
return state.setIn(['kid', 'isFetching'], false)
.setIn(['kid', 'list'], Immutable.fromJS(action.payload.list))
.setIn(['kid', 'content_code'], Immutable.fromJS(action.payload.content_code))
.setIn(['kid', 'error'], null)
.setIn(['kid', 'isFirstLoad'], false);
}
case HOME_LIFESTYLE_FLOOR_SUCCESS:{
return state.setIn(['lifeStyle', 'isFetching'], false)
.setIn(['lifeStyle', 'list'], Immutable.fromJS(action.payload.list))
.setIn(['lifeStyle', 'content_code'], Immutable.fromJS(action.payload.content_code))
.setIn(['lifeStyle', 'error'], null)
.setIn(['lifeStyle', 'isFirstLoad'], false);
}
case HOME_BOY_FLOOR_FAILURE:{
return state.setIn(['boy', 'isFetching'], false)
.setIn(['boy', 'error'], action.payload)
.setIn(['boy', 'isFirstLoad'], false);
}
case HOME_GIRL_FLOOR_FAILURE:{
return state.setIn(['girl', 'isFetching'], false)
.setIn(['girl', 'error'], action.payload)
.setIn(['girl', 'isFirstLoad'], false);
}
case HOME_KIDS_FLOOR_FAILURE:{
return state.setIn(['kid', 'isFetching'], false)
.setIn(['kid', 'error'], action.payload)
.setIn(['kid', 'isFirstLoad'], false);
}
case HOME_LIFESTYLE_FLOOR_FAILURE:{
return state.setIn(['lifeStyle', 'isFetching'], false)
.setIn(['lifeStyle', 'error'], action.payload)
.setIn(['lifeStyle', 'isFirstLoad'], false);
}
case HOME_BOY_FAVORITE_REQUEST:{
}
case HOME_GIRL_FAVORITE_REQUEST:{
}
case HOME_KIDS_FAVORITE_REQUEST:{
}
case HOME_LIFESTYLE_FAVORITE_REQUEST:{
}
case HOME_BOY_FAVORITE_SUCCESS:{
}
case HOME_GIRL_FAVORITE_SUCCESS:{
}
case HOME_KIDS_FAVORITE_SUCCESS:{
}
case HOME_LIFESTYLE_FAVORITE_SUCCESS:{
}
case HOME_BOY_FAVORITE_FAILURE:{
}
case HOME_GIRL_FAVORITE_FAILURE:{
}
case HOME_KIDS_FAVORITE_FAILURE:{
}
case HOME_LIFESTYLE_FAVORITE_FAILURE:{
}
}
return state;
... ...
... ... @@ -11,5 +11,115 @@ export default class HomeService {
}
this.api = new Request(baseURL);
}
async fetchHomeFloorRequest(contentCode, channel, gender, fromPage, new_device, page) {
return await this.api.get({
url: '/operations/api/v5/resource/home',
body: {
page: 1,
limit: 100,
gender,
new_device,
fromPage,
content_code: contentCode,
yh_channel: channel,
v: 7,
}
})
.then((json) => {
json.channel = channel;
return json;
})
.catch((error) => {
throw(error);
});
}
async fetchHomeFavoriteData(channel, contentCode, gender, fromPage, page) {
let rec_pos = '';
switch (channel) {
case 1:
rec_pos = '100001';
break;
case 2:
rec_pos = '100002';
break;
default:
break;
}
console.log(rec_pos);
return await this.api.get({
url: '',
body: {
method: 'app.search.newLast7day',
limit: 50,
page,
yh_channel: channel,
gender,
content_code: contentCode,
fromPage,
rec_pos,
}
})
.then((json) => {
json.channel = channel;
return json;
})
.catch((error) => {
throw(error);
});
}
async fetchHomeKidFavoriteData(fromPage, page) {
return await this.api.get({
url: '',
body: {
method: 'app.search.kids',
limit: 50,
page,
fromPage,
}
})
.then((json) => {
json.channel = 3;
return json;
})
.catch((error) => {
throw(error);
});
}
async fetchHomeHotNewData(fromPage, page) {
return await this.api.get({
url: '',
body: {
method: 'app.search.lifeStyle',
limit: 50,
page,
fromPage,
}
})
.then((json) => {
json.channel = 4;
return json;
})
.catch((error) => {
throw(error);
});
}
async fetchHomeBottomBannerData(contentCode, channel, fromPage) {
return await this.api.get({
url: '/operations/api/v5/resource/get',
body: {
fromPage,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
}
... ...