Authored by chenl

将获取缓存方法调整至Action.js中,删除了部分调试log。review by yuliang。

@@ -39,6 +39,10 @@ import { @@ -39,6 +39,10 @@ import {
39 } from './reducers/category/categoryActions'; 39 } from './reducers/category/categoryActions';
40 40
41 import { 41 import {
  42 + setCurrentChannelB,
  43 +} from './reducers/categoryB/categoryBActions';
  44 +
  45 +import {
42 setBrandSelectedChannel, 46 setBrandSelectedChannel,
43 } from './reducers/brand/brandActions'; 47 } from './reducers/brand/brandActions';
44 48
@@ -77,12 +81,20 @@ export default function native(platform) { @@ -77,12 +81,20 @@ export default function native(platform) {
77 if (this.props.type == 0) { 81 if (this.props.type == 0) {
78 if (this.props.channelId == '1') { 82 if (this.props.channelId == '1') {
79 store.dispatch(setCurrentChannelId('boy')); 83 store.dispatch(setCurrentChannelId('boy'));
  84 + //B版设置channelID和名称
  85 + store.dispatch(setCurrentChannelB('1', 'boy'));
80 } else if (this.props.channelId == '2') { 86 } else if (this.props.channelId == '2') {
81 store.dispatch(setCurrentChannelId('girl')); 87 store.dispatch(setCurrentChannelId('girl'));
  88 + //B版设置channelID和名称
  89 + store.dispatch(setCurrentChannelB('2', 'girl'));
82 } else if (this.props.channelId == '3') { 90 } else if (this.props.channelId == '3') {
83 store.dispatch(setCurrentChannelId('kids')); 91 store.dispatch(setCurrentChannelId('kids'));
  92 + //B版设置channelID和名称
  93 + store.dispatch(setCurrentChannelB('3', 'kids'));
84 } else if (this.props.channelId == '4') { 94 } else if (this.props.channelId == '4') {
85 store.dispatch(setCurrentChannelId('lifestyle')); 95 store.dispatch(setCurrentChannelId('lifestyle'));
  96 + //B版设置channelID和名称
  97 + store.dispatch(setCurrentChannelB('4', 'lifestyle'));
86 } 98 }
87 } else if (this.props.type == 1) { 99 } else if (this.props.type == 1) {
88 if (this.props.channelId) { 100 if (this.props.channelId) {
@@ -27,6 +27,7 @@ export default class CategoryB extends Component { @@ -27,6 +27,7 @@ export default class CategoryB extends Component {
27 let { 27 let {
28 isFetching, 28 isFetching,
29 currentChannelId, 29 currentChannelId,
  30 + currentChannelValue,
30 currentCateId, 31 currentCateId,
31 categoryList, 32 categoryList,
32 currentCateValue, 33 currentCateValue,
@@ -41,6 +42,7 @@ export default class CategoryB extends Component { @@ -41,6 +42,7 @@ export default class CategoryB extends Component {
41 categoryList={categoryList} 42 categoryList={categoryList}
42 currentCateId={currentCateId} 43 currentCateId={currentCateId}
43 currentChannelId={currentChannelId} 44 currentChannelId={currentChannelId}
  45 + currentChannelValue={currentChannelValue}
44 currentCateValue={currentCateValue} 46 currentCateValue={currentCateValue}
45 currentSubCateData={currentSubCateData} 47 currentSubCateData={currentSubCateData}
46 cacheSubCateData={cacheSubCateData} 48 cacheSubCateData={cacheSubCateData}
@@ -24,13 +24,10 @@ export default class CategoryBList extends Component { @@ -24,13 +24,10 @@ export default class CategoryBList extends Component {
24 super(props); 24 super(props);
25 this.renderRow = this.renderRow.bind(this); 25 this.renderRow = this.renderRow.bind(this);
26 this.renderSeparator = this.renderSeparator.bind(this); 26 this.renderSeparator = this.renderSeparator.bind(this);
27 - // this._pressLeftRow = this._pressLeftRow.bind(this);  
28 this.dataSource = new ListView.DataSource({rowHasChanged: (r1, r2) => !immutable.is(r1, r2)}); 27 this.dataSource = new ListView.DataSource({rowHasChanged: (r1, r2) => !immutable.is(r1, r2)});
29 this.subRenderRow = this.subRenderRow.bind(this); 28 this.subRenderRow = this.subRenderRow.bind(this);
30 - this.state = {  
31 - offsetx: 0,  
32 - };  
33 this.cacheChannel=''; 29 this.cacheChannel='';
  30 + this.cacheCategory='';
34 } 31 }
35 componentWillMount() { 32 componentWillMount() {
36 LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); 33 LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
@@ -38,11 +35,15 @@ export default class CategoryBList extends Component { @@ -38,11 +35,15 @@ export default class CategoryBList extends Component {
38 35
39 componentWillUpdate(nextProps,nextState){ 36 componentWillUpdate(nextProps,nextState){
40 if(this.cacheChannel!=nextProps.currentChannelId){ 37 if(this.cacheChannel!=nextProps.currentChannelId){
41 - this.setState({offsetx:0});  
42 this.refs.categoryList && this.refs.categoryList.scrollTo({x: 0, y: 0, animated: false}); 38 this.refs.categoryList && this.refs.categoryList.scrollTo({x: 0, y: 0, animated: false});
43 this.cacheChannel=nextProps.currentChannelId; 39 this.cacheChannel=nextProps.currentChannelId;
44 } 40 }
45 41
  42 + if(this.cacheCategory != nextProps.currentCateId){
  43 + this.refs.subCategoryList && this.refs.subCategoryList.scrollTo({x: 0, y: 0, animated: false});
  44 + this.cacheCategory = nextProps.currentCateId;
  45 + }
  46 +
46 } 47 }
47 // _pressLeftRow(value,rowID){ 48 // _pressLeftRow(value,rowID){
48 // if(value.sub.length==1){ 49 // if(value.sub.length==1){
@@ -129,22 +130,11 @@ export default class CategoryBList extends Component { @@ -129,22 +130,11 @@ export default class CategoryBList extends Component {
129 render() { 130 render() {
130 131
131 let {categoryList, currentSubCateData} = this.props; 132 let {categoryList, currentSubCateData} = this.props;
132 -  
133 -  
134 - if(!categoryList || categoryList.length == 0 || !currentSubCateData || currentSubCateData.length == 0 || categoryList == null) 133 +
  134 + if(!categoryList || categoryList.length == 0 || !currentSubCateData || currentSubCateData.length == 0)
135 return; 135 return;
136 136
137 - let cateList = [];  
138 - let subCateList;  
139 - if(categoryList.get("boy")){  
140 - cateList=categoryList.get("boy").toArray();  
141 - }  
142 - // if(categoryList.get(this.props.currentChannelId).get(this.props.currentCateId)){  
143 - // let currentCate=categoryList.get(this.props.currentChannelId).get(this.props.currentCateId);  
144 - // subCateList=currentCate.get('sub').toArray();  
145 - // }  
146 -  
147 - // console.log("chenlin", "currentSubCateData:" + JSON.stringify(currentSubCateData)); 137 + let cateList = categoryList.get(this.props.currentChannelValue) ? categoryList.get(this.props.currentChannelValue).toArray() : [];
148 138
149 let detailDataSource = { 139 let detailDataSource = {
150 bannerInfo: currentSubCateData.get('bannerInfo'), 140 bannerInfo: currentSubCateData.get('bannerInfo'),
@@ -198,7 +188,7 @@ let styles = StyleSheet.create({ @@ -198,7 +188,7 @@ let styles = StyleSheet.create({
198 subContentContainer: { 188 subContentContainer: {
199 backgroundColor: 'white', 189 backgroundColor: 'white',
200 width: 210 * DEVICE_WIDTH_RATIO, 190 width: 210 * DEVICE_WIDTH_RATIO,
201 - height: height - 156, 191 + height: height - 156 - 5,
202 marginLeft: 5 * DEVICE_WIDTH_RATIO, 192 marginLeft: 5 * DEVICE_WIDTH_RATIO,
203 marginTop: 5 * DEVICE_WIDTH_RATIO, 193 marginTop: 5 * DEVICE_WIDTH_RATIO,
204 marginRight: 5 * DEVICE_WIDTH_RATIO, 194 marginRight: 5 * DEVICE_WIDTH_RATIO,
@@ -53,13 +53,13 @@ export default class HotBrandList extends Component{ @@ -53,13 +53,13 @@ export default class HotBrandList extends Component{
53 return null; 53 return null;
54 } 54 }
55 55
56 - let imageUrl = getSlicedUrl(rowData.get("brand_ico"), 106, 106, 2); 56 + let imageUrl = getSlicedUrl(rowData.get("brand_ico"), 70, 29, 2);
57 let brandName = rowData.get("brand_name"); 57 let brandName = rowData.get("brand_name");
58 58
59 return ( 59 return (
60 - <TouchableOpacity onPress={() => this.props.onPressHotBrandItem && this.props.onPressHotBrandItem(rowData.toJS(),rowID)}> 60 + <TouchableOpacity onPress={() => this.props.onPressHotBrandItem && this.props.onPressHotBrandItem(rowData.toJS())}>
61 <View style={styles.rowContainer}> 61 <View style={styles.rowContainer}>
62 - <Image style={styles.rowThumbnail} source={{uri: imageUrl}}/> 62 + <View style={styles.rowImageContainer}><Image style={styles.rowThumbnail} source={{uri: imageUrl}}/></View>
63 <Text style={styles.rowText} numberOfLines={1}>{brandName}</Text> 63 <Text style={styles.rowText} numberOfLines={1}>{brandName}</Text>
64 </View> 64 </View>
65 </TouchableOpacity> 65 </TouchableOpacity>
@@ -72,14 +72,19 @@ export default class HotBrandList extends Component{ @@ -72,14 +72,19 @@ export default class HotBrandList extends Component{
72 render(){ 72 render(){
73 let {data} = this.props; 73 let {data} = this.props;
74 74
  75 + console.log("chenlin", "data数据长度:" + data.length);
  76 +
  77 +
75 return( 78 return(
76 - <ListView  
77 - contentContainerStyle={styles.contentContainer}  
78 - dataSource={this.dataSource.cloneWithRows(data)}  
79 - enableEmptySections={true}  
80 - renderRow={this.renderRow}  
81 - renderHeader={this.renderHeader}  
82 - /> 79 + <View style={styles.container}>
  80 + <ListView
  81 + contentContainerStyle={styles.contentContainer}
  82 + dataSource={this.dataSource.cloneWithRows(data)}
  83 + enableEmptySections={true}
  84 + renderRow={this.renderRow}
  85 + renderHeader={this.renderHeader}
  86 + />
  87 + </View>
83 ); 88 );
84 } 89 }
85 90
@@ -91,6 +96,10 @@ const DEVICE_WIDTH_RATIO = width / 320; @@ -91,6 +96,10 @@ const DEVICE_WIDTH_RATIO = width / 320;
91 96
92 let styles = StyleSheet.create({ 97 let styles = StyleSheet.create({
93 98
  99 + container: {
  100 + flexWrap: 'wrap',
  101 + },
  102 +
94 contentContainer: { 103 contentContainer: {
95 flexDirection: 'row', 104 flexDirection: 'row',
96 flexWrap: 'wrap', 105 flexWrap: 'wrap',
@@ -99,15 +108,15 @@ let styles = StyleSheet.create({ @@ -99,15 +108,15 @@ let styles = StyleSheet.create({
99 }, 108 },
100 109
101 headerContainer:{ 110 headerContainer:{
102 - width: 200 * DEVICE_WIDTH_RATIO, 111 + width: 210 * DEVICE_WIDTH_RATIO,
103 height: 50 * DEVICE_WIDTH_RATIO, 112 height: 50 * DEVICE_WIDTH_RATIO,
104 - marginLeft: 5 * DEVICE_WIDTH_RATIO,  
105 - marginRight: 5 * DEVICE_WIDTH_RATIO, 113 + paddingLeft: 5 * DEVICE_WIDTH_RATIO,
  114 + paddingRight: 5 * DEVICE_WIDTH_RATIO,
106 }, 115 },
107 116
108 headerText:{ 117 headerText:{
109 position: 'absolute', 118 position: 'absolute',
110 - left: 0, 119 + left: 5 * DEVICE_WIDTH_RATIO,
111 bottom: 11 * DEVICE_WIDTH_RATIO, 120 bottom: 11 * DEVICE_WIDTH_RATIO,
112 fontSize: 12 * DEVICE_WIDTH_RATIO, 121 fontSize: 12 * DEVICE_WIDTH_RATIO,
113 color: '#B0B0B0', 122 color: '#B0B0B0',
@@ -124,23 +133,30 @@ let styles = StyleSheet.create({ @@ -124,23 +133,30 @@ let styles = StyleSheet.create({
124 headerLine:{ 133 headerLine:{
125 width: 200 * DEVICE_WIDTH_RATIO, 134 width: 200 * DEVICE_WIDTH_RATIO,
126 height: 0.5 * DEVICE_WIDTH_RATIO, 135 height: 0.5 * DEVICE_WIDTH_RATIO,
127 - backgroundColor: '#f0f0f0', 136 + backgroundColor: '#E0E0E0',
128 left: 0, 137 left: 0,
129 top: 45 * DEVICE_WIDTH_RATIO, 138 top: 45 * DEVICE_WIDTH_RATIO,
130 }, 139 },
131 140
132 rowContainer:{ 141 rowContainer:{
133 width: 70 * DEVICE_WIDTH_RATIO, 142 width: 70 * DEVICE_WIDTH_RATIO,
134 - height: 90 * DEVICE_WIDTH_RATIO, 143 + height: 70 * DEVICE_WIDTH_RATIO,
135 }, 144 },
136 145
  146 + rowImageContainer:{
  147 + width: 70 * DEVICE_WIDTH_RATIO,
  148 + height: 50 * DEVICE_WIDTH_RATIO,
  149 + justifyContent: 'center',
  150 + },
  151 +
137 rowThumbnail:{ 152 rowThumbnail:{
138 width: 70 * DEVICE_WIDTH_RATIO, 153 width: 70 * DEVICE_WIDTH_RATIO,
139 - height: 70 * DEVICE_WIDTH_RATIO, 154 + height: 29 * DEVICE_WIDTH_RATIO,
140 }, 155 },
141 156
142 rowText:{ 157 rowText:{
143 width: 70 * DEVICE_WIDTH_RATIO, 158 width: 70 * DEVICE_WIDTH_RATIO,
  159 + height: 20 * DEVICE_WIDTH_RATIO,
144 fontSize: 10 * DEVICE_WIDTH_RATIO, 160 fontSize: 10 * DEVICE_WIDTH_RATIO,
145 color: '#B0B0B0', 161 color: '#B0B0B0',
146 textAlign: 'center', 162 textAlign: 'center',
@@ -51,6 +51,9 @@ export default class HotCategoryList extends Component{ @@ -51,6 +51,9 @@ export default class HotCategoryList extends Component{
51 51
52 renderRow(rowData, sectionID, rowID, highlightRow){ 52 renderRow(rowData, sectionID, rowID, highlightRow){
53 53
  54 + // console.log("chenlin", "rowData数据:" + JSON.stringify(rowData));
  55 +
  56 +
54 if (!rowData || rowData.length == 0) { 57 if (!rowData || rowData.length == 0) {
55 return null; 58 return null;
56 } 59 }
@@ -59,8 +62,15 @@ export default class HotCategoryList extends Component{ @@ -59,8 +62,15 @@ export default class HotCategoryList extends Component{
59 let categoryName = rowData.get("category_name"); 62 let categoryName = rowData.get("category_name");
60 63
61 //数据类型,纯文字型和图片型,列表中会出现纯文本的情况,比如MORE 64 //数据类型,纯文字型和图片型,列表中会出现纯文本的情况,比如MORE
62 - let dataType = rowData.get("type");  
63 - if(dataType && dataType === 'text') 65 + let dataType = rowData.get("data_type");
  66 + // console.log("chenlin", "rowData数据:" + JSON.stringify(rowData));
  67 + // console.log("chenlin", "dataType数据:" + dataType);
  68 +
  69 + // return(
  70 + // <Text style={styles.rowText} numberOfLines={1}>{categoryName}</Text>
  71 + // );
  72 +
  73 + if(dataType && dataType == 'text')
64 return ( 74 return (
65 <TouchableOpacity onPress={() => this.props.onPressHotCategoryItem && this.props.onPressHotCategoryItem(rowData.toJS(),rowID)}> 75 <TouchableOpacity onPress={() => this.props.onPressHotCategoryItem && this.props.onPressHotCategoryItem(rowData.toJS(),rowID)}>
66 <View style={styles.rowContainer}> 76 <View style={styles.rowContainer}>
@@ -85,14 +95,21 @@ export default class HotCategoryList extends Component{ @@ -85,14 +95,21 @@ export default class HotCategoryList extends Component{
85 render(){ 95 render(){
86 let {data} = this.props; 96 let {data} = this.props;
87 97
  98 + console.log("chenlin", "data数据长度:" + data.length);
  99 +
  100 + // console.log("chenlin", "data数据:" + JSON.stringify(data));
  101 +
  102 +
88 return( 103 return(
89 - <ListView  
90 - contentContainerStyle={styles.contentContainer}  
91 - dataSource={this.dataSource.cloneWithRows(data)}  
92 - enableEmptySections={true}  
93 - renderRow={this.renderRow}  
94 - renderHeader={this.renderHeader}  
95 - /> 104 + <View style={styles.container}>
  105 + <ListView
  106 + contentContainerStyle={styles.contentContainer}
  107 + dataSource={this.dataSource.cloneWithRows(data)}
  108 + enableEmptySections={true}
  109 + renderRow={this.renderRow}
  110 + renderHeader={this.renderHeader}
  111 + />
  112 + </View>
96 ); 113 );
97 } 114 }
98 115
@@ -104,23 +121,28 @@ const DEVICE_WIDTH_RATIO = width / 320; @@ -104,23 +121,28 @@ const DEVICE_WIDTH_RATIO = width / 320;
104 121
105 let styles = StyleSheet.create({ 122 let styles = StyleSheet.create({
106 123
  124 + container: {
  125 + flexWrap: 'wrap',
  126 + },
  127 +
107 contentContainer: { 128 contentContainer: {
108 flexDirection: 'row', 129 flexDirection: 'row',
109 flexWrap: 'wrap', 130 flexWrap: 'wrap',
110 - alignItems:'flex-start',  
111 - backgroundColor:'white', 131 + alignItems:'center',
  132 + backgroundColor: '#f5f7f6',
112 }, 133 },
113 134
114 headerContainer:{ 135 headerContainer:{
115 - width: 200 * DEVICE_WIDTH_RATIO, 136 + width: 210 * DEVICE_WIDTH_RATIO,
116 height: 50 * DEVICE_WIDTH_RATIO, 137 height: 50 * DEVICE_WIDTH_RATIO,
117 - marginLeft: 5 * DEVICE_WIDTH_RATIO,  
118 - marginRight: 5 * DEVICE_WIDTH_RATIO, 138 + paddingLeft: 5 * DEVICE_WIDTH_RATIO,
  139 + paddingRight: 5 * DEVICE_WIDTH_RATIO,
  140 + backgroundColor: '#ffffff',
119 }, 141 },
120 142
121 headerText:{ 143 headerText:{
122 position: 'absolute', 144 position: 'absolute',
123 - left: 0, 145 + left: 5 * DEVICE_WIDTH_RATIO,
124 bottom: 11 * DEVICE_WIDTH_RATIO, 146 bottom: 11 * DEVICE_WIDTH_RATIO,
125 fontSize: 12 * DEVICE_WIDTH_RATIO, 147 fontSize: 12 * DEVICE_WIDTH_RATIO,
126 color: '#B0B0B0', 148 color: '#B0B0B0',
@@ -137,23 +159,26 @@ let styles = StyleSheet.create({ @@ -137,23 +159,26 @@ let styles = StyleSheet.create({
137 headerLine:{ 159 headerLine:{
138 width: 200 * DEVICE_WIDTH_RATIO, 160 width: 200 * DEVICE_WIDTH_RATIO,
139 height: 0.5 * DEVICE_WIDTH_RATIO, 161 height: 0.5 * DEVICE_WIDTH_RATIO,
140 - backgroundColor: '#f0f0f0', 162 + backgroundColor: '#E0E0E0',
141 left: 0, 163 left: 0,
142 top: 45 * DEVICE_WIDTH_RATIO, 164 top: 45 * DEVICE_WIDTH_RATIO,
143 }, 165 },
144 166
145 rowContainer:{ 167 rowContainer:{
146 width: 70 * DEVICE_WIDTH_RATIO, 168 width: 70 * DEVICE_WIDTH_RATIO,
147 - height: 90 * DEVICE_WIDTH_RATIO, 169 + height: 70 * DEVICE_WIDTH_RATIO,
  170 + paddingLeft: 8.5 * DEVICE_WIDTH_RATIO,
  171 + paddingRight: 8.5 * DEVICE_WIDTH_RATIO,
148 }, 172 },
149 173
150 rowThumbnail:{ 174 rowThumbnail:{
151 - width: 70 * DEVICE_WIDTH_RATIO,  
152 - height: 70 * DEVICE_WIDTH_RATIO, 175 + width: 53 * DEVICE_WIDTH_RATIO,
  176 + height: 53 * DEVICE_WIDTH_RATIO,
153 }, 177 },
154 178
155 rowText:{ 179 rowText:{
156 - width: 70 * DEVICE_WIDTH_RATIO, 180 + width: 53 * DEVICE_WIDTH_RATIO,
  181 + height: 17 * DEVICE_WIDTH_RATIO,
157 fontSize: 10 * DEVICE_WIDTH_RATIO, 182 fontSize: 10 * DEVICE_WIDTH_RATIO,
158 color: '#B0B0B0', 183 color: '#B0B0B0',
159 textAlign: 'center', 184 textAlign: 'center',
@@ -67,46 +67,32 @@ class CategoryBContainer extends Component { @@ -67,46 +67,32 @@ class CategoryBContainer extends Component {
67 id = 1; 67 id = 1;
68 value='boy'; 68 value='boy';
69 } 69 }
70 - this._onSelectChannel(id, value); 70 + this._onSelectChannel({id, value});
71 } 71 }
72 ); 72 );
73 } 73 }
74 74
75 componentDidMount() { 75 componentDidMount() {
76 - this.props.actions.getCategoryBList(); 76 + let currentChannelId = this.props.categoryB.currentChannelId;
  77 + this.props.actions.getCategoryBList(currentChannelId);
77 } 78 }
78 79
79 componentWillUnmount() { 80 componentWillUnmount() {
80 81
81 } 82 }
82 83
83 - _onSelectChannel(channelId, channelValue) {  
84 - //this.props.actions.setCurrentCateB(0, "");  
85 - this.props.actions.setCurrentChannelB(channelId, channelValue); 84 + _onSelectChannel(channel) {
  85 + this.props.actions.setCurrentChannelB(channel.id, channel.value);
  86 + this.props.actions.getCategoryBFirstSubCategoryDetail(channel.id);
86 } 87 }
87 88
88 _onSelectCategory(category,rowID) { 89 _onSelectCategory(category,rowID) {
89 // console.log("chenlin", "调用点击事件:_onSelectCategory,参数为:" + JSON.stringify(category) + "ID: " + rowID); 90 // console.log("chenlin", "调用点击事件:_onSelectCategory,参数为:" + JSON.stringify(category) + "ID: " + rowID);
90 91
91 - let currentChannelId = this.props.categoryB.currentChannelId;  
92 let categoryId = category.category_id; 92 let categoryId = category.category_id;
93 let categoryValue = category.category_name; 93 let categoryValue = category.category_name;
94 94
95 - //检查缓存是否存在数据,如果不存在则获取  
96 - let cache = this.props.categoryB.cacheSubCateData;  
97 - let key = "CHA_" + currentChannelId + "_CAT_" + categoryId;  
98 - let categoryData = cache.get(key);  
99 -  
100 - //未命中,访问网络数据  
101 - if (!categoryData) {  
102 - // console.log("chenlin", "未命中缓存,调用接口访问数据:" + key);  
103 - this.props.actions.getCategoryBSubDetail(currentChannelId, categoryId, categoryValue);  
104 - }  
105 - //已命中,展示缓存数据  
106 - else{  
107 - // console.log("chenlin", "命中缓存:" + key);  
108 - this.props.actions.getCategoryBSubDetailFromCache(categoryData, categoryId, categoryValue);  
109 - } 95 + this.props.actions.getCategoryBSubCategoryDetail(categoryId, categoryValue);
110 } 96 }
111 97
112 _onPressBannerResourceItem(value){ 98 _onPressBannerResourceItem(value){
@@ -114,20 +100,22 @@ class CategoryBContainer extends Component { @@ -114,20 +100,22 @@ class CategoryBContainer extends Component {
114 } 100 }
115 101
116 _onPressHotCategoryItem(value, index) { 102 _onPressHotCategoryItem(value, index) {
117 - // console.log("chenlin", "调用点击事件:_onPressHotCategoryItem,参数为:" + value + "index: " + index); 103 + console.log("chenlin", "调用点击事件:_onPressHotCategoryItem,参数为:" + JSON.stringify(value) + "index: " + index);
118 104
119 let currentChannelId = this.props.categoryB.currentChannelId; 105 let currentChannelId = this.props.categoryB.currentChannelId;
120 this.props.actions.jumpToCategory(value, index, currentChannelId); 106 this.props.actions.jumpToCategory(value, index, currentChannelId);
121 } 107 }
122 108
123 - _onPressHotBrandItem(){  
124 - // console.log("chenlin", "调用点击事件:_onPressHotBrandItem"); 109 + _onPressHotBrandItem(data){
  110 + console.log("chenlin", "调用点击事件:_onPressHotBrandItem,参数:" + JSON.stringify(data));
  111 + ReactNative.NativeModules.YH_CommonHelper.pushBrandVC(data);
125 } 112 }
126 113
127 render() { 114 render() {
128 let { 115 let {
129 isFetching, 116 isFetching,
130 currentChannelId, 117 currentChannelId,
  118 + currentChannelValue,
131 currentCateId, 119 currentCateId,
132 categoryList, 120 categoryList,
133 currentCateValue, 121 currentCateValue,
@@ -141,6 +129,7 @@ class CategoryBContainer extends Component { @@ -141,6 +129,7 @@ class CategoryBContainer extends Component {
141 isFetching={isFetching} 129 isFetching={isFetching}
142 categoryList={categoryList} 130 categoryList={categoryList}
143 currentChannelId={currentChannelId} 131 currentChannelId={currentChannelId}
  132 + currentChannelValue={currentChannelValue}
144 currentCateId={currentCateId} 133 currentCateId={currentCateId}
145 currentCateValue={currentCateValue} 134 currentCateValue={currentCateValue}
146 currentSubCateData={currentSubCateData} 135 currentSubCateData={currentSubCateData}
@@ -23,7 +23,7 @@ const { @@ -23,7 +23,7 @@ const {
23 23
24 } = require('../../constants/actionTypes').default; 24 } = require('../../constants/actionTypes').default;
25 25
26 -export function getCategoryBList() { 26 +export function getCategoryBList(channel_id) {
27 return (dispatch, getState) => { 27 return (dispatch, getState) => {
28 let {app, classify} = getState(); 28 let {app, classify} = getState();
29 29
@@ -32,7 +32,8 @@ export function getCategoryBList() { @@ -32,7 +32,8 @@ export function getCategoryBList() {
32 return new CategoryBService(app.host).getCategoryBList() 32 return new CategoryBService(app.host).getCategoryBList()
33 .then(json => { 33 .then(json => {
34 dispatch(getCategoryBListSuccess(json)); 34 dispatch(getCategoryBListSuccess(json));
35 - dispatch(getCategoryBSubDetail(1, 5, "")); 35 +
  36 + dispatch(getCategoryBFirstSubCategoryDetail(channel_id));
36 }) 37 })
37 .catch(error => { 38 .catch(error => {
38 dispatch(getCategoryBListFailure()); 39 dispatch(getCategoryBListFailure());
@@ -40,19 +41,61 @@ export function getCategoryBList() { @@ -40,19 +41,61 @@ export function getCategoryBList() {
40 }; 41 };
41 } 42 }
42 43
  44 +
  45 +/**
  46 + * 获取子分类的数据,逻辑上先判断缓存数据是否存在,不存在则从网络获取
  47 + **/
  48 +export function getCategoryBSubCategoryDetail(category_id, category_value){
  49 +
  50 + return (dispatch, getState) => {
  51 +
  52 + let {categoryB} = getState();
  53 +
  54 + let currentChannelId = categoryB.currentChannelId;
  55 +
  56 + //检查缓存是否存在数据,如果不存在则获取
  57 + let cache = categoryB.cacheSubCateData;
  58 + let key = getSubDetailCacheKey(currentChannelId, category_id);
  59 + let categoryData = cache.get(key);
  60 +
  61 + //设置当前的类别信息
  62 + dispatch(setCurrentCateB(category_id, category_value));
  63 +
  64 + //未命中,访问网络数据
  65 + if (!categoryData) {
  66 + // console.log("chenlin", "未命中缓存,调用接口访问数据:" + key);
  67 + dispatch(getCategoryBSubDetail(currentChannelId, category_id, category_value));
  68 + }
  69 + //已命中,展示缓存数据
  70 + else{
  71 + // console.log("chenlin", "命中缓存:" + JSON.stringify(categoryData));
  72 + dispatch(getCategoryBSubDetailData(categoryData));
  73 + }
  74 +
  75 + };
  76 +}
  77 +
  78 +/**
  79 + * 获取子分类
  80 + **/
  81 +function getSubDetailCacheKey(channel_id, category_id){
  82 + let key = "CHA_" + channel_id + "_CAT_" + category_id;
  83 + return key;
  84 +}
  85 +
  86 +
43 /** 87 /**
44 * 网络获取子分类的数据 88 * 网络获取子分类的数据
45 **/ 89 **/
46 export function getCategoryBSubDetail(channel_id, category_id, category_value) { 90 export function getCategoryBSubDetail(channel_id, category_id, category_value) {
47 return (dispatch, getState) => { 91 return (dispatch, getState) => {
48 - let {app, classify} = getState(); 92 + let {app} = getState();
49 93
50 dispatch(getCategoryBSubDetailRequest()); 94 dispatch(getCategoryBSubDetailRequest());
51 95
52 return new CategoryBService(app.host).getCategoryBSubDetail(channel_id, category_id) 96 return new CategoryBService(app.host).getCategoryBSubDetail(channel_id, category_id)
53 .then(json => { 97 .then(json => {
54 let payload = parseCategoryBSubDetail(channel_id, category_id, json); 98 let payload = parseCategoryBSubDetail(channel_id, category_id, json);
55 - dispatch(setCurrentCateB(category_id, category_value));  
56 dispatch(getCategoryBSubDetailSuccess(payload)); 99 dispatch(getCategoryBSubDetailSuccess(payload));
57 }) 100 })
58 .catch(error => { 101 .catch(error => {
@@ -62,12 +105,29 @@ export function getCategoryBSubDetail(channel_id, category_id, category_value) { @@ -62,12 +105,29 @@ export function getCategoryBSubDetail(channel_id, category_id, category_value) {
62 } 105 }
63 106
64 /** 107 /**
65 - * 从缓存获取的子分类的数据 108 + *获取指定channel的第一个分类数据
66 **/ 109 **/
67 -export function getCategoryBSubDetailFromCache(sub_data, category_id, category_value) { 110 +export function getCategoryBFirstSubCategoryDetail(channel_id) {
  111 +
68 return (dispatch, getState) => { 112 return (dispatch, getState) => {
69 - dispatch(setCurrentCateB(category_id, category_value));  
70 - dispatch(getCategoryBSubDetailData(sub_data)); 113 + let {categoryB} = getState();
  114 +
  115 + let categoryList = categoryB.categoryList;
  116 +
  117 + let category = null;
  118 + if(channel_id == '1'){
  119 + category = categoryList.get('boy').get(0);
  120 + }
  121 + else if(channel_id == '2'){
  122 + category = categoryList.get('girl').get(0);
  123 + }
  124 + else if(channel_id == '3'){
  125 + category = categoryList.get('kids').get(0);
  126 + }
  127 + else if(channel_id == '4'){
  128 + category = categoryList.get('lifestyle').get(0);
  129 + }
  130 + dispatch(getCategoryBSubCategoryDetail(category.get('category_id'), category.get('category_name')));
71 }; 131 };
72 } 132 }
73 133
@@ -75,138 +135,33 @@ export function getCategoryBSubDetailFromCache(sub_data, category_id, category_v @@ -75,138 +135,33 @@ export function getCategoryBSubDetailFromCache(sub_data, category_id, category_v
75 /** 135 /**
76 *在尾部添加一个MORE 136 *在尾部添加一个MORE
77 **/ 137 **/
78 -function parseCategoryBSubDetail(channel_id, category_id, json) {  
79 - if(!json){ 138 +function parseCategoryBSubDetail(channel_id, category_id, data) {
  139 + if(!data){
80 return; 140 return;
81 } 141 }
82 - // let oldData = json ? json : [];  
83 -  
84 - // let newData=[];  
85 -  
86 -  
87 - // oldData.map((item, i) => {  
88 - // let newSortInfo = [];  
89 - // let all = {  
90 - // category_name: '全部'+item.category_name,  
91 - // parent_id: item.category_id,  
92 - // // parent_id: item.parent_id,  
93 - // relation_parameter:item.relation_parameter,  
94 - // node_count:item.node_count,  
95 - // };  
96 - // if(item.sortInfo){  
97 - // newSortInfo=[...item.sortInfo, all];  
98 - // }else{  
99 - // newSortInfo.push(all);  
100 - // }  
101 -  
102 - // newData.push({  
103 - // sortInfo:newSortInfo,  
104 - // category_name:item.category_name,  
105 - // category_id:item.category_id,  
106 - // parent_id:item.parent_id,  
107 - // relation_parameter:item.relation_parameter,  
108 - // sort_ico:item.sort_ico,  
109 - // node_count:item.node_count,  
110 - // brandInfo: item.brandInfo,  
111 - // });  
112 - // });  
113 -  
114 - // console.log("chenlin", "处理后的JSON数据:" + JSON.stringify(newData));  
115 142
116 - let key = "CHA_" + channel_id + "_CAT_" + category_id; 143 + if(data.sortInfo){
  144 + let more = {
  145 + category_name: 'more',
  146 + parent_id: category_id,
  147 + relation_parameter:{},
  148 + data_type:'text',
  149 + };
  150 + data.sortInfo.push(more);
  151 + }
  152 +
  153 + let key = getSubDetailCacheKey(channel_id, category_id);
  154 + // let newData = {
  155 + // bannerInfo: data.bannerInfo,
  156 + // sortInfo: data.sortInfo,
  157 + // brandInfo: data.brandInfo,
  158 + // }
  159 +
  160 + // console.log("chenlin", "parseCategoryBSubDetail处理后的JSON数据:" + JSON.stringify(data));
  161 +
  162 +
  163 + return {key: key, data: data};
117 164
118 - return {key: key, data: json};  
119 - // return json;  
120 - // //女  
121 - // girl.map((item, i) => {  
122 - // let newGirlSub=[];  
123 - // let all={  
124 - // category_name: '全部'+item.category_name,  
125 - // parent_id: item.category_id,  
126 - // // parent_id: item.parent_id,  
127 - // relation_parameter:item.relation_parameter,  
128 - // node_count:item.node_count,  
129 - // };  
130 -  
131 - // if(item.sub){  
132 - // newGirlSub=[all,...item.sub];  
133 - // }else{  
134 - // newGirlSub.push(all);  
135 - // }  
136 -  
137 - // newGirl.push({  
138 - // sub:newGirlSub,  
139 - // category_name:item.category_name,  
140 - // category_id:item.category_id,  
141 - // parent_id:item.parent_id,  
142 - // relation_parameter:item.relation_parameter,  
143 - // sort_ico:item.sort_ico,  
144 - // node_count:item.node_count,  
145 - // });  
146 - // });  
147 -  
148 - // //kid  
149 - // kids.map((item, i) => {  
150 - // let newKidsSub=[];  
151 - // let all={  
152 - // category_name: '全部'+item.category_name,  
153 - // parent_id: item.category_id,  
154 - // // parent_id: item.parent_id,  
155 - // relation_parameter:item.relation_parameter,  
156 - // node_count:item.node_count,  
157 - // };  
158 -  
159 - // if(item.sub){  
160 - // newKidsSub=[all,...item.sub];  
161 - // }else{  
162 - // newKidsSub.push(all);  
163 - // }  
164 -  
165 - // newKids.push({  
166 - // sub:newKidsSub,  
167 - // category_name:item.category_name,  
168 - // category_id:item.category_id,  
169 - // parent_id:item.parent_id,  
170 - // relation_parameter:item.relation_parameter,  
171 - // sort_ico:item.sort_ico,  
172 - // node_count:item.node_count,  
173 - // });  
174 - // });  
175 -  
176 - // //家居  
177 - // lifestyle.map((item, i) => {  
178 - // let newLifestyleSub=[];  
179 - // let all={  
180 - // category_name: '全部'+item.category_name,  
181 - // parent_id: item.category_id,  
182 - // // parent_id: item.parent_id,  
183 - // relation_parameter:item.relation_parameter,  
184 - // node_count:item.node_count,  
185 - // };  
186 - // if(item.sub){  
187 - // newLifestyleSub=[all,...item.sub];  
188 -  
189 - // }else{  
190 - // newLifestyleSub.push(all);  
191 - // }  
192 -  
193 - // newLifestyle.push({  
194 - // sub:newLifestyleSub,  
195 - // category_name:item.category_name,  
196 - // category_id:item.category_id,  
197 - // parent_id:item.parent_id,  
198 - // relation_parameter:item.relation_parameter,  
199 - // sort_ico:item.sort_ico,  
200 - // node_count:item.node_count,  
201 - // });  
202 - // });  
203 -  
204 - // return {  
205 - // boy:newBoy,  
206 - // girl:newGirl,  
207 - // kids:newKids,  
208 - // lifestyle:newLifestyle,  
209 - // };  
210 } 165 }
211 166
212 167