<template>
  <div class="navbar">
    <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav" />

    <div class="right-menu">
      <template v-if="device !== 'mobile'">
        <!-- <search id="header-search" class="right-menu-item" />

        <el-tooltip content="源码地址" effect="dark" placement="bottom">
          <ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />
        </el-tooltip> -->

        <span class="mode" @click.stop="modeChange">
          <span v-if="mode === 1">日常模式</span>
          <span v-if="mode === 2">紧急模式</span>
        </span>

        <el-tooltip content="数据大屏" effect="light" placement="bottom">
          <i
            class="bigscreen el-icon-data-analysis right-menu-item hover-effect"
            @click.stop="toBigscreen"
          ></i>
          <!-- <ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" /> -->
        </el-tooltip>
        <!-- <el-tooltip
          content="大屏"
          effect="light"
          placement="bottom"
          class="bigscreen"
        >
          <i class="el-icon-data-analysis" @click.stop="toBigscreen"></i>
        </el-tooltip> -->

        <!-- <screenfull id="screenfull" class="right-menu-item hover-effect" /> -->

        <!-- <el-tooltip content="布局大小" effect="dark" placement="bottom">
          <size-select id="size-select" class="right-menu-item hover-effect" />
        </el-tooltip> -->
      </template>

      <!-- <a href="/Screen" target="_blank"
        ><span
          class="el-icon-data-board"
          style="font-size: 0.2rem; line-heigth: 0.6rem !important"
        /><span style="font-size: 0.2rem; line-heigth: 0.6rem"
          >三维大屏</span
        ></a
      > -->

      <el-dropdown
        class="avatar-container right-menu-item hover-effect"
        trigger="click"
      >
        <div class="avatar-wrapper">
          <img :src="avatar" class="user-avatar" />
          <i class="el-icon-caret-bottom" />
        </div>
        <el-dropdown-menu slot="dropdown">
          <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>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import Breadcrumb from "@/components/Breadcrumb";
import TopNav from "@/components/TopNav";
import Hamburger from "@/components/Hamburger";
import Screenfull from "@/components/Screenfull";
import SizeSelect from "@/components/SizeSelect";
import Search from "@/components/HeaderSearch";
import RuoYiGit from "@/components/RuoYi/Git";
import RuoYiDoc from "@/components/RuoYi/Doc";
import { modelChangeConfig, modelConfig } from "@/api/lclApi/lclapi";
export default {
  data() {
    return {
      mode: 1,
    };
  },
  components: {
    Breadcrumb,
    TopNav,
    Hamburger,
    Screenfull,
    SizeSelect,
    Search,
    RuoYiGit,
    RuoYiDoc,
  },
  computed: {
    ...mapGetters(["sidebar", "avatar", "device"]),
    setting: {
      get() {
        return this.$store.state.settings.showSettings;
      },
      set(val) {
        this.$store.dispatch("settings/changeSetting", {
          key: "showSettings",
          value: val,
        });
      },
    },
    topNav: {
      get() {
        return this.$store.state.settings.topNav;
      },
    },
  },
  mounted() {
    this.$nextTick(this.getMode());
  },
  methods: {
    getMode() {
      modelConfig().then((res) => {
        if (res && res.code === 200) {
          this.mode = res.data;
        }
      });
    },
    modeChange() {
      if (this.mode === 1) {
        modelChangeConfig({ model: 2 }).then((res) => {
          if (res && res.code === 200) {
            this.$modal.msgSuccess("模式切换成功");
            this.getMode();
          }
        });
      } else if (this.mode === 2) {
        modelChangeConfig({ model: 1 }).then((res) => {
          if (res && res.code === 200) {
            this.$modal.msgSuccess("模式切换成功");
            this.getMode();
          }
        });
      }
    },
    toggleSideBar() {
      this.$store.dispatch("app/toggleSideBar");
    },
    async logout() {
      this.$confirm("确定注销并退出系统吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.dispatch("LogOut").then(() => {
            location.href = "/index";
          });
        })
        .catch(() => {});
    },
    toBigscreen() {
      console.log(
        this.$router.resolve({
          path: "/user",
        }),
        process,
        "this.$router.resolve"
      );

      // this.$router.push({ path: "/bigscreen" });
      // clearInterval(this.curTimer)
      var link = this.$router.resolve({
        path: "/bigscreen",
      });
      window.open(link.href, "_blank");
      return;
    },
  },
};
</script>

<style lang="scss" scoped>
.mode {
  width: 82px;
  height: 40px;
  display: inline-block;
  color: #fff;
  font-size: 20px;
  line-height: 40px;
  margin-top: -67px;
  vertical-align: middle;
  cursor: pointer;
}
.navbar {
  height: 64px;
  overflow: hidden;
  position: relative;

  .hamburger-container {
    line-height: 64px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;

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

  .breadcrumb-container {
    float: left;
  }

  .topmenu-container {
    position: absolute;
    left: 0.5rem;
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 0.8rem;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

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

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

    .avatar-container {
      margin-right: 30px;

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

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
          color: #fff;
        }
      }
    }
  }
}
.navbar .right-menu .bigscreen {
  color: #fff;
  width: 50px;
  height: 50px;
  font-size: 30px;
}
</style>
