长城汽车软件包管理平台
whychdw
2025-04-27 37c0df01e23bf7a4c946bd6a798bf433965d1731
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<template>
  <div :class="['navbar__right', navbarRightClass]">
    <!-- 桌面端显示 -->
    <template v-if="isDesktop">
      <!-- 全屏 -->
      <Fullscreen />
 
      <!-- 布局大小 -->
      <SizeSelect />
    </template>
 
    <!-- 用户头像(个人中心、注销登录等) -->
    <el-dropdown trigger="click">
      <div class="user-profile">
        <img class="user-profile__avatar" :src="userImg" />
        <span class="user-profile__name">{{ userStore.userInfo.name }}</span>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="handleProfileClick">个人中心</el-dropdown-item>
          <el-dropdown-item divided @click="logout">注销登录</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
 
    <!-- 设置面板 -->
    <div v-if="defaultSettings.showSettings" @click="settingStore.settingsVisible = true">
      <div class="i-svg:setting" />
    </div>
  </div>
</template>
<script setup lang="ts">
import defaultSettings from "@/settings";
import { DeviceEnum } from "@/enums/settings/device.enum";
import { ThemeMode } from "@/enums/settings/theme.enum";
import { useAppStore, useSettingsStore, useUserStore, useTagsViewStore } from "@/store";
import userImg from "@/assets/images/user-logo.gif";
 
const appStore = useAppStore();
const settingStore = useSettingsStore();
const userStore = useUserStore();
const tagsViewStore = useTagsViewStore();
 
const route = useRoute();
const router = useRouter();
const isDesktop = computed(() => appStore.device === DeviceEnum.DESKTOP);
 
/**
 * 打开个人中心页面
 */
function handleProfileClick() {
  router.push({ name: "Profile" });
}
 
// 根据主题和侧边栏配色方案选择 navbar 右侧的样式类
const navbarRightClass = computed(() => {
  // 如果暗黑主题
  if (settingStore.theme === ThemeMode.DARK) {
    return "navbar__right--white";
  }
});
 
/**
 * 注销登录
 */
function logout() {
  ElMessageBox.confirm("确定注销并退出系统吗?", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
    lockScroll: false,
  }).then(() => {
    userStore
      .logout()
      .then(() => {
        tagsViewStore.delAllViews();
      })
      .then(() => {
        router.push(`/login?redirect=${route.fullPath}`);
      })
      .catch(() => {
        tagsViewStore.delAllViews();
        router.push(`/login?redirect=${route.fullPath}`);
      });
  });
}
</script>
 
<style lang="scss" scoped>
.navbar__right {
  display: flex;
  align-items: center;
  justify-content: center;
 
  & > * {
    display: inline-block;
    min-width: 40px;
    height: $navbar-height;
    line-height: $navbar-height;
    color: var(--el-text-color);
    text-align: center;
    cursor: pointer;
 
    &:hover {
      background: rgb(0 0 0 / 10%);
    }
  }
 
  .user-profile {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 0 13px;
 
    &__avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
    }
 
    &__name {
      margin-left: 10px;
    }
  }
}
 
.layout-top .navbar__right > *,
.layout-mix .navbar__right > * {
  color: #fff;
}
 
.dark .navbar__right > *:hover {
  color: #ccc;
}
</style>