fix: 后端代码格式化

This commit is contained in:
Tim
2025-09-18 14:42:25 +08:00
parent 70f7442f0c
commit 72b2b82e02
325 changed files with 15341 additions and 12370 deletions

View File

@@ -3,73 +3,73 @@ import { useWebSocket } from './useWebSocket'
import { getToken } from '~/utils/auth'
const count = ref(0)
let isInitialized = false;
let isInitialized = false
export function useChannelsUnreadCount() {
const config = useRuntimeConfig();
const API_BASE_URL = config.public.apiBaseUrl;
const { subscribe, isConnected, connect } = useWebSocket();
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const { subscribe, isConnected, connect } = useWebSocket()
const fetchChannelUnread = async () => {
const token = getToken();
const token = getToken()
if (!token) {
count.value = 0;
return;
count.value = 0
return
}
try {
const response = await fetch(`${API_BASE_URL}/api/channels/unread-count`, {
headers: { Authorization: `Bearer ${token}` },
});
})
if (response.ok) {
const data = await response.json();
count.value = data;
const data = await response.json()
count.value = data
}
} catch (e) {
console.error('Failed to fetch channel unread count:', e);
console.error('Failed to fetch channel unread count:', e)
}
};
}
const setupWebSocketListener = () => {
const destination = '/user/queue/channel-unread';
const destination = '/user/queue/channel-unread'
subscribe(destination, (message) => {
const unread = parseInt(message.body, 10);
const unread = parseInt(message.body, 10)
if (!isNaN(unread)) {
count.value = unread;
count.value = unread
}
}).then(subscription => {
}).then((subscription) => {
if (subscription) {
console.log('频道未读消息订阅成功');
console.log('频道未读消息订阅成功')
}
});
};
})
}
const initialize = () => {
const token = getToken();
const token = getToken()
if (!token) {
count.value = 0;
return;
count.value = 0
return
}
if (!isConnected.value) {
connect(token);
connect(token)
}
fetchChannelUnread();
setupWebSocketListener();
};
fetchChannelUnread()
setupWebSocketListener()
}
const setFromList = (channels) => {
count.value = Array.isArray(channels) ? channels.filter((c) => c.unreadCount > 0).length : 0;
};
count.value = Array.isArray(channels) ? channels.filter((c) => c.unreadCount > 0).length : 0
}
const hasUnread = computed(() => count.value > 0);
const hasUnread = computed(() => count.value > 0)
if (!isInitialized) {
const token = getToken();
const token = getToken()
if (token) {
isInitialized = true;
initialize();
isInitialized = true
initialize()
}
}
@@ -79,5 +79,5 @@ export function useChannelsUnreadCount() {
fetchChannelUnread,
initialize,
setFromList,
};
}
}