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-29 16:43:41 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a5fde45eb6446e664c6c4b02ed145c5ca889efd5
a5fde45e
1 parent
a3614674
增加手机和公司 可修改
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
27 deletions
src/pages/Login.js
src/pages/Mine/index.js
src/pages/Login.js
View file @
a5fde45
...
...
@@ -32,6 +32,8 @@ export default class Login extends Component {
USER_ID
:
""
,
NICKNAME
:
""
,
PROFESSION
:
""
,
COMPANY
:
""
,
PHONE
:
""
,
};
}
componentWillMount
()
{
...
...
@@ -43,11 +45,10 @@ export default class Login extends Component {
_that
.
setState
({
IS_LOGIN
:
result
});
// console.log("Login页面的AsyncStorage", result);
});
}
componentDidMount
()
{
console
.
log
(
"thisprops"
,
this
.
props
);
//
console.log("thisprops", this.props);
}
render
()
{
const
{
navigate
}
=
this
.
props
.
navigation
;
...
...
@@ -227,27 +228,31 @@ export default class Login extends Component {
if
(
respJson
.
enmsg
!=
"ok"
)
{
alert
(
respJson
.
cnmsg
);
}
else
{
console
.
log
(
"登录后
拿到的ID和nickname
"
,
respJson
.
data
);
console
.
log
(
"登录后
返回值
"
,
respJson
.
data
);
let
id
=
JSON
.
stringify
(
respJson
.
data
.
id
),
nickname
=
respJson
.
data
.
nickname
,
phone
=
respJson
.
data
.
phone
.
toString
(),
company
=
respJson
.
data
.
company
,
profession
=
respJson
.
data
.
profession
;
AsyncStorage
.
multiSet
(
[[
"IS_LOGIN"
,
"yes"
],
[
"USER_ID"
,
id
],
[
"NICKNAME"
,
nickname
],
[
"PROFESSION"
,
profession
]],
[[
"IS_LOGIN"
,
"yes"
],
[
"USER_ID"
,
id
],
[
"NICKNAME"
,
nickname
],
[
"PROFESSION"
,
profession
]
,
[
"COMPANY"
,
company
],
[
"PHONE"
,
phone
]
],
function
(
err
)
{
if
(
err
)
{
console
.
log
(
"存储出错"
,
err
);
return
false
;
}
AsyncStorage
.
multiGet
([
"IS_LOGIN"
,
"USER_ID"
,
"NICKNAME"
,
"PROFESSION"
],(
err
,
result
)
=>
{
AsyncStorage
.
multiGet
([
"IS_LOGIN"
,
"USER_ID"
,
"NICKNAME"
,
"PROFESSION"
,
"COMPANY"
,
"PHONE"
],(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
err
);
}
console
.
log
(
"点击登录后的值"
,
result
)
//
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
]
:
""
,
COMPANY
:
(
result
[
4
][
1
]
!=
null
)
?
result
[
4
][
1
]
:
""
,
PHONE
:
(
result
[
5
][
1
]
!=
null
)
?
result
[
5
][
1
]
:
""
,
})
})
that
.
props
.
navigation
.
state
.
params
.
refreshCallback
({
...
...
@@ -255,6 +260,8 @@ export default class Login extends Component {
USER_ID
:
id
,
NICKNAME
:
nickname
,
PROFESSION
:
profession
,
COMPANY
:
company
,
PHONE
:
phone
,
});
setTimeout
(
function
()
{
that
.
props
.
navigation
.
goBack
();
...
...
src/pages/Mine/index.js
View file @
a5fde45
...
...
@@ -55,25 +55,30 @@ export default class Mine extends Component {
NICKNAME
:
""
,
PROFESSION
:
""
,
PHONT
:
""
,
COMPONY
:
""
COMPANY
:
""
,
PHONE
:
""
,
};
this
.
saveResponse1
=
this
.
saveResponse1
.
bind
(
this
);
this
.
saveResponse2
=
this
.
saveResponse2
.
bind
(
this
);
this
.
saveResponse3
=
this
.
saveResponse3
.
bind
(
this
);
this
.
saveResponse4
=
this
.
saveResponse4
.
bind
(
this
);
}
componentWillMount
()
{
var
_that
=
this
;
AsyncStorage
.
multiGet
(
[
"IS_LOGIN"
,
"USER_ID"
,
"NICKNAME"
,
"PROFESSION"
],
[
"IS_LOGIN"
,
"USER_ID"
,
"NICKNAME"
,
"PROFESSION"
,
"COMPANY"
,
"PHONE"
],
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
err
);
}
console
.
log
(
"最初始的
四个个
值"
,
result
);
console
.
log
(
"最初始的
全局
值"
,
result
);
_that
.
setState
({
IS_LOGIN
:
result
[
0
][
1
],
USER_ID
:
result
[
1
][
1
]
!=
null
?
result
[
1
][
1
].
toString
()
:
""
,
NICKNAME
:
result
[
2
][
1
]
!=
null
?
result
[
2
][
1
].
toString
()
:
""
,
PROFESSION
:
result
[
3
][
1
]
!=
null
?
result
[
3
][
1
].
toString
()
:
""
PROFESSION
:
result
[
3
][
1
]
!=
null
?
result
[
3
][
1
].
toString
()
:
""
,
COMPANY
:
result
[
4
][
1
]
!=
null
?
result
[
4
][
1
].
toString
()
:
""
,
PHONE
:
result
[
5
][
1
]
!=
null
?
result
[
5
][
1
].
toString
()
:
""
,
});
}
);
...
...
@@ -108,12 +113,11 @@ export default class Mine extends Component {
saveResponse1
(
d
)
{
let
that
=
this
,
formData
=
new
FormData
();
if
(
that
.
state
.
IS_LOGIN
!=
"yes"
)
{
Alert
.
alert
(
"请先登录账号"
);
return
false
;
}
//
if (that.state.IS_LOGIN != "yes") {
//
Alert.alert("请先登录账号");
//
return false;
//
}
formData
.
append
(
"user"
,
this
.
state
.
USER_ID
);
formData
.
append
(
"profession"
,
""
);
formData
.
append
(
"nickname"
,
d
);
return
fetch
(
`https://devpay.brae.co/test/insurance/change`
,
{
method
:
"POST"
,
...
...
@@ -145,13 +149,12 @@ export default class Mine extends Component {
saveResponse2
(
d
)
{
let
that
=
this
,
formData
=
new
FormData
();
if
(
that
.
state
.
IS_LOGIN
!=
"yes"
)
{
Alert
.
alert
(
"请先登录账号"
);
return
false
;
}
//
if (that.state.IS_LOGIN != "yes") {
//
Alert.alert("请先登录账号");
//
return false;
//
}
formData
.
append
(
"user"
,
this
.
state
.
USER_ID
);
formData
.
append
(
"profession"
,
d
);
formData
.
append
(
"nickname"
,
""
);
return
fetch
(
`https://devpay.brae.co/test/insurance/change`
,
{
method
:
"POST"
,
headers
:
{
...
...
@@ -179,6 +182,78 @@ export default class Mine extends Component {
})
.
catch
(
err
=>
console
.
error
(
err
));
}
saveResponse3
(
d
)
{
let
that
=
this
,
formData
=
new
FormData
();
// if (that.state.IS_LOGIN != "yes") {
// Alert.alert("请先登录账号");
// return false;
// }
formData
.
append
(
"user"
,
this
.
state
.
USER_ID
);
formData
.
append
(
"phone"
,
d
);
return
fetch
(
`https://devpay.brae.co/test/insurance/change`
,
{
method
:
"POST"
,
headers
:
{
Accept
:
"application/json"
,
"Content-Type"
:
"application/json"
},
body
:
formData
})
.
then
(
resp
=>
{
if
(
resp
.
status
===
200
)
{
return
resp
.
json
();
}
else
{
console
.
error
(
"something went wrong!"
);
}
})
.
then
(
respJson
=>
{
if
(
respJson
.
enmsg
!=
"ok"
)
{
Alert
.
alert
(
respJson
.
cnmsg
);
}
else
{
AsyncStorage
.
setItem
(
"PHONE"
,
d
).
then
(()
=>
{
console
.
log
(
"保存修改成功"
);
that
.
setState
({
PHONE
:
d
});
});
}
})
.
catch
(
err
=>
console
.
error
(
err
));
}
saveResponse4
(
d
)
{
let
that
=
this
,
formData
=
new
FormData
();
// if (that.state.IS_LOGIN != "yes") {
// Alert.alert("请先登录账号");
// return false;
// }
formData
.
append
(
"user"
,
this
.
state
.
USER_ID
);
formData
.
append
(
"company"
,
d
);
return
fetch
(
`https://devpay.brae.co/test/insurance/change`
,
{
method
:
"POST"
,
headers
:
{
Accept
:
"application/json"
,
"Content-Type"
:
"application/json"
},
body
:
formData
})
.
then
(
resp
=>
{
if
(
resp
.
status
===
200
)
{
return
resp
.
json
();
}
else
{
console
.
error
(
"something went wrong!"
);
}
})
.
then
(
respJson
=>
{
if
(
respJson
.
enmsg
!=
"ok"
)
{
Alert
.
alert
(
respJson
.
cnmsg
);
}
else
{
AsyncStorage
.
setItem
(
"COMPANY"
,
d
).
then
(()
=>
{
console
.
log
(
"保存修改成功"
);
that
.
setState
({
COMPANY
:
d
});
});
}
})
.
catch
(
err
=>
console
.
error
(
err
));
}
render
()
{
const
{
navigate
}
=
this
.
props
.
navigation
;
...
...
@@ -258,12 +333,12 @@ export default class Mine extends Component {
/
>
<
/View
>
<
/TouchableOpacity
>
{
/*
公司
*/
}
{
/*
手机
*/
}
<
TouchableOpacity
style
=
{
styles
.
itemContainer
}
onPress
=
{()
=>
{
if
(
this
.
state
.
IS_LOGIN
==
"yes"
)
{
AlertIOS
.
prompt
(
"更改手机"
,
null
,
this
.
saveResponse
2
);
AlertIOS
.
prompt
(
"更改手机"
,
null
,
this
.
saveResponse
3
);
}
else
{
Alert
.
alert
(
"请先登录账号"
);
}
...
...
@@ -275,7 +350,7 @@ export default class Mine extends Component {
<
View
style
=
{
styles
.
itemRight
}
>
{
this
.
state
.
IS_LOGIN
===
"yes"
?
(
<
Text
style
=
{
styles
.
itemRightContent
}
>
{
this
.
state
.
PHON
T
}
{
this
.
state
.
PHON
E
}
<
/Text
>
)
:
null
}
<
Image
...
...
@@ -284,12 +359,12 @@ export default class Mine extends Component {
/
>
<
/View
>
<
/TouchableOpacity
>
{
/*
手机
*/
}
{
/*
公司
*/
}
<
TouchableOpacity
style
=
{
styles
.
itemContainer
}
onPress
=
{()
=>
{
if
(
this
.
state
.
IS_LOGIN
==
"yes"
)
{
AlertIOS
.
prompt
(
"更改公司"
,
null
,
this
.
saveResponse
2
);
AlertIOS
.
prompt
(
"更改公司"
,
null
,
this
.
saveResponse
4
);
}
else
{
Alert
.
alert
(
"请先登录账号"
);
}
...
...
@@ -301,7 +376,7 @@ export default class Mine extends Component {
<
View
style
=
{
styles
.
itemRight
}
>
{
this
.
state
.
IS_LOGIN
===
"yes"
?
(
<
Text
style
=
{
styles
.
itemRightContent
}
>
{
this
.
state
.
COMP
O
NY
}
{
this
.
state
.
COMP
A
NY
}
<
/Text
>
)
:
null
}
<
Image
...
...
@@ -400,7 +475,9 @@ export default class Mine extends Component {
IS_LOGIN
:
data
.
IS_LOGIN
,
USER_ID
:
data
.
USER_ID
,
NICKNAME
:
data
.
NICKNAME
,
PROFESSION
:
data
.
PROFESSION
PROFESSION
:
data
.
PROFESSION
,
COMPANY
:
data
.
COMPANY
,
PHONE
:
data
.
PHONE
,
});
}
});
...
...
Please
register
or
login
to post a comment