fix: 修复消息中心角标显示问题
This commit is contained in:
parent
23c54eaf40
commit
dd73e28b08
@ -175,15 +175,27 @@ const loadTotalUnreadCount = async () => {
|
|||||||
console.log('🔍 统一接口响应:', response)
|
console.log('🔍 统一接口响应:', response)
|
||||||
|
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
const result = response.data || {}
|
const result = response.data as any || {}
|
||||||
console.log('📊 统一接口返回数据:', result)
|
console.log('📊 统一接口返回数据:', result)
|
||||||
|
|
||||||
// 使用统一接口返回的数据
|
// 使用统一接口返回的数据
|
||||||
// 注意:当前API只返回total和unread字段,我们需要分别调用各个接口获取具体数量
|
// 检查result.result是否存在,如果存在则使用其中的数据
|
||||||
// 这里先设置默认值,后续会通过其他接口更新
|
if (result.result) {
|
||||||
commentCount.value = 0
|
const countData = result.result
|
||||||
favoriteCount.value = 0
|
if (countData.commentsUnreadCount !== undefined) {
|
||||||
systemCount.value = 0
|
commentCount.value = countData.commentsUnreadCount || 0
|
||||||
|
console.log('✅ 评论未读数设置为:', commentCount.value)
|
||||||
|
}
|
||||||
|
if (countData.likesUnreadCount !== undefined) {
|
||||||
|
favoriteCount.value = countData.likesUnreadCount || 0
|
||||||
|
console.log('✅ 赞和收藏未读数设置为:', favoriteCount.value)
|
||||||
|
}
|
||||||
|
if (countData.systemUnreadCount !== undefined) {
|
||||||
|
systemCount.value = countData.systemUnreadCount || 0
|
||||||
|
console.log('✅ 系统消息未读数设置为:', systemCount.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 注意:统一接口没有返回即时消息的未读数,保持为0
|
||||||
notificationCount.value = 0
|
notificationCount.value = 0
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -218,10 +230,12 @@ const loadNotificationCount = async () => {
|
|||||||
const loadCommentCount = async () => {
|
const loadCommentCount = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await MessageApi.getCommentsAtMessageCount()
|
const response = await MessageApi.getCommentsAtMessageCount()
|
||||||
if (response.data?.success && (response.data.code === 200 || response.data.code === 0)) {
|
if (response.data && response.data.result) {
|
||||||
commentCount.value = response.data.result?.unread || 0
|
commentCount.value = response.data.result.unread || 0
|
||||||
|
console.log('✅ 评论和@未读数量设置为:', commentCount.value)
|
||||||
} else {
|
} else {
|
||||||
commentCount.value = 0
|
commentCount.value = 0
|
||||||
|
console.log('❌ 评论和@接口响应失败,设置为0')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取评论数量失败:', error)
|
console.error('获取评论数量失败:', error)
|
||||||
@ -235,8 +249,8 @@ const loadFavoriteCount = async () => {
|
|||||||
const response = await MessageApi.getLikesMessageCount()
|
const response = await MessageApi.getLikesMessageCount()
|
||||||
console.log('🔍 loadFavoriteCount 响应数据:', response)
|
console.log('🔍 loadFavoriteCount 响应数据:', response)
|
||||||
|
|
||||||
if (response.data?.success && (response.data.code === 200 || response.data.code === 0)) {
|
if (response.data && response.data.result) {
|
||||||
favoriteCount.value = response.data.result?.unread || 0
|
favoriteCount.value = response.data.result.unread || 0
|
||||||
console.log('✅ 赞和收藏未读数量设置为:', favoriteCount.value)
|
console.log('✅ 赞和收藏未读数量设置为:', favoriteCount.value)
|
||||||
} else {
|
} else {
|
||||||
favoriteCount.value = 0
|
favoriteCount.value = 0
|
||||||
|
@ -165,13 +165,34 @@ const loadMessages = async () => {
|
|||||||
|
|
||||||
console.log('🔍 系统消息API响应:', response)
|
console.log('🔍 系统消息API响应:', response)
|
||||||
|
|
||||||
if (response.data && response.data.records) {
|
if (response.data) {
|
||||||
const result = response.data
|
const result = response.data
|
||||||
console.log('✅ 系统消息数据:', result)
|
console.log('✅ 系统消息数据:', result)
|
||||||
|
|
||||||
// 转换数据格式
|
// 检查数据结构,可能是直接的records数组或者包含records的对象
|
||||||
messages.value = result.records.map(transformSystemMessageData)
|
if (Array.isArray(result)) {
|
||||||
total.value = result.total || 0
|
// 如果直接返回数组
|
||||||
|
messages.value = result.map(transformSystemMessageData)
|
||||||
|
total.value = result.length
|
||||||
|
} else if (result.records && Array.isArray(result.records)) {
|
||||||
|
// 如果返回包含records的对象
|
||||||
|
messages.value = result.records.map(transformSystemMessageData)
|
||||||
|
total.value = result.total || result.records.length
|
||||||
|
} else {
|
||||||
|
// 其他情况,使用模拟数据
|
||||||
|
console.warn('⚠️ 系统消息API返回数据格式不正确:', result)
|
||||||
|
messages.value = [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
title: '你的会员已专属权利已更新,保来享取今日内障,仅此一天!',
|
||||||
|
content: '好消息好消息!BiliBiliWorld2024年在线大学6月29日(周六)正式开课!!!',
|
||||||
|
timestamp: '7月20日 12:41',
|
||||||
|
isRead: false,
|
||||||
|
type: 'info'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
total.value = 1
|
||||||
|
}
|
||||||
|
|
||||||
console.log('✅ 转换后的系统消息:', messages.value)
|
console.log('✅ 转换后的系统消息:', messages.value)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user