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
254cfb55
Commit
254cfb55
authored
Mar 27, 2018
by
Junling Bu
Browse files
处理用户初始没有授权用户信息的情况。
parent
d98b76d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
litemall-wx/pages/goods/goods.js
View file @
254cfb55
...
@@ -2,6 +2,7 @@ var app = getApp();
...
@@ -2,6 +2,7 @@ var app = getApp();
var
WxParse
=
require
(
'
../../lib/wxParse/wxParse.js
'
);
var
WxParse
=
require
(
'
../../lib/wxParse/wxParse.js
'
);
var
util
=
require
(
'
../../utils/util.js
'
);
var
util
=
require
(
'
../../utils/util.js
'
);
var
api
=
require
(
'
../../config/api.js
'
);
var
api
=
require
(
'
../../config/api.js
'
);
var
user
=
require
(
'
../../services/user.js
'
);
Page
({
Page
({
data
:
{
data
:
{
...
@@ -190,16 +191,7 @@ Page({
...
@@ -190,16 +191,7 @@ Page({
this
.
setData
({
this
.
setData
({
id
:
parseInt
(
options
.
id
)
id
:
parseInt
(
options
.
id
)
});
});
var
that
=
this
;
this
.
getGoodsInfo
();
this
.
getGoodsInfo
();
util
.
request
(
api
.
CartGoodsCount
).
then
(
function
(
res
)
{
if
(
res
.
errno
===
0
)
{
that
.
setData
({
cartGoodsCount
:
res
.
data
});
}
});
},
},
onReady
:
function
()
{
onReady
:
function
()
{
// 页面渲染完成
// 页面渲染完成
...
@@ -207,7 +199,14 @@ Page({
...
@@ -207,7 +199,14 @@ Page({
},
},
onShow
:
function
()
{
onShow
:
function
()
{
// 页面显示
// 页面显示
var
that
=
this
;
util
.
request
(
api
.
CartGoodsCount
).
then
(
function
(
res
)
{
if
(
res
.
errno
===
0
)
{
that
.
setData
({
cartGoodsCount
:
res
.
data
});
}
});
},
},
onHide
:
function
()
{
onHide
:
function
()
{
// 页面隐藏
// 页面隐藏
...
@@ -269,8 +268,11 @@ Page({
...
@@ -269,8 +268,11 @@ Page({
},
},
openCartPage
:
function
()
{
openCartPage
:
function
()
{
wx
.
switchTab
({
user
.
checkLogin
().
then
(()
=>
{
url
:
'
/pages/cart/cart
'
,
wx
.
switchTab
({
url
:
'
/pages/cart/cart
'
});
})
.
catch
(()
=>
{
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
});
});
},
},
addFast
:
function
()
{
addFast
:
function
()
{
...
...
litemall-wx/services/user.js
View file @
254cfb55
...
@@ -52,7 +52,31 @@ function getUserInfo() {
...
@@ -52,7 +52,31 @@ function getUserInfo() {
resolve
(
res
);
resolve
(
res
);
},
},
fail
:
function
(
err
)
{
fail
:
function
(
err
)
{
reject
(
err
);
wx
.
showModal
({
title
:
'
用户未授权
'
,
content
:
'
请给予您的用户信息授权。
'
,
success
:
function
(
res
)
{
if
(
res
.
confirm
)
{
wx
.
openSetting
({
success
:
(
res
)
=>
{
if
(
res
.
authSetting
[
"
scope.userInfo
"
]
===
true
)
{
wx
.
getUserInfo
({
withCredentials
:
true
,
success
:
function
(
res
)
{
resolve
(
res
);
},
})
}
}
})
}
else
if
(
res
.
cancel
)
{
wx
.
navigateBack
({
delta
:
1
})
}
}
})
}
}
})
})
});
});
...
@@ -95,13 +119,11 @@ function loginByWeixin() {
...
@@ -95,13 +119,11 @@ function loginByWeixin() {
function
checkLogin
()
{
function
checkLogin
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
if
(
wx
.
getStorageSync
(
'
userInfo
'
)
&&
wx
.
getStorageSync
(
'
token
'
))
{
if
(
wx
.
getStorageSync
(
'
userInfo
'
)
&&
wx
.
getStorageSync
(
'
token
'
))
{
checkSession
().
then
(()
=>
{
checkSession
().
then
(()
=>
{
resolve
(
true
);
resolve
(
true
);
}).
catch
(()
=>
{
}).
catch
(()
=>
{
reject
(
false
);
reject
(
false
);
});
});
}
else
{
}
else
{
reject
(
false
);
reject
(
false
);
}
}
...
...
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