进一步调整登录逻辑。
This commit is contained in:
@@ -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
|
||||
}
|
||||
})
|
||||
@@ -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地址
|
||||
// 本机开发时使用
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,50 +1,59 @@
|
||||
<view class="container">
|
||||
<view class="service-policy">
|
||||
<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="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>
|
||||
<text>还没有登录</text>
|
||||
<button type="primary" bindtap="goLogin">去登录</button>
|
||||
</view>
|
||||
</view>
|
||||
<view class="cart-view" wx:if="{{cartGoods.length > 0}}">
|
||||
<view class="list">
|
||||
<view class="group-item">
|
||||
<view class="goods">
|
||||
<view class="item {{isEditCart ? 'edit' : ''}}" wx:for="{{cartGoods}}" wx:key="id">
|
||||
<view class="checkbox {{item.checked ? 'checked' : ''}}" bindtap="checkedItem" data-item-index="{{index}}"></view>
|
||||
<view class="cart-goods">
|
||||
<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 class='login' wx:else>
|
||||
<view class="service-policy">
|
||||
<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">
|
||||
<image src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/noCart-a8fe3f12e5.png" />
|
||||
<text>去添加点什么吧</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="cart-view" wx:else>
|
||||
<view class="list">
|
||||
<view class="group-item">
|
||||
<view class="goods">
|
||||
<view class="item {{isEditCart ? 'edit' : ''}}" wx:for="{{cartGoods}}" wx:key="id">
|
||||
<view class="checkbox {{item.checked ? 'checked' : ''}}" bindtap="checkedItem" data-item-index="{{index}}"></view>
|
||||
<view class="cart-goods">
|
||||
<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 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 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>
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user