<template>
  <div class="navbar">
    <div class="nav-title">车辆大屏管理系统</div>
    <div class="right">
      <p class="time">{{ time }}</p>

      <div class="photo">
        <div>
          <el-avatar icon="el-icon-user-solid" style="width: 38px; height: 38px"></el-avatar>
        </div>
        <div
          style="font-size: 14px;line-height;line-height:30px;padding-left:10px
        "
        >{{$store.state.user.username}}</div>
      </div>
      <div class="name">{{ $store.state.user.userName }}</div>
      <div class="out" @click="outLogin">
        <img src="../../assets/images/out.png" />
        <div class="title">退出</div>
      </div>
    </div>
  </div>
</template>

<script>
import { removeToken } from "@/utils/auth";
import moment from "moment";
import "moment/locale/zh-cn";
export default {
  name: "Navbar",
  data() {
    return {
      time: moment().format("YYYY-M-D  dddd  HH:mm:ss"),
      timer: null
    };
  },
  mounted() {
    this.time = moment().format("YYYY-M-D  dddd  HH:mm:ss");
    this.timer = setInterval(() => {
      this.time = moment().format("YYYY-M-D  dddd  HH:mm:ss");
    }, 1000);
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer);
      this.timer = null;
    }
  },
  methods: {
    informs() {
      this.$router
        .replace({ name: "Inform" })
        .then(res => {})
        .catch(err => {
          console.log();
        });
    },
    outLogin() {
      this.$confirm("确认退出登录？")
        .then(_ => {
          this.$store.dispatch("user/logout").then(() => {
            this.$message({
              message: "退出成功",
              type: "success"
            });
            this.$router.replace({ path: "/login" });
          });
        })
        .catch(_ => {});
    }
  }
};
</script>

<style lang="scss" scoped>
.navbar {
  height: 96px;
  overflow: hidden;
  background: rgba(19, 41, 73, 1);
  display: flex;
  align-items: center;
  justify-content: space-between;

  .nav-title {
    width: 324px;
    height: 53px;
    line-height: 53px;
    color: transparent;
    font-size: 36px;
    font-weight: 500;
    margin-left: 22px;
  }

  .right {
    display: flex;
    align-items: center;

    .time {
      width: 241px;
      height: 27px;
      line-height: 27px;
      color: #fff;
      font-size: 18px;
      font-weight: 400;
      margin-right: 5px;
      // float: right;
    }

    .photo {
      height: 28px;
      padding: 0 5px 0 15px;
      border-left: 2px solid #fff;
      border-right: 2px solid #fff;
      display: flex;
      align-items: center;
      color: #fff;
    }

    .name {
      // width: 50px;
      height: 28px;
      color: #fff;
      font-size: 14px;
      font-weight: 500;
      line-height: 28px;
      padding: 0 15px 0 5px;
      margin-right: 13px;
    }

    .out {
      display: flex;
      align-items: center;
      padding-right: 18px;
      cursor: pointer;

      .title {
        margin-left: 6px;
        font-size: 14px;
        color: #fff;
      }
    }
  }
}
</style>