优化若干功能
This commit is contained in:
@@ -75,7 +75,10 @@
|
||||
<el-dropdown trigger="click" @command="handleCommand">
|
||||
<span class="el-dropdown-link" style="cursor: pointer;">
|
||||
<img :src="getImageUrl('user')" class="user" />
|
||||
<span class="user-name">{{ displayName }}</span>
|
||||
<span class="user-meta">
|
||||
<span class="user-name">{{ displayName }}</span>
|
||||
<span v-if="loginRoleLabel" class="user-role">{{ loginRoleLabel }}</span>
|
||||
</span>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
@@ -108,11 +111,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted } from "vue";
|
||||
import { ref, computed, reactive, onMounted, onUnmounted } from "vue";
|
||||
import { useRouter, useRoute } from "vue-router";
|
||||
import { useAllDataStore, useMenuStore, useTabsStore } from "@/stores";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { logout } from "@/api/login";
|
||||
import { logout, getCurrentUserProfile } from "@/api/login";
|
||||
import { User, SwitchButton, Sunny, Moon, Refresh, Bell, HomeFilled, Loading, Message } from '@element-plus/icons-vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { getMySiteReminders, readAllSiteReminders } from "@/api/sitereminder";
|
||||
@@ -297,6 +300,33 @@ const companyName = computed(() => {
|
||||
return authStore.user?.tenant_name || '';
|
||||
});
|
||||
|
||||
// 当前登录用户的角色 / 部门 / 职位(来自后端 /backend/getCurrentUserProfile)
|
||||
const userProfile = reactive({ department: '', position: '', role_name: '' });
|
||||
|
||||
// 优先展示「部门·职位」,二者皆无时回退到角色名
|
||||
const loginRoleLabel = computed(() => {
|
||||
const dept = (userProfile.department || '').trim();
|
||||
const pos = (userProfile.position || '').trim();
|
||||
if (dept || pos) {
|
||||
return [dept, pos].filter(Boolean).join(' · ');
|
||||
}
|
||||
return (userProfile.role_name || '').trim();
|
||||
});
|
||||
|
||||
const fetchUserProfile = async () => {
|
||||
if (!authStore.token) return;
|
||||
try {
|
||||
const res = await getCurrentUserProfile();
|
||||
if (res && res.code === 200 && res.data) {
|
||||
userProfile.department = res.data.department || '';
|
||||
userProfile.position = res.data.position || '';
|
||||
userProfile.role_name = res.data.role_name || '';
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to fetch current user profile:', e);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCollapse = () => {
|
||||
store.state.isCollapse = !store.state.isCollapse;
|
||||
};
|
||||
@@ -436,6 +466,8 @@ onMounted(async () => {
|
||||
if (authStore.token) {
|
||||
// 仅在后台页面刷新/首次挂载时更新未读数量,不再自动轮询。
|
||||
fetchUnreadCount();
|
||||
// 拉取当前登录用户的角色 / 部门 / 职位
|
||||
fetchUserProfile();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -560,7 +592,7 @@ onUnmounted(() => {
|
||||
color: var(--el-color-primary);
|
||||
background-color: var(--el-color-primary-light-9);
|
||||
border: 1px solid var(--el-color-primary-light-7);
|
||||
border-radius: 14px;
|
||||
border-radius: 4px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
@@ -572,6 +604,14 @@ onUnmounted(() => {
|
||||
cursor: pointer;
|
||||
gap: 12px;
|
||||
|
||||
.user-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
line-height: 1.2;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
font-size: 14px;
|
||||
color: var(--el-text-color-primary);
|
||||
@@ -586,6 +626,20 @@ onUnmounted(() => {
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
|
||||
.user-role {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
white-space: nowrap;
|
||||
max-width: 160px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
// 亮色主题下使用半透明白色
|
||||
html:not(.dark) & {
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user