个人信息数据请求及更新,review by Redding
Showing
7 changed files
with
156 additions
and
41 deletions
@@ -11,7 +11,7 @@ import { | @@ -11,7 +11,7 @@ import { | ||
11 | } from 'react-native'; | 11 | } from 'react-native'; |
12 | 12 | ||
13 | import {Map} from 'immutable'; | 13 | import {Map} from 'immutable'; |
14 | - | 14 | +import YH_Image from '../../common/components/YH_Image'; |
15 | 15 | ||
16 | export default class PersonalInfo extends Component { | 16 | export default class PersonalInfo extends Component { |
17 | constructor(props) { | 17 | constructor(props) { |
@@ -26,13 +26,14 @@ export default class PersonalInfo extends Component { | @@ -26,13 +26,14 @@ export default class PersonalInfo extends Component { | ||
26 | } | 26 | } |
27 | let withoutBottomLine = dataSource.get('withoutBottomLine'); | 27 | let withoutBottomLine = dataSource.get('withoutBottomLine'); |
28 | let imageUrl = ''; | 28 | let imageUrl = ''; |
29 | - if (dataSource.get('id') == 'portrait') { | 29 | + if (dataSource.get('id') == 'portrait' && dataSource.get('url') == '') { |
30 | imageUrl = require('../image/avatar_icon.png'); | 30 | imageUrl = require('../image/avatar_icon.png'); |
31 | } else if (dataSource.get('id') == 'VIPLevel') { | 31 | } else if (dataSource.get('id') == 'VIPLevel') { |
32 | imageUrl = require('../image/VIP1.png'); | 32 | imageUrl = require('../image/VIP1.png'); |
33 | } else if (dataSource.get('id') == 'mineQRCode') { | 33 | } else if (dataSource.get('id') == 'mineQRCode') { |
34 | imageUrl = require('../image/mine_qr.png'); | 34 | imageUrl = require('../image/mine_qr.png'); |
35 | } | 35 | } |
36 | + let url = YH_Image.getSlicedUrl(dataSource.get('url'), 40, 40, 2); // 商品缩略图 | ||
36 | return ( | 37 | return ( |
37 | <View style={[styles.container,{height: cellHeight + (withoutBottomLine?0.0:0.5)}]}> | 38 | <View style={[styles.container,{height: cellHeight + (withoutBottomLine?0.0:0.5)}]}> |
38 | <View style={[styles.contentContainer,{height: cellHeight}]}> | 39 | <View style={[styles.contentContainer,{height: cellHeight}]}> |
@@ -45,6 +46,10 @@ export default class PersonalInfo extends Component { | @@ -45,6 +46,10 @@ export default class PersonalInfo extends Component { | ||
45 | <Text style={styles.content}> | 46 | <Text style={styles.content}> |
46 | {dataSource.get('content')} | 47 | {dataSource.get('content')} |
47 | </Text> | 48 | </Text> |
49 | + {dataSource.get('id') == 'portrait' && dataSource.get('url') != '' ? | ||
50 | + <YH_Image url={url} style={styles.userImage} /> | ||
51 | + :null | ||
52 | + } | ||
48 | {imageUrl==''?null: | 53 | {imageUrl==''?null: |
49 | <Image style={styles.arrow} | 54 | <Image style={styles.arrow} |
50 | source={imageUrl} | 55 | source={imageUrl} |
@@ -72,6 +77,12 @@ let styles = StyleSheet.create({ | @@ -72,6 +77,12 @@ let styles = StyleSheet.create({ | ||
72 | title: { | 77 | title: { |
73 | marginLeft: 15, | 78 | marginLeft: 15, |
74 | }, | 79 | }, |
80 | + userImage: { | ||
81 | + width: 40, | ||
82 | + height: 40, | ||
83 | + borderRadius: 20, | ||
84 | + marginRight: 15, | ||
85 | + }, | ||
75 | content:{ | 86 | content:{ |
76 | color: '#b0b0b0', | 87 | color: '#b0b0b0', |
77 | marginRight: 14, | 88 | marginRight: 14, |
@@ -2,4 +2,10 @@ import keyMirror from 'key-mirror'; | @@ -2,4 +2,10 @@ import keyMirror from 'key-mirror'; | ||
2 | 2 | ||
3 | export default keyMirror({ | 3 | export default keyMirror({ |
4 | SET_TYPE: null, | 4 | SET_TYPE: null, |
5 | + | ||
6 | + FETCH_PROFILE_REQUEST: null, | ||
7 | + FETCH_PROFILE_SUCCESS: null, | ||
8 | + FETCH_PROFILE_FAILURE: null, | ||
9 | + | ||
10 | + UPDATE_PAGE_CELL_LIST: null, | ||
5 | }); | 11 | }); |
@@ -8,4 +8,112 @@ import {Record, List, Map} from 'immutable'; | @@ -8,4 +8,112 @@ import {Record, List, Map} from 'immutable'; | ||
8 | const { | 8 | const { |
9 | SET_TYPE, | 9 | SET_TYPE, |
10 | 10 | ||
11 | + FETCH_PROFILE_REQUEST, | ||
12 | + FETCH_PROFILE_SUCCESS, | ||
13 | + FETCH_PROFILE_FAILURE, | ||
14 | + | ||
15 | + UPDATE_PAGE_CELL_LIST, | ||
16 | + | ||
11 | } = require('../../constants/actionTypes').default; | 17 | } = require('../../constants/actionTypes').default; |
18 | + | ||
19 | +export function fetchProfileRequest() { | ||
20 | + return{ | ||
21 | + type: FETCH_PROFILE_REQUEST, | ||
22 | + } | ||
23 | +} | ||
24 | + | ||
25 | +export function fetchProfileSuccess(json) { | ||
26 | + return{ | ||
27 | + type: FETCH_PROFILE_SUCCESS, | ||
28 | + payload: json, | ||
29 | + } | ||
30 | +} | ||
31 | + | ||
32 | +export function fetchProfileFailure(error) { | ||
33 | + return{ | ||
34 | + type: FETCH_PROFILE_FAILURE, | ||
35 | + payload: error, | ||
36 | + } | ||
37 | +} | ||
38 | + | ||
39 | +export function updatePageCellList(list) { | ||
40 | + return{ | ||
41 | + type: UPDATE_PAGE_CELL_LIST, | ||
42 | + payload: list, | ||
43 | + } | ||
44 | +} | ||
45 | + | ||
46 | +export function fetchPersonalInfo() { | ||
47 | + return (dispatch, getState) => { | ||
48 | + let {app, personalInfo} = getState(); | ||
49 | + let getProfileFunction = (uid) => { | ||
50 | + dispatch(fetchProfileRequest()); | ||
51 | + return new PersonalInfoService(app.host).getProfile(uid) | ||
52 | + .then(json => { | ||
53 | + dispatch(fetchProfileSuccess(json)); | ||
54 | + dispatch(processProfile(json)); | ||
55 | + }) | ||
56 | + .catch(error => { | ||
57 | + dispatch(fetchProfileFailure()); | ||
58 | + }) | ||
59 | + } | ||
60 | + | ||
61 | + ReactNative.NativeModules.YH_CommonHelper.uid() | ||
62 | + .then(uid => { | ||
63 | + getProfileFunction(uid); | ||
64 | + }) | ||
65 | + .catch(error => { | ||
66 | + ReactNative.NativeModules.YH_CommonHelper.login() | ||
67 | + .then(uid => { | ||
68 | + getProfileFunction(uid); | ||
69 | + }) | ||
70 | + .catch(error => { | ||
71 | + | ||
72 | + }); | ||
73 | + }); | ||
74 | + } | ||
75 | +} | ||
76 | + | ||
77 | +function processProfile(profile){ | ||
78 | + return (dispatch, getState) => { | ||
79 | + let {app, personalInfo} = getState(); | ||
80 | + let {pageCellList} = personalInfo; | ||
81 | + pageCellList = pageCellList.toJS(); | ||
82 | + pageCellList.map((cellItem, i) => { | ||
83 | + switch (cellItem.id) { | ||
84 | + case 'portrait': | ||
85 | + cellItem.url = profile.head_ico; | ||
86 | + break; | ||
87 | + case 'nickname': | ||
88 | + cellItem.content = profile.nickname; | ||
89 | + break; | ||
90 | + case 'gender':{ | ||
91 | + if (profile.gender == 1) { | ||
92 | + cellItem.content = 'BOY'; | ||
93 | + } else if (profile.gender == 2) { | ||
94 | + cellItem.content = 'GIRL'; | ||
95 | + } | ||
96 | + } | ||
97 | + break; | ||
98 | + case 'birthDay': | ||
99 | + cellItem.content = profile.birthday; | ||
100 | + break; | ||
101 | + case 'VIPLevel':{ | ||
102 | + if (profile.vip_info.cur_level != '0') { | ||
103 | + cellItem.content = profile.vip_info.cur_level; | ||
104 | + } | ||
105 | + } | ||
106 | + break; | ||
107 | + case 'height': | ||
108 | + cellItem.content = profile.height; | ||
109 | + break; | ||
110 | + case 'weight': | ||
111 | + cellItem.content = profile.weight; | ||
112 | + break; | ||
113 | + default: | ||
114 | + | ||
115 | + } | ||
116 | + }) | ||
117 | + dispatch(updatePageCellList(pageCellList)); | ||
118 | + } | ||
119 | +} |
@@ -9,15 +9,15 @@ let personalInfoCelllist = [ | @@ -9,15 +9,15 @@ let personalInfoCelllist = [ | ||
9 | },{ | 9 | },{ |
10 | id: 'nickname', | 10 | id: 'nickname', |
11 | title: '昵称', | 11 | title: '昵称', |
12 | - content: 'berry', | 12 | + content: '', |
13 | },{ | 13 | },{ |
14 | id: 'gender', | 14 | id: 'gender', |
15 | title: '性别', | 15 | title: '性别', |
16 | - content: 'formale', | 16 | + content: '', |
17 | },{ | 17 | },{ |
18 | id: 'birthDay', | 18 | id: 'birthDay', |
19 | title: '生日', | 19 | title: '生日', |
20 | - content: '6月12日', | 20 | + content: '', |
21 | },{ | 21 | },{ |
22 | id: 'VIPLevel', | 22 | id: 'VIPLevel', |
23 | title: '会员等级', | 23 | title: '会员等级', |
@@ -55,6 +55,10 @@ let personalInfoCelllist = [ | @@ -55,6 +55,10 @@ let personalInfoCelllist = [ | ||
55 | 55 | ||
56 | let InitialState = Record({ | 56 | let InitialState = Record({ |
57 | pageCellList: Immutable.fromJS(personalInfoCelllist), | 57 | pageCellList: Immutable.fromJS(personalInfoCelllist), |
58 | + userProfile: new (Record({ | ||
59 | + isFetching: false, | ||
60 | + profile: Map(), | ||
61 | + })) | ||
58 | }); | 62 | }); |
59 | 63 | ||
60 | export default InitialState; | 64 | export default InitialState; |
@@ -5,13 +5,27 @@ import Immutable, {Map} from 'immutable'; | @@ -5,13 +5,27 @@ import Immutable, {Map} from 'immutable'; | ||
5 | 5 | ||
6 | const { | 6 | const { |
7 | SET_TYPE, | 7 | SET_TYPE, |
8 | + | ||
9 | + FETCH_PROFILE_REQUEST, | ||
10 | + FETCH_PROFILE_SUCCESS, | ||
11 | + FETCH_PROFILE_FAILURE, | ||
12 | + | ||
13 | + UPDATE_PAGE_CELL_LIST, | ||
8 | } = require('../../constants/actionTypes').default; | 14 | } = require('../../constants/actionTypes').default; |
9 | 15 | ||
10 | const initialState = new InitialState; | 16 | const initialState = new InitialState; |
11 | 17 | ||
12 | export default function brandReducer(state=initialState, action) { | 18 | export default function brandReducer(state=initialState, action) { |
13 | - // switch(action.type) { | ||
14 | - // return state; | ||
15 | - // } | 19 | + switch(action.type) { |
20 | + case FETCH_PROFILE_REQUEST: | ||
21 | + return state.setIn(['userProfile', 'isFetching'], true); | ||
22 | + case FETCH_PROFILE_FAILURE: | ||
23 | + return state.setIn(['userProfile', 'isFetching'], false); | ||
24 | + case FETCH_PROFILE_SUCCESS: | ||
25 | + return state.setIn(['userProfile', 'isFetching'], false) | ||
26 | + .setIn(['userProfile', 'profile'], Immutable.fromJS(action.payload)); | ||
27 | + case UPDATE_PAGE_CELL_LIST: | ||
28 | + return state.set('pageCellList', Immutable.fromJS(action.payload)); | ||
29 | + } | ||
16 | return state; | 30 | return state; |
17 | } | 31 | } |
@@ -12,41 +12,12 @@ export default class MineGuangService { | @@ -12,41 +12,12 @@ export default class MineGuangService { | ||
12 | this.api = new Request(baseURL); | 12 | this.api = new Request(baseURL); |
13 | } | 13 | } |
14 | 14 | ||
15 | - async getUserFavArticleList(params) { | 15 | + async getProfile(uid) { |
16 | return await this.api.get({ | 16 | return await this.api.get({ |
17 | - url: '/guang/api/v1/favorite/getUserFavArticleList', | 17 | + url: '', |
18 | body: { | 18 | body: { |
19 | - ...params, | ||
20 | - } | ||
21 | - }) | ||
22 | - .then((json) => { | ||
23 | - return json; | ||
24 | - }) | ||
25 | - .catch((error) => { | ||
26 | - throw(error); | ||
27 | - }); | ||
28 | - } | ||
29 | - | ||
30 | - async getSimpleArticleList(params) { | ||
31 | - return await this.api.get({ | ||
32 | - url: '/guang/api/v2/article/getSimpleArticleList', | ||
33 | - body: { | ||
34 | - ...params, | ||
35 | - } | ||
36 | - }) | ||
37 | - .then((json) => { | ||
38 | - return json; | ||
39 | - }) | ||
40 | - .catch((error) => { | ||
41 | - throw(error); | ||
42 | - }); | ||
43 | - } | ||
44 | - | ||
45 | - async cancelFavorite(params) { | ||
46 | - return await this.api.get({ | ||
47 | - url: '/guang/api/v1/favorite/cancelFavorite', | ||
48 | - body: { | ||
49 | - ...params, | 19 | + method: 'app.passport.profile', |
20 | + uid, | ||
50 | } | 21 | } |
51 | }) | 22 | }) |
52 | .then((json) => { | 23 | .then((json) => { |
-
Please register or login to post a comment