Refactor(购物车&我的):增加未登录或者登录过期显示以便微信审核

This commit is contained in:
lifizer
2025-04-15 15:33:01 +08:00
parent 4fa9c6a594
commit 2f55b0bfb8
3 changed files with 411 additions and 302 deletions
+45 -2
View File
@@ -10,7 +10,16 @@
title="购物车"
fixed
/>
<view v-if="isLoad" :style="{paddingBottom: list.length > 0 ? '120rpx;' : ''}" class="list-wrap">
<view
v-if="isLoad"
:style="{paddingBottom: list.length > 0 ? '120rpx;' : ''}"
class="list-wrap"
>
<view v-if="isNoLogin" class="no-login-wrap">
<view class="txt">您还未登录</view>
<view class="btn">去登录&nbsp;→</view>
</view>
<view v-else>
<view class="v12-justify-between v12-px-2">
<view class="v12-font-28 v12-dark-text v12-align-center" @click="show = true">
<image :src="webUrl+'/orderIcon/map.png'" style="width: 30rpx;height: 30rpx" class="v12-mr-1"/>
@@ -302,6 +311,7 @@
</view>
</view>
</view>
</view>
<goo-skeleton
v-else
:show-avatar="false"
@@ -374,7 +384,9 @@ export default {
isEdit: false,
addressList:[],
addressInfo: {},
userLikeList: []
userLikeList: [],
// 是否已登录
isNoLogin: false
}
},
computed: {
@@ -450,6 +462,10 @@ export default {
},
getAddress() {
getAddressList({page: 1, limit: 9999}).then(res => {
if (res.isNoLogin) {
this.isNoLogin = true
return
} else {
const { data = [] } = res
this.addressList = data
this.addressInfo = data.find(e => e.isDefault == 1) || uni.getStorageSync('cartChooseAddress') || (data && data[0]) || null
@@ -467,6 +483,7 @@ export default {
this.addressInfo = data.find(e => e.isDefault == 1) || (data && data[0]) || null
}
}
}
})
},
clearCart() {
@@ -500,6 +517,11 @@ export default {
},
async getCart() {
const res = await getCartGroup()
if (res.isNoLogin) {
this.isNoLogin = true
this.isLoad = true
return
}
if (res.success) {
this.isLoad = true
const invalid = res.data['invalid'].map(e => {
@@ -1093,4 +1115,25 @@ view {
overflow: hidden;
border-radius: 20rpx;
}
.no-login-wrap {
display: flex;
flex-direction: column;
align-items: center;
padding: 20vh 0;
.txt {
font-size: 36rpx;
line-height: 56rpx;
color: #333;
}
.btn {
height: 60rpx;
margin: 40rpx 0 0 0;
padding: 0 30rpx;
border-radius: 8rpx;
border: 1px solid #C52733;
line-height: 56rpx;
color: #C52733;
font-size: 28rpx;
}
}
</style>
+71 -12
View File
@@ -1,9 +1,6 @@
<template>
<view class="user user-page tabbar-page">
<view
v-if="$store.getters.token || userInfo.uid"
class="acea-row row-column"
>
<view class="acea-row row-column">
<view class="my-hearder">
<view class="my-header-bg">
<image
@@ -28,7 +25,10 @@
>
地标文化特产
</view>
<view class="info">
<view
v-if="$store.getters.token || userInfo.uid"
class="info"
>
<view class="name-cont">
<view class="txt flex">
<view class="txt-cont">
@@ -59,21 +59,52 @@
<image :src="userInfo.avatar" class="img" />
</view>
</view>
<view
v-else
class="info"
>
<view class="name-cont">
<view class="txt flex">
<view class="txt-cont">
您还未登录
</view>
</view>
<view>
<view class="qrcode qrcode2" @click="toLoginHandle">
<text class="v12-font-30">
去登录
</text>
</view>
</view>
</view>
<view class="avatar-cont">
<image
:src="webUrl + '/page/my/avatar.jpg'"
class="img"
/>
</view>
</view>
</view>
<view class="my-hdeader-bottom">
<view class="item" @click="linkTo('/pages/user/UserBill/index')">
<view class="number">
<view v-if="!isNoLogin" class="number">
{{ userInfo.nowMoney ? force2Decimal(userInfo.nowMoney) : 0.00 }}
</view>
<view v-else class="number">
--
</view>
<view class="txt">
<image :src="webUrl + '/icon/icon-yue.png'" class="img" />
余额
</view>
</view>
<view class="item" @click="linkTo('/pages/user/Points/index')">
<view class="number">
<view v-if="!isNoLogin" class="number">
{{ userInfo.integral || 0 }}
</view>
<view v-else class="number">
--
</view>
<view class="txt">
<image :src="webUrl + '/icon/icon-jifen.png'" class="img" />
积分
@@ -359,7 +390,9 @@ export default {
bannerBgUrl: '',
userCenterBannerUrl: '',
pageKeyId: Object.freeze('userIndex'),
nowrap: true
nowrap: true,
// 是否已登录
isNoLogin: false
}
},
computed: mapGetters(['userInfo']),
@@ -370,19 +403,23 @@ export default {
},
onShow() {
if (this.$store.getters.token) {
this.isNoLogin = false
uni.showLoading({
title: '加载中'
})
this.$store.dispatch('getUser', true)
// 获取用户等级信息
this.getUserLevelInfo()
this.getUserLevelInfoReq()
this.isWeixin = isWeixin()
this.getUnreadMsgList()
// this.getUnreadMsgList()
} else {
this.isNoLogin = true
/*
cookie.set('redirect', '/pages/user/User/index')
uni.reLaunch({
url: '/pages/authorization/index'
})
*/
}
},
onHide() {
@@ -451,6 +488,9 @@ export default {
this.$yrouter.push('/pages/order/ReturnList/index')
},
goMyOrder(type) {
if (this.isNoLogin) {
return
}
const types = {
0: 0,
1: 1,
@@ -475,14 +515,18 @@ export default {
this.$yrouter.push('/pkg_user/views/personalData')
},
// 获取用户等级信息
getUserLevelInfo: function () {
getUserLevelInfoReq() {
const _this = this
getUserLevelInfo().then((res) => {
if (res.isNoLogin) {
this.isNoLogin = true
return
} else {
if (res.data) {
_this.getTextWidth()
_this.userLevelInfo = res.data
}
uni.hideLoading()
}
}).catch(err => {
uni.hideLoading()
if (err.toLogin) {
@@ -534,6 +578,9 @@ export default {
})
},
toolItemClickHandle(item) {
if (this.isNoLogin) {
return
}
const url = item.url
if (item.showTip) {
this.$dialog.toast({
@@ -550,6 +597,9 @@ export default {
if (!url) {
return
}
if (this.isNoLogin) {
return
}
uni.navigateTo({ url })
},
bannerClickHandle() {
@@ -557,6 +607,12 @@ export default {
return
}
this.linkTo(this.userCenterBannerUrl)
},
toLoginHandle() {
cookie.set('redirect', '/pages/user/User/index')
uni.reLaunch({
url: '/pages/authorization/index'
})
}
}
}
@@ -736,6 +792,9 @@ export default {
font-size: 13px;
}
}
.qrcode2 {
width: 92rpx;
}
}
.avatar-cont {
.img {
+10 -3
View File
@@ -99,15 +99,22 @@ function baseRequest(options) {
return Promise.reject({msg: "请求失败", res, resData})
}
if (resData.status === 401) {
const whiteApiList = ['guide/status', 'cart/count', 'product/hasFavorite']
const whiteApiList = [
'guide/status',
'cart/count',
'product/hasFavorite',
'cart/listGroup',
'address/list',
'user/levelInfo'
]
let flag = false
whiteApiList.map(item => {
if (options.url.indexOf(item) > -1) {
if (url.indexOf(item) > -1) {
flag = true
}
})
if (flag) {
return Promise.resolve(resData, res)
return Promise.resolve({ ...resData, isNoLogin: true }, res)
} else {
handleLoginFailure();
return Promise.reject({msg: '未登录', res, resData, toLogin: true})