Authored by 于良

分类数据上报等到页面出现再上报 review by chenlin

... ... @@ -42,6 +42,7 @@ import {
import {
setCurrentChannelB,
setPerloadStatus,
} from './reducers/categoryB/categoryBActions';
import {
... ... @@ -104,6 +105,11 @@ export default function native(platform) {
//B版设置channelID和名称
store.dispatch(setCurrentChannelB('4', 'lifestyle'));
}
//如果是B版,则打开B版品类
if (this.props.abversion == "B") {
store.dispatch(setPerloadStatus(this.props.perload));
}
} else if (this.props.type == 1) {
if (this.props.channelId) {
store.dispatch(setBrandSelectedChannel(this.props.channelId));
... ...
... ... @@ -9,6 +9,9 @@ export default keyMirror({
SET_CHANNEL: null,
SET_TYPE: null,
SET_INITIALLISTSIZE: null,
SET_PERLOAD_STATUS: null,
RESET_LIST_PAGE_INFO: null,
SHOW_LOGIN_TIP: null,
... ...
... ... @@ -76,6 +76,14 @@ class CategoryBContainer extends Component {
this._onSelectChannel({id, value});
}
);
this.subscription2 = NativeAppEventEmitter.addListener(
'CategoryViewDidAppearEvent',
() => {
this.props.categoryB.perload && this.props.actions.startExposeData();
this.props.actions.setPerloadStatus(false);
}
);
}
componentDidMount() {
... ... @@ -84,6 +92,7 @@ class CategoryBContainer extends Component {
componentWillUnmount() {
this.subscription && this.subscription.remove();
this.subscription2 && this.subscription2.remove();
}
_onSelectChannel(channel) {
... ...
... ... @@ -5,6 +5,7 @@ import CategoryBService from '../../services/CategoryBService';
import Immutable, {Map} from 'immutable';
const {
SET_TYPE,
SET_PERLOAD_STATUS,
GET_CATEGORY_B_LIST_REQUEST,
GET_CATEGORY_B_LIST_SUCCESS,
... ... @@ -23,6 +24,14 @@ const {
} = require('../../constants/actionTypes').default;
export function setPerloadStatus(perload) {
return {
type: SET_PERLOAD_STATUS,
payload: perload,
}
}
export function getCategoryBList() {
return (dispatch, getState) => {
let {app, categoryB} = getState();
... ... @@ -84,17 +93,22 @@ export function fetchSubCategory(categoryId, categoryValue, callback) {
currentCateId,
currentCateValue,
cacheSubCateData,
perload,
} = categoryB;
//检查缓存是否存在数据,如果不存在则获取
let key = getSubDetailCacheKey(currentChannelId, categoryId);
let categoryData = cacheSubCateData ? cacheSubCateData.get(key) : "";
//未命中,访问网络数据
//已命中,展示缓存数据
if (categoryData) {
dispatch(getCategoryBSubDetailFromCache(categoryData));
//曝光从缓存获取的数据
dispatch(dataExposure(currentChannelId, categoryId, categoryValue, categoryData));
//已命中,展示缓存数据
if (perload) {
} else {
//曝光从缓存获取的数据
dispatch(dataExposure(currentChannelId, categoryId, categoryValue, categoryData));
}
//未命中,访问网络数据
} else {
callback && callback();
}
... ... @@ -166,8 +180,13 @@ export function getCategoryBSubDetail(channel_id, category_id, category_value) {
.then(json => {
let payload = parseCategoryBSubDetail(channel_id, category_id, json, categoryB);
dispatch(getCategoryBSubDetailSuccess(payload));
//曝光从网络获取的数据
dispatch(dataExposure(channel_id, category_id, category_value, json));
if (categoryB.perload) {
} else {
//曝光从网络获取的数据
dispatch(dataExposure(channel_id, category_id, category_value, json));
}
})
.catch(error => {
dispatch(getCategoryBSubDetailFailure(error));
... ... @@ -282,6 +301,30 @@ export function jumpToCategory(value, index, channelId){
}
}
export function startExposeData() {
return (dispatch, getState) => {
let {
categoryB
} = getState();
let {
currentChannelId,
currentCateId,
currentCateValue,
cacheSubCateData,
perload,
} = categoryB;
//检查缓存是否存在数据,如果不存在则获取
let key = getSubDetailCacheKey(currentChannelId, currentCateId);
let categoryData = cacheSubCateData ? cacheSubCateData.get(key) : "";
//已命中,展示缓存数据
if (categoryData) {
//曝光从缓存获取的数据
dispatch(dataExposure(currentChannelId, currentCateId, currentCateValue, categoryData));
}
}
}
function dataExposure(channel_id, category_id, category_value, json) {
return (dispatch, getState) => {
... ... @@ -289,79 +332,85 @@ function dataExposure(channel_id, category_id, category_value, json) {
return;
}
let dataList = [];
//bannerInfo数据曝光
let bannerInfo = json.bannerInfo;
if(bannerInfo && bannerInfo.length > 0){
let bannerList = [];
bannerInfo.map((item, i) => {
bannerList.push({
I_INDEX: i + 1 + '',
F_URL: item.data[0].url,
});
})
let bannerData = {
L1_CATE: category_id + '',
F_ID: '1001',
F_NAME: 'BANNER',
LIST: bannerList,
try {
let dataList = [];
//bannerInfo数据曝光
let bannerInfo = json.bannerInfo;
if(bannerInfo && bannerInfo.length > 0){
let bannerList = [];
bannerInfo.map((item, i) => {
bannerList.push({
I_INDEX: i + 1 + '',
F_URL: item.data[0].url,
});
})
let bannerData = {
L1_CATE: category_id + '',
F_ID: '1001',
F_NAME: 'BANNER',
LIST: bannerList,
}
dataList.push(bannerData);
}
dataList.push(bannerData);
}
//sortInfo数据
let sortInfo = json.sortInfo;
if(sortInfo && sortInfo.length > 0){
let sortList = [];
sortInfo.map((item, i) => {
sortList.push({
I_INDEX: i + 1 + '',
PRD_SKN: item.product_skn + '',
L2_CATE: item.category_id + '',
});
})
let sortData = {
L1_CATE: category_id + '',
F_ID: '1002',
F_NAME: '全部'+category_value,
LIST: sortList,
//sortInfo数据
let sortInfo = json.sortInfo;
if(sortInfo && sortInfo.length > 0){
let sortList = [];
sortInfo.map((item, i) => {
sortList.push({
I_INDEX: i + 1 + '',
PRD_SKN: item.product_skn + '',
L2_CATE: item.category_id + '',
});
})
let sortData = {
L1_CATE: category_id + '',
F_ID: '1002',
F_NAME: '全部'+category_value,
LIST: sortList,
}
dataList.push(sortData);
}
dataList.push(sortData);
}
//brandInfo数据
let brandInfo = json.brandInfo;
if(brandInfo && brandInfo.length > 0){
let brandList = [];
brandInfo.map((item, i) => {
brandList.push({
I_INDEX: i + 1 + '',
BRAND_ID: item.id + '',
});
})
let brandData = {
L1_CATE: category_id + '',
F_ID: '1003',
F_NAME: '热门品牌',
LIST: brandList,
//brandInfo数据
let brandInfo = json.brandInfo;
if(brandInfo && brandInfo.length > 0){
let brandList = [];
brandInfo.map((item, i) => {
brandList.push({
I_INDEX: i + 1 + '',
BRAND_ID: item.id + '',
});
})
let brandData = {
L1_CATE: category_id + '',
F_ID: '1003',
F_NAME: '热门品牌',
LIST: brandList,
}
dataList.push(brandData);
}
dataList.push(brandData);
}
let params = {
TAB_ID: channel_id + '',
DATA: dataList,
};
let params = {
TAB_ID: channel_id + '',
DATA: dataList,
};
ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_SHOW_CATEGORY', params);
} catch (e) {
__DEV__ && console.error(e);
} finally {
ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_SHOW_CATEGORY', params);
}
};
}
\ No newline at end of file
... ...
... ... @@ -13,7 +13,7 @@ let InitialStateB = Record({
cacheSubCateData: Map(),
categoryList: Map(),
contentFetching: false,
perload: true,
});
export default InitialStateB;
... ...
... ... @@ -4,6 +4,8 @@ import InitialStateB from './categoryBInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_PERLOAD_STATUS,
GET_CATEGORY_B_LIST_REQUEST,
GET_CATEGORY_B_LIST_SUCCESS,
GET_CATEGORY_B_LIST_FAILURE,
... ... @@ -24,6 +26,9 @@ const initialStateB = new InitialStateB;
export default function categoryBReducer(state=initialStateB, action) {
switch(action.type) {
case SET_PERLOAD_STATUS: {
return state.set('perload', action.payload);
}
case GET_CATEGORY_B_LIST_REQUEST: {
return state.set('isFetching', true)
... ...