Header.vue 3.59 KB
<template>
  <div class="header">
    <div class="header-left">
      <img src="../assets/logo.png" alt="Logo" class="header-logo" />
      <span class="header-title">怀化移动智能质检</span>
    </div>
    <div class="header-right">
      <div class="header-actions" @click="downLoad">
        <el-tooltip content="操作手册" placement="bottom" effect="dark">
          <div class="manual-icon">
            <el-icon><Document /></el-icon>
          </div>
        </el-tooltip>
      </div>
      <el-dropdown @command="handleCommand">
        <div class="user-info">
          <span class="username">Hi,{{ username }}</span>
          <el-icon class="arrow-icon">
            <ArrowDown />
          </el-icon>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="logout">
              <el-icon><SwitchButton /></el-icon>
              退出登录
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ArrowDown, SwitchButton, Document } from '@element-plus/icons-vue'

const router = useRouter()
const username = ref('')

onMounted(() => {
  // 从localStorage获取用户名,如果没有则使用默认值
  username.value = localStorage.getItem('adminNum') || '用户'
})

const downLoad = () => {
  window.open('https://jfq5tn3wbn.feishu.cn/docx/P5bvdCV3jo0E2axFa9bczwdQnQc?from=from_copylink')
}

const handleCommand = async (command) => {
  if (command === 'logout') {
    try {
      await ElMessageBox.confirm(
        '确定要退出登录吗?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )

      // 清除本地存储
      localStorage.removeItem('token')
      localStorage.removeItem('adminNum')

      ElMessage.success('退出登录成功')
      router.push('/login')
    } catch (error) {
      // 用户取消操作
    }
  }
}
</script>

<style scoped>
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  margin-right: 8px;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: #333333;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
}

.manual-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  color: #666666;
}

.manual-icon:hover {
  background-color: #f5f5f5;
  color: #409eff;
}

.manual-icon .el-icon {
  font-size: 18px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 6px;
  transition: background-color 0.3s ease;
  border: none !important;
  outline: none !important;
}

.user-info:hover {
  background-color: #f5f5f5;
  border: none !important;
  outline: none !important;
}

.username {
  font-size: 14px;
  color: #666666;
}

.arrow-icon {
  font-size: 12px;
  color: #666666;
  transition: transform 0.3s ease;
}

.user-info:hover .arrow-icon {
  transform: rotate(180deg);
}
</style>