Skip to content

Commit 232927f

Browse files
committed
信息展示
2 parents 5a74ba0 + d831a8a commit 232927f

File tree

8 files changed

+157
-66
lines changed

8 files changed

+157
-66
lines changed

src/actions/articleInfoActions.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,39 @@ const articleInfoActions = {
1313
return dispatch=> {
1414
callApi(
1515
api.getArticleInfo(data),
16-
(data)=>dispatch(articleInfoActions.requestArticleSuccess(data)),
16+
(data)=>dispatch(articleInfoActions.getArticleInfoRequest(data)),
1717
(err)=>console.warn(err)
1818
);
1919
}
2020
},
21-
requestArticleSuccess: (data)=> {
21+
getArticleInfoRequest: (data)=> {
2222
return dispatch=> {
2323
dispatch(
2424
articleInfoActions.setArticleData(data)
2525
);
26+
dispatch(Actions.ArticleInfo());
27+
}
28+
},
29+
updateArticleInfoById: (data)=> {
30+
return dispatch=> {
31+
callApi(
32+
api.updateArticleInfo(data),
33+
(data)=>dispatch(articleInfoActions.getArticleInfoRequest(data)),
34+
(err)=>console.warn(err)
35+
);
36+
}
37+
},
38+
addArticleInfoById: (data)=> {
39+
return dispatch=> {
40+
callApi(
41+
api.updateArticleInfo(data),
42+
(data)=>dispatch(articleInfoActions.getArticleInfoRequest(data)),
43+
(err)=>console.warn(err)
44+
);
2645
}
2746
}
2847

48+
2949
}
3050

3151
export default articleInfoActions;

src/actions/listViewActions.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ const listViewActions = {
1111
setListView:createAction(listViewActionEnum.SET_LIST_VIEW),
1212
toDesOfList: (data)=> {
1313
return dispatch=> {
14+
let p={tableName:"article",condition:"id = "+data};
1415
dispatch(
15-
listViewActions.setListView(data)
16-
);
17-
dispatch(
18-
articleInfoAction.setArticleId(data),
19-
Actions.ArticleInfo()
16+
articleInfoAction.getArticleInfoById(p)
17+
2018
);
2119
}
2220
},

src/apis/api.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ const api = {
1616
`${appConfig.serviceRoot}test/sql/select`,
1717
fetchMethod.Get,
1818
{parameter: parameter}
19+
),
20+
updateArticleInfo: (parameter)=> createFetch(
21+
`${appConfig.serviceRoot}test/sql/update`,
22+
fetchMethod.Get,
23+
{parameter: parameter}
24+
),
25+
addArticleInfo: (parameter)=> createFetch(
26+
`${appConfig.serviceRoot}test/sql/add`,
27+
fetchMethod.Get,
28+
{parameter: parameter}
1929
)
2030
};
2131

