<template>
  <div class="combarr">
    <div class="combar">
      <div class="bar">
      </div>
      <el-row>
        <el-col :span="12">
          <span>
            <img src="../assets/images/comlo.png" alt="" class="imgg" />
          </span>
        </el-col>
        <el-col :span="4" :offset="8">
            <el-dropdown
              class="avatar-container right-menu-item hover-effect"
              trigger="click"
            >
              <div class="avatar-wrapper">
                <img :src="avatar" class="user-avatar" />
                <span style="">
                  <button class="jianbiase">{{userName}}</button>
                </span>
                <i class="el-icon-caret-bottom" />
              </div>
              <el-dropdown-menu slot="dropdown" style="margin-top: -20px;">
                <router-link to="/user/profile">
                  <el-dropdown-item>个人中心</el-dropdown-item>
                </router-link>
                <el-dropdown-item @click.native="setting = true">
                  <span>布局设置</span>
                </el-dropdown-item>
                <el-dropdown-item divided @click.native="logout">
                  <span>退出登录</span>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
        </el-col>
      </el-row>
    </div>
    <div style="height: 100px"></div>
    <div
      :class="classObj"
      class="app-wrapper"
      :style="{ '--current-color': theme }"
    >
      <div
        v-if="device === 'mobile' && sidebar.opened"
        class="drawer-bg"
        @click="handleClickOutside"
      />
      <sidebar
        v-if="!sidebar.hide"
        class="sidebar-container"
        style="background-color: #222653;"
      />
      <div
        :class="{ hasTagsView: needTagsView, sidebarHide: sidebar.hide }"
        class="main-container"
      >
        <div :class="{ 'fixed-header': fixedHeader }">
          <!-- <navbar /> -->
          <tags-view v-if="needTagsView" />
        </div>
        <app-main />
        <right-panel>
          <settings />
        </right-panel>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import RightPanel from "@/components/RightPanel";
import { AppMain, Navbar, Settings, Sidebar, TagsView } from "./components";
import ResizeMixin from "./mixin/ResizeHandler";
import { mapState } from "vuex";
import variables from "@/assets/styles/variables.scss";

export default {
  name: "Layout",
  components: {
    AppMain,
    Navbar,
    RightPanel,
    Settings,
    Sidebar,
    TagsView,
  },
  mixins: [ResizeMixin],
  computed: {
    ...mapState({
      theme: (state) => state.settings.theme,
      sideTheme: (state) => state.settings.sideTheme, 
      sidebar: (state) => state.app.sidebar,
      device: (state) => state.app.device,
      needTagsView: (state) => state.settings.tagsView,
      fixedHeader: (state) => state.settings.fixedHeader,
      ...mapGetters(["avatar"]),
    }),
    classObj() {
      return {
        // hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === "mobile",
      };
    },
    variables() {
      return variables;
    },
    setting: {
      get() {
        return this.$store.state.settings.showSettings;
      },
      set(val) {
        this.$store.dispatch("settings/changeSetting", {
          key: "showSettings",
          value: val,
        });
      },
    },
  },
  methods: {
    async logout() {
      this.$confirm("确定注销并退出系统吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.dispatch("LogOut").then(() => {
            location.href = "/index";
          });
        })
        .catch(() => {});
    },
    handleClickOutside() {
      this.$store.dispatch("app/closeSideBar", { withoutAnimation: false });
    },
  },
  mounted() {
    var user = sessionStorage.getItem('sessionObj')
    var user = JSON.parse(user);
    this.userName = JSON.parse(user.data).username
  },


};
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/mixin.scss";
@import "~@/assets/styles/variables.scss";


.el-dropdown-menu {
    z-index: 10000 !important;
}

/* .main-container{
  position: relative;
}
.navbar{
  position:sticky !important;
} */

.combar {
  position: fixed;
  display: block;
  width: 100%;
  z-index: 1000;
  background: #fff;
  border-bottom: 1px solid #6f7af3;
  box-shadow: 0px 0px 2px 0px #222653;
}

.jianbiase {
  width: 100px;
  height: 37px;
  /* height: 25px; */
  background: linear-gradient(128.13deg, rgba(82, 79, 255, 1) 0%, rgba(255, 74, 74, 1) 100%);
  box-shadow: 0px 4px 16px  rgba(179, 192, 231, 1);
  border-radius: 27px;
  margin-top: 15px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0px;
  line-height: 20.27px;
  color: rgba(255, 255, 255, 1);

}
.user-avatar {
  cursor: pointer;
  width: 50px;
  height: 50px;
  border-radius: 50px; //是谁的样式来着
  z-index: 2;

  vertical-align: middle;
  margin-right: -18px;
  position: relative;
}

.right-menu-item {
  display: inline-block;
  padding: 0 8px;
  height: 100%;
  font-size: 18px;
  color: #7c008a;
  vertical-align: text-bottom;
  float: right;
  margin-right: 50px;
  margin-top: 18px;
}

#dropdown-menu-1780{
  z-index: 1000000;
}
.imgg {
  width: 553px;
  height: 80px;
  float: left;
  margin-top: 15px;
  /* margin-left: 50px; */
}
.spann {
  text-align: center;
  line-height: 100px;
  font-size: 30px;
  color: #003e8a;
  font-weight: bolder;
  margin-left: -335px;
}

.app-wrapper {
  @include clearfix;
  position: relative;
  height: 100%;
  width: 100%;

  &.mobile.openSidebar {
    position: fixed;
    top: 0;
  }
}

.drawer-bg {
  background: #000;
  opacity: 0.3;
  width: 100%;
  top: 0;
  height: 100%;
  position: absolute;
  z-index: 999;
}

.fixed-header {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 9;
  width: calc(100% - #{$base-sidebar-width});
  transition: width 0.28s;
}

.hideSidebar .fixed-header {
  width: calc(100% - 54px);
}

.sidebarHide .fixed-header {
  width: 100%;
}

.mobile .fixed-header {
  width: 100%;
}


</style>
