release.js
4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import React, { Component } from "react";
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
ScrollView,
ListView,
Dimensions,
TextInput,
AsyncStorage,
Alert
} from "react-native";
import { StackNavigator, TabNavigator } from "react-navigation";
export default class Home extends Component {
constructor(props) {
super(props);
this.state = {
title: "",
content: "",
IS_LOGIN: "",
USER_ID: "",
NICKNAME: "",
PROFESSION: ""
};
}
componentWillMount() {
this.getAsyncStorage();
}
componentDidMount() {}
getAsyncStorage() {
const that = this;
AsyncStorage.multiGet(
["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION"],
(err, result) => {
if (err) {
console.error(err);
}
console.log("点击登录后的值", result);
that.setState({
IS_LOGIN: result[0][1],
USER_ID: result[1][1] != null ? result[1][1] : "",
NICKNAME: result[2][1] != null ? result[2][1] : "",
PROFESSION: result[3][1] != null ? result[3][1] : ""
});
}
);
}
getListData() {
let that = this;
return fetch(`https://devpay.brae.co/test/insurance/topic`, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
})
.then(resp => {
if (resp.status === 200) {
return resp.json();
} else {
console.error("something went wrong!");
}
})
.then(respJson => {
if (respJson.enmsg != "ok") {
alert(respJson.cnmsg);
} else {
that.setState({
ListData: respJson.data.topic
});
console.log("首页列表", this.state.ListData);
}
});
}
submit() {
if (!this.state.title) {
Alert.alert("请填写标题");
return false;
}
if (!this.state.content) {
Alert.alert("请填写内容");
return false;
}
console.log("title和content",this.state.title,this.state.content);
}
render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<View style={styles.inputContaier}>
<TextInput
style={styles.titleInput}
placeholder="文章标题"
onChangeText={title => this.setState({ title })}
value={this.state.title}
autoCapitalize="none"
selectionColor="#1B9341"
numberOfLines={1}
clearButtonMode="always"
keyboardType="default"
enablesReturnKeyAutomatically={true}
returnKeyType="send"
onSubmitEditing={() => {
Keyboard.dismiss();
}}
/>
</View>
<View style={styles.inputContaier}>
<TextInput
style={styles.contentInput}
placeholder="填写发布内容"
onChangeText={content => this.setState({ content })}
value={this.state.content}
autoCapitalize="none"
multiline={true}
selectionColor="#1B9341"
clearButtonMode="always"
keyboardType="default"
enablesReturnKeyAutomatically={true}
returnKeyType="send"
onSubmitEditing={() => {
Keyboard.dismiss();
}}
/>
</View>
<TouchableOpacity
onPress={() => {
this.submit();
}}
style={styles.confirmBtn}
>
<Text style={styles.confirmBtnText}>发布</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "flex-start",
alignItems: "stretch",
backgroundColor: "#EFEFEF"
},
inputContaier: {
backgroundColor: "white",
paddingHorizontal: 15,
paddingVertical: 10,
borderStyle: "solid",
borderColor: "#EFEFEF",
borderTopWidth: 1
},
titleInput: {
fontSize: 15,
paddingTop: 8,
paddingBottom: 7
},
contentInput: {
fontSize: 15,
paddingTop: 8,
paddingBottom: 7,
height: 200
},
confirmBtn: {
marginVertical: 20,
marginHorizontal: 40,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#1B9341",
height: 45,
borderRadius: 5
},
confirmBtnText: {
fontSize: 16,
color: "white"
}
});