/** * 对话页:当前登录用户展示名、工号与登出/管理入口。 */ import { computed, ref } from 'vue'; import type { Router } from 'vue-router'; import { getStoredAuthUser, logoutAuth } from '@/shared/utils/auth'; export function useChatPageUser(router: Router) { const currentUser = ref(getStoredAuthUser()); const currentUserDisplayName = computed(() => { const realName = currentUser.value?.real_name?.trim(); if (realName) return realName; const aliasName = (currentUser.value as { name?: string; wecom_name?: string } | null)?.name?.trim?.() || (currentUser.value as { wecom_name?: string } | null)?.wecom_name?.trim?.(); if (aliasName) return aliasName; const username = currentUser.value?.username?.trim(); if (username && !/^\d+$/.test(username)) return username; return '当前用户'; }); const currentUserEmployeeId = computed(() => { const employeeId = currentUser.value?.employee_id?.trim(); if (employeeId) return employeeId; const username = currentUser.value?.username?.trim(); return username || '-'; }); const onAuthLogout = () => { currentUser.value = null; }; const handleLogout = () => { logoutAuth(); onAuthLogout(); router.push('/login'); }; const goToAdmin = () => { router.push('/admin'); }; return { currentUser, currentUserDisplayName, currentUserEmployeeId, onAuthLogout, handleLogout, goToAdmin, }; }