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="购物车" title="购物车"
fixed 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-justify-between v12-px-2">
<view class="v12-font-28 v12-dark-text v12-align-center" @click="show = true"> <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"/> <image :src="webUrl+'/orderIcon/map.png'" style="width: 30rpx;height: 30rpx" class="v12-mr-1"/>
@@ -302,6 +311,7 @@
</view> </view>
</view> </view>
</view> </view>
</view>
<goo-skeleton <goo-skeleton
v-else v-else
:show-avatar="false" :show-avatar="false"
@@ -374,7 +384,9 @@ export default {
isEdit: false, isEdit: false,
addressList:[], addressList:[],
addressInfo: {}, addressInfo: {},
userLikeList: [] userLikeList: [],
// 是否已登录
isNoLogin: false
} }
}, },
computed: { computed: {
@@ -450,6 +462,10 @@ export default {
}, },
getAddress() { getAddress() {
getAddressList({page: 1, limit: 9999}).then(res => { getAddressList({page: 1, limit: 9999}).then(res => {
if (res.isNoLogin) {
this.isNoLogin = true
return
} else {
const { data = [] } = res const { data = [] } = res
this.addressList = data this.addressList = data
this.addressInfo = data.find(e => e.isDefault == 1) || uni.getStorageSync('cartChooseAddress') || (data && data[0]) || null 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 this.addressInfo = data.find(e => e.isDefault == 1) || (data && data[0]) || null
} }
} }
}
}) })
}, },
clearCart() { clearCart() {
@@ -500,6 +517,11 @@ export default {
}, },
async getCart() { async getCart() {
const res = await getCartGroup() const res = await getCartGroup()
if (res.isNoLogin) {
this.isNoLogin = true
this.isLoad = true
return
}
if (res.success) { if (res.success) {
this.isLoad = true this.isLoad = true
const invalid = res.data['invalid'].map(e => { const invalid = res.data['invalid'].map(e => {
@@ -1093,4 +1115,25 @@ view {
overflow: hidden; overflow: hidden;
border-radius: 20rpx; 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> </style>
+71 -12
View File
@@ -1,9 +1,6 @@
<template> <template>
<view class="user user-page tabbar-page"> <view class="user user-page tabbar-page">
<view <view class="acea-row row-column">
v-if="$store.getters.token || userInfo.uid"
class="acea-row row-column"
>
<view class="my-hearder"> <view class="my-hearder">
<view class="my-header-bg"> <view class="my-header-bg">
<image <image
@@ -28,7 +25,10 @@
> >
地标文化特产 地标文化特产
</view> </view>
<view class="info"> <view
v-if="$store.getters.token || userInfo.uid"
class="info"
>
<view class="name-cont"> <view class="name-cont">
<view class="txt flex"> <view class="txt flex">
<view class="txt-cont"> <view class="txt-cont">
@@ -59,21 +59,52 @@
<image :src="userInfo.avatar" class="img" /> <image :src="userInfo.avatar" class="img" />
</view> </view>
</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>
<view class="my-hdeader-bottom"> <view class="my-hdeader-bottom">
<view class="item" @click="linkTo('/pages/user/UserBill/index')"> <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 }} {{ userInfo.nowMoney ? force2Decimal(userInfo.nowMoney) : 0.00 }}
</view> </view>
<view v-else class="number">
--
</view>
<view class="txt"> <view class="txt">
<image :src="webUrl + '/icon/icon-yue.png'" class="img" /> <image :src="webUrl + '/icon/icon-yue.png'" class="img" />
余额 余额
</view> </view>
</view> </view>
<view class="item" @click="linkTo('/pages/user/Points/index')"> <view class="item" @click="linkTo('/pages/user/Points/index')">
<view class="number"> <view v-if="!isNoLogin" class="number">
{{ userInfo.integral || 0 }} {{ userInfo.integral || 0 }}
</view> </view>
<view v-else class="number">
--
</view>
<view class="txt"> <view class="txt">
<image :src="webUrl + '/icon/icon-jifen.png'" class="img" /> <image :src="webUrl + '/icon/icon-jifen.png'" class="img" />
积分 积分
@@ -359,7 +390,9 @@ export default {
bannerBgUrl: '', bannerBgUrl: '',
userCenterBannerUrl: '', userCenterBannerUrl: '',
pageKeyId: Object.freeze('userIndex'), pageKeyId: Object.freeze('userIndex'),
nowrap: true nowrap: true,
// 是否已登录
isNoLogin: false
} }
}, },
computed: mapGetters(['userInfo']), computed: mapGetters(['userInfo']),
@@ -370,19 +403,23 @@ export default {
}, },
onShow() { onShow() {
if (this.$store.getters.token) { if (this.$store.getters.token) {
this.isNoLogin = false
uni.showLoading({ uni.showLoading({
title: '加载中' title: '加载中'
}) })
this.$store.dispatch('getUser', true) this.$store.dispatch('getUser', true)
// 获取用户等级信息 // 获取用户等级信息
this.getUserLevelInfo() this.getUserLevelInfoReq()
this.isWeixin = isWeixin() this.isWeixin = isWeixin()
this.getUnreadMsgList() // this.getUnreadMsgList()
} else { } else {
this.isNoLogin = true
/*
cookie.set('redirect', '/pages/user/User/index') cookie.set('redirect', '/pages/user/User/index')
uni.reLaunch({ uni.reLaunch({
url: '/pages/authorization/index' url: '/pages/authorization/index'
}) })
*/
} }
}, },
onHide() { onHide() {
@@ -451,6 +488,9 @@ export default {
this.$yrouter.push('/pages/order/ReturnList/index') this.$yrouter.push('/pages/order/ReturnList/index')
}, },
goMyOrder(type) { goMyOrder(type) {
if (this.isNoLogin) {
return
}
const types = { const types = {
0: 0, 0: 0,
1: 1, 1: 1,
@@ -475,14 +515,18 @@ export default {
this.$yrouter.push('/pkg_user/views/personalData') this.$yrouter.push('/pkg_user/views/personalData')
}, },
// 获取用户等级信息 // 获取用户等级信息
getUserLevelInfo: function () { getUserLevelInfoReq() {
const _this = this const _this = this
getUserLevelInfo().then((res) => { getUserLevelInfo().then((res) => {
if (res.isNoLogin) {
this.isNoLogin = true
return
} else {
if (res.data) { if (res.data) {
_this.getTextWidth() _this.getTextWidth()
_this.userLevelInfo = res.data _this.userLevelInfo = res.data
} }
uni.hideLoading() }
}).catch(err => { }).catch(err => {
uni.hideLoading() uni.hideLoading()
if (err.toLogin) { if (err.toLogin) {
@@ -534,6 +578,9 @@ export default {
}) })
}, },
toolItemClickHandle(item) { toolItemClickHandle(item) {
if (this.isNoLogin) {
return
}
const url = item.url const url = item.url
if (item.showTip) { if (item.showTip) {
this.$dialog.toast({ this.$dialog.toast({
@@ -550,6 +597,9 @@ export default {
if (!url) { if (!url) {
return return
} }
if (this.isNoLogin) {
return
}
uni.navigateTo({ url }) uni.navigateTo({ url })
}, },
bannerClickHandle() { bannerClickHandle() {
@@ -557,6 +607,12 @@ export default {
return return
} }
this.linkTo(this.userCenterBannerUrl) 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; font-size: 13px;
} }
} }
.qrcode2 {
width: 92rpx;
}
} }
.avatar-cont { .avatar-cont {
.img { .img {
+10 -3
View File
@@ -99,15 +99,22 @@ function baseRequest(options) {
return Promise.reject({msg: "请求失败", res, resData}) return Promise.reject({msg: "请求失败", res, resData})
} }
if (resData.status === 401) { 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 let flag = false
whiteApiList.map(item => { whiteApiList.map(item => {
if (options.url.indexOf(item) > -1) { if (url.indexOf(item) > -1) {
flag = true flag = true
} }
}) })
if (flag) { if (flag) {
return Promise.resolve(resData, res) return Promise.resolve({ ...resData, isNoLogin: true }, res)
} else { } else {
handleLoginFailure(); handleLoginFailure();
return Promise.reject({msg: '未登录', res, resData, toLogin: true}) return Promise.reject({msg: '未登录', res, resData, toLogin: true})