Files
medical-mall/layouts/admin/components/AdminHeader.uvue

306 lines
6.2 KiB
Plaintext

<template>
<view class="header">
<view class="header-left">
<!-- 移动端菜单切换按钮 (CSS 控制显隐) -->
<view class="menu-toggle mobile-only" @click="onToggleSubSider">
<text class="menu-icon">☰</text>
</view>
<!-- Desktop/Tablet Hamburger (1:1 复刻 CRMEB 切换二级侧边栏) -->
<view class="menu-toggle desktop-only" @click="onToggleSubSider">
<text class="menu-icon">☰</text>
</view>
<view class="breadcrumb-container desktop-only">
<text class="crumb" v-for="(item, index) in breadcrumb" :key="item.id">
{{ item.title }}
<text v-if="index < breadcrumb.length - 1" class="separator"> / </text>
</text>
</view>
<!-- 移动端简单标题 (CSS 控制显隐) -->
<text class="mobile-title mobile-only">{{ currentTitle }}</text>
</view>
<view class="header-right">
<view class="hbtn" @click="$emit('search')"><text>🔍</text></view>
<view v-if="!isMobile" class="hbtn" @click="$emit('refresh')"><text>⟳</text></view>
<view class="hbtn" @click="$emit('notify')">
<text>🔔</text>
<view class="dot" v-if="hasNotification"></view>
</view>
<!-- 用户个人中心 / 下拉菜单 -->
<view class="user-profile-container" @click="goToUserCenter">
<text class="user-name">crmeb demo</text>
<text class="user-arrow">▼</text>
<view class="user-dropdown" v-if="showUserMenu">
<view class="dropdown-item" @click.stop="goToUserCenter">个人中心</view>
<view class="dropdown-item" @click.stop="handleLogout">退出登录</view>
</view>
</view>
</view>
</view>
</template>
<script setup lang="uts">
import { ref, computed } from 'vue'
import {
toggleSubSider,
showSubSider,
layoutMode,
isOverlayVisible,
isMobileMenuOpen,
openRoute
} from '@/layouts/admin/store/adminNavStore.uts'
const showUserMenu = ref(false)
function closeUserMenu() {
showUserMenu.value = false
}
function toggleUserMenu() {
showUserMenu.value = !showUserMenu.value
}
function goToUserCenter() {
uni.showToast({ title: "尝试打开个人中心...", icon: "none", duration: 2000 });
uni.showToast({ title: "尝试打开个人中心...", icon: "none", duration: 2000 });
console.log("[AdminHeader] goToUserCenter called");
console.log("[AdminHeader] goToUserCenter called");
showUserMenu.value = false
openRoute('home_user_center')
}
function handleLogout() {
showUserMenu.value = false
uni.showModal({
title: '提示',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
uni.removeStorageSync('adminRole')
uni.removeStorageSync('token')
uni.reLaunch({
url: '/pages/user/login'
})
}
}
})
}
const props = defineProps<{
breadcrumb: Array<{id: string, title: string}>
hasNotification: boolean
isMobile: boolean
}>()
defineEmits<{
(e:'search'): void
(e:'refresh'): void
(e:'notify'): void
(e:'toggle-mobile-menu'): void
}>()
/**
* 核心切换逻辑:
* 1. Desktop: 切换 showSubSider (Dock状态)
* 2. Tablet: 切换 isOverlayVisible (Overlay状态)
* 3. Mobile: 切换 isMobileMenuOpen (Mobile Aside)
*/
function onToggleSubSider(): void {
if (layoutMode.value === 'desktop') {
toggleSubSider()
} else if (layoutMode.value === 'tablet') {
isOverlayVisible.value = !isOverlayVisible.value
} else {
isMobileMenuOpen.value = !isMobileMenuOpen.value
}
}
const currentTitle = computed((): string => {
if (props.breadcrumb.length > 0) {
return props.breadcrumb[props.breadcrumb.length - 1].title
}
return '管理后台'
})
</script>
<style>
.header{
position: relative;
z-index: 1001;
position: relative;
z-index: 1001;
height: 56px;
background:#fff;
border-bottom: 1px solid #eef2f7;
display:flex;
flex-direction:row;
align-items:center;
justify-content: space-between;
padding: 0 16px;
}
.header-left {
display: flex;
flex-direction: row;
align-items: center;
}
.menu-toggle {
margin-right: 12px;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
}
.menu-icon {
font-size: 20px;
color: #333;
}
.mobile-title {
font-size: 16px;
font-weight: 500;
color: #333;
}
.breadcrumb-container {
display: flex;
flex-direction: row;
align-items: center;
}
.crumb {
color: #374151;
font-size: 14px;
}
/* 响应式控制 */
.mobile-only {
display: none;
}
@media screen and (max-width: 768px) {
.desktop-only {
display: none !important;
}
.mobile-only {
display: flex !important;
}
.header-right {
position: relative;
z-index: 100;
pointer-events: auto;
position: relative;
z-index: 100;
pointer-events: auto;
gap: 5px;
}
}
.separator {
color: #d1d5db;
margin: 0 8px;
}
.header-right{
position: relative;
z-index: 100;
pointer-events: auto;
position: relative;
z-index: 100;
pointer-events: auto;
display:flex;
flex-direction:row;
align-items:center;
gap: 10px;
}
.hbtn{
width: 34px;
height: 34px;
border-radius: 8px;
display:flex;
align-items:center;
justify-content:center;
background:#f6f7fb;
position: relative;
}
.dot{
width: 8px;
height: 8px;
border-radius: 50%;
background:#ff4d4f;
position:absolute;
top: 6px;
right: 6px;
}
.user-profile-container {
position: relative;
display: flex;
flex-direction: row;
align-items: center;
margin-left: 10px;
cursor: pointer;
}
.user-name {
font-size: 14px;
color: #333;
}
.user-arrow {
font-size: 12px;
color: #666;
margin-left: 4px;
}
.user-dropdown {
z-index: 1002;
z-index: 1002;
position: absolute;
top: 40px;
right: 0;
width: 120px;
background-color: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px rgba(0,0,0,0.1);
z-index: 1000;
display: flex;
flex-direction: column;
}
.dropdown-item {
height: 40px;
line-height: 40px;
text-align: center;
font-size: 14px;
color: #333;
cursor: pointer;
}
.dropdown-item:hover {
background-color: #f5f7fa;
color: #1890ff;
}
.user-dropdown-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;
background-color: transparent;
}
</style>