Showing
2 changed files
with
125 additions
and
21 deletions
| @@ -17,14 +17,17 @@ export default class Login extends Component { | @@ -17,14 +17,17 @@ export default class Login extends Component { | ||
| 17 | this.state = { | 17 | this.state = { |
| 18 | phone: "", | 18 | phone: "", |
| 19 | password: "", | 19 | password: "", |
| 20 | + nickname: "", | ||
| 20 | // 处于登录还是注册页面 | 21 | // 处于登录还是注册页面 |
| 21 | - isRegister: false | 22 | + isRegister: false, |
| 23 | + testData: null, | ||
| 22 | }; | 24 | }; |
| 23 | } | 25 | } |
| 24 | componentDidMount() { | 26 | componentDidMount() { |
| 25 | console.log("thisprops", this.props); | 27 | console.log("thisprops", this.props); |
| 26 | } | 28 | } |
| 27 | render() { | 29 | render() { |
| 30 | + const { navigate } = this.props.navigation; | ||
| 28 | return ( | 31 | return ( |
| 29 | <View style={styles.container}> | 32 | <View style={styles.container}> |
| 30 | <KeyboardAvoidingView behavior="padding" style={styles.KAVContainer}> | 33 | <KeyboardAvoidingView behavior="padding" style={styles.KAVContainer}> |
| @@ -65,6 +68,24 @@ export default class Login extends Component { | @@ -65,6 +68,24 @@ export default class Login extends Component { | ||
| 65 | keyboardType="default" | 68 | keyboardType="default" |
| 66 | /> | 69 | /> |
| 67 | </View> | 70 | </View> |
| 71 | + {/* 昵称 */} | ||
| 72 | + {/* <View style={styles.inputField}> | ||
| 73 | + <Image | ||
| 74 | + style={styles.icon} | ||
| 75 | + source={require("../assets/login/ic_password2.png")} | ||
| 76 | + /> | ||
| 77 | + <TextInput | ||
| 78 | + style={styles.textInput} | ||
| 79 | + placeholder="请输入昵称" | ||
| 80 | + value={this.state.nickname} | ||
| 81 | + onChangeText={nickname => this.setState({ nickname })} | ||
| 82 | + selectionColor="#1B9341" | ||
| 83 | + clearTextOnFocus={true} | ||
| 84 | + numberOfLines={1} | ||
| 85 | + clearButtonMode="always" | ||
| 86 | + keyboardType="default" | ||
| 87 | + /> | ||
| 88 | + </View> */} | ||
| 68 | {/* 登录/注册 按钮 */} | 89 | {/* 登录/注册 按钮 */} |
| 69 | {!this.state.isRegister ? ( | 90 | {!this.state.isRegister ? ( |
| 70 | <TouchableOpacity | 91 | <TouchableOpacity |
| @@ -108,21 +129,52 @@ export default class Login extends Component { | @@ -108,21 +129,52 @@ export default class Login extends Component { | ||
| 108 | } | 129 | } |
| 109 | 130 | ||
| 110 | loginRequest() { | 131 | loginRequest() { |
| 111 | - if (this.props.loginSuccess) return; | 132 | + // if (this.props.loginSuccess) return; |
| 112 | let phone = this.state.phone, | 133 | let phone = this.state.phone, |
| 113 | password = this.state.password; | 134 | password = this.state.password; |
| 114 | - if (!/^1(3|4|5|7|8)\d{9}$/.test(phone)) { | 135 | + // if (!/^1(3|4|5|7|8)\d{9}$/.test(phone)) { |
| 115 | - alert("请正确输入手机号码"); | 136 | + // alert("请正确输入手机号码"); |
| 116 | - return; | 137 | + // return; |
| 117 | - } | 138 | + // } |
| 118 | - if (password === "") { | 139 | + // if (password === "") { |
| 119 | - alert("请输入密码"); | 140 | + // alert("请输入密码"); |
| 120 | - return; | 141 | + // return; |
| 121 | - } else if (password !== "000000") { | 142 | + // } |
| 122 | - alert("账号密码有误"); | 143 | + // this.props.onLogin(true); |
| 123 | - return; | 144 | + let that = this; |
| 145 | + let formData = new FormData(); | ||
| 146 | + formData.append("phone",phone); | ||
| 147 | + formData.append("password",password); | ||
| 148 | + | ||
| 149 | + return fetch(`https://devpay.brae.co/test/insurance/login`,{ | ||
| 150 | + method: "POST", | ||
| 151 | + headers: { | ||
| 152 | + 'Accept': 'application/json', | ||
| 153 | + 'Content-Type': 'application/json', | ||
| 154 | + }, | ||
| 155 | + body: formData, | ||
| 156 | + }) | ||
| 157 | + .then((resp) => { | ||
| 158 | + console.log("测试接口",resp); | ||
| 159 | + // return false; | ||
| 160 | + if (resp.status === 200) { | ||
| 161 | + return resp.json(); | ||
| 162 | + } else { | ||
| 163 | + console.error("something went wrong!"); | ||
| 124 | } | 164 | } |
| 125 | - this.props.onLogin(true); | 165 | + }) |
| 166 | + .then((respJson) => { | ||
| 167 | + // if (respJson.enmsg != 'ok') { | ||
| 168 | + // console.error(err); | ||
| 169 | + // alert(respJson.cnmsg); | ||
| 170 | + // } else { | ||
| 171 | + that.setState({ | ||
| 172 | + testData: respJson.data | ||
| 173 | + }); | ||
| 174 | + console.log('看看登录能获得啥数据',that.state.testData); | ||
| 175 | + // } | ||
| 176 | + }) | ||
| 177 | + .catch((err) => console.error(err)) | ||
| 126 | } | 178 | } |
| 127 | } | 179 | } |
| 128 | 180 |
| @@ -6,7 +6,9 @@ import { | @@ -6,7 +6,9 @@ import { | ||
| 6 | View, | 6 | View, |
| 7 | TouchableOpacity, | 7 | TouchableOpacity, |
| 8 | Image, | 8 | Image, |
| 9 | - AlertIOS | 9 | + AlertIOS, |
| 10 | + AsyncStorage, | ||
| 11 | + Button, | ||
| 10 | } from "react-native"; | 12 | } from "react-native"; |
| 11 | import { StackNavigator, TabNavigator } from 'react-navigation'; | 13 | import { StackNavigator, TabNavigator } from 'react-navigation'; |
| 12 | 14 | ||
| @@ -17,25 +19,69 @@ export default class Mine extends Component { | @@ -17,25 +19,69 @@ export default class Mine extends Component { | ||
| 17 | constructor(props) { | 19 | constructor(props) { |
| 18 | super(props); | 20 | super(props); |
| 19 | this.state = { | 21 | this.state = { |
| 22 | + IS_LOGIN: "no", | ||
| 20 | name: "哈哈哈", | 23 | name: "哈哈哈", |
| 21 | identity: "职业代理人", | 24 | identity: "职业代理人", |
| 22 | }; | 25 | }; |
| 23 | this.saveResponse1 = this.saveResponse1.bind(this); | 26 | this.saveResponse1 = this.saveResponse1.bind(this); |
| 24 | this.saveResponse2 = this.saveResponse2.bind(this); | 27 | this.saveResponse2 = this.saveResponse2.bind(this); |
| 25 | } | 28 | } |
| 29 | + componentWillMount() { | ||
| 30 | + var _that = this; | ||
| 31 | + AsyncStorage.getItem("IS_LOGIN",(err, result) => { | ||
| 32 | + if (err) { | ||
| 33 | + console.error(err); | ||
| 34 | + } | ||
| 35 | + _that.setState({ | ||
| 36 | + IS_LOGIN: result | ||
| 37 | + }) | ||
| 38 | + console.log("能拿到IS_LOGIN吗?",this.state.IS_LOGIN); | ||
| 39 | + }) | ||
| 40 | + } | ||
| 41 | + componentDidMount() { | ||
| 42 | + // console.log("hello,AsyncStorage"); | ||
| 43 | + } | ||
| 44 | + signIn() { | ||
| 45 | + var _that = this | ||
| 46 | + AsyncStorage.setItem("IS_LOGIN","yes",function (err) { | ||
| 47 | + if (err) { | ||
| 48 | + console.log("存储出错",err); | ||
| 49 | + return false; | ||
| 50 | + } | ||
| 51 | + }) | ||
| 52 | + _that.setState({ | ||
| 53 | + IS_LOGIN: "yes" | ||
| 54 | + }) | ||
| 55 | + console.log("改变AsyncStorage",this.state.IS_LOGIN); | ||
| 56 | + } | ||
| 57 | + signOut() { | ||
| 58 | + var _that = this | ||
| 59 | + AsyncStorage.setItem("IS_LOGIN","no",function (err) { | ||
| 60 | + if (err) { | ||
| 61 | + console.log("存储出错",err); | ||
| 62 | + return false; | ||
| 63 | + } | ||
| 64 | + }) | ||
| 65 | + _that.setState({ | ||
| 66 | + IS_LOGIN: "no" | ||
| 67 | + }) | ||
| 68 | + console.log("改变AsyncStorage",this.state.IS_LOGIN); | ||
| 69 | + } | ||
| 26 | saveResponse1(d) { | 70 | saveResponse1(d) { |
| 71 | + if (this.state.IS_LOGIN == "yes") { | ||
| 27 | this.setState({ name: d }); | 72 | this.setState({ name: d }); |
| 28 | } | 73 | } |
| 74 | + } | ||
| 29 | saveResponse2(d) { | 75 | saveResponse2(d) { |
| 76 | + if (this.state.IS_LOGIN == "yes") { | ||
| 30 | this.setState({ identity: d }); | 77 | this.setState({ identity: d }); |
| 31 | } | 78 | } |
| 32 | - loginOut() { | ||
| 33 | - console.log("看看this是什么", this); | ||
| 34 | - this.props.onLogin(false); | ||
| 35 | } | 79 | } |
| 36 | render() { | 80 | render() { |
| 81 | + const { navigate } = this.props.navigation; | ||
| 37 | return ( | 82 | return ( |
| 38 | <View style={styles.container}> | 83 | <View style={styles.container}> |
| 84 | + {/* 头部头像 */} | ||
| 39 | <View style={styles.header}> | 85 | <View style={styles.header}> |
| 40 | <Image | 86 | <Image |
| 41 | source={require("../../assets/Mine/iconpic1.png")} | 87 | source={require("../../assets/Mine/iconpic1.png")} |
| @@ -43,6 +89,7 @@ export default class Mine extends Component { | @@ -43,6 +89,7 @@ export default class Mine extends Component { | ||
| 43 | /> | 89 | /> |
| 44 | </View> | 90 | </View> |
| 45 | <View style={styles.midContainer}> | 91 | <View style={styles.midContainer}> |
| 92 | + {/* 更改昵称 */} | ||
| 46 | <TouchableOpacity | 93 | <TouchableOpacity |
| 47 | style={styles.itemContainer} | 94 | style={styles.itemContainer} |
| 48 | onPress={() => { | 95 | onPress={() => { |
| @@ -55,15 +102,18 @@ export default class Mine extends Component { | @@ -55,15 +102,18 @@ export default class Mine extends Component { | ||
| 55 | source={require("../../assets/tabbar/ic_circle_s.png")} | 102 | source={require("../../assets/tabbar/ic_circle_s.png")} |
| 56 | /> | 103 | /> |
| 57 | <Text style={styles.leftTitle}>昵称</Text> | 104 | <Text style={styles.leftTitle}>昵称</Text> |
| 105 | + {/* {this.state.IS_LOGIN ? <Text style={styles.leftTitle}>昵称</Text> : null} */} | ||
| 58 | </View> | 106 | </View> |
| 59 | <View style={styles.itemRight}> | 107 | <View style={styles.itemRight}> |
| 60 | - <Text style={styles.itemRightContent}>{this.state.name}</Text> | 108 | + { this.state.IS_LOGIN === "yes" ? <Text style={styles.itemRightContent}>{this.state.name}</Text> : null} |
| 109 | + {/* <Text style={styles.itemRightContent}>{this.state.name}</Text> */} | ||
| 61 | <Image | 110 | <Image |
| 62 | style={styles.itemRightImg} | 111 | style={styles.itemRightImg} |
| 63 | source={require("../../assets/Mine/rightArrow_gray.png")} | 112 | source={require("../../assets/Mine/rightArrow_gray.png")} |
| 64 | /> | 113 | /> |
| 65 | </View> | 114 | </View> |
| 66 | </TouchableOpacity> | 115 | </TouchableOpacity> |
| 116 | + {/* 更改职业 */} | ||
| 67 | <TouchableOpacity | 117 | <TouchableOpacity |
| 68 | style={styles.itemContainer} | 118 | style={styles.itemContainer} |
| 69 | onPress={() => { | 119 | onPress={() => { |
| @@ -78,7 +128,8 @@ export default class Mine extends Component { | @@ -78,7 +128,8 @@ export default class Mine extends Component { | ||
| 78 | <Text style={styles.leftTitle}>职业</Text> | 128 | <Text style={styles.leftTitle}>职业</Text> |
| 79 | </View> | 129 | </View> |
| 80 | <View style={styles.itemRight}> | 130 | <View style={styles.itemRight}> |
| 81 | - <Text style={styles.itemRightContent}>{this.state.identity}</Text> | 131 | + {/* <Text style={styles.itemRightContent}>{this.state.identity}</Text> */} |
| 132 | + { this.state.IS_LOGIN === "yes"? <Text style={styles.itemRightContent}>{this.state.identity}</Text> : null} | ||
| 82 | <Image | 133 | <Image |
| 83 | style={styles.itemRightImg} | 134 | style={styles.itemRightImg} |
| 84 | source={require("../../assets/Mine/rightArrow_gray.png")} | 135 | source={require("../../assets/Mine/rightArrow_gray.png")} |
| @@ -92,10 +143,11 @@ export default class Mine extends Component { | @@ -92,10 +143,11 @@ export default class Mine extends Component { | ||
| 92 | style={styles.loginOut} | 143 | style={styles.loginOut} |
| 93 | onLogin={this.props.onLogin} | 144 | onLogin={this.props.onLogin} |
| 94 | onPress={() => { | 145 | onPress={() => { |
| 95 | - this.loginOut(); | 146 | + this.signOut(); |
| 147 | + navigate("Login"); | ||
| 96 | }} | 148 | }} |
| 97 | > | 149 | > |
| 98 | - <Text style={styles.loginOutText}>退出登录</Text> | 150 | + <Text style={styles.loginOutText}>{this.state.IS_LOGIN ? "登录" : "退出登录"}</Text> |
| 99 | </TouchableOpacity> | 151 | </TouchableOpacity> |
| 100 | </View> | 152 | </View> |
| 101 | ); | 153 | ); |
-
Please register or login to post a comment