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
ca188343
Commit
ca188343
authored
Mar 30, 2018
by
Junling Bu
Browse files
进一步调整登录逻辑。
parent
d566edc4
Changes
8
Hide whitespace changes
Inline
Side-by-side
litemall-wx/app.js
View file @
ca188343
...
@@ -5,7 +5,14 @@ var user = require('./services/user.js');
...
@@ -5,7 +5,14 @@ var user = require('./services/user.js');
App
({
App
({
onLaunch
:
function
()
{
onLaunch
:
function
()
{
},
},
onShow
:
function
(
options
)
{
user
.
checkLogin
().
then
(
res
=>
{
this
.
globalData
.
hasLogin
=
true
;
}).
catch
(()
=>
{
this
.
globalData
.
hasLogin
=
false
;
});
},
globalData
:
{
globalData
:
{
hasLogin
:
false
}
}
})
})
\ No newline at end of file
litemall-wx/config/api.js
View file @
ca188343
// 以下是业务服务器API地址
// 以下是业务服务器API地址
// 本机开发时使用
// 本机开发时使用
//
var WxApiRoot = 'http://localhost:8082/wx/';
var
WxApiRoot
=
'
http://localhost:8082/wx/
'
;
// 局域网测试使用
// 局域网测试使用
// var WxApiRoot = 'http://192.168.0.101:8082/wx/';
// var WxApiRoot = 'http://192.168.0.101:8082/wx/';
// 云平台部署时使用
// 云平台部署时使用
var
WxApiRoot
=
'
http://122.152.206.172:8082/wx/
'
;
//
var WxApiRoot = 'http://122.152.206.172:8082/wx/';
// 以下是图片存储服务器API地址
// 以下是图片存储服务器API地址
// 本机开发时使用
// 本机开发时使用
...
...
litemall-wx/pages/auth/login/login.js
View file @
ca188343
...
@@ -33,6 +33,8 @@ Page({
...
@@ -33,6 +33,8 @@ Page({
user
.
checkLogin
().
catch
(()
=>
{
user
.
checkLogin
().
catch
(()
=>
{
user
.
loginByWeixin
().
then
(
res
=>
{
user
.
loginByWeixin
().
then
(
res
=>
{
app
.
globalData
.
hasLogin
=
true
;
wx
.
navigateBack
({
wx
.
navigateBack
({
delta
:
1
delta
:
1
})
})
...
@@ -69,6 +71,7 @@ Page({
...
@@ -69,6 +71,7 @@ Page({
that
.
setData
({
that
.
setData
({
'
loginErrorCount
'
:
0
'
loginErrorCount
'
:
0
});
});
app
.
globalData
.
hasLogin
=
true
;
wx
.
setStorage
({
wx
.
setStorage
({
key
:
"
token
"
,
key
:
"
token
"
,
data
:
res
.
data
.
data
.
token
,
data
:
res
.
data
.
data
.
token
,
...
...
litemall-wx/pages/cart/cart.js
View file @
ca188343
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
'
);
var
app
=
getApp
();
var
app
=
getApp
();
...
@@ -14,7 +15,8 @@ Page({
...
@@ -14,7 +15,8 @@ Page({
},
},
isEditCart
:
false
,
isEditCart
:
false
,
checkedAllStatus
:
true
,
checkedAllStatus
:
true
,
editCartList
:
[]
editCartList
:
[],
hasLogin
:
false
},
},
onLoad
:
function
(
options
)
{
onLoad
:
function
(
options
)
{
// 页面初始化 options为页面跳转所带来的参数
// 页面初始化 options为页面跳转所带来的参数
...
@@ -24,7 +26,14 @@ Page({
...
@@ -24,7 +26,14 @@ Page({
},
},
onShow
:
function
()
{
onShow
:
function
()
{
// 页面显示
// 页面显示
this
.
getCartList
();
if
(
app
.
globalData
.
hasLogin
){
this
.
getCartList
();
}
this
.
setData
({
hasLogin
:
app
.
globalData
.
hasLogin
});
},
},
onHide
:
function
()
{
onHide
:
function
()
{
// 页面隐藏
// 页面隐藏
...
@@ -32,6 +41,9 @@ Page({
...
@@ -32,6 +41,9 @@ Page({
onUnload
:
function
()
{
onUnload
:
function
()
{
// 页面关闭
// 页面关闭
},
},
goLogin
()
{
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
},
getCartList
:
function
()
{
getCartList
:
function
()
{
let
that
=
this
;
let
that
=
this
;
util
.
request
(
api
.
CartList
).
then
(
function
(
res
)
{
util
.
request
(
api
.
CartList
).
then
(
function
(
res
)
{
...
...
litemall-wx/pages/cart/cart.wxml
View file @
ca188343
<view class="container">
<view class="container">
<view class="service-policy">
<view class="no-login" wx:if="{{!hasLogin}}">
<view class="item">30天无忧退货</view>
<view class="item">48小时快速退款</view>
<view class="item">满88元免邮费</view>
</view>
<view class="no-cart" wx:if="{{cartGoods.length <= 0}}">
<view class="c">
<view class="c">
<image src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/noCart-a8fe3f12e5.png" />
<image src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/noCart-a8fe3f12e5.png" />
<text>去添加点什么吧</text>
<text>还没有登录</text>
<button type="primary" bindtap="goLogin">去登录</button>
</view>
</view>
</view>
</view>
<view class="cart-view" wx:if="{{cartGoods.length > 0}}">
<view class='login' wx:else>
<view class="list">
<view class="service-policy">
<view class="group-item">
<view class="item">30天无忧退货</view>
<view class="goods">
<view class="item">48小时快速退款</view>
<view class="item {{isEditCart ? 'edit' : ''}}" wx:for="{{cartGoods}}" wx:key="id">
<view class="item">满88元免邮费</view>
<view class="checkbox {{item.checked ? 'checked' : ''}}" bindtap="checkedItem" data-item-index="{{index}}"></view>
</view>
<view class="cart-goods">
<view class="no-cart" wx:if="{{cartGoods.length <= 0}}">
<image class="img" src="{{item.picUrl}}"></image>
<view class="c">
<view class="info">
<image src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/noCart-a8fe3f12e5.png" />
<view class="t">
<text>去添加点什么吧</text>
<text class="name">{{item.goodsName}}</text>
</view>
<text class="num">x{{item.number}}</text>
</view>
</view>
<view class="cart-view" wx:else>
<view class="attr">{{ isEditCart ? '已选择:' : ''}}{{item.goodsSpecificationValues||''}}</view>
<view class="list">
<view class="b">
<view class="group-item">
<text class="price">¥{{item.retailPrice}}</text>
<view class="goods">
<view class="selnum">
<view class="item {{isEditCart ? 'edit' : ''}}" wx:for="{{cartGoods}}" wx:key="id">
<view class="cut" bindtap="cutNumber" data-item-index="{{index}}">-</view>
<view class="checkbox {{item.checked ? 'checked' : ''}}" bindtap="checkedItem" data-item-index="{{index}}"></view>
<input value="{{item.number}}" class="number" disabled="true" type="number" />
<view class="cart-goods">
<view class="add" bindtap="addNumber" data-item-index="{{index}}">+</view>
<image class="img" src="{{item.picUrl}}"></image>
<view class="info">
<view class="t">
<text class="name">{{item.goodsName}}</text>
<text class="num">x{{item.number}}</text>
</view>
<view class="attr">{{ isEditCart ? '已选择:' : ''}}{{item.goodsSpecificationValues||''}}</view>
<view class="b">
<text class="price">¥{{item.retailPrice}}</text>
<view class="selnum">
<view class="cut" bindtap="cutNumber" data-item-index="{{index}}">-</view>
<input value="{{item.number}}" class="number" disabled="true" type="number" />
<view class="add" bindtap="addNumber" data-item-index="{{index}}">+</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<view class="cart-bottom">
<view class="checkbox {{checkedAllStatus ? 'checked' : ''}}" bindtap="checkedAll">全选({{cartTotal.checkedGoodsCount}})</view>
<view class="total">{{!isEditCart ? '¥'+cartTotal.checkedGoodsAmount : ''}}</view>
<view class="delete" bindtap="editCart">{{!isEditCart ? '编辑' : '完成'}}</view>
<view class="checkout" bindtap="deleteCart" wx:if="{{isEditCart}}">删除所选</view>
<view class="checkout" bindtap="checkoutOrder" wx:if="{{!isEditCart}}">下单</view>
</view>
</view>
</view>
<view class="cart-bottom">
<view class="checkbox {{checkedAllStatus ? 'checked' : ''}}" bindtap="checkedAll">全选({{cartTotal.checkedGoodsCount}})</view>
<view class="total">{{!isEditCart ? '¥'+cartTotal.checkedGoodsAmount : ''}}</view>
<view class="delete" bindtap="editCart">{{!isEditCart ? '编辑' : '完成'}}</view>
<view class="checkout" bindtap="deleteCart" wx:if="{{isEditCart}}">删除所选</view>
<view class="checkout" bindtap="checkoutOrder" wx:if="{{!isEditCart}}">下单</view>
</view>
</view>
</view>
</view>
</view>
</view>
\ No newline at end of file
litemall-wx/pages/cart/cart.wxss
View file @
ca188343
...
@@ -31,6 +31,38 @@ page{
...
@@ -31,6 +31,38 @@ page{
color: #666;
color: #666;
}
}
.no-login{
width: 100%;
height: auto;
margin: 0 auto;
}
.no-login .c{
width: 100%;
height: auto;
margin-top: 200rpx;
}
.no-login .c image{
margin: 0 auto;
display: block;
text-align: center;
width: 258rpx;
height: 258rpx;
}
.no-login .c text{
margin: 0 auto;
display: block;
width: 258rpx;
height: 59rpx;
line-height: 29rpx;
text-align: center;
font-size: 50rpx;
color: #999;
}
.no-cart{
.no-cart{
width: 100%;
width: 100%;
height: auto;
height: auto;
...
...
litemall-wx/pages/goods/goods.js
View file @
ca188343
...
@@ -268,12 +268,7 @@ Page({
...
@@ -268,12 +268,7 @@ Page({
},
},
openCartPage
:
function
()
{
openCartPage
:
function
()
{
user
.
checkLogin
().
then
(()
=>
{
wx
.
switchTab
({
url
:
'
/pages/cart/cart
'
});
wx
.
switchTab
({
url
:
'
/pages/cart/cart
'
});
})
.
catch
(()
=>
{
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
});
},
},
addFast
:
function
()
{
addFast
:
function
()
{
var
that
=
this
;
var
that
=
this
;
...
...
litemall-wx/pages/ucenter/index/index.js
View file @
ca188343
...
@@ -19,16 +19,12 @@ Page({
...
@@ -19,16 +19,12 @@ Page({
onShow
:
function
()
{
onShow
:
function
()
{
//获取用户的登录信息
//获取用户的登录信息
user
.
checkLogin
().
then
(
res
=>
{
if
(
app
.
globalData
.
hasLogin
)
{
let
userInfo
=
wx
.
getStorageSync
(
'
userInfo
'
);
let
userInfo
=
wx
.
getStorageSync
(
'
userInfo
'
);
this
.
setData
({
this
.
setData
({
userInfo
:
userInfo
,
userInfo
:
userInfo
,
});
});
}
}).
catch
(()
=>
{
});
},
},
onHide
:
function
()
{
onHide
:
function
()
{
...
@@ -39,58 +35,48 @@ Page({
...
@@ -39,58 +35,48 @@ Page({
// 页面关闭
// 页面关闭
},
},
goLogin
(){
goLogin
(){
user
.
checkLogin
().
catch
(()
=>
{
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
user
.
loginByWeixin
().
then
(
res
=>
{
this
.
setData
({
userInfo
:
res
.
data
.
userInfo
,
});
}).
catch
((
err
)
=>
{
util
.
showErrorToast
(
'
登陆失败
'
);
});
});
},
},
goOrder
()
{
goOrder
()
{
user
.
checkLogin
().
then
(()
=>
{
if
(
app
.
globalData
.
hasLogin
)
{
wx
.
navigateTo
({
url
:
"
/pages/ucenter/order/order
"
});
wx
.
navigateTo
({
url
:
"
/pages/ucenter/order/order
"
});
}
)
}
.
catch
(()
=>
{
else
{
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
}
);
}
},
},
goCoupon
()
{
goCoupon
()
{
user
.
checkLogin
().
then
(()
=>
{
if
(
app
.
globalData
.
hasLogin
)
{
wx
.
navigateTo
({
url
:
"
/pages/ucenter/coupon/coupon
"
});
wx
.
navigateTo
({
url
:
"
/pages/ucenter/coupon/coupon
"
});
}
)
}
.
catch
(()
=>
{
else
{
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
}
)
;
};
},
},
goCollect
()
{
goCollect
()
{
user
.
checkLogin
().
then
(()
=>
{
if
(
app
.
globalData
.
hasLogin
)
{
wx
.
navigateTo
({
url
:
"
/pages/ucenter/collect/collect
"
});
wx
.
navigateTo
({
url
:
"
/pages/ucenter/collect/collect
"
});
}
)
}
.
catch
(()
=>
{
else
{
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
}
)
;
};
},
},
goFootprint
()
{
goFootprint
()
{
user
.
checkLogin
().
then
(()
=>
{
if
(
app
.
globalData
.
hasLogin
)
{
wx
.
navigateTo
({
url
:
"
/pages/ucenter/footprint/footprint
"
});
wx
.
navigateTo
({
url
:
"
/pages/ucenter/footprint/footprint
"
});
}
)
}
.
catch
(()
=>
{
else
{
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
}
)
;
};
},
},
goAddress
()
{
goAddress
()
{
user
.
checkLogin
().
then
(()
=>
{
if
(
app
.
globalData
.
hasLogin
)
{
wx
.
navigateTo
({
url
:
"
/pages/ucenter/address/address
"
});
wx
.
navigateTo
({
url
:
"
/pages/ucenter/address/address
"
});
}
)
}
.
catch
(()
=>
{
else
{
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
}
)
;
};
},
},
exitLogin
:
function
()
{
exitLogin
:
function
()
{
wx
.
showModal
({
wx
.
showModal
({
...
...
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