<template>
  <div class="combarr">
    <div class="combar">
      <div class="bar"></div>
      <el-row>
        <el-col :span="12">
          <div class="logo-title">
            <img :src="logo" alt="" class="imgg" />
            <span class="title">{{ title }}</span>
            <!-- <img src="../assets/images/comlo.png" alt="" class="imgg" /> -->
          </div>
        </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="sidebar.opened ? '' : 'width:50px !important'"
      />
      <div
        :class="{ hasTagsView: needTagsView, sidebarHide: sidebar.hide }"
        class="main-container"
        :style="sidebar.opened ? '' : 'margin-left: 50px !important'"
      >
        <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";
import meclogo1 from "@/assets/images/mec-logo1.svg";
import mecLogoLogin from "@/assets/images/mec-logo-login.svg";
export default {
  name: "Layout",
  components: {
    AppMain,
    Navbar,
    RightPanel,
    Settings,
    Sidebar,
    TagsView,
  },
  data() {
    return {
      userName: "默认用户",
      title: "",
      logo: "",
    };
  },
  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,
      username: (state) => state.user.name,
      ...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 });
    },
    getlogo() {
      let logo = sessionStorage.getItem("logo");
      this.title = sessionStorage.getItem("title") || "工业应用操作系统";
      if (logo) {
        this.logo = process.env.VUE_APP_BASE_API + logo;
      } else {
        this.logo = mecLogoLogin;
      }
    },
  },
  mounted() {
    var user = sessionStorage.getItem("sessionObj");
    var user = JSON.parse(user);
    this.userName = JSON.parse(user.data).username;
    this.getlogo();
  },
};
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/mixin.scss";
@import "~@/assets/styles/variables.scss";
.combarr {
  /* height: 100vh !important; */
  /* overflow: scroll; */
}

.avatar-wrapper {
  white-space: nowrap;
}
.el-dropdown-menu {
  z-index: 10000 !important;
}
.sidebar-container {
  background-color: #222653 !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: 120px; */
  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);
  padding: 0px 20px 0px 25px;
  box-sizing: border-box;
}
.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;
  width: 270px;
  height: 80px;
  float: left;
  margin-top: 7px;
  margin-bottom: 8px;
  /* margin-left: 50px; */
}
.logo-title {
  width: 100%;
  display: flex;
  align-items: center;
  .title {
    flex: 1;
    margin-left: 5px;
    display: block;

    font-size: 32px;
    font-weight: 700;
    letter-spacing: 0px;
    line-height: 38.4px;
    color: rgba(7, 68, 138, 1);
    text-align: left;
    vertical-align: top;
    float: left;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    // max-width: ;
  }
}

.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: 100px;
  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>
