chat-pc/src/hooks/useConnectStatus.ts
2024-12-24 16:14:21 +08:00

27 lines
616 B
TypeScript

import { watchEffect } from 'vue'
import { useRouter } from 'vue-router'
import { useSettingsStore } from '@/store'
import { isLoggedIn } from '@/utils/auth'
import ws from '@/connect'
export const useConnectStatus = () => {
const settingsStore = useSettingsStore()
const router = useRouter()
watchEffect(() => {
if (settingsStore.isLeaveWeb) {
return
}
const pathname = router.currentRoute.value.path
const paths = ['/auth/login', '/auth/register', '/auth/forget']
if (!paths.includes(pathname) && isLoggedIn()) {
!ws.isConnect() && ws.connect()
}
})
return {}
}