<template>
  <el-dropdown class="avatar-container" trigger="click">
    <div class="avatar-wrapper flex align-center pointer" title="退出登录">
      <el-avatar shape="circle" :size="28" :src="getImgUrl('system/user.jpg')"></el-avatar>
      <div class="f14 ml10" style="color: #fff">{{ getItem("USERNAME") }}</div>
    </div>
    <template #dropdown>
      <el-dropdown-menu class="user-dropdown">
        <el-dropdown-item>
          <div style='display:flex;align-items:center;'>
            <el-avatar shape="circle" :size="28" :src="getImgUrl('system/user.jpg')"></el-avatar>
            <div class='ml10'>
              <div>姓名：{{ getItem("USERNAME") }}</div>
              <div>所属单位：{{ getItem("deptId").ssdwmc }}</div>
              <div>所属部门：{{ getItem("deptId").ssbmmc }}</div>
            </div>

          </div>
        </el-dropdown-item>
        <el-dropdown-item divided @click="updatePwd()">
          <span style='text-decoration:underline;'>修改密码</span>
        </el-dropdown-item>
        <!-- 操作手册 -->
        <el-dropdown-item divided @click="Manualopen()">
          <span style='text-decoration:underline;'>操作手册</span>

        </el-dropdown-item>
        <!-- <a target="_blank" href="#">
          <el-dropdown-item>主页</el-dropdown-item>
        </a> -->
        <el-dropdown-item divided>
          <div class='tcbtn'>
            <el-button class="login-btn" @click="logout()">
              退出登录
            </el-button>
          </div>

        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
  <!-- </div> -->
  <UpdatePwdDialog v-model="UpdatePwdVisible"></UpdatePwdDialog>
  <!-- </div> -->
</template>

<script setup>
import { getImgUrl } from "@/utils/tools.js"
import { ref } from "vue";
import { useStore } from "vuex";
import UpdatePwdDialog from "./UpdatePwdDialog.vue";
import router from "../../router";
import { getItem } from "@/utils/storage";
import { useRouter } from "vue-router";
const $router = useRouter();
const UpdatePwdVisible = ref(false);
const Manualopen = () => {
  $router.push({ path: '/systemConfig/Procedures' })
}
const updatePwd = () => {
  UpdatePwdVisible.value = true;
};
const store = useStore();
const logout = () => {
  console.log('4 退出登录！');
  store.dispatch("user/logout");
  store.commit("app/clearTag", null, {
    immediate: true
  });
  store.commit("permission/deleteRouter", {
    immediate: true
  });
  router.go(0)
  localStorage.clear();
};

</script>

<style lang="scss" scoped>
.tcbtn {
  width: 100%;
  display: flex;
  justify-content: center;
}

.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    // hover 动画
    transition: background 0.5s;

    &:hover {
      background: rgba(0, 0, 0, 0.1);
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .right-menu {
    display: flex;
    align-items: center;
    float: right;
    padding-right: 16px;

    ::v-deep .right-menu-item {
      display: inline-block;
      padding: 0 18px 0 0;
      font-size: 24px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }
    }

    ::v-deep .avatar-container {
      cursor: pointer;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;

        .el-avatar {
          --el-avatar-background-color: none;
          margin-right: 12px;
        }
      }
    }
  }
}
</style>
