优化一些问题
This commit is contained in:
@@ -6,11 +6,11 @@
|
||||
<!-- 用户信息区域 -->
|
||||
<div class="user-info" @click="handleUserClick">
|
||||
<div class="avatar">
|
||||
<a-avatar :size="40" :src="userInfo.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" />
|
||||
<a-avatar :size="40" :src="userInfo?.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" />
|
||||
</div>
|
||||
<div class="welcome">
|
||||
<p class="greeting">Hello!</p>
|
||||
<p class="username">{{ userInfo.nickname || '用户' }}</p>
|
||||
<p class="username">{{ userInfo?.nickname || '用户' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 通知按钮 -->
|
||||
@@ -139,6 +139,8 @@ const userInfo = ref<UserVO>({
|
||||
nickname: '',
|
||||
account: '',
|
||||
avatar: '',
|
||||
type: 0,
|
||||
status: 0,
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
@@ -159,8 +161,8 @@ const pageSize = ref(10)
|
||||
// 加载用户信息
|
||||
const loadUserInfo = async () => {
|
||||
try {
|
||||
const data = await userApi.getUserInfo()
|
||||
userInfo.value = data as unknown as UserVO
|
||||
const response = await userApi.getUserInfo() as any
|
||||
userInfo.value = response || {}
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
}
|
||||
@@ -169,10 +171,11 @@ const loadUserInfo = async () => {
|
||||
// 加载精选商品
|
||||
const loadFeaturedProducts = async () => {
|
||||
try {
|
||||
const data = await productApi.getProductsByTag('精选')
|
||||
// 随机选择5个商品
|
||||
const shuffled = data.sort(() => 0.5 - Math.random())
|
||||
featuredItems.value = shuffled.slice(0, 5).map(item => ({
|
||||
const response = await productApi.getProductsByTag('精选') as any
|
||||
const data = response || []
|
||||
const productList = Array.isArray(data) ? data : []
|
||||
const shuffled = productList.sort(() => 0.5 - Math.random())
|
||||
featuredItems.value = shuffled.slice(0, 5).map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
price: item.price,
|
||||
@@ -189,34 +192,34 @@ const loadPopularProducts = async (loadMore = false) => {
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await productApi.getProductsByTag('热门')
|
||||
const response = await productApi.getProductsByTag('热门') as any
|
||||
const data = response || []
|
||||
const productList = Array.isArray(data) ? data : []
|
||||
|
||||
if (loadMore) {
|
||||
// 模拟分页,实际应该在API中实现
|
||||
const start = (page.value - 1) * pageSize.value
|
||||
const end = start + pageSize.value
|
||||
const newItems = data.slice(start, end)
|
||||
const newItems = productList.slice(start, end)
|
||||
|
||||
if (newItems.length < pageSize.value) {
|
||||
hasMore.value = false
|
||||
}
|
||||
|
||||
popularItems.value = [...popularItems.value, ...newItems.map(item => ({
|
||||
popularItems.value = [...popularItems.value, ...newItems.map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
price: item.price,
|
||||
bgColor: getRandomColor()
|
||||
}))]
|
||||
} else {
|
||||
// 初始加载
|
||||
popularItems.value = data.slice(0, pageSize.value).map(item => ({
|
||||
popularItems.value = productList.slice(0, pageSize.value).map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
price: item.price,
|
||||
bgColor: getRandomColor()
|
||||
}))
|
||||
|
||||
if (data.length <= pageSize.value) {
|
||||
if (productList.length <= pageSize.value) {
|
||||
hasMore.value = false
|
||||
}
|
||||
}
|
||||
@@ -277,8 +280,8 @@ const handleNotificationClick = () => {
|
||||
}
|
||||
|
||||
// 处理搜索输入
|
||||
const handleSearch = (val: string) => {
|
||||
console.log('搜索内容改变:', val)
|
||||
const handleSearch = (e: any) => {
|
||||
console.log('搜索内容改变:', e.target.value)
|
||||
}
|
||||
|
||||
// 处理筛选按钮点击
|
||||
|
||||
Reference in New Issue
Block a user