...
|
...
|
@@ -23,7 +23,7 @@ const { |
|
|
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
export function getCategoryBList() {
|
|
|
export function getCategoryBList(channel_id) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, classify} = getState();
|
|
|
|
...
|
...
|
@@ -32,7 +32,8 @@ export function getCategoryBList() { |
|
|
return new CategoryBService(app.host).getCategoryBList()
|
|
|
.then(json => {
|
|
|
dispatch(getCategoryBListSuccess(json));
|
|
|
dispatch(getCategoryBSubDetail(1, 5, ""));
|
|
|
|
|
|
dispatch(getCategoryBFirstSubCategoryDetail(channel_id));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(getCategoryBListFailure());
|
...
|
...
|
@@ -40,19 +41,61 @@ export function getCategoryBList() { |
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取子分类的数据,逻辑上先判断缓存数据是否存在,不存在则从网络获取
|
|
|
**/
|
|
|
export function getCategoryBSubCategoryDetail(category_id, category_value){
|
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
|
let {categoryB} = getState();
|
|
|
|
|
|
let currentChannelId = categoryB.currentChannelId;
|
|
|
|
|
|
//检查缓存是否存在数据,如果不存在则获取
|
|
|
let cache = categoryB.cacheSubCateData;
|
|
|
let key = getSubDetailCacheKey(currentChannelId, category_id);
|
|
|
let categoryData = cache.get(key);
|
|
|
|
|
|
//设置当前的类别信息
|
|
|
dispatch(setCurrentCateB(category_id, category_value));
|
|
|
|
|
|
//未命中,访问网络数据
|
|
|
if (!categoryData) {
|
|
|
// console.log("chenlin", "未命中缓存,调用接口访问数据:" + key);
|
|
|
dispatch(getCategoryBSubDetail(currentChannelId, category_id, category_value));
|
|
|
}
|
|
|
//已命中,展示缓存数据
|
|
|
else{
|
|
|
// console.log("chenlin", "命中缓存:" + JSON.stringify(categoryData));
|
|
|
dispatch(getCategoryBSubDetailData(categoryData));
|
|
|
}
|
|
|
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取子分类
|
|
|
**/
|
|
|
function getSubDetailCacheKey(channel_id, category_id){
|
|
|
let key = "CHA_" + channel_id + "_CAT_" + category_id;
|
|
|
return key;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 网络获取子分类的数据
|
|
|
**/
|
|
|
export function getCategoryBSubDetail(channel_id, category_id, category_value) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, classify} = getState();
|
|
|
let {app} = getState();
|
|
|
|
|
|
dispatch(getCategoryBSubDetailRequest());
|
|
|
|
|
|
return new CategoryBService(app.host).getCategoryBSubDetail(channel_id, category_id)
|
|
|
.then(json => {
|
|
|
let payload = parseCategoryBSubDetail(channel_id, category_id, json);
|
|
|
dispatch(setCurrentCateB(category_id, category_value));
|
|
|
dispatch(getCategoryBSubDetailSuccess(payload));
|
|
|
})
|
|
|
.catch(error => {
|
...
|
...
|
@@ -62,12 +105,29 @@ export function getCategoryBSubDetail(channel_id, category_id, category_value) { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 从缓存获取的子分类的数据
|
|
|
*获取指定channel的第一个分类数据
|
|
|
**/
|
|
|
export function getCategoryBSubDetailFromCache(sub_data, category_id, category_value) {
|
|
|
export function getCategoryBFirstSubCategoryDetail(channel_id) {
|
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
dispatch(setCurrentCateB(category_id, category_value));
|
|
|
dispatch(getCategoryBSubDetailData(sub_data));
|
|
|
let {categoryB} = getState();
|
|
|
|
|
|
let categoryList = categoryB.categoryList;
|
|
|
|
|
|
let category = null;
|
|
|
if(channel_id == '1'){
|
|
|
category = categoryList.get('boy').get(0);
|
|
|
}
|
|
|
else if(channel_id == '2'){
|
|
|
category = categoryList.get('girl').get(0);
|
|
|
}
|
|
|
else if(channel_id == '3'){
|
|
|
category = categoryList.get('kids').get(0);
|
|
|
}
|
|
|
else if(channel_id == '4'){
|
|
|
category = categoryList.get('lifestyle').get(0);
|
|
|
}
|
|
|
dispatch(getCategoryBSubCategoryDetail(category.get('category_id'), category.get('category_name')));
|
|
|
};
|
|
|
}
|
|
|
|
...
|
...
|
@@ -75,138 +135,33 @@ export function getCategoryBSubDetailFromCache(sub_data, category_id, category_v |
|
|
/**
|
|
|
*在尾部添加一个MORE
|
|
|
**/
|
|
|
function parseCategoryBSubDetail(channel_id, category_id, json) {
|
|
|
if(!json){
|
|
|
function parseCategoryBSubDetail(channel_id, category_id, data) {
|
|
|
if(!data){
|
|
|
return;
|
|
|
}
|
|
|
// let oldData = json ? json : [];
|
|
|
|
|
|
// let newData=[];
|
|
|
|
|
|
|
|
|
// oldData.map((item, i) => {
|
|
|
// let newSortInfo = [];
|
|
|
// let all = {
|
|
|
// category_name: '全部'+item.category_name,
|
|
|
// parent_id: item.category_id,
|
|
|
// // parent_id: item.parent_id,
|
|
|
// relation_parameter:item.relation_parameter,
|
|
|
// node_count:item.node_count,
|
|
|
// };
|
|
|
// if(item.sortInfo){
|
|
|
// newSortInfo=[...item.sortInfo, all];
|
|
|
// }else{
|
|
|
// newSortInfo.push(all);
|
|
|
// }
|
|
|
|
|
|
// newData.push({
|
|
|
// sortInfo:newSortInfo,
|
|
|
// category_name:item.category_name,
|
|
|
// category_id:item.category_id,
|
|
|
// parent_id:item.parent_id,
|
|
|
// relation_parameter:item.relation_parameter,
|
|
|
// sort_ico:item.sort_ico,
|
|
|
// node_count:item.node_count,
|
|
|
// brandInfo: item.brandInfo,
|
|
|
// });
|
|
|
// });
|
|
|
|
|
|
// console.log("chenlin", "处理后的JSON数据:" + JSON.stringify(newData));
|
|
|
|
|
|
let key = "CHA_" + channel_id + "_CAT_" + category_id;
|
|
|
if(data.sortInfo){
|
|
|
let more = {
|
|
|
category_name: 'more',
|
|
|
parent_id: category_id,
|
|
|
relation_parameter:{},
|
|
|
data_type:'text',
|
|
|
};
|
|
|
data.sortInfo.push(more);
|
|
|
}
|
|
|
|
|
|
let key = getSubDetailCacheKey(channel_id, category_id);
|
|
|
// let newData = {
|
|
|
// bannerInfo: data.bannerInfo,
|
|
|
// sortInfo: data.sortInfo,
|
|
|
// brandInfo: data.brandInfo,
|
|
|
// }
|
|
|
|
|
|
// console.log("chenlin", "parseCategoryBSubDetail处理后的JSON数据:" + JSON.stringify(data));
|
|
|
|
|
|
|
|
|
return {key: key, data: data};
|
|
|
|
|
|
return {key: key, data: json};
|
|
|
// return json;
|
|
|
// //女
|
|
|
// girl.map((item, i) => {
|
|
|
// let newGirlSub=[];
|
|
|
// let all={
|
|
|
// category_name: '全部'+item.category_name,
|
|
|
// parent_id: item.category_id,
|
|
|
// // parent_id: item.parent_id,
|
|
|
// relation_parameter:item.relation_parameter,
|
|
|
// node_count:item.node_count,
|
|
|
// };
|
|
|
|
|
|
// if(item.sub){
|
|
|
// newGirlSub=[all,...item.sub];
|
|
|
// }else{
|
|
|
// newGirlSub.push(all);
|
|
|
// }
|
|
|
|
|
|
// newGirl.push({
|
|
|
// sub:newGirlSub,
|
|
|
// category_name:item.category_name,
|
|
|
// category_id:item.category_id,
|
|
|
// parent_id:item.parent_id,
|
|
|
// relation_parameter:item.relation_parameter,
|
|
|
// sort_ico:item.sort_ico,
|
|
|
// node_count:item.node_count,
|
|
|
// });
|
|
|
// });
|
|
|
|
|
|
// //kid
|
|
|
// kids.map((item, i) => {
|
|
|
// let newKidsSub=[];
|
|
|
// let all={
|
|
|
// category_name: '全部'+item.category_name,
|
|
|
// parent_id: item.category_id,
|
|
|
// // parent_id: item.parent_id,
|
|
|
// relation_parameter:item.relation_parameter,
|
|
|
// node_count:item.node_count,
|
|
|
// };
|
|
|
|
|
|
// if(item.sub){
|
|
|
// newKidsSub=[all,...item.sub];
|
|
|
// }else{
|
|
|
// newKidsSub.push(all);
|
|
|
// }
|
|
|
|
|
|
// newKids.push({
|
|
|
// sub:newKidsSub,
|
|
|
// category_name:item.category_name,
|
|
|
// category_id:item.category_id,
|
|
|
// parent_id:item.parent_id,
|
|
|
// relation_parameter:item.relation_parameter,
|
|
|
// sort_ico:item.sort_ico,
|
|
|
// node_count:item.node_count,
|
|
|
// });
|
|
|
// });
|
|
|
|
|
|
// //家居
|
|
|
// lifestyle.map((item, i) => {
|
|
|
// let newLifestyleSub=[];
|
|
|
// let all={
|
|
|
// category_name: '全部'+item.category_name,
|
|
|
// parent_id: item.category_id,
|
|
|
// // parent_id: item.parent_id,
|
|
|
// relation_parameter:item.relation_parameter,
|
|
|
// node_count:item.node_count,
|
|
|
// };
|
|
|
// if(item.sub){
|
|
|
// newLifestyleSub=[all,...item.sub];
|
|
|
|
|
|
// }else{
|
|
|
// newLifestyleSub.push(all);
|
|
|
// }
|
|
|
|
|
|
// newLifestyle.push({
|
|
|
// sub:newLifestyleSub,
|
|
|
// category_name:item.category_name,
|
|
|
// category_id:item.category_id,
|
|
|
// parent_id:item.parent_id,
|
|
|
// relation_parameter:item.relation_parameter,
|
|
|
// sort_ico:item.sort_ico,
|
|
|
// node_count:item.node_count,
|
|
|
// });
|
|
|
// });
|
|
|
|
|
|
// return {
|
|
|
// boy:newBoy,
|
|
|
// girl:newGirl,
|
|
|
// kids:newKids,
|
|
|
// lifestyle:newLifestyle,
|
|
|
// };
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|