<template>
  <div :style="{ zoom: zoom }">
    <div class="nav-header">
      <div class="left-nav">
        <div class="weather">
          <img
            class="weather-img"
            :src="screenDetail.weather_code_url"
            alt=""
          />
          <div class="weather-text">
            <div class="temperature">
              {{ screenDetail.temperature }}
              <span style="font-size: 14px">℃</span>
            </div>
            <div class="condition">{{ screenDetail.weather_condition }}</div>
          </div>
        </div>
        <router-link
          v-for="(router, index) in leftNav"
          :key="index"
          :to="{ path: router.menu_url, query: { token_code: token } }"
        >
          {{ router.right_name }}</router-link
        >
      </div>
      <div class="mid-title">
        <el-tooltip
          class="item"
          effect="dark"
          :content="screenDetail.project_name"
          placement="bottom"
        >
          <div class="overflowed">{{ screenDetail.short_name }}</div>
        </el-tooltip>
      </div>
      <div class="right-nav">
        <router-link
          v-for="(router, index) in rightNav"
          :key="index"
          :to="{ path: router.menu_url, query: { token_code: token } }"
        >
          {{ router.right_name }}</router-link
        >
        <div class="clock">
          <div class="time">
            {{ time }}
          </div>
          <div class="date">
            <div class="week">{{ weekDay }}</div>
            <div class="day">{{ date }}</div>
          </div>
        </div>
      </div>
    </div>
    <div>
      <router-view></router-view>
    </div>
  </div>
</template>
<script>
import { getBaseInfo } from "@/api/index";
export default {
  name: "Index",
  data() {
    return {
      time: "",
      weekDay: "",
      date: "",
      zoom: 1,
      screenDetail: {},
      leftNav: [],
      rightNav: [],
    };
  },
  methods: {
    getTime() {
      let date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month = month > 9 ? month : "0" + month;
      day = day < 10 ? "0" + day : day;
      let today = year + "-" + month + "-" + day;
      this.date = today;
      let hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      let min =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      let sec =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      this.time = `${hour}:${min}:${sec}`;

      let str = "星期";
      let weekDay = new Date().getDay();
      switch (weekDay) {
        case 0:
          str += "日";
          break;
        case 1:
          str += "一";
          break;
        case 2:
          str += "二";
          break;
        case 3:
          str += "三";
          break;
        case 4:
          str += "四";
          break;
        case 5:
          str += "五";
          break;
        case 6:
          str += "六";
          break;
      }
      this.weekDay = str;
    },
    bodyScale() {
      var devicewidth = document.documentElement.clientWidth; //获取当前分辨率下的可是区域宽度
      var scale = devicewidth / 1920; // 分母——设计稿的尺寸
      this.zoom = scale; //放大缩小相应倍数
      let charts = document.getElementsByClassName("chart-container");
      for (let i = 0; i < charts.length; i++) {
        charts[i].style.zoom = 1;
      }
    },
    jumpBack() {
      window.location.href = window.location.origin + "/pweb/m/";
    },
  },
  computed: {
    token() {
      return localStorage.getItem("token");
    },
  },
  mounted() {
    getBaseInfo().then((res) => {
      console.log(res);
      this.screenDetail = res.data;
      document.title = res.data.project_name;
      if (res.data.menu.length >= 4) {
        this.leftNav = res.data.menu.slice(0, 4);
        this.rightNav = res.data.menu.slice(4, res.data.menu.length);
      } else {
        this.leftNav = [...res.data.menu];
      }
    });
    this.$nextTick(() => {
      this.bodyScale();
    });

    this.getTime();
    setInterval(() => {
      this.getTime();
    }, 1000);
  },
};
</script>
<style scoped lang="less">
.nav-header {
  display: flex;
  align-content: center;
  line-height: 70px;
  padding: 0 18px;
  min-height: 78px;
  margin: 0px;
  background: url("@/assets/nav.png") no-repeat;
  background-size: 100% 100%;
  .left-nav {
    width: calc(100% / 3);
    span {
      color: #fff;
      margin-right: 16px;
    }
  }
  .mid-title {
    width: calc(100% / 3);
    font-size: 28px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #fefeff;
    text-align: center;
    letter-spacing: 3px;
  }
  .right-nav {
    width: calc(100% / 3);
    text-align: left;
    .clock {
      float: right;
      width: 124px;
      text-align: center;
      .time {
        text-align: center;
        font-size: 24px;
        color: #22c3ed;
        letter-spacing: 4px;
        line-height: 46px;
      }
      .date {
        font-size: 12px;
        color: #fff;
        display: flex;
        justify-content: space-between;
        line-height: 14px;
      }
    }
  }
}
a {
  min-width: 66px;
  text-align: center;
  display: inline-block;
  text-decoration: none;
  margin-right: 16px;
  color: #80a1c6;
  padding: 9px 12px;
  border: 1px solid #0f5da6;
  border-radius: 4px;
  line-height: 16px;
  font-size: 16px;
  background-image: linear-gradient(#0d3353, #183e75);
  &:hover {
    color: #fff;
    border-color: #27acfb;
    position: relative;
    &::after {
      position: absolute;
      content: "";
      width: 0;
      height: 0;
      bottom: 0px;
      left: 50%;
      transform: translateX(-50%);
      border-right: solid 6px transparent;
      border-left: solid 6px transparent;
      border-bottom: solid 6px #22c3ed;
      filter: drop-shadow(0px -1px 3px rgba(0, 234, 255, 0.8));
    }
  }
}
.router-link-exact-active.router-link-active {
  color: #fff;
  border-color: #27acfb;
  position: relative;
}

.router-link-exact-active.router-link-active::after {
  position: absolute;
  content: "";
  width: 0;
  height: 0;
  bottom: 0px;
  left: 50%;
  transform: translateX(-50%);
  border-right: solid 6px transparent;
  border-left: solid 6px transparent;
  border-bottom: solid 6px #22c3ed;
  filter: drop-shadow(0px -1px 3px rgba(0, 234, 255, 0.8));
}
.overflowed {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  padding: 0 30px;
}
.weather {
  display: inline-block;
  line-height: 24px;
  vertical-align: top;
  margin-right: 20px;
  margin-top: 8px;
  .weather-text {
    color: #fff;
    font-size: 18px;
    display: inline-block;
  }
  .weather-img {
    vertical-align: top;
    width: 50px;
    margin-right: 6px;
  }
}
</style>