合并代码

This commit is contained in:
szz
2025-08-01 09:33:46 +08:00
parent 1cfbd79eef
commit e18ed68d30
12 changed files with 363 additions and 53 deletions

View File

@@ -192,7 +192,7 @@
<script setup>
import { ref, reactive, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useRouter, useRoute } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
@@ -207,6 +207,7 @@ import api from '@/utils/api'
import { debounce } from 'lodash-es'
const router = useRouter()
const route = useRoute()
const userStore = useUserStore()
// 响应式数据
@@ -227,12 +228,12 @@ const userPoints = ref(0)
// 分类数据
const categories = ref([
{ id: 'all', name: '全部', icon: '🛍️' },
{ id: 'electronics', name: '数码', icon: '📱' },
{ id: 'books', name: '图书', icon: '📚' },
{ id: 'lifestyle', name: '生活', icon: '🏠' },
{ id: 'food', name: '食', icon: '🍔' },
{ id: 'sports', name: '运动', icon: '' },
{ id: 'beauty', name: '美妆', icon: '💄' }
{ id: '数码产品', name: '数码产品', icon: '📱' },
{ id: '图书文具', name: '图书文具', icon: '📚' },
{ id: '生活用品', name: '生活用品', icon: '🏠' },
{ id: '食品饮料', name: '食品饮料', icon: '🍔' },
{ id: '服装配饰', name: '服装配饰', icon: '👕' },
{ id: '其他', name: '其他', icon: '📦' }
])
// 计算属性
@@ -382,7 +383,7 @@ const getProducts = async (isLoadMore = false) => {
loadingMore.value = true
}
const response = await api.get('/products', {
const {data} = await api.get('/products', {
params: {
page: page.value,
limit: 20,
@@ -391,14 +392,15 @@ const getProducts = async (isLoadMore = false) => {
sort: sortBy.value
}
})
console.log(data,'response');
if (isLoadMore) {
products.value.push(...response.data.products)
products.value.push(...data.data.products)
} else {
products.value = response.data.products
products.value = data.data.products
}
hasMore.value = response.data.hasMore
hasMore.value = data.data.hasMore
page.value++
} catch (error) {
ElMessage.error('获取商品列表失败')
@@ -414,8 +416,8 @@ const loadMore = () => {
const getUserPoints = async () => {
try {
const response = await api.get('/user/points')
userPoints.value = response.data.points
const {data} = await api.get('/user/points')
userPoints.value = data.data.points
} catch (error) {
console.error('获取用户积分失败:', error)
}
@@ -428,6 +430,12 @@ const truncateText = (text, maxLength) => {
// 生命周期
onMounted(() => {
// 检查URL参数中是否有分类
const categoryFromQuery = route.query.category
if (categoryFromQuery && categories.value.some(cat => cat.id === categoryFromQuery)) {
selectedCategory.value = categoryFromQuery
}
getProducts()
getUserPoints()
})