Authored by 张丽霞

个人信息数据请求及更新,review by Redding

... ... @@ -11,7 +11,7 @@ import {
} from 'react-native';
import {Map} from 'immutable';
import YH_Image from '../../common/components/YH_Image';
export default class PersonalInfo extends Component {
constructor(props) {
... ... @@ -26,13 +26,14 @@ export default class PersonalInfo extends Component {
}
let withoutBottomLine = dataSource.get('withoutBottomLine');
let imageUrl = '';
if (dataSource.get('id') == 'portrait') {
if (dataSource.get('id') == 'portrait' && dataSource.get('url') == '') {
imageUrl = require('../image/avatar_icon.png');
} else if (dataSource.get('id') == 'VIPLevel') {
imageUrl = require('../image/VIP1.png');
} else if (dataSource.get('id') == 'mineQRCode') {
imageUrl = require('../image/mine_qr.png');
}
let url = YH_Image.getSlicedUrl(dataSource.get('url'), 40, 40, 2); // 商品缩略图
return (
<View style={[styles.container,{height: cellHeight + (withoutBottomLine?0.0:0.5)}]}>
<View style={[styles.contentContainer,{height: cellHeight}]}>
... ... @@ -45,6 +46,10 @@ export default class PersonalInfo extends Component {
<Text style={styles.content}>
{dataSource.get('content')}
</Text>
{dataSource.get('id') == 'portrait' && dataSource.get('url') != '' ?
<YH_Image url={url} style={styles.userImage} />
:null
}
{imageUrl==''?null:
<Image style={styles.arrow}
source={imageUrl}
... ... @@ -72,6 +77,12 @@ let styles = StyleSheet.create({
title: {
marginLeft: 15,
},
userImage: {
width: 40,
height: 40,
borderRadius: 20,
marginRight: 15,
},
content:{
color: '#b0b0b0',
marginRight: 14,
... ...
... ... @@ -2,4 +2,10 @@ import keyMirror from 'key-mirror';
export default keyMirror({
SET_TYPE: null,
FETCH_PROFILE_REQUEST: null,
FETCH_PROFILE_SUCCESS: null,
FETCH_PROFILE_FAILURE: null,
UPDATE_PAGE_CELL_LIST: null,
});
... ...
... ... @@ -50,6 +50,7 @@ class PersonalInfoContainer extends Component {
}
componentDidMount() {
this.props.actions.fetchPersonalInfo();
}
render() {
... ...
... ... @@ -8,4 +8,112 @@ import {Record, List, Map} from 'immutable';
const {
SET_TYPE,
FETCH_PROFILE_REQUEST,
FETCH_PROFILE_SUCCESS,
FETCH_PROFILE_FAILURE,
UPDATE_PAGE_CELL_LIST,
} = require('../../constants/actionTypes').default;
export function fetchProfileRequest() {
return{
type: FETCH_PROFILE_REQUEST,
}
}
export function fetchProfileSuccess(json) {
return{
type: FETCH_PROFILE_SUCCESS,
payload: json,
}
}
export function fetchProfileFailure(error) {
return{
type: FETCH_PROFILE_FAILURE,
payload: error,
}
}
export function updatePageCellList(list) {
return{
type: UPDATE_PAGE_CELL_LIST,
payload: list,
}
}
export function fetchPersonalInfo() {
return (dispatch, getState) => {
let {app, personalInfo} = getState();
let getProfileFunction = (uid) => {
dispatch(fetchProfileRequest());
return new PersonalInfoService(app.host).getProfile(uid)
.then(json => {
dispatch(fetchProfileSuccess(json));
dispatch(processProfile(json));
})
.catch(error => {
dispatch(fetchProfileFailure());
})
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
getProfileFunction(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
getProfileFunction(uid);
})
.catch(error => {
});
});
}
}
function processProfile(profile){
return (dispatch, getState) => {
let {app, personalInfo} = getState();
let {pageCellList} = personalInfo;
pageCellList = pageCellList.toJS();
pageCellList.map((cellItem, i) => {
switch (cellItem.id) {
case 'portrait':
cellItem.url = profile.head_ico;
break;
case 'nickname':
cellItem.content = profile.nickname;
break;
case 'gender':{
if (profile.gender == 1) {
cellItem.content = 'BOY';
} else if (profile.gender == 2) {
cellItem.content = 'GIRL';
}
}
break;
case 'birthDay':
cellItem.content = profile.birthday;
break;
case 'VIPLevel':{
if (profile.vip_info.cur_level != '0') {
cellItem.content = profile.vip_info.cur_level;
}
}
break;
case 'height':
cellItem.content = profile.height;
break;
case 'weight':
cellItem.content = profile.weight;
break;
default:
}
})
dispatch(updatePageCellList(pageCellList));
}
}
... ...
... ... @@ -9,15 +9,15 @@ let personalInfoCelllist = [
},{
id: 'nickname',
title: '昵称',
content: 'berry',
content: '',
},{
id: 'gender',
title: '性别',
content: 'formale',
content: '',
},{
id: 'birthDay',
title: '生日',
content: '6月12日',
content: '',
},{
id: 'VIPLevel',
title: '会员等级',
... ... @@ -55,6 +55,10 @@ let personalInfoCelllist = [
let InitialState = Record({
pageCellList: Immutable.fromJS(personalInfoCelllist),
userProfile: new (Record({
isFetching: false,
profile: Map(),
}))
});
export default InitialState;
... ...
... ... @@ -5,13 +5,27 @@ import Immutable, {Map} from 'immutable';
const {
SET_TYPE,
FETCH_PROFILE_REQUEST,
FETCH_PROFILE_SUCCESS,
FETCH_PROFILE_FAILURE,
UPDATE_PAGE_CELL_LIST,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function brandReducer(state=initialState, action) {
// switch(action.type) {
// return state;
// }
switch(action.type) {
case FETCH_PROFILE_REQUEST:
return state.setIn(['userProfile', 'isFetching'], true);
case FETCH_PROFILE_FAILURE:
return state.setIn(['userProfile', 'isFetching'], false);
case FETCH_PROFILE_SUCCESS:
return state.setIn(['userProfile', 'isFetching'], false)
.setIn(['userProfile', 'profile'], Immutable.fromJS(action.payload));
case UPDATE_PAGE_CELL_LIST:
return state.set('pageCellList', Immutable.fromJS(action.payload));
}
return state;
}
... ...
... ... @@ -12,41 +12,12 @@ export default class MineGuangService {
this.api = new Request(baseURL);
}
async getUserFavArticleList(params) {
async getProfile(uid) {
return await this.api.get({
url: '/guang/api/v1/favorite/getUserFavArticleList',
url: '',
body: {
...params,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
async getSimpleArticleList(params) {
return await this.api.get({
url: '/guang/api/v2/article/getSimpleArticleList',
body: {
...params,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
async cancelFavorite(params) {
return await this.api.get({
url: '/guang/api/v1/favorite/cancelFavorite',
body: {
...params,
method: 'app.passport.profile',
uid,
}
})
.then((json) => {
... ...