<template>
  <div class="app">
    <newSidebar class="app-aside" :class="asideClass" />
    <section :class="sectionClass" class="app-wrapper">
      <div v-if="isFullScreen" class="zoomIn" @click="showNormal" title="缩小">
        <IconFont icon="suoxiao" size="22" color="#333" />
      </div>
      <baseHeader
        :userSetIsShow="isVisible"
        @changeUserSet="changeUserSet"
        @handleDrawerBar="handleDrawerBar"
      />
      <div class="app-content">
        <div :class="contentClass">
          <template v-if="appTheme == 'three'">
            <bottomBar v-if="!isFullScreen" />
          </template>
          <navbar v-if="!isFullScreen" />
        </div>
        <app-main />
      </div>
      <div class="app-layout-footer">
        <img src="../assets/layout/copy-right.png" alt="" />
        Copyright @ 2020 By 武汉迎风聚智科技有限公司
      </div>
    </section>
    <userSetting :isVisible="isVisible" @changeVisible="changeVisible" />
    <el-drawer
      :custom-class="appStyle == 'dark' ? 'change-drawer-dark' : ''"
      direction="ltr"
      size="220px"
      :visible.sync="isDrawerOpen"
      :with-header="false"
    >
      <drawerBar />
    </el-drawer>
  </div>
</template>

<script>
import { mapState, mapGetters } from "vuex";
import { Navbar, newSidebar, AppMain } from "./components";
import ResizeMixin from "./mixin/ResizeHandler";
import userSetting from "@/views/users/userSetting.vue";
import bottomBar from "./components/bottomBar/index.vue";
import drawerBar from "./components/drawerBar/index.vue";
import baseHeader from "./components/header/baseHeader.vue";

export default {
  name: "Layout",
  components: {
    Navbar,
    newSidebar,
    AppMain,
    userSetting,
    bottomBar,
    drawerBar,
    baseHeader,
  },
  mixins: [ResizeMixin],
  computed: {
    ...mapGetters(["isFullScreen"]),
    ...mapState("settings", ["headerTitle", "userblockShow"]),
    ...mapState("user", [
      "appStyle",
      "appTheme",
      "isFixedSide",
      "isFixedWidth",
    ]),
    sidebar() {
      return this.$store.state.app.sidebar;
    },
    device() {
      return this.$store.state.app.device;
    },
    fixedHeader() {
      return this.$store.state.settings.fixedHeader;
    },
    sectionClass() {
      return {
        // hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === "mobile",
        fullExpand: this.isFullScreen,
      };
    },
    asideClass() {
      return {
        "el-hide": this.isFullScreen || this.appTheme != "one",
        "fixed-aside": this.appTheme == "one" && this.isFixedSide,
        "fixed-aside-open":
          this.appTheme == "one" &&
          this.isFixedSide &&
          this.sidebar.opened == true,
        "fixed-aside-close":
          this.appTheme == "one" &&
          this.isFixedSide &&
          this.sidebar.opened == false,
      };
    },
    contentClass() {
      return {
        "app-content-setWidth": this.isFixedWidth,
      };
    },
    userName() {
      return this.$store.getters.name;
    },
  },
  data: () => {
    return {
      isVisible: false,
      isDrawerOpen: false,
    };
  },
  mounted() {
    // console.log('this.$store',this.$store);
    document.addEventListener("keyup", (e) => {
      if (e.keyCode == 27) {
        this.$store.dispatch("settings/handleFullScreen", false);
      }
    });
  },
  methods: {
    handleClickOutside() {
      this.$store.dispatch("app/closeSideBar", { withoutAnimation: false });
    },
    logout() {
      var url = this.$client.apiUrlprefix() + "/logout";
      var that = this;
      this.$axios.post(url, {}, function(res) {
        console.log(res);
        that.$store.dispatch("user/removeToken");
        that.$router.push({ path: "/login" });
      });
    },
    changeVisible(msg) {
      this.isVisible = msg;
    },
    handleDrawerBar() {
      this.isDrawerOpen = !this.isDrawerOpen;
    },
    changeUserSet(msg) {
      this.isVisible = msg;
    },
    showNormal() {
      this.$store.dispatch("settings/handleFullScreen", false);
    },
  },
};
</script>

<style lang="scss" scoped>
@import "~@/styles/mixin.scss";
@import "~@/styles/variables.scss";
.app >>> {
  .change-drawer-dark {
    .el-drawer__body {
      background-color: #04142a;
    }
    .el-menu {
      border-right: none;
    }
  }
}

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

.zoomIn {
  position: fixed;
  z-index: 1;
  top: 5px;
  right: 5px;
  color: #fff;
  cursor: pointer;
  // background: #52c41a;
  background: #fff;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(2, 48, 101, 0.2);
  padding: 5px;
}
</style>
