1
This commit is contained in:
@ -48,6 +48,9 @@
|
||||
<view class="loginBtn" @click="toLogin" v-if="!userInfo.userID">
|
||||
注册/登陆
|
||||
</view>
|
||||
<view class="logoutBtn" @click="logout" v-if="userInfo.userID">
|
||||
退出登录
|
||||
</view>
|
||||
|
||||
</view>
|
||||
<view class="shadowBackground" />
|
||||
@ -59,11 +62,11 @@
|
||||
</view> -->
|
||||
<view class="goods-list">
|
||||
<view class="goods-list-item left">
|
||||
<good-item v-for="(good, i) in leftColumnGoods" :index="2 * i" :key="2 * i" :data="good"
|
||||
<good-item v-for="(good, i) in leftColumnGoods" :index="2 * i" :key="2 * i" :data="good" :isHome="true"
|
||||
@addToCar="addToCar" />
|
||||
</view>
|
||||
<view class="goods-list-item right">
|
||||
<good-item v-for="(good, i) in rightColumnGoods" :index="2 * i + 1" :key="2 * i + 1" :data="good"
|
||||
<good-item v-for="(good, i) in rightColumnGoods" :index="2 * i + 1" :key="2 * i + 1" :data="good" :isHome="true"
|
||||
@addToCar="addToCar" />
|
||||
</view>
|
||||
</view>
|
||||
@ -85,6 +88,9 @@ import {
|
||||
import {
|
||||
userWllet
|
||||
} from "../../../api/login";
|
||||
import {
|
||||
loginOut,
|
||||
} from "../../../api/user";
|
||||
import WeChatCopyModal from "@/components/WeChatCopyModal.vue";
|
||||
import GoodItem from "../shop/components/GoodItem.vue";
|
||||
import DraggableContact from "@/components/DraggableContact.vue";
|
||||
@ -92,6 +98,7 @@ import {
|
||||
getGoodsClassify,
|
||||
getGoodsListData
|
||||
} from "@/api/shop";
|
||||
import { getHomeGoodsWithCache } from "@/utils/goodsCache";
|
||||
|
||||
export default {
|
||||
name: "HomePage",
|
||||
@ -174,19 +181,28 @@ export default {
|
||||
created() {
|
||||
this.getGoodsList()
|
||||
},
|
||||
onShow() {
|
||||
// 页面显示时检查是否需要刷新商品数据
|
||||
this.getGoodsList(false);
|
||||
},
|
||||
methods: {
|
||||
getGoodsList() {
|
||||
getGoodsList(forceRefresh = false) {
|
||||
if (this.isLoadingGoods) return;
|
||||
this.isLoadingGoods = true;
|
||||
const params = {
|
||||
type: 0
|
||||
}
|
||||
getGoodsListData(params)
|
||||
getHomeGoodsWithCache(params, forceRefresh)
|
||||
.then((res) => {
|
||||
const list = res?.data.data.products || [];
|
||||
this.goodsList = list;
|
||||
console.log(this.goodsList,'???')
|
||||
this.goodsTotal = res?.count || 0;
|
||||
// 只有当数据有变化时才更新商品列表,避免不必要的刷新
|
||||
if (res.hasChanged !== false || this.goodsList.length === 0) {
|
||||
this.goodsList = list;
|
||||
}
|
||||
this.goodsTotal = res?.count || list.length || 0;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('获取商品列表失败', err);
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoadingGoods = false;
|
||||
@ -198,6 +214,17 @@ export default {
|
||||
url: "/pages/client/auth/index",
|
||||
});
|
||||
},
|
||||
logout() {
|
||||
loginOut();
|
||||
// 清除Vuex中的用户状态
|
||||
this.$store.dispatch('user/deleteToken');
|
||||
this.$store.dispatch('user/clearUserInfo');
|
||||
// 清除本地缓存
|
||||
uni.clearStorageSync();
|
||||
uni.reLaunch({
|
||||
url: "/pages/client/auth/index",
|
||||
});
|
||||
},
|
||||
// 统一的 token 检查方法,未登录时弹窗让用户自主选择
|
||||
async checkTokenAndExecute(callback) {
|
||||
const token = uni.getStorageSync('token');
|
||||
@ -398,6 +425,7 @@ export default {
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
margin-top: 50rpx;
|
||||
padding: 0 20rpx;
|
||||
|
||||
.goods-list-item {
|
||||
flex: 1;
|
||||
@ -591,6 +619,16 @@ export default {
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.logoutBtn {
|
||||
background: linear-gradient(270deg, #FF19A0 0%, #FF6BB3 100%);
|
||||
border-radius: 218px;
|
||||
color: #fff;
|
||||
font-size: 23rpx;
|
||||
padding: 16rpx 24rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.shadowBackground {
|
||||
|
||||
Reference in New Issue
Block a user