增加了赞的点击事件。review by 于良。
Showing
11 changed files
with
151 additions
and
13 deletions
@@ -36,6 +36,7 @@ import { | @@ -36,6 +36,7 @@ import { | ||
36 | 36 | ||
37 | import { | 37 | import { |
38 | setBrandId, | 38 | setBrandId, |
39 | + setUdid, | ||
39 | } from './reducers/detail/detailActions'; | 40 | } from './reducers/detail/detailActions'; |
40 | 41 | ||
41 | function getInitialState() { | 42 | function getInitialState() { |
@@ -101,7 +102,9 @@ export default function native(platform) { | @@ -101,7 +102,9 @@ export default function native(platform) { | ||
101 | ); | 102 | ); |
102 | } else { | 103 | } else { |
103 | let brandId=this.props.id; | 104 | let brandId=this.props.id; |
105 | + let udid=this.props.udid; | ||
104 | store.dispatch(setBrandId(brandId)); | 106 | store.dispatch(setBrandId(brandId)); |
107 | + store.dispatch(setUdid(udid)); | ||
105 | return ( | 108 | return ( |
106 | <Provider store={store}> | 109 | <Provider store={store}> |
107 | <DetailContainer /> | 110 | <DetailContainer /> |
@@ -32,8 +32,10 @@ export default class BrandArticleCell extends Component { | @@ -32,8 +32,10 @@ export default class BrandArticleCell extends Component { | ||
32 | } | 32 | } |
33 | 33 | ||
34 | 34 | ||
35 | - //内容 | ||
36 | - _renderTimeAndVisit(time, visit, likeNum, isliked){ | 35 | + //时间和访问次数以及是否喜欢 |
36 | + _renderTimeAndVisit(time, visit, likeNum, id, isliked){ | ||
37 | + | ||
38 | + let likeicon = isliked ? require("../../images/like_on.png") : require("../../images/like_off.png"); | ||
37 | 39 | ||
38 | return ( | 40 | return ( |
39 | <View style={styles.timebar}> | 41 | <View style={styles.timebar}> |
@@ -41,7 +43,15 @@ export default class BrandArticleCell extends Component { | @@ -41,7 +43,15 @@ export default class BrandArticleCell extends Component { | ||
41 | 43 | ||
42 | <Text style={styles.time} numberOfLines={1}>{visit} </Text> | 44 | <Text style={styles.time} numberOfLines={1}>{visit} </Text> |
43 | 45 | ||
44 | - <Text style={styles.time} numberOfLines={1}>{likeNum}</Text> | 46 | + <TouchableOpacity |
47 | + activeOpacity={1} | ||
48 | + onPress={()=>{ | ||
49 | + this.props.onPressArticleLike && this.props.onPressArticleLike(id, !isliked) | ||
50 | + }}> | ||
51 | + <Image style={styles.likeicon} source={likeicon} /> | ||
52 | + | ||
53 | + <Text style={styles.time} numberOfLines={1}>{likeNum}</Text> | ||
54 | + </TouchableOpacity> | ||
45 | 55 | ||
46 | 56 | ||
47 | </View> | 57 | </View> |
@@ -52,11 +62,16 @@ export default class BrandArticleCell extends Component { | @@ -52,11 +62,16 @@ export default class BrandArticleCell extends Component { | ||
52 | 62 | ||
53 | render() { | 63 | render() { |
54 | let {rowData} = this.props; | 64 | let {rowData} = this.props; |
65 | + //url跳转地址 | ||
66 | + let url = rowData.get('url'); | ||
67 | + //id | ||
68 | + let id = rowData.get('id'); | ||
55 | //标题 | 69 | //标题 |
56 | let title = rowData.get('title'); | 70 | let title = rowData.get('title'); |
57 | //图片 | 71 | //图片 |
58 | let imgUrl = rowData.get('src').replace('{mode}', 2).replace('{width}', 290).replace('{height}', 386); | 72 | let imgUrl = rowData.get('src').replace('{mode}', 2).replace('{width}', 290).replace('{height}', 386); |
59 | //imgUrl = SlicedImage.getSlicedUrl(rowData.get('src'), 290, 386, 2); | 73 | //imgUrl = SlicedImage.getSlicedUrl(rowData.get('src'), 290, 386, 2); |
74 | + //let brandIconUrl = SlicedImage.getSlicedUrl(data.get('brand_img', ''), 150, 80, 2); | ||
60 | //介绍 | 75 | //介绍 |
61 | let intro = rowData.get('intro'); | 76 | let intro = rowData.get('intro'); |
62 | //发布时间 | 77 | //发布时间 |
@@ -70,10 +85,6 @@ export default class BrandArticleCell extends Component { | @@ -70,10 +85,6 @@ export default class BrandArticleCell extends Component { | ||
70 | //喜欢人数 | 85 | //喜欢人数 |
71 | let likeCount = like.get("count"); | 86 | let likeCount = like.get("count"); |
72 | 87 | ||
73 | - //console.log("chenlin444", JSON.stringify(rowData)); | ||
74 | - //console.log("chenlin444", "isLiked" + isLiked + "----likeCount" + likeCount); | ||
75 | - | ||
76 | - | ||
77 | return ( | 88 | return ( |
78 | <View style={styles.cellContainer}> | 89 | <View style={styles.cellContainer}> |
79 | 90 | ||
@@ -81,7 +92,7 @@ export default class BrandArticleCell extends Component { | @@ -81,7 +92,7 @@ export default class BrandArticleCell extends Component { | ||
81 | style={[styles.touchableContainer]} | 92 | style={[styles.touchableContainer]} |
82 | activeOpacity={1} | 93 | activeOpacity={1} |
83 | onPress={()=>{ | 94 | onPress={()=>{ |
84 | - this.props.onPressTopic && this.props.onPressTopic() | 95 | + this.props.onPressArticle && this.props.onPressArticle(url) |
85 | }}> | 96 | }}> |
86 | 97 | ||
87 | <Image style={styles.image} source={{uri:imgUrl}} /> | 98 | <Image style={styles.image} source={{uri:imgUrl}} /> |
@@ -92,7 +103,7 @@ export default class BrandArticleCell extends Component { | @@ -92,7 +103,7 @@ export default class BrandArticleCell extends Component { | ||
92 | 103 | ||
93 | <Text style={styles.content} numberOfLines={4}>{intro}</Text> | 104 | <Text style={styles.content} numberOfLines={4}>{intro}</Text> |
94 | 105 | ||
95 | - {this._renderTimeAndVisit(publishTime, viewsNum, likeCount, isLiked)} | 106 | + {this._renderTimeAndVisit(publishTime, viewsNum, likeCount, id, isLiked)} |
96 | 107 | ||
97 | 108 | ||
98 | </View> | 109 | </View> |
@@ -141,7 +152,11 @@ let styles = StyleSheet.create({ | @@ -141,7 +152,11 @@ let styles = StyleSheet.create({ | ||
141 | paddingBottom:5, | 152 | paddingBottom:5, |
142 | }, | 153 | }, |
143 | time:{ | 154 | time:{ |
144 | - fontSize: 9, | 155 | + fontSize: 15, |
145 | color: '#b0b0b0', | 156 | color: '#b0b0b0', |
146 | }, | 157 | }, |
158 | + likeicon:{ | ||
159 | + width: 20, | ||
160 | + height:20, | ||
161 | + }, | ||
147 | }); | 162 | }); |
@@ -47,7 +47,8 @@ export default class BrandArticleList extends Component { | @@ -47,7 +47,8 @@ export default class BrandArticleList extends Component { | ||
47 | key={'row' + rowID} | 47 | key={'row' + rowID} |
48 | rowID={rowID} | 48 | rowID={rowID} |
49 | rowData={rowData} | 49 | rowData={rowData} |
50 | - // onPressProduct={this.props.onPressProduct} | 50 | + onPressArticle={this.props.onPressArticle} |
51 | + onPressArticleLike={this.props.onPressArticleLike} | ||
51 | /> | 52 | /> |
52 | 53 | ||
53 | ); | 54 | ); |
@@ -71,6 +72,8 @@ export default class BrandArticleList extends Component { | @@ -71,6 +72,8 @@ export default class BrandArticleList extends Component { | ||
71 | renderRow={this._renderRow} | 72 | renderRow={this._renderRow} |
72 | enableEmptySections = {true} | 73 | enableEmptySections = {true} |
73 | renderSeparator={this._renderSeparator} | 74 | renderSeparator={this._renderSeparator} |
75 | + onPressArticle={this.props.onPressArticle} | ||
76 | + onPressArticleLike={this.props.onPressArticleLike} | ||
74 | //renderHeader={this._renderHeader} | 77 | //renderHeader={this._renderHeader} |
75 | /> | 78 | /> |
76 | 79 |
@@ -7,6 +7,7 @@ export default keyMirror({ | @@ -7,6 +7,7 @@ export default keyMirror({ | ||
7 | SET_SEGMENT: null, | 7 | SET_SEGMENT: null, |
8 | SET_GENDER: null, | 8 | SET_GENDER: null, |
9 | SET_BRAND_ID:null, | 9 | SET_BRAND_ID:null, |
10 | + SET_UDID:null, | ||
10 | 11 | ||
11 | PLUSTAR_LIST_REQUEST: null, | 12 | PLUSTAR_LIST_REQUEST: null, |
12 | PLUSTAR_LIST_SUCCESS: null, | 13 | PLUSTAR_LIST_SUCCESS: null, |
@@ -44,4 +45,8 @@ export default keyMirror({ | @@ -44,4 +45,8 @@ export default keyMirror({ | ||
44 | CANCEL_FAVORITE_REQUEST: null, | 45 | CANCEL_FAVORITE_REQUEST: null, |
45 | CANCEL_FAVORITE_SUCCESS: null, | 46 | CANCEL_FAVORITE_SUCCESS: null, |
46 | CANCEL_FAVORITE_FAILURE: null, | 47 | CANCEL_FAVORITE_FAILURE: null, |
48 | + | ||
49 | + PRAISE_ARTICLE_REQUEST: null, | ||
50 | + PRAISE_ARTICLE_SUCCESS: null, | ||
51 | + PRAISE_ARTICLE_FAILURE: null, | ||
47 | }); | 52 | }); |
@@ -49,6 +49,8 @@ class DetailContainer extends Component { | @@ -49,6 +49,8 @@ class DetailContainer extends Component { | ||
49 | } | 49 | } |
50 | constructor(props) { | 50 | constructor(props) { |
51 | super(props); | 51 | super(props); |
52 | + this._onPressArticle = this._onPressArticle.bind(this); | ||
53 | + this._onPressArticleLike = this._onPressArticleLike.bind(this); | ||
52 | } | 54 | } |
53 | 55 | ||
54 | componentDidMount() { | 56 | componentDidMount() { |
@@ -58,6 +60,17 @@ class DetailContainer extends Component { | @@ -58,6 +60,17 @@ class DetailContainer extends Component { | ||
58 | this.props.actions.articleByBrand(); | 60 | this.props.actions.articleByBrand(); |
59 | } | 61 | } |
60 | 62 | ||
63 | + _onPressArticle(url) { | ||
64 | + console.log("chenlin", "_onPressArticle:URL:" + url); | ||
65 | + } | ||
66 | + | ||
67 | + _onPressArticleLike(id, isLiked) { | ||
68 | + console.log("chenlin", "_onPressArticleLike:id" + id + ",isLiked:" + isLiked); | ||
69 | + let opt = isLiked ? "ok" : "cancel"; | ||
70 | + | ||
71 | + this.props.actions.praiseArticle(id,opt); | ||
72 | + } | ||
73 | + | ||
61 | render() { | 74 | render() { |
62 | let {detail} = this.props; | 75 | let {detail} = this.props; |
63 | //console.log("chenlin", JSON.stringify(detail)); | 76 | //console.log("chenlin", JSON.stringify(detail)); |
@@ -66,9 +79,12 @@ class DetailContainer extends Component { | @@ -66,9 +79,12 @@ class DetailContainer extends Component { | ||
66 | <BrandIntro | 79 | <BrandIntro |
67 | brandIntro={detail.get('brandInfo')} | 80 | brandIntro={detail.get('brandInfo')} |
68 | /> | 81 | /> |
82 | + | ||
69 | 83 | ||
70 | <BrandArticleList | 84 | <BrandArticleList |
71 | - articleList={detail.get('articleList')} /> | 85 | + articleList={detail.get('articleList')} |
86 | + onPressArticle={this._onPressArticle} | ||
87 | + onPressArticleLike={this._onPressArticleLike} /> | ||
72 | </View> | 88 | </View> |
73 | ); | 89 | ); |
74 | } | 90 | } |
js/plustar/images/like_off.png
0 → 100644
18.8 KB
js/plustar/images/like_on.png
0 → 100644
19.3 KB
@@ -13,6 +13,7 @@ const { | @@ -13,6 +13,7 @@ const { | ||
13 | 13 | ||
14 | SET_BRAND_ID, | 14 | SET_BRAND_ID, |
15 | SET_GENDER, | 15 | SET_GENDER, |
16 | + SET_UDID, | ||
16 | 17 | ||
17 | BRADN_FAV_REQUEST, | 18 | BRADN_FAV_REQUEST, |
18 | BRADN_FAV_SUCCESS, | 19 | BRADN_FAV_SUCCESS, |
@@ -35,6 +36,10 @@ const { | @@ -35,6 +36,10 @@ const { | ||
35 | CANCEL_FAVORITE_SUCCESS, | 36 | CANCEL_FAVORITE_SUCCESS, |
36 | CANCEL_FAVORITE_FAILURE, | 37 | CANCEL_FAVORITE_FAILURE, |
37 | 38 | ||
39 | + PRAISE_ARTICLE_REQUEST, | ||
40 | + PRAISE_ARTICLE_SUCCESS, | ||
41 | + PRAISE_ARTICLE_FAILURE, | ||
42 | + | ||
38 | } = require('../../constants/actionTypes').default; | 43 | } = require('../../constants/actionTypes').default; |
39 | 44 | ||
40 | export function jumpWithUrl(url) { | 45 | export function jumpWithUrl(url) { |
@@ -125,6 +130,13 @@ export function setGender(gender) { | @@ -125,6 +130,13 @@ export function setGender(gender) { | ||
125 | }; | 130 | }; |
126 | } | 131 | } |
127 | 132 | ||
133 | +export function setUdid(udid){ | ||
134 | + return { | ||
135 | + type: SET_UDID, | ||
136 | + payload:udid | ||
137 | + }; | ||
138 | +} | ||
139 | + | ||
128 | export function uidBrandFavRequest(){ | 140 | export function uidBrandFavRequest(){ |
129 | return { | 141 | return { |
130 | type: BRADN_FAV_REQUEST, | 142 | type: BRADN_FAV_REQUEST, |
@@ -358,3 +370,47 @@ export function cancelFavorite() { | @@ -358,3 +370,47 @@ export function cancelFavorite() { | ||
358 | }); | 370 | }); |
359 | }; | 371 | }; |
360 | } | 372 | } |
373 | + | ||
374 | + | ||
375 | +export function praiseArticleRequest(){ | ||
376 | + return { | ||
377 | + type: PRAISE_ARTICLE_REQUEST, | ||
378 | + }; | ||
379 | +} | ||
380 | + | ||
381 | +export function praiseArticleSuccess(json){ | ||
382 | + return { | ||
383 | + type: PRAISE_ARTICLE_SUCCESS, | ||
384 | + payload:json | ||
385 | + }; | ||
386 | +} | ||
387 | + | ||
388 | +export function praiseArticleFailure(error){ | ||
389 | + return { | ||
390 | + type: PRAISE_ARTICLE_FAILURE, | ||
391 | + payload:error | ||
392 | + }; | ||
393 | +} | ||
394 | + | ||
395 | +export function praiseArticle(articleId, opt) { | ||
396 | + return (dispatch, getState) => { | ||
397 | + let {app, detail} = getState(); | ||
398 | + let {udid} = detail; | ||
399 | + console.log("chenlin", "getState:" + JSON.stringify(getState())); | ||
400 | + | ||
401 | + let articleRequest = (articleId, udid, opt) => { | ||
402 | + dispatch(praiseArticleRequest()); | ||
403 | + return new DetailService(app.servicehost).praiseArticle(articleId, udid, opt) | ||
404 | + .then(json=>{ | ||
405 | + dispatch(praiseArticleSuccess(json)); | ||
406 | + }) | ||
407 | + .catch(error=>{ | ||
408 | + dispatch(praiseArticleFailure(error)); | ||
409 | + }); | ||
410 | + } | ||
411 | + | ||
412 | + articleRequest(articleId, udid, opt); | ||
413 | + | ||
414 | + | ||
415 | + }; | ||
416 | +} |
@@ -10,6 +10,7 @@ let InitialState = Record({ | @@ -10,6 +10,7 @@ let InitialState = Record({ | ||
10 | error: null, | 10 | error: null, |
11 | })), | 11 | })), |
12 | brandId:'', | 12 | brandId:'', |
13 | + udid:'', | ||
13 | gender:'', | 14 | gender:'', |
14 | productList: List(), | 15 | productList: List(), |
15 | articleList: List(), | 16 | articleList: List(), |
@@ -11,6 +11,7 @@ const { | @@ -11,6 +11,7 @@ const { | ||
11 | JUMP_WITH_URL, | 11 | JUMP_WITH_URL, |
12 | SET_BRAND_ID, | 12 | SET_BRAND_ID, |
13 | SET_GENDER, | 13 | SET_GENDER, |
14 | + SET_UDID, | ||
14 | 15 | ||
15 | BRADN_FAV_REQUEST, | 16 | BRADN_FAV_REQUEST, |
16 | BRADN_FAV_SUCCESS, | 17 | BRADN_FAV_SUCCESS, |
@@ -31,6 +32,11 @@ const { | @@ -31,6 +32,11 @@ const { | ||
31 | CANCEL_FAVORITE_REQUEST, | 32 | CANCEL_FAVORITE_REQUEST, |
32 | CANCEL_FAVORITE_SUCCESS, | 33 | CANCEL_FAVORITE_SUCCESS, |
33 | CANCEL_FAVORITE_FAILURE, | 34 | CANCEL_FAVORITE_FAILURE, |
35 | + | ||
36 | + PRAISE_ARTICLE_REQUEST, | ||
37 | + PRAISE_ARTICLE_SUCCESS, | ||
38 | + PRAISE_ARTICLE_FAILURE, | ||
39 | + | ||
34 | } = require('../../constants/actionTypes').default; | 40 | } = require('../../constants/actionTypes').default; |
35 | 41 | ||
36 | const initialState = new InitialState; | 42 | const initialState = new InitialState; |
@@ -53,12 +59,21 @@ export default function plustarReducer(state=initialState, action) { | @@ -53,12 +59,21 @@ export default function plustarReducer(state=initialState, action) { | ||
53 | case SET_BRAND_ID:{ | 59 | case SET_BRAND_ID:{ |
54 | return state.set('brandId', action.payload); | 60 | return state.set('brandId', action.payload); |
55 | } | 61 | } |
62 | + case SET_UDID:{ | ||
63 | + return state.set('udid', action.payload); | ||
64 | + } | ||
56 | case NEW_ARRIVE_SUCCESS:{ | 65 | case NEW_ARRIVE_SUCCESS:{ |
57 | return state.set('productList', Immutable.fromJS(action.payload)); | 66 | return state.set('productList', Immutable.fromJS(action.payload)); |
58 | } | 67 | } |
59 | case ARTICLE_BY_BRAND_SUCCESS:{ | 68 | case ARTICLE_BY_BRAND_SUCCESS:{ |
60 | return state.set('articleList', Immutable.fromJS(action.payload)); | 69 | return state.set('articleList', Immutable.fromJS(action.payload)); |
61 | } | 70 | } |
71 | + case PRAISE_ARTICLE_SUCCESS:{ | ||
72 | + console.log("chenlin", "PRAISE_ARTICLE_SUCCESS:" + JSON.stringify(action.payload)); | ||
73 | + } | ||
74 | + case PRAISE_ARTICLE_FAILURE:{ | ||
75 | + console.log("chenlin", "PRAISE_ARTICLE_FAILURE:" + JSON.stringify(action.payload)); | ||
76 | + } | ||
62 | } | 77 | } |
63 | 78 | ||
64 | return state; | 79 | return state; |
@@ -66,15 +66,20 @@ export default class DetailService { | @@ -66,15 +66,20 @@ export default class DetailService { | ||
66 | }); | 66 | }); |
67 | } | 67 | } |
68 | 68 | ||
69 | - async getArticleByBrand(brandId,uid) { | 69 | + async getArticleByBrand(brandId,uid,udid) { |
70 | return await this.api.get({ | 70 | return await this.api.get({ |
71 | url: '/guang/service/v1/article/getArticleByBrand', | 71 | url: '/guang/service/v1/article/getArticleByBrand', |
72 | body: { | 72 | body: { |
73 | brand_id: brandId, | 73 | brand_id: brandId, |
74 | uid: uid, | 74 | uid: uid, |
75 | + udid: udid, | ||
76 | + // client_type: clientType, | ||
77 | + // limit: 3, | ||
78 | + // private_key: privateKeyList[clientType], | ||
75 | } | 79 | } |
76 | }) | 80 | }) |
77 | .then((json) => { | 81 | .then((json) => { |
82 | + | ||
78 | return json; | 83 | return json; |
79 | }) | 84 | }) |
80 | .catch((error) => { | 85 | .catch((error) => { |
@@ -116,5 +121,24 @@ export default class DetailService { | @@ -116,5 +121,24 @@ export default class DetailService { | ||
116 | throw(error); | 121 | throw(error); |
117 | }); | 122 | }); |
118 | } | 123 | } |
124 | + | ||
125 | + //点赞,opt:ok表示点赞,cancel表示取消点赞 | ||
126 | + async praiseArticle(id, udid, opt='ok') { | ||
127 | + return await this.api.post({ | ||
128 | + url: '/guang/opt/praiseArticle', | ||
129 | + body: { | ||
130 | + id: id, | ||
131 | + udid: udid, | ||
132 | + opt: opt | ||
133 | + } | ||
134 | + }) | ||
135 | + .then((json) => { | ||
136 | + console.log("chenlin", "点赞返回数据:" + JSON.stringify(json)); | ||
137 | + return json; | ||
138 | + }) | ||
139 | + .catch((error) => { | ||
140 | + throw(error); | ||
141 | + }); | ||
142 | + } | ||
119 | } | 143 | } |
120 | 144 |
-
mentioned in commit 3abaf7a6
-
Please register or login to post a comment