Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
c0fb0732
Commit
c0fb0732
authored
Mar 26, 2018
by
Junling Bu
Browse files
重新实现小商场的用户登陆流程。
parent
24c99f45
Changes
3
Hide whitespace changes
Inline
Side-by-side
litemall-wx/app.js
View file @
c0fb0732
...
...
@@ -4,23 +4,8 @@ var user = require('./services/user.js');
App
({
onLaunch
:
function
()
{
//获取用户的登录信息
user
.
checkLogin
().
then
(
res
=>
{
console
.
log
(
'
app login
'
)
this
.
globalData
.
userInfo
=
wx
.
getStorageSync
(
'
userInfo
'
);
this
.
globalData
.
token
=
wx
.
getStorageSync
(
'
token
'
);
}).
catch
(()
=>
{
});
},
globalData
:
{
userInfo
:
{
nickName
:
'
Hi,游客
'
,
userName
:
'
点击去登录
'
,
avatarUrl
:
'
http://yanxuan.nosdn.127.net/8945ae63d940cc42406c3f67019c5cb6.png
'
},
token
:
''
,
hasLogin
:
false
}
})
\ No newline at end of file
litemall-wx/pages/ucenter/index/index.js
View file @
c0fb0732
...
...
@@ -5,28 +5,29 @@ var app = getApp();
Page
({
data
:
{
userInfo
:
{}
userInfo
:
{
nickName
:
'
点击登录
'
,
avatarUrl
:
'
http://yanxuan.nosdn.127.net/8945ae63d940cc42406c3f67019c5cb6.png
'
}
},
onLoad
:
function
(
options
)
{
// 页面初始化 options为页面跳转所带来的参数
console
.
log
(
app
.
globalData
)
},
onReady
:
function
()
{
},
onShow
:
function
()
{
let
userInfo
=
wx
.
getStorageSync
(
'
userInfo
'
);
let
token
=
wx
.
getStorageSync
(
'
token
'
);
//获取用户的登录信息
user
.
checkLogin
().
then
(
res
=>
{
let
userInfo
=
wx
.
getStorageSync
(
'
userInfo
'
);
// 页面显示
if
(
userInfo
&&
token
)
{
app
.
globalData
.
userInfo
=
userInfo
;
app
.
globalData
.
token
=
token
;
}
this
.
setData
({
userInfo
:
userInfo
,
})
;
}
).
catch
(()
=>
{
this
.
setData
({
userInfo
:
app
.
globalData
.
userInfo
,
});
},
...
...
@@ -38,14 +39,16 @@ Page({
// 页面关闭
},
goLogin
(){
user
.
loginByWeixin
().
then
(
res
=>
{
this
.
setData
({
userInfo
:
res
.
data
.
userInfo
user
.
checkLogin
().
catch
(()
=>
{
user
.
loginByWeixin
().
then
(
res
=>
{
this
.
setData
({
userInfo
:
res
.
data
.
userInfo
,
});
}).
catch
((
err
)
=>
{
util
.
showErrorToast
(
'
登陆失败
'
);
});
app
.
globalData
.
userInfo
=
res
.
data
.
userInfo
;
app
.
globalData
.
token
=
res
.
data
.
token
;
}).
catch
((
err
)
=>
{
console
.
log
(
err
)
});
},
exitLogin
:
function
()
{
...
...
litemall-wx/pages/ucenter/index/index.wxml
View file @
c0fb0732
...
...
@@ -2,9 +2,7 @@
<view class="profile-info" bindtap="goLogin">
<image class="avatar" src="{{userInfo.avatarUrl}}"></image>
<view class="info">
<!-- <text class="name">{{userInfo.nickName}}</text> -->
<text class="name">litemall用户</text>
<text class="level">{{userInfo.userName}}</text>
<text class="name">{{userInfo.nickName}}</text>
</view>
</view>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment