<template>
  <div class="navbar">
    <hamburger
      :is-active="sidebar.opened"
      class="hamburger-container"
      @toggleClick="toggleSideBar"
    />
    <breadcrumb
      id="breadcrumb-container"
      class="breadcrumb-container"
      v-if="!topNav"
    />
    <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav" />
    <div class="right-menu">
	    <div>
			
			<!-- 线上 -->
			
		<!-- 	<a :href="'http://10.90.105.122:8045/edge/monitor?username='+username" target="_blank" style="margin-right: 1.875rem;">
				<span class="el-icon-data-line" style="font-size: 1.5rem; color:#fff; line-heigth: 3rem !important"/>
				<span style="font-size: 1rem; color:#fff;margin-left:5px;line-heigth::1.2rem;">大屏总览</span>
			</a>
			<a :href="'http://10.90.105.122:8045/edge/ScreenFX?username='+username" target="_blank" >
				<span class="el-icon-data-line" style="font-size: 1.5rem; color:#fff; line-heigth: 3rem !important"/>
				<span style="font-size: 1rem; color:#fff;margin-left:5px;line-heigth::1.2rem;">水平衡分析</span>
			</a> -->
			
			<!--本地  -->
			<a :href="'http://192.168.1.97:8046/edge/monitor?username='+username" target="_blank" style="margin-right: 1.875rem;">
				<span class="el-icon-data-line" style="font-size: 1.5rem; color:#fff; line-heigth: 3rem !important"/>
				<span style="font-size: 1rem; color:#fff;margin-left:5px;line-heigth::1.2rem;">大屏总览</span>
			</a>
			
			<a :href="'http://192.168.1.97:8046/edge/ScreenFX?username='+username" target="_blank" >
				<span class="el-icon-data-line" style="font-size: 1.5rem; color:#fff; line-heigth: 3rem !important"/>
				<span style="font-size: 1rem; color:#fff;margin-left:5px;line-heigth::1.2rem;">平衡分析</span>
			</a>
		</div> 
      <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 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";

export default {
  data() {
    return {
      alarmtotle: 0,
      url: "ws://39.102.206.67/prod-api/websocket/message",
      message: "",
      text_content: "",
      ws: null,
	  username:'',
    };
  },
  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;
      },
    },
  },
  created() {
    this.join();
	this.username=this.$store.getters.name;

  },
  methods: {
    join() {
      const wsuri = this.url;
      this.ws = new WebSocket(wsuri);
      const self = this;
      this.ws.onopen = function (event) {
        self.text_content = self.text_content + "已经打开连接!" + "\n";
      };
      this.ws.onmessage = function (event) {
        console.log(event.data, "sssssssssss");
        self.alarmtotle = event.data + "\n";
      };
      this.ws.onclose = function (event) {
        self.text_content = self.text_content + "已经关闭连接!" + "\n";
      };
    },
    exit() {
      if (this.ws) {
        this.ws.close();
        this.ws = null;
      }
    },
    send() {
      if (this.ws) {
        this.ws.send(this.message);
      } else {
        alert("未连接到服务器");
      }
    },
    toggleSideBar() {
      this.$store.dispatch("app/toggleSideBar");
    },
    async logout() {
      this.$confirm("确定注销并退出系统吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.dispatch("LogOut").then(() => {
            location.href = "/alarm/alarm/cab";
          });
        })
        .catch(() => {});
    },
    alarmMsg() {
      console.log(11111,"1111111111111");
      this.$router.replace("/login");
    },
  },
};
</script>

<style lang="scss" scoped>
.navbar {
  width:100%;
  height: 90px;
  overflow: hidden;
  display: flex;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
	background-color: #001c44;
	/*首先我们设置边框只显示底部，宽度为2px的实线。*/
	border-bottom: 2px solid;
	/*设置线性渐变*/
	border-image: linear-gradient(90deg, rgba(0, 216, 247, 0) 0%, #00afed 100%) 2 2 2 2;
  .alarm-msg {
    ::v-deep.el-badge__content.is-fixed {
      position: absolute;
      top: 14px;
    }
  }

  .hamburger-container {
    line-height: 46px;
    height: 100%;
	width:3%;
    float: left;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;
	display: flex;
	justify-content: center;
	align-items: center;

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

  .breadcrumb-container {
    float: left;
  }
  .app-breadcrumb{
	width:20%;
	height: 100%;
	display: flex;
	justify-content: flex-start;
	align-items: center;
  }
  .topmenu-container {
    position: absolute;
    left: 50px;
  }

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

  .right-menu {
	 width: 94%;
      height: 100%;
      display: flex;
      justify-content: flex-end;
      align-items: center;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      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;
		margin-left:20px;
        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;
        }
      }
    }
  }
  @-webkit-keyframes tada {
    0% {
      -webkit-transform: scale(1);
      transform: scale(1);
    }
    10%,
    20% {
      -webkit-transform: scale(0.9) rotate(-3deg);
      transform: scale(0.9) rotate(-3deg);
    }
    30%,
    50%,
    70%,
    90% {
      -webkit-transform: scale(1.1) rotate(3deg);
      transform: scale(1.1) rotate(3deg);
    }
    40%,
    60%,
    80% {
      -webkit-transform: scale(1.1) rotate(-3deg);
      transform: scale(1.1) rotate(-3deg);
    }
    100% {
      -webkit-transform: scale(1) rotate(0);
      transform: scale(1) rotate(0);
    }
  }
  @keyframes tada {
    0% {
      -webkit-transform: scale(1);
      -ms-transform: scale(1);
      transform: scale(1);
    }
    10%,
    20% {
      -webkit-transform: scale(0.9) rotate(-3deg);
      -ms-transform: scale(0.9) rotate(-3deg);
      transform: scale(0.9) rotate(-3deg);
    }
    30%,
    50%,
    70%,
    90% {
      -webkit-transform: scale(1.1) rotate(3deg);
      -ms-transform: scale(1.1) rotate(3deg);
      transform: scale(1.1) rotate(3deg);
    }
    40%,
    60%,
    80% {
      -webkit-transform: scale(1.1) rotate(-3deg);
      -ms-transform: scale(1.1) rotate(-3deg);
      transform: scale(1.1) rotate(-3deg);
    }
    100% {
      -webkit-transform: scale(1) rotate(0);
      -ms-transform: scale(1) rotate(0);
      transform: scale(1) rotate(0);
    }
  }
  .tada {
    -webkit-animation-name: tada;
    animation-name: tada;
  }
  .tada {
    -webkit-animation-name: tada;
    animation-name: tada;
    -webkit-animation-timing-function: linear;
    animation-timing-function: linear;
    -webkit-animation-iteration-count: infinite;
    animation-iteration-count: infinite;
    -webkit-animation-direction: normal;
    animation-direction: normal;
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
  }
}
</style>
