130 lines
3.7 KiB
Vue
Raw Normal View History

<script lang="ts" setup>
import { useAppStore } from "@/pinia/stores/app"
import { useSettingsStore } from "@/pinia/stores/settings"
import { useUserStore } from "@/pinia/stores/user"
import Notify from "@@/components/Notify/index.vue"
import Screenfull from "@@/components/Screenfull/index.vue"
import SearchMenu from "@@/components/SearchMenu/index.vue"
import ThemeSwitch from "@@/components/ThemeSwitch/index.vue"
import { useDevice } from "@@/composables/useDevice"
import { useLayoutMode } from "@@/composables/useLayoutMode"
import { UserFilled } from "@element-plus/icons-vue"
2024-11-26 11:08:05 +08:00
import { Breadcrumb, Hamburger, Sidebar } from "../index"
2024-02-06 13:39:56 +08:00
const { isMobile } = useDevice()
2024-02-06 15:25:16 +08:00
const { isTop } = useLayoutMode()
const router = useRouter()
const appStore = useAppStore()
const userStore = useUserStore()
2024-02-06 13:39:56 +08:00
const settingsStore = useSettingsStore()
2024-02-06 15:25:16 +08:00
const { showNotify, showThemeSwitch, showScreenfull, showSearchMenu } = storeToRefs(settingsStore)
/** 切换侧边栏 */
2024-11-18 19:40:44 +08:00
function toggleSidebar() {
2022-08-23 15:07:29 +08:00
appStore.toggleSidebar(false)
}
2023-07-18 11:14:07 +08:00
/** 登出 */
2024-11-18 19:40:44 +08:00
function logout() {
2022-08-23 15:07:29 +08:00
userStore.logout()
router.push("/login")
}
</script>
<template>
2022-08-23 14:36:43 +08:00
<div class="navigation-bar">
2024-02-06 13:39:56 +08:00
<Hamburger
v-if="!isTop || isMobile"
:is-active="appStore.sidebar.opened"
class="hamburger"
@toggle-click="toggleSidebar"
/>
2023-07-18 11:14:07 +08:00
<Breadcrumb v-if="!isTop || isMobile" class="breadcrumb" />
<Sidebar v-if="isTop && !isMobile" class="sidebar" />
<div class="right-menu">
2023-08-10 14:48:22 +08:00
<SearchMenu v-if="showSearchMenu" class="right-menu-item" />
<Screenfull v-if="showScreenfull" class="right-menu-item" />
<ThemeSwitch v-if="showThemeSwitch" class="right-menu-item" />
<Notify v-if="showNotify" class="right-menu-item" />
<el-dropdown class="right-menu-item">
2022-11-02 16:57:43 +08:00
<div class="right-menu-avatar">
<el-avatar :icon="UserFilled" :size="30" />
<span>{{ userStore.username }}</span>
</div>
<template #dropdown>
<el-dropdown-menu>
<a target="_blank" href="https://github.com/un-pany/v3-admin-vite">
2022-11-07 17:46:28 +08:00
<el-dropdown-item>GitHub</el-dropdown-item>
</a>
2022-04-23 10:33:30 +08:00
<a target="_blank" href="https://gitee.com/un-pany/v3-admin-vite">
2022-11-07 17:46:28 +08:00
<el-dropdown-item>Gitee</el-dropdown-item>
</a>
2022-08-23 15:07:29 +08:00
<el-dropdown-item divided @click="logout">
<span style="display: block">退出登录</span>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</template>
<style lang="scss" scoped>
2022-08-23 14:36:43 +08:00
.navigation-bar {
2022-05-25 21:53:38 +08:00
height: var(--v3-navigationbar-height);
overflow: hidden;
2024-03-28 21:34:24 +08:00
color: var(--v3-navigationbar-text-color);
2023-07-19 09:05:55 +08:00
display: flex;
justify-content: space-between;
.hamburger {
display: flex;
align-items: center;
height: 100%;
padding: 0 15px;
cursor: pointer;
}
.breadcrumb {
2023-07-19 09:05:55 +08:00
flex: 1;
// 参考 Bootstrap 的响应式设计将宽度设置为 576
2022-11-02 16:57:43 +08:00
@media screen and (max-width: 576px) {
display: none;
}
}
2023-07-18 11:14:07 +08:00
.sidebar {
2023-07-19 09:05:55 +08:00
flex: 1;
2023-07-19 18:14:42 +08:00
// 设置 min-width 是为了让 Sidebar 里的 el-menu 宽度自适应
min-width: 0px;
2023-07-19 09:05:55 +08:00
:deep(.el-menu) {
background-color: transparent;
}
2023-07-19 13:11:52 +08:00
:deep(.el-sub-menu) {
&.is-active {
.el-sub-menu__title {
2024-11-21 11:03:40 +08:00
color: var(--el-color-primary);
2023-07-19 13:11:52 +08:00
}
}
}
2023-07-18 11:14:07 +08:00
}
.right-menu {
margin-right: 10px;
height: 100%;
display: flex;
align-items: center;
.right-menu-item {
padding: 0 10px;
cursor: pointer;
2022-11-02 16:57:43 +08:00
.right-menu-avatar {
display: flex;
align-items: center;
.el-avatar {
margin-right: 10px;
}
span {
font-size: 16px;
}
}
}
}
}
</style>