Toggle navigation
Toggle navigation
This project
Loading...
Sign in
罗广聪
/
ProtectGod
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
罗广聪
2017-09-10 18:07:42 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3732395ec206370e226cfc787bed81466db85c77
3732395e
1 parent
8bdffa5e
可以持久存储数据了 登录模块还没搞定
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
26 deletions
src/pages/Login.js
src/pages/Mine/index.js
src/pages/Login.js
View file @
3732395
...
...
@@ -17,14 +17,17 @@ export default class Login extends Component {
this
.
state
=
{
phone
:
""
,
password
:
""
,
nickname
:
""
,
// 处于登录还是注册页面
isRegister
:
false
isRegister
:
false
,
testData
:
null
,
};
}
componentDidMount
()
{
console
.
log
(
"thisprops"
,
this
.
props
);
}
render
()
{
const
{
navigate
}
=
this
.
props
.
navigation
;
return
(
<
View
style
=
{
styles
.
container
}
>
<
KeyboardAvoidingView
behavior
=
"padding"
style
=
{
styles
.
KAVContainer
}
>
...
...
@@ -65,6 +68,24 @@ export default class Login extends Component {
keyboardType
=
"default"
/
>
<
/View
>
{
/* 昵称 */
}
{
/* <View style={styles.inputField}>
<Image
style={styles.icon}
source={require("../assets/login/ic_password2.png")}
/>
<TextInput
style={styles.textInput}
placeholder="请输入昵称"
value={this.state.nickname}
onChangeText={nickname => this.setState({ nickname })}
selectionColor="#1B9341"
clearTextOnFocus={true}
numberOfLines={1}
clearButtonMode="always"
keyboardType="default"
/>
</View> */
}
{
/* 登录/注册 按钮 */
}
{
!
this
.
state
.
isRegister
?
(
<
TouchableOpacity
...
...
@@ -108,21 +129,52 @@ export default class Login extends Component {
}
loginRequest
()
{
if
(
this
.
props
.
loginSuccess
)
return
;
//
if (this.props.loginSuccess) return;
let
phone
=
this
.
state
.
phone
,
password
=
this
.
state
.
password
;
if
(
!
/^1
(
3|4|5|7|8
)\d{9}
$/
.
test
(
phone
))
{
alert
(
"请正确输入手机号码"
);
return
;
}
if
(
password
===
""
)
{
alert
(
"请输入密码"
);
return
;
}
else
if
(
password
!==
"000000"
)
{
alert
(
"账号密码有误"
);
return
;
}
this
.
props
.
onLogin
(
true
);
password
=
this
.
state
.
password
;
// if (!/^1(3|4|5|7|8)\d{9}$/.test(phone)) {
// alert("请正确输入手机号码");
// return;
// }
// if (password === "") {
// alert("请输入密码");
// return;
// }
// this.props.onLogin(true);
let
that
=
this
;
let
formData
=
new
FormData
();
formData
.
append
(
"phone"
,
phone
);
formData
.
append
(
"password"
,
password
);
return
fetch
(
`https://devpay.brae.co/test/insurance/login`
,{
method
:
"POST"
,
headers
:
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
},
body
:
formData
,
})
.
then
((
resp
)
=>
{
console
.
log
(
"测试接口"
,
resp
);
// return false;
if
(
resp
.
status
===
200
)
{
return
resp
.
json
();
}
else
{
console
.
error
(
"something went wrong!"
);
}
})
.
then
((
respJson
)
=>
{
// if (respJson.enmsg != 'ok') {
// console.error(err);
// alert(respJson.cnmsg);
// } else {
that
.
setState
({
testData
:
respJson
.
data
});
console
.
log
(
'看看登录能获得啥数据'
,
that
.
state
.
testData
);
// }
})
.
catch
((
err
)
=>
console
.
error
(
err
))
}
}
...
...
src/pages/Mine/index.js
View file @
3732395
...
...
@@ -6,7 +6,9 @@ import {
View
,
TouchableOpacity
,
Image
,
AlertIOS
AlertIOS
,
AsyncStorage
,
Button
,
}
from
"react-native"
;
import
{
StackNavigator
,
TabNavigator
}
from
'react-navigation'
;
...
...
@@ -17,25 +19,69 @@ export default class Mine extends Component {
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
IS_LOGIN
:
"no"
,
name
:
"哈哈哈"
,
identity
:
"职业代理人"
,
};
this
.
saveResponse1
=
this
.
saveResponse1
.
bind
(
this
);
this
.
saveResponse2
=
this
.
saveResponse2
.
bind
(
this
);
}
componentWillMount
()
{
var
_that
=
this
;
AsyncStorage
.
getItem
(
"IS_LOGIN"
,(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
err
);
}
_that
.
setState
({
IS_LOGIN
:
result
})
console
.
log
(
"能拿到IS_LOGIN吗?"
,
this
.
state
.
IS_LOGIN
);
})
}
componentDidMount
()
{
// console.log("hello,AsyncStorage");
}
signIn
()
{
var
_that
=
this
AsyncStorage
.
setItem
(
"IS_LOGIN"
,
"yes"
,
function
(
err
)
{
if
(
err
)
{
console
.
log
(
"存储出错"
,
err
);
return
false
;
}
})
_that
.
setState
({
IS_LOGIN
:
"yes"
})
console
.
log
(
"改变AsyncStorage"
,
this
.
state
.
IS_LOGIN
);
}
signOut
()
{
var
_that
=
this
AsyncStorage
.
setItem
(
"IS_LOGIN"
,
"no"
,
function
(
err
)
{
if
(
err
)
{
console
.
log
(
"存储出错"
,
err
);
return
false
;
}
})
_that
.
setState
({
IS_LOGIN
:
"no"
})
console
.
log
(
"改变AsyncStorage"
,
this
.
state
.
IS_LOGIN
);
}
saveResponse1
(
d
)
{
this
.
setState
({
name
:
d
});
if
(
this
.
state
.
IS_LOGIN
==
"yes"
)
{
this
.
setState
({
name
:
d
});
}
}
saveResponse2
(
d
)
{
this
.
setState
({
identity
:
d
});
}
loginOut
()
{
console
.
log
(
"看看this是什么"
,
this
);
this
.
props
.
onLogin
(
false
);
if
(
this
.
state
.
IS_LOGIN
==
"yes"
)
{
this
.
setState
({
identity
:
d
});
}
}
render
()
{
const
{
navigate
}
=
this
.
props
.
navigation
;
return
(
<
View
style
=
{
styles
.
container
}
>
{
/* 头部头像 */
}
<
View
style
=
{
styles
.
header
}
>
<
Image
source
=
{
require
(
"../../assets/Mine/iconpic1.png"
)}
...
...
@@ -43,6 +89,7 @@ export default class Mine extends Component {
/
>
<
/View
>
<
View
style
=
{
styles
.
midContainer
}
>
{
/* 更改昵称 */
}
<
TouchableOpacity
style
=
{
styles
.
itemContainer
}
onPress
=
{()
=>
{
...
...
@@ -55,15 +102,18 @@ export default class Mine extends Component {
source
=
{
require
(
"../../assets/tabbar/ic_circle_s.png"
)}
/
>
<
Text
style
=
{
styles
.
leftTitle
}
>
昵称
<
/Text
>
{
/* {this.state.IS_LOGIN ? <Text style={styles.leftTitle}>昵称</Text> : null} */
}
<
/View
>
<
View
style
=
{
styles
.
itemRight
}
>
<
Text
style
=
{
styles
.
itemRightContent
}
>
{
this
.
state
.
name
}
<
/Text
>
{
this
.
state
.
IS_LOGIN
===
"yes"
?
<
Text
style
=
{
styles
.
itemRightContent
}
>
{
this
.
state
.
name
}
<
/Text> : null
}
{
/* <Text style={styles.itemRightContent}>{this.state.name}</Text> */
}
<
Image
style
=
{
styles
.
itemRightImg
}
source
=
{
require
(
"../../assets/Mine/rightArrow_gray.png"
)}
/
>
<
/View
>
<
/TouchableOpacity
>
{
/* 更改职业 */
}
<
TouchableOpacity
style
=
{
styles
.
itemContainer
}
onPress
=
{()
=>
{
...
...
@@ -78,7 +128,8 @@ export default class Mine extends Component {
<
Text
style
=
{
styles
.
leftTitle
}
>
职业
<
/Text
>
<
/View
>
<
View
style
=
{
styles
.
itemRight
}
>
<
Text
style
=
{
styles
.
itemRightContent
}
>
{
this
.
state
.
identity
}
<
/Text
>
{
/* <Text style={styles.itemRightContent}>{this.state.identity}</Text> */
}
{
this
.
state
.
IS_LOGIN
===
"yes"
?
<
Text
style
=
{
styles
.
itemRightContent
}
>
{
this
.
state
.
identity
}
<
/Text> : null
}
<
Image
style
=
{
styles
.
itemRightImg
}
source
=
{
require
(
"../../assets/Mine/rightArrow_gray.png"
)}
...
...
@@ -92,10 +143,11 @@ export default class Mine extends Component {
style
=
{
styles
.
loginOut
}
onLogin
=
{
this
.
props
.
onLogin
}
onPress
=
{()
=>
{
this
.
loginOut
();
this
.
signOut
();
navigate
(
"Login"
);
}}
>
<
Text
style
=
{
styles
.
loginOutText
}
>
退出登录
<
/Text
>
<
Text
style
=
{
styles
.
loginOutText
}
>
{
this
.
state
.
IS_LOGIN
?
"登录"
:
"退出登录"
}
<
/Text
>
<
/TouchableOpacity
>
<
/View
>
);
...
...
Please
register
or
login
to post a comment