Skip to content

Commit 5a74ba0

Browse files
committed
修改
1 parent 6549681 commit 5a74ba0

File tree

9 files changed

+160
-43
lines changed

9 files changed

+160
-43
lines changed

src/actions/articleInfoActions.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Created by 123 on 2016/7/29.
3+
*/
4+
import { createAction } from 'redux-actions';
5+
import listViewActionEnum from '../constants/listViewActionEnum'
6+
import { api, callApi } from '../apis/api'
7+
import { Actions } from "react-native-router-flux";
8+
9+
const articleInfoActions = {
10+
setArticleId:createAction(listViewActionEnum.SET_ARTICLEID_INFO),
11+
setArticleData:createAction(listViewActionEnum.SET_ARTICLEDATA),
12+
getArticleInfoById: (data)=> {
13+
return dispatch=> {
14+
callApi(
15+
api.getArticleInfo(data),
16+
(data)=>dispatch(articleInfoActions.requestArticleSuccess(data)),
17+
(err)=>console.warn(err)
18+
);
19+
}
20+
},
21+
requestArticleSuccess: (data)=> {
22+
return dispatch=> {
23+
dispatch(
24+
articleInfoActions.setArticleData(data)
25+
);
26+
}
27+
}
28+
29+
}
30+
31+
export default articleInfoActions;

