<template>
  <div class="header-wp">
    <div class="header-left-wp">
      <div class="title">两江资本</div>
      <div class="sub-title">无敌中控</div>
    </div>
    <div class="header-right-wp">
      <div class="info-wp">
        <div class="info-name">欢迎, {{ nickname }}</div>

        <lay-dropdown trigger="hover" placement="bottom-end" updateAtScroll>
          <div class="info-avatar">
            <img :src="avatarUrl" />
          </div>
          <template #content>
            <lay-dropdown-menu>
              <lay-dropdown-menu-item @click="handeLoginOut()">退出登录</lay-dropdown-menu-item>
            </lay-dropdown-menu>
          </template>
        </lay-dropdown>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { useRouter } from "vue-router";
import { client_logout } from "@/api/index";

const router = useRouter();

defineProps({
  nickname: String,
  avatarUrl: String,
});

const handeLoginOut = () => {
  client_logout({}, () => {
    window.sessionStorage.removeItem("_4L_TOKEN");
    window.sessionStorage.removeItem("_4L_MENU_PATH");
    window.sessionStorage.removeItem("_4L_S_MENU_PATH");
    window.sessionStorage.removeItem("_4L_TAG_LIST");
    window.sessionStorage.removeItem("_4L_API_LIST");
    window.sessionStorage.removeItem("_4L_MENU_COLLAPSE");
    router.push({ path: "/login" });
  });
};
</script>
<style lang="scss" scoped>
.header-wp {
  box-sizing: border-box;
  height: 100%;
  width: 100%;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  display: flex;
  .header-left-wp {
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    flex-direction: column;
    text-align: center;
    width: 256px;
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    .title {
      font-size: 18px;
      font-weight: bold;
    }
    .sub-title {
      font-weight: bold;
    }
  }
  .header-right-wp {
    flex: 1;
    display: flex;
    justify-content: right;
    align-items: center;
    .info-wp {
      display: flex;
      align-items: center;
      padding: 0 20px;
      .info-name {
        padding-right: 10px;
        font-size: 14px;
      }
      .info-avatar {
        font-size: 0;
        img {
          border-radius: 50%;
          width: 32px;
          height: 32px;
        }
      }
    }
  }
}
</style>
