<template>
  <div>
    <div class="home-header d-flex a-c pl-16">
      <div class="d-flex jc-space-between full-width">
        <div class="d-flex" style="width: 3.375rem; cursor: pointer">
          <div class="d-flex">
            <img
              style="width: 0.4375rem; height: 0.4375rem"
              src="../../../assets/images/yunpingtai.png"
              mode="scaleToFill"
            />
          </div>
          <div class="home-btn" @click="handleIconClick">
            {{ leftName }}
            <div>
              <dv-decoration-3
                style="width: 1.625rem; height: 0.0625rem; padding-top: 00.0375rem"
              />
            </div>
          </div>
        </div>
        <div class="header-title">{{ appName }}</div>
        <div class="d-flex a-c">
          <div>
            <span class="header-time"> {{ currentTime }}</span>
            <span class="header-day">{{ currentDay }}</span>
            <div>
              <dv-decoration-10 style="width: 2.5rem; height: 0.0625rem" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentTime: "",
      currentDay: "",
      intervalId: null,
    };
  },
  mounted() {
    this.updateTime(); // 初始化时先设置一次时间
    this.intervalId = setInterval(this.updateTime, 1000); // 每秒更新一次
  },
  computed: {
    appName() {
      return this.$store.state.app_name;
    },
    leftName() {
      return this.$store.state.leftName;
    },
  },
  beforeDestroy() {
    clearInterval(this.intervalId);
  },
  destroyed() {
    clearInterval(this.intervalId);
  },
  methods: {
    handleIconClick() {
      if (this.appName == "江夏住宅小区电梯大数据管理平台") {
        this.$router.push("/");
      } else {
        window.close();
      }
    },
    updateTime() {
      const now = new Date();
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, "0");
      const day = String(now.getDate()).padStart(2, "0");
      const hour = String(now.getHours()).padStart(2, "0");
      const minute = String(now.getMinutes()).padStart(2, "0");
      const second = String(now.getSeconds()).padStart(2, "0");
      this.currentDay = `${year}-${month}-${day}`;
      this.currentTime = `${hour}:${minute}:${second}`;
    },
  },
};
</script>
<style lang="scss" scoped>
.home-header {
  width: 100%;
  height: 1.25rem;
  //   border-bottom: blue dashed 1px;

  background: linear-gradient(
      rgba(2, 21, 92, 1) 0%,
      rgba(2, 21, 92, 0.8) 20%,
      rgba(2, 21, 92, 0.6) 40%,
      rgba(2, 21, 92, 0.4) 60%,
      rgba(2, 21, 92, 0.2) 80%,
      rgba(2, 21, 92, 0) 100%
    ),
    url("../../../assets/images/title-bck.png") no-repeat center;
  background-size: 100% 100%;
  position: fixed;
  top: 0;
  left: 0;

  color: red;
  z-index: 9;
  padding: 0 0.2rem;
}
.header-title {
  font-size: 0.45rem;
  line-height: 0.5875rem;
  float: left;
  color: #e8ffff;
  font-weight: normal;
  text-shadow: 0 0 0.5em #00befd, 0 0 0.5em #00befd;
  padding-bottom: 0.125rem;
}
.header-time {
  color: #87ccff;
  font-size: 0.5rem;
  padding-right: 0.15rem;
  line-height: 30px;
}
.header-day {
  font-size: 0.255rem;

  font-weight: normal;
  padding-right: 0.15rem;
  line-height: 30px;

  color: #87ccff;
}
.home-btn {
  font-size: 0.225rem;
  line-height: 14px;
  color: #ffffff;
  text-shadow: 0 0 0.8em #00befd, -0 -0 0.8em #00befd;
  padding-top: 0.125rem;
  padding-left: 0.125rem;
}
</style>