src/actions/listViewActions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ import { createAction } from 'redux-actions';
66
import listViewActionEnum from '../constants/listViewActionEnum'
77
import { api, callApi } from '../apis/api'
88
import { Actions } from "react-native-router-flux";
9+
import articleInfoAction from './articleInfoActions'
910
const listViewActions = {
1011
setListView:createAction(listViewActionEnum.SET_LIST_VIEW),
1112
toDesOfList: (data)=> {
1213
return dispatch=> {
1314
dispatch(
1415
listViewActions.setListView(data)
1516
);
17+
dispatch(
18+
articleInfoAction.setArticleId(data),
19+
Actions.ArticleInfo()
20+
);
1621
}
1722
},
1823
getListRequest: (data)=> {

src/apis/api.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const api = {
1111
`${appConfig.serviceRoot}app/listAll`,
1212
fetchMethod.Get,
1313
{parameter: parameter}
14+
),
15+
getArticleInfo: (parameter)=> createFetch(
16+
`${appConfig.serviceRoot}test/sql/select`,
17+
fetchMethod.Get,
18+
{parameter: parameter}
1419
)
1520
};
1621

src/constants/listViewActionEnum.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* Created by zhaohang on 2016/7/28.
33
*/
44
const listViewActionEnum = {
5-
SET_LIST_VIEW: 'SET_LIST_VIEW'
5+
SET_LIST_VIEW: 'SET_LIST_VIEW',
6+
SET_ARTICLEID_INFO:'SET_ARTICLEID_INFO',
7+
SET_ARTICLEDATA:"SET_ARTICLEDATA"
68
};
79

810
export default listViewActionEnum;

src/containers/android/ListView.js

Lines changed: 19 additions & 36 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,TouchableHighlight} from "react-native";
5+
import {View, Text, StyleSheet,TextInput,Image,ListView} 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 listViewActions from '../../actions/listViewActions'
9+
import loginActions from '../../actions/loginActions'
1010
import {bindActionCreators} from 'redux'
1111
const styles = StyleSheet.create({
1212
row: {
@@ -34,42 +34,27 @@ 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-
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+
}])
4047
};
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-
50-
componentWillMount() {
51-
//控件加载的时候先发起服务请求
52-
this.props.getListRequest(1);
53-
}
54-
pressRow(id) {
55-
this.props.toDesOfList(id);
56-
}
57-
getAllList(aa) {
58-
alert(aa);
5948
}
6049
render() {
61-
let data = this.props.state.listData;
62-
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
63-
let dataSource = ds.cloneWithRows(data);
6450
return (
65-
<ListView enableEmptySections = {true} onEndReached = {this.getAllList} onEndReachedThreshold = {20}
66-
dataSource={dataSource}
51+
<ListView
52+
dataSource={this.state.dataSource}
6753
renderRow={(rowData) =>
68-
<Swipeout right={[{text:'删除',backgroundColor:'red'}]} backgroundColor={'#FFF'}>
69-
<TouchableHighlight onPress={() => this.pressRow(rowData.id)}>
54+
<Swipeout right={[{text:'删除',backgroundColor:'red'}]} backgroundColor={'#FFF'}>
7055
<View style={styles.row}>
7156
<View>
72-
<Image style={styles.thumb} source={{uri:rowData.image}} />
57+
<Image style={styles.thumb} source={require('../../image/login.png')} />
7358
</View>
7459
<View>
7560
<View>
@@ -79,15 +64,12 @@ class listView extends Component {
7964
</View>
8065
<View>
8166
<Text style={styles.desc}>
82-
{rowData.author} {rowData.date}
67+
{rowData.author} {rowData.data}
8368
</Text>
8469
</View>
8570
</View>
8671
</View>
87-
</TouchableHighlight>
8872
</Swipeout>
89-
90-
9173
}
9274
/>
9375
);
@@ -96,12 +78,13 @@ class listView extends Component {
9678

9779
function mapStateToProps(state) {
9880
return {
99-
state:state.listViewReducer
81+
state:{
82+
}
10083
}
10184
}
10285

10386
function mapDispatchToProps(dispatch) {
104-
return bindActionCreators(listViewActions, dispatch);
87+
return bindActionCreators(loginActions, dispatch);
10588
}
10689

10790
export default connect(

src/containers/android/MessInfo.js

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import React, { Component } from 'react';
66
import {View, Text,TextInput,ListView ,StyleSheet,Picker,TouchableHighlight} from "react-native";
77
import DataPickerDemo from './CustomButton'
88
import Button from "react-native-button";
9+
import { connect } from 'react-redux'
10+
import articleInfoActions from '../../actions/articleInfoActions'
11+
import {bindActionCreators} from 'redux'
912

1013
const styles = StyleSheet.create({
1114
container: {
@@ -35,14 +38,47 @@ const styles = StyleSheet.create({
3538
alignSelf: 'center',
3639
borderBottomColor:'#FFFFFF',
3740
borderBottomWidth:1
38-
}
41+
},
42+
buttonview: {
43+
backgroundColor: '#1DBAF1',
44+
margin: 20,
45+
borderRadius: 6,
46+
justifyContent: 'center',
47+
alignItems: 'center'
48+
},
49+
logintext: {
50+
fontSize: 17,
51+
color: '#FFFFFF',
52+
marginTop: 10,
53+
marginBottom: 10
54+
},
3955
});
4056
class MessInfo extends React.Component {
4157
// 初始化模拟数据
4258
constructor(props) {
4359
super(props);
44-
this.state={language:""};
60+
this.state={
61+
language:"",
62+
infoDataId:this.props.infoDataId,
63+
infoData:this.props.infoData
64+
};
4565
}
66+
67+
componentWillReceiveProps(nextProps) {
68+
this.setState({
69+
infoDataId:nextProps.infoDataId,
70+
infoData:nextProps.infoData
71+
});
72+
}
73+
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+
}
81+
4682
render(){
4783
return (
4884
<View style={{backgroundColor: '#2B3745',flex: 1}}>
@@ -51,7 +87,9 @@ class MessInfo extends React.Component {
5187
<Text style={styles.textTitle}>文章名称:</Text>
5288
</View>
5389
<View style={{borderBottomColor:'#FFFFFF',borderBottomWidth:1}}>
54-
<TextInput placeholder="请输入文章名称" placeholderTextColor ='#E0E0E0' underlineColorAndroid='transparent' style={styles.inputText}></TextInput>
90+
<TextInput placeholder="请输入文章名称" placeholderTextColor ='#E0E0E0' underlineColorAndroid='transparent' style={styles.inputText} value={this.state.infoData.title}>
91+
92+
</TextInput>
5593
</View>
5694
</View>
5795

@@ -107,10 +145,33 @@ class MessInfo extends React.Component {
107145
</View>
108146
</View>
109147

148+
<View style={styles.container}>
149+
<View style={styles.buttonview}>
150+
<Text style={styles.logintext} onPress={this.login}>修改</Text>
151+
</View>
152+
<View style={styles.buttonview}>
153+
<Text style={styles.logintext} onPress={this.login}>返回</Text>
154+
</View>
155+
</View>
156+
110157
</View>
111158
)
112159
}
113160

114161
}
115162

116-
export default MessInfo;
163+
function mapStateToProps(state) {
164+
return {
165+
infoDataId:state.articleInfoReducer.infoDataId,
166+
infoData:state.articleInfoReducer.infoData
167+
}
168+
}
169+
170+
function mapDispatchToProps(dispatch) {
171+
return bindActionCreators(articleInfoActions, dispatch);
172+
}
173+
174+
export default connect(
175+
mapStateToProps,
176+
mapDispatchToProps
177+
)(MessInfo)

src/containers/android/app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import main from './../../components/android/Main';
1212
import routeReducerCreator from './../../reducers/routeReducerCreator';
1313
import helper from './../../utils/helper'
1414
import store from './../../store/store';
15-
import info from './../../containers/android/MessInfo'
15+
import ArticleInfo from './../../containers/android/MessInfo'
1616

1717
class App extends React.Component {
1818
constructor(props) {
@@ -34,6 +34,8 @@ class App extends React.Component {
3434
hideNavBar/>
3535
<Scene key="ListView" direction="vertical" component={ListView} title="ListView"
3636
hideNavBar/>
37+
<Scene key="ArticleInfo" direction="vertical" component={ArticleInfo} title="ArticleInfo"
38+
hideNavBar/>
3739
</Scene>
3840
<Scene key="error" component={Error}/>
3941
</Scene>

src/reducers/articleInfoReducer.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Created by 123 on 2016/7/29.
3+
*/
4+
import { handleActions } from 'redux-actions'
5+
import articleInfoActions from '../actions/articleInfoActions'
6+
import {ListView} from "react-native";
7+
8+
const initialState = {
9+
infoDataId :114,
10+
infoData:[]
11+
};
12+
13+
const articleInfoReducer = handleActions({
14+
[articleInfoActions.setArticleId]: (state, action) => {
15+
state = Object.assign({}, state);
16+
state.infoDataId = action.payload;
17+
return state;
18+
},
19+
[articleInfoActions.setArticleData]: (state, action) => {
20+
state = Object.assign({}, state);
21+
state.infoData = action.payload;
22+
return state;
23+
}
24+
25+
}, initialState);
26+
27+
export default articleInfoReducer;

src/reducers/rootReducer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import { combineReducers } from 'redux';
55
import loginReducer from './loginReducer';
66
import listViewReducer from './listViewReducer';
7+
import articleInfoReducer from './articleInfoReducer'
78
// ... other reducers
89

910
const rootReducer = combineReducers({
10-
loginReducer,listViewReducer
11+
loginReducer,listViewReducer,articleInfoReducer
1112
// ... other reducers
1213
});
1314

0 commit comments

Comments
 (0)