Commit ca188343 authored by Junling Bu's avatar Junling Bu
Browse files

进一步调整登录逻辑。

parent d566edc4
...@@ -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
// 以下是业务服务器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地址
// 本机开发时使用 // 本机开发时使用
......
...@@ -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,
......
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 () {
// 页面显示 // 页面显示
if (app.globalData.hasLogin){
this.getCartList(); 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) {
......
<view class="container"> <view class="container">
<view class="no-login" wx:if="{{!hasLogin}}">
<view class="c">
<image src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/noCart-a8fe3f12e5.png" />
<text>还没有登录</text>
<button type="primary" bindtap="goLogin">去登录</button>
</view>
</view>
<view class='login' wx:else>
<view class="service-policy"> <view class="service-policy">
<view class="item">30天无忧退货</view> <view class="item">30天无忧退货</view>
<view class="item">48小时快速退款</view> <view class="item">48小时快速退款</view>
...@@ -10,7 +18,7 @@ ...@@ -10,7 +18,7 @@
<text>去添加点什么吧</text> <text>去添加点什么吧</text>
</view> </view>
</view> </view>
<view class="cart-view" wx:if="{{cartGoods.length > 0}}"> <view class="cart-view" wx:else>
<view class="list"> <view class="list">
<view class="group-item"> <view class="group-item">
<view class="goods"> <view class="goods">
...@@ -47,4 +55,5 @@ ...@@ -47,4 +55,5 @@
<view class="checkout" bindtap="checkoutOrder" wx:if="{{!isEditCart}}">下单</view> <view class="checkout" bindtap="checkoutOrder" wx:if="{{!isEditCart}}">下单</view>
</view> </view>
</view> </view>
</view>
</view> </view>
\ No newline at end of file
...@@ -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;
......
...@@ -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;
......
...@@ -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({
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment