<style lang="scss" scoped>
.layout_menu {
  border: none;

  .title {
    font-size: 24px;
    color: rgba(255, 255, 255, 0.88);
    font-style: normal;
    font-weight: bold;
  }

  .user {
    margin: 5px;
    width: 30px;
    height: 30px;
  }
}

.el-menu--horizontal>.el-menu-item:nth-child(1) {
  margin-right: auto;
}
.el-menu--horizontal > .el-menu-item {
  border-bottom: none;
  text-decoration: none;
}
</style>
<template>
  <el-menu :default-active="activeIndex" class="layout_menu" mode="horizontal" :ellipsis="false" @select="handleSelect"
    background-color="#0A397D" text-color="#fff" active-text-color="#fff">
    <el-menu-item index=" 0">
      <span class="title">{{ systemName }}</span>
    </el-menu-item>
    <el-menu-item index="1" @click="handleLogout">系统切换</el-menu-item>
    <el-sub-menu index="2">
      <template #title>{{ userName }}</template>
      <el-menu-item index="2-1" @click="reset">密码重置</el-menu-item>
      <el-menu-item index="2-2" @click="onExit">退出系统</el-menu-item>
    </el-sub-menu>
    <ResetDetail v-if="resetDetailFlag" :resetDetailFlag = resetDetailFlag @close="handleClose" />
  </el-menu>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useUserStore } from '@/stores/user'
import ResetDetail from "./resetDetail.vue";

const userStore = useUserStore()
const systemName = JSON.parse(sessionStorage.getItem('system')).systemName
const userName = JSON.parse(sessionStorage.getItem('userInfo')).idp
const resetDetailFlag = ref(false)

const reset = () => {
  resetDetailFlag.value = true
}

const handleClose = () => {
  resetDetailFlag.value = false
}
const handleLogout = () => {
  userStore.logout()
  sessionStorage.clear()
  window.open(import.meta.env.VITE_HOME_URL, '_self')
}
const activeIndex = ref('1')
const currentTheme = ref('default')

const toggleTheme = (type = 'default') => {
  currentTheme.value = type
  document.documentElement.style.setProperty('--color-bg1', `var(--color-${currentTheme.value}-bg1)`)
  document.documentElement.style.setProperty('--color-color1', `var(--color-${currentTheme.value}-color1)`)
}
const handleSelect = () => { }

const onExit = () => {
  userStore.logout()
  sessionStorage.clear()
  window.open(import.meta.env.VITE_HOME_URL + '?access=exit', '_self');
}
onMounted(() => {
  toggleTheme()
})
</script>
