From 84ce205ee633f7c1f18459e69464e2b0c31212f9 Mon Sep 17 00:00:00 2001 From: xuwenyang Date: Mon, 20 May 2019 22:16:47 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E7=94=A8=E6=88=B7=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=202.=20=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AF=A6=E6=83=85=E9=A1=B5=E4=BB=8A=E5=A4=A9=E6=97=A5?= =?UTF-8?q?=E8=AE=B0=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/diary/diaryBrief.js | 40 ++++++-- src/component/diary/diaryList.js | 5 +- src/component/follow/followUserList.js | 1 + src/component/loading.js | 2 +- src/component/notebook/notebookDiaryList.js | 5 +- src/component/notebook/notebookList.js | 2 - src/component/userIcon.js | 4 +- src/component/userIntro.js | 105 ++++++++++++++++++++ src/dataLoader/userDiaryData.js | 24 +++++ src/page/FollowPage.js | 4 +- src/page/HomePage.js | 23 +---- src/page/UserPage.js | 28 +++--- src/util/api.js | 11 ++ 13 files changed, 204 insertions(+), 50 deletions(-) create mode 100644 src/component/userIntro.js create mode 100644 src/dataLoader/userDiaryData.js diff --git a/src/component/diary/diaryBrief.js b/src/component/diary/diaryBrief.js index cd918c8..f89cba5 100644 --- a/src/component/diary/diaryBrief.js +++ b/src/component/diary/diaryBrief.js @@ -12,31 +12,53 @@ import DiaryActionIcon from './diaryActionIcon'; export default class DiaryBrief extends Component { + constructor(props) { + super(props); + + this.diary = props.diary; + this.editable = props.editable || false; + + this.showField = ['icon', 'userName', 'subject', 'createdTime']; + if(props.showField && props.showField.length > 0) { + this.showField = props.showField + } + } + + show(field) { + return this.showField.indexOf(field) >= 0; + } + render() { - let diary = this.props.diary; + let diary = this.diary; + if(!diary) { + return null; + } + let user = diary.user; - let editable = this.props.editable; return ( - {(user && user.iconUrl) + {(user && user.iconUrl && this.show('icon')) ? : null} - {(user && user.name) + {(user && user.name && this.show('userName')) ? ( {user.name} ) : null} - {(user && user.name) + {(diary.notebook_subject && this.show('subject')) ? ( 《{diary.notebook_subject}》 ) : null} - - {moment(diary.created).format('H:mm')} - + {(diary.created && this.show('createdTime')) + ? ( + {moment(diary.created).format('H:mm')} + + ) : null} + @@ -53,7 +75,7 @@ export default class DiaryBrief extends Component { } { - editable + this.editable ? : null } diff --git a/src/component/diary/diaryList.js b/src/component/diary/diaryList.js index 6d62dc1..cecc7f2 100644 --- a/src/component/diary/diaryList.js +++ b/src/component/diary/diaryList.js @@ -66,6 +66,7 @@ export default class DiaryList extends Component { this.setState({ diaries: result.list ? result.list : [], + hasMore: result.more, refreshFailed: false }); } @@ -130,7 +131,9 @@ export default class DiaryList extends Component { renderItem={({item}) => { return ( this.props.onDiaryPress(item)}> - + + ) }} diff --git a/src/component/follow/followUserList.js b/src/component/follow/followUserList.js index 718f387..eeda3f6 100644 --- a/src/component/follow/followUserList.js +++ b/src/component/follow/followUserList.js @@ -53,6 +53,7 @@ export default class FollowUserList extends Component { this.setState({ users: result.list ? result.list : [], + hasMore: result.more, refreshFailed: false }); } diff --git a/src/component/loading.js b/src/component/loading.js index 1eb1852..252f619 100644 --- a/src/component/loading.js +++ b/src/component/loading.js @@ -22,7 +22,7 @@ export default class Loading extends Component { ); } else { - return + return null; } } } diff --git a/src/component/notebook/notebookDiaryList.js b/src/component/notebook/notebookDiaryList.js index 1b934e0..3496468 100644 --- a/src/component/notebook/notebookDiaryList.js +++ b/src/component/notebook/notebookDiaryList.js @@ -97,6 +97,7 @@ export default class NotebookDiaryList extends Component { let diaries = this.formatDiaries(result.list); this.setState({ diaries, + hasMore: result.more, refreshFailed: false }); } @@ -159,7 +160,9 @@ export default class NotebookDiaryList extends Component { renderItem={(rowData) => { return ( {}}> - + + ); }} diff --git a/src/component/notebook/notebookList.js b/src/component/notebook/notebookList.js index a714392..19c38ab 100644 --- a/src/component/notebook/notebookList.js +++ b/src/component/notebook/notebookList.js @@ -60,8 +60,6 @@ export default class NotebookList extends Component { this.setState({refreshing: true}); Api.getSelfNotebooks() .then(notebooks => { - console.log('get notebooks:', notebooks); - let groups = this.createGroup(notebooks, this.itemsPerRow); this.setState({ notebooks: groups diff --git a/src/component/userIcon.js b/src/component/userIcon.js index 694b7f5..18fa4c5 100644 --- a/src/component/userIcon.js +++ b/src/component/userIcon.js @@ -11,8 +11,10 @@ export default class UserIcon extends Component { render() { return ( - { + this.loadUser(); + }); + } + + loadUser() { + Api.getSelfInfoByStore() + .then(user => { + this.setState({ + user: user + }); + }) + .catch(e => { + Msg.showMsg('用户信息加载失败'); + }) + .done(() => { + this.setState({ + isLoading: false + }) + }); + } + + render() { + const user = this.state.user; + + return this.state.isLoading + ? + : ( + + + + {user.name} + + + { + user.intro && user.intro.length > 0 + ? ({user.intro}) : null + } + + + {moment(user.created).format('YYYY年M月D日')}加入胶囊 + + + + ); + } +} + +const localStyle = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: 'white' + }, + userIcon: { + height: 230, + backgroundColor: 'white', + alignItems: 'center', + justifyContent: 'center' + }, + userTitle: { + fontSize: 22, + marginTop: 30, + fontWeight: 'bold', + color: '#000' + }, + introText: { + padding: 15, + color: Color.text, + lineHeight: 24, + textAlign: 'center' + }, + joinTime: { + marginTop: 30, + marginBottom:60, + padding: 15, + color: Color.inactiveText, + lineHeight: 20, + textAlign: 'center' + } +}); diff --git a/src/dataLoader/userDiaryData.js b/src/dataLoader/userDiaryData.js new file mode 100644 index 0000000..2c7e4b6 --- /dev/null +++ b/src/dataLoader/userDiaryData.js @@ -0,0 +1,24 @@ +import Api from '../util/api' + + +const PAGE_SIZE = 21; + +export default class UserDiaryData { + + constructor(userId = 0) { + this.userId = userId; + } + + async refresh() { + if(this.userId === 0) { + let user = await Api.getSelfInfoByStore(); + this.userId = user.id; + } + + let list = await Api.getUserTodayDiaries(this.userId); + return { + list, + more: false + }; + } +} \ No newline at end of file diff --git a/src/page/FollowPage.js b/src/page/FollowPage.js index 71cb542..e7b1ccb 100644 --- a/src/page/FollowPage.js +++ b/src/page/FollowPage.js @@ -6,7 +6,7 @@ import Api from '../util/api' import {Icon} from '../style/icon' import DiaryList from '../component/diary/diaryList' -import FollowListData from '../dataLoader/followDiaryData'; +import FollowDiaryData from '../dataLoader/followDiaryData'; export default class FollowPage extends Component { @@ -15,7 +15,7 @@ export default class FollowPage extends Component { super(props); Navigation.events().bindComponent(this); - this.dataSource = new FollowListData(); + this.dataSource = new FollowDiaryData(); } static options(passProps) { diff --git a/src/page/HomePage.js b/src/page/HomePage.js index 8af3f2d..5e547f5 100644 --- a/src/page/HomePage.js +++ b/src/page/HomePage.js @@ -5,14 +5,14 @@ import {Navigation} from 'react-native-navigation'; import Api from '../util/api'; import DiaryList from '../component/diary/diaryList' -import HomeListData from '../dataLoader/homeDiaryData'; +import HomeDiaryData from '../dataLoader/homeDiaryData'; export default class HomePage extends Component { constructor(props) { super(props); - this.dataSource = new HomeListData(); + this.dataSource = new HomeDiaryData(); } _onDiaryPress(diary) { @@ -28,20 +28,11 @@ export default class HomePage extends Component { } - renderHeader() { - return ( - - 胶囊日记 - - ); - } - render() { return ( this.list = r} dataSource={this.dataSource} - header={this.renderHeader.bind(this)} onDiaryPress={this._onDiaryPress.bind(this)} navigator={this.props.navigator} @@ -56,15 +47,5 @@ const localStyle = StyleSheet.create({ wrap: { flex: 1, backgroundColor: '#fff' - }, - header: { - paddingLeft: 20, - paddingTop: 20, - flexDirection: "row" - }, - title: { - flex: 1, - fontSize: 30, - color: '#000' } }); diff --git a/src/page/UserPage.js b/src/page/UserPage.js index b0f6644..8a819f1 100644 --- a/src/page/UserPage.js +++ b/src/page/UserPage.js @@ -11,17 +11,23 @@ import {Navigation} from 'react-native-navigation'; import Api from '../util/api'; import Color from '../style/color'; -import NotebookList from '../component/notebook/notebookList' +import UserIntro from '../component/userIntro'; +import UserDiaryData from '../dataLoader/userDiaryData'; +import DiaryList from '../component/diary/diaryList'; +import NotebookList from '../component/notebook/notebookList'; export default class UserPage extends Component { constructor(props) { super(props); + + this.dataSource = new UserDiaryData(); + this.state = { index: 0, routes: [ - { key: 'userInfo', title: '简介' }, + { key: 'userIntro', title: '简介' }, { key: 'diary', title: '日记' }, { key: 'notebook', title: '日记本' } ] @@ -68,8 +74,14 @@ export default class UserPage extends Component { }; _renderScene = SceneMap({ - userInfo: () => user info !, - diary: () => diary !, + userIntro: () => , + diary: () => {}} + + navigator={this.props.navigator} + />, notebook: () =>