diff --git a/litemall-wx/app.js b/litemall-wx/app.js index eb0bf8bd..115ef992 100644 --- a/litemall-wx/app.js +++ b/litemall-wx/app.js @@ -5,7 +5,14 @@ var user = require('./services/user.js'); App({ onLaunch: function () { }, - + onShow: function (options) { + user.checkLogin().then(res => { + this.globalData.hasLogin = true; + }).catch(() => { + this.globalData.hasLogin = false; + }); + }, globalData: { + hasLogin: false } }) \ No newline at end of file diff --git a/litemall-wx/config/api.js b/litemall-wx/config/api.js index cf61315e..68e627ec 100644 --- a/litemall-wx/config/api.js +++ b/litemall-wx/config/api.js @@ -1,10 +1,10 @@ // 以下是业务服务器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://122.152.206.172:8082/wx/'; +// var WxApiRoot = 'http://122.152.206.172:8082/wx/'; // 以下是图片存储服务器API地址 // 本机开发时使用 diff --git a/litemall-wx/pages/auth/login/login.js b/litemall-wx/pages/auth/login/login.js index b33a0006..ad0cc244 100644 --- a/litemall-wx/pages/auth/login/login.js +++ b/litemall-wx/pages/auth/login/login.js @@ -33,6 +33,8 @@ Page({ user.checkLogin().catch(() => { user.loginByWeixin().then(res => { + app.globalData.hasLogin = true; + wx.navigateBack({ delta: 1 }) @@ -69,6 +71,7 @@ Page({ that.setData({ 'loginErrorCount': 0 }); + app.globalData.hasLogin = true; wx.setStorage({ key:"token", data: res.data.data.token, diff --git a/litemall-wx/pages/cart/cart.js b/litemall-wx/pages/cart/cart.js index aedad74c..a60bc399 100644 --- a/litemall-wx/pages/cart/cart.js +++ b/litemall-wx/pages/cart/cart.js @@ -1,5 +1,6 @@ var util = require('../../utils/util.js'); var api = require('../../config/api.js'); +var user = require('../../services/user.js'); var app = getApp(); @@ -14,7 +15,8 @@ Page({ }, isEditCart: false, checkedAllStatus: true, - editCartList: [] + editCartList: [], + hasLogin: false }, onLoad: function (options) { // 页面初始化 options为页面跳转所带来的参数 @@ -24,7 +26,14 @@ Page({ }, onShow: function () { // 页面显示 - this.getCartList(); + if (app.globalData.hasLogin){ + this.getCartList(); + } + + this.setData({ + hasLogin: app.globalData.hasLogin + }); + }, onHide: function () { // 页面隐藏 @@ -32,6 +41,9 @@ Page({ onUnload: function () { // 页面关闭 }, + goLogin() { + wx.navigateTo({ url: "/pages/auth/login/login" }); + }, getCartList: function () { let that = this; util.request(api.CartList).then(function (res) { diff --git a/litemall-wx/pages/cart/cart.wxml b/litemall-wx/pages/cart/cart.wxml index 4eb2b5d4..4c8a3135 100644 --- a/litemall-wx/pages/cart/cart.wxml +++ b/litemall-wx/pages/cart/cart.wxml @@ -1,50 +1,59 @@ - - 30天无忧退货 - 48小时快速退款 - 满88元免邮费 - - + - - - - - - - - - - - {{item.goodsName}} - x{{item.number}} - - {{ isEditCart ? '已选择:' : ''}}{{item.goodsSpecificationValues||''}} - - ¥{{item.retailPrice}} - - - - - + + \ No newline at end of file diff --git a/litemall-wx/pages/cart/cart.wxss b/litemall-wx/pages/cart/cart.wxss index a3d33a6d..b2214517 100644 --- a/litemall-wx/pages/cart/cart.wxss +++ b/litemall-wx/pages/cart/cart.wxss @@ -31,6 +31,38 @@ page{ 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{ width: 100%; height: auto; diff --git a/litemall-wx/pages/goods/goods.js b/litemall-wx/pages/goods/goods.js index 9e0be4c5..e7419644 100644 --- a/litemall-wx/pages/goods/goods.js +++ b/litemall-wx/pages/goods/goods.js @@ -268,12 +268,7 @@ Page({ }, openCartPage: function () { - user.checkLogin().then(() => { - wx.switchTab({ url: '/pages/cart/cart' }); - }) - .catch(() => { - wx.navigateTo({ url: "/pages/auth/login/login" }); - }); + wx.switchTab({ url: '/pages/cart/cart' }); }, addFast: function () { var that = this; diff --git a/litemall-wx/pages/ucenter/index/index.js b/litemall-wx/pages/ucenter/index/index.js index ff44863b..bf7184ba 100644 --- a/litemall-wx/pages/ucenter/index/index.js +++ b/litemall-wx/pages/ucenter/index/index.js @@ -19,16 +19,12 @@ Page({ onShow: function () { //获取用户的登录信息 - user.checkLogin().then(res => { + if (app.globalData.hasLogin){ let userInfo = wx.getStorageSync('userInfo'); - this.setData({ userInfo: userInfo, }); - - }).catch(() => { - - }); + } }, onHide: function () { @@ -39,58 +35,48 @@ Page({ // 页面关闭 }, goLogin(){ - user.checkLogin().catch(() => { - - user.loginByWeixin().then(res => { - this.setData({ - userInfo: res.data.userInfo, - }); - }).catch((err) => { - util.showErrorToast('登陆失败'); - }); - - }); + wx.navigateTo({ url: "/pages/auth/login/login" }); }, goOrder() { - user.checkLogin().then(() => { + if (app.globalData.hasLogin) { wx.navigateTo({ url: "/pages/ucenter/order/order" }); - }) - .catch(() => { + } + else { wx.navigateTo({ url: "/pages/auth/login/login" }); - }); + } }, goCoupon() { - user.checkLogin().then(() => { + if (app.globalData.hasLogin) { wx.navigateTo({ url: "/pages/ucenter/coupon/coupon" }); - }) - .catch(() => { + } + else { wx.navigateTo({ url: "/pages/auth/login/login" }); - }); + }; }, goCollect() { - user.checkLogin().then(() => { + if (app.globalData.hasLogin) { wx.navigateTo({ url: "/pages/ucenter/collect/collect" }); - }) - .catch(() => { + } + else { wx.navigateTo({ url: "/pages/auth/login/login" }); - }); + }; }, goFootprint() { - user.checkLogin().then(() => { + if (app.globalData.hasLogin) { wx.navigateTo({ url: "/pages/ucenter/footprint/footprint" }); - }) - .catch(() => { + } + else { wx.navigateTo({ url: "/pages/auth/login/login" }); - }); + }; }, goAddress() { - user.checkLogin().then(() => { + if (app.globalData.hasLogin) { wx.navigateTo({ url: "/pages/ucenter/address/address" }); - }) - .catch(() => { + } + else { wx.navigateTo({ url: "/pages/auth/login/login" }); - }); + }; }, exitLogin: function () { wx.showModal({