refactor(frontend): 重构前端第二版
This commit is contained in:
1 parent
2631f78b00
commit
4b562cfa82
205 files changed
+15399
-12015
No files matched your search
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 对话页:当前登录用户展示名、工号与登出/管理入口。
|
||||
*/
|
||||
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('/');
|
||||
};
|
||||
|
||||
const goToAdmin = () => {
|
||||
router.push('/admin');
|
||||
};
|
||||
|
||||
return {
|
||||
currentUser,
|
||||
currentUserDisplayName,
|
||||
currentUserEmployeeId,
|
||||
onAuthLogout,
|
||||
handleLogout,
|
||||
goToAdmin,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user