src/containers/android/CustomButton.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ class CustomButton extends React.Component {
1717
style={styles.button}
1818
underlineColorAndroid='transparent'
1919
onPress={this.props.onPress}>
20-
<Text style={styles.dateT}>{this.props.text}</Text>
20+
<Text ref="pickerDate" style={styles.dateT}>{this.props.text}</Text>
2121
</TouchableHighlight>
2222
);
2323
}
2424
}
2525
class DataPickerDemo extends Component {
2626
constructor(props){
2727
super(props);
28+
2829
this.state={
2930
presetDate: new Date(2016, 3, 5),
3031
allDate: new Date(2020, 4, 5),
@@ -53,9 +54,10 @@ class DataPickerDemo extends Component {
5354
}
5455

5556
render() {
57+
let date=this.props.Times;
5658
return (
5759
<View>
58-
<CustomButton text={this.state.minText}
60+
<CustomButton text={date}
5961
onPress={this.showPicker.bind(this, 'min', {date: this.state.minDate,minDate:new Date()})}/>
6062
</View>
6163
);

src/containers/android/ListView.js

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* Created by zhaohang on 2016/7/25.
33
*/
44
import React ,{Component}from 'react';
5-
import {View, Text, StyleSheet,TextInput,Image,ListView} from "react-native";
5+
import {View, Text, StyleSheet,TextInput,Image,ListView,TouchableHighlight} from "react-native";
66
import { connect } from 'react-redux'
77
import Button from "react-native-button";
88
import Swipeout from "react-native-swipeout";
9-
import loginActions from '../../actions/loginActions'
9+
import listViewActions from '../../actions/listViewActions'
1010
import {bindActionCreators} from 'redux'
1111
const styles = StyleSheet.create({
1212
row: {
@@ -34,27 +34,49 @@ const styles = StyleSheet.create({
3434
class listView extends Component {
3535
constructor(props) {
3636
super(props);
37-
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
37+
//let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
3838
this.state = {
39-
dataSource :ds.cloneWithRows([{
40-
url: '../image/logo.png', title: '第四代活塞,谁发的第四代活塞,谁发的第四代活塞,谁发的', author: '张三', data: '2016-01-01'
41-
}, {
42-
url: '/src/image/login.png',
43-
title: '库克将怒火几年级',
44-
author: 'lily',
45-
data: '2016-08-08'
46-
}])
39+
pageNum:1
4740
};
41+
this.getAllList = this.getAllList.bind(this);
42+
this.pressRow = this.pressRow.bind(this);
43+
}
44+
componentWillReceiveProps(nextProps) {
45+
this.setState({
46+
});
47+
}
48+
49+
componentWillMount() {
50+
//控件加载的时候先发起服务请求
51+
this.props.getListRequest(1);
52+
}
53+
pressRow(id) {
54+
this.props.toDesOfList(id);
55+
}
56+
getAllList() {
57+
const pageNum = this.state.pageNum;
58+
59+
const pageTotal = Math.ceil(this.props.state.totalNum/10);
60+
if (pageNum<pageTotal) {
61+
this.state.pageNum = pageNum+1;
62+
this.setState({pageNum: this.state.pageNum});
63+
this.props.getListRequest(pageNum+1);
64+
}
65+
4866
}
4967
render() {
68+
let data = this.props.state.listData;
69+
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
70+
let dataSource = ds.cloneWithRows(data);
5071
return (
51-
<ListView
52-
dataSource={this.state.dataSource}
53-
renderRow={(rowData) =>
54-
<Swipeout right={[{text:'删除',backgroundColor:'red'}]} backgroundColor={'#FFF'}>
72+
<ListView enableEmptySections = {true} onEndReached = {this.getAllList} onEndReachedThreshold = {20}
73+
dataSource={dataSource}
74+
renderRow={(rowData) =>
75+
<Swipeout right={[{text:'删除',backgroundColor:'red'}]} backgroundColor={'#FFF'}>
76+
<TouchableHighlight onPress={() => this.pressRow(rowData.id)}>
5577
<View style={styles.row}>
5678
<View>
57-
<Image style={styles.thumb} source={require('../../image/login.png')} />
79+
<Image style={styles.thumb} source={{uri:rowData.image}} />
5880
</View>
5981
<View>
6082
<View>
@@ -64,12 +86,15 @@ class listView extends Component {
6486
</View>
6587
<View>
6688
<Text style={styles.desc}>
67-
{rowData.author} {rowData.data}
89+
{rowData.author} {rowData.date}
6890
</Text>
6991
</View>
7092
</View>
7193
</View>
94+
</TouchableHighlight>
7295
</Swipeout>
96+
97+
7398
}
7499
/>
75100
);
@@ -78,13 +103,12 @@ class listView extends Component {
78103

79104
function mapStateToProps(state) {
80105
return {
81-
state:{
82-
}
106+
state:state.listViewReducer
83107
}
84108
}
85109

86110
function mapDispatchToProps(dispatch) {
87-
return bindActionCreators(loginActions, dispatch);
111+
return bindActionCreators(listViewActions, dispatch);
88112
}
89113

90114
export default connect(

src/containers/android/MessInfo.js

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,46 +38,72 @@ const styles = StyleSheet.create({
3838
alignSelf: 'center',
3939
borderBottomColor:'#FFFFFF',
4040
borderBottomWidth:1
41+
4142
},
42-
buttonview: {
43+
textView: {
4344
backgroundColor: '#1DBAF1',
4445
margin: 20,
4546
borderRadius: 6,
46-
justifyContent: 'center',
47-
alignItems: 'center'
47+
width:75
4848
},
49-
logintext: {
49+
infoText: {
5050
fontSize: 17,
5151
color: '#FFFFFF',
5252
marginTop: 10,
53-
marginBottom: 10
54-
},
53+
marginBottom: 10,
54+
width:70
55+
}
5556
});
5657
class MessInfo extends React.Component {
5758
// 初始化模拟数据
5859
constructor(props) {
5960
super(props);
6061
this.state={
6162
language:"",
62-
infoDataId:this.props.infoDataId,
6363
infoData:this.props.infoData
6464
};
65+
this.updateArticle=this.updateArticle.bind(this);
66+
this.backListView=this.backListView.bind(this);
67+
this.addArticle=this.addArticle.bind(this);
68+
}
69+
70+
updateArticle(){
71+
let title = this.refs.title._lastNativeText;
72+
let url = this.refs.url._lastNativeText;
73+
let author=this.refs.author._lastNativeText;
74+
let pickerDate=this.refs.pickerDate.value;
75+
let p={
76+
tableName:"article",
77+
filed:" title="+title+",url="+url+",author="+author+",type="+this.state.language,
78+
condition:"id = "+this.state.infoData.id
79+
};
80+
this.props.updateArticleInfoById(p);
81+
}
82+
83+
backListView(){
84+
85+
}
86+
87+
addArticle(){
88+
let title = this.refs.title._lastNativeText;
89+
let url = this.refs.url._lastNativeText;
90+
let author=this.refs.author._lastNativeText;
91+
let pickerDate=this.refs.pickerDate.value;
92+
let p={
93+
tableName:"article",
94+
filed:" title="+title+",url="+url+",author="+author+",type="+this.state.language,
95+
condition:"id = "+this.state.infoData.id
96+
};
97+
this.props.addArticleInfoById(p);
6598
}
6699

67100
componentWillReceiveProps(nextProps) {
68101
this.setState({
69-
infoDataId:nextProps.infoDataId,
70102
infoData:nextProps.infoData
71103
});
72104
}
73105

74-
componentWillMount() {
75-
//控件加载的时候先发起服务请求
76-
//var p={tableName:"article",condition:"id = "+this.state.infoDataId}
77-
alert(114);
78-
var p={tableName:"article",condition:"id = 114"}
79-
this.props.getArticleInfoById(p);
80-
}
106+
81107

82108
render(){
83109
return (
@@ -87,7 +113,9 @@ class MessInfo extends React.Component {
87113
<Text style={styles.textTitle}>文章名称:</Text>
88114
</View>
89115
<View style={{borderBottomColor:'#FFFFFF',borderBottomWidth:1}}>
90-
<TextInput placeholder="请输入文章名称" placeholderTextColor ='#E0E0E0' underlineColorAndroid='transparent' style={styles.inputText} value={this.state.infoData.title}>
116+
<TextInput placeholder="请输入文章名称" placeholderTextColor ='#E0E0E0'
117+
underlineColorAndroid='transparent' style={styles.inputText}
118+
value={this.state.infoData.title} ref="title">
91119

92120
</TextInput>
93121
</View>
@@ -99,7 +127,11 @@ class MessInfo extends React.Component {
99127
</View>
100128
<View style={{borderBottomColor:'#FFFFFF',borderBottomWidth:1}}>
101129

102-
<TextInput placeholder="请输入文章链接" placeholderTextColor ='#E0E0E0' underlineColorAndroid='transparent' style={styles.inputText}></TextInput>
130+
<TextInput placeholder="请输入文章链接" placeholderTextColor ='#E0E0E0'
131+
underlineColorAndroid='transparent' style={styles.inputText}
132+
value={this.state.infoData.url} ref="url">
133+
134+
</TextInput>
103135

104136
</View>
105137
</View>
@@ -111,11 +143,13 @@ class MessInfo extends React.Component {
111143
<Picker
112144
mode={'dropdown'}
113145
prompt="请选择文章类型"
146+
ref="type"
114147
style={styles.inputText} placeholderTextColor ='#E0E0E0' underlineColorAndroid='transparent'
115-
selectedValue={this.state.language}
148+
selectedValue={this.state.infoData.type}
116149
onValueChange={(lang) =>this.setState({language: lang})}>
117-
<Picker.Item label="测试" value="test" />
118-
<Picker.Item label="开发" value="js" />
150+
<Picker.Item label="测试" value="0" />
151+
<Picker.Item label="开发" value="1" />
152+
<Picker.Item label="杂记" value="2" />
119153
</Picker>
120154
</View>
121155
</View>
@@ -124,7 +158,11 @@ class MessInfo extends React.Component {
124158
<Text style={styles.textTitle}>文章作者:</Text>
125159
</View>
126160
<View style={{borderBottomColor:'#FFFFFF',borderBottomWidth:1}}>
127-
<TextInput placeholder="请输入文章作者" placeholderTextColor ='#E0E0E0' underlineColorAndroid='transparent' style={styles.inputText}></TextInput>
161+
<TextInput placeholder="请输入文章作者" placeholderTextColor ='#E0E0E0'
162+
underlineColorAndroid='transparent' style={styles.inputText}
163+
value={this.state.infoData.author} ref="author">
164+
165+
</TextInput>
128166

129167
</View>
130168
</View>
@@ -133,7 +171,7 @@ class MessInfo extends React.Component {
133171
<Text style={styles.textTitle}>发表时间:</Text>
134172
</View>
135173
<View style={{borderBottomColor:'#FFFFFF',borderBottomWidth:1}}>
136-
<DataPickerDemo underlineColorAndroid='transparent'/>
174+
<DataPickerDemo Times={this.state.infoData.date} underlineColorAndroid='transparent'/>
137175
</View>
138176
</View>
139177
<View style={styles.container}>
@@ -146,11 +184,14 @@ class MessInfo extends React.Component {
146184
</View>
147185

148186
<View style={styles.container}>
149-
<View style={styles.buttonview}>
150-
<Text style={styles.logintext} onPress={this.login}>修改</Text>
187+
<View style={styles.textView}>
188+
<Text style={styles.infoText} onPress={this.updateArticle}>修改</Text>
189+
</View>
190+
<View style={styles.textView}>
191+
<Text style={styles.infoText} onPress={this.addArticle}>新增</Text>
151192
</View>
152-
<View style={styles.buttonview}>
153-
<Text style={styles.logintext} onPress={this.login}>返回</Text>
193+
<View style={styles.textView}>
194+
<Text style={styles.infoText} onPress={this.backListView}>返回</Text>
154195
</View>
155196
</View>
156197

@@ -162,7 +203,6 @@ class MessInfo extends React.Component {
162203

163204
function mapStateToProps(state) {
164205
return {
165-
infoDataId:state.articleInfoReducer.infoDataId,
166206
infoData:state.articleInfoReducer.infoData
167207
}
168208
}

0 commit comments

Comments
 (0)