<template>
  <div :class="classObj" class="app-wrapper">
    <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside"/>
    <sidebar class="sidebar-container"/>
    <div class="main-container">
      <div :class="{'fixed-header':fixedHeader}">
        <navbar/>
        <tags-view/>
        <!--收藏夹-->
        <el-input id="sys_favoritesInput" v-show="false" placeholder="请输入内容"></el-input>
        <el-button id="sys_favoritesButton" v-show="false" @click="onClickJumpButton">转跳</el-button>
      </div>
      <app-main/>
    </div>
  </div>
</template>

<script>
import { AppMain, Navbar, Sidebar } from './components'
import TagsView from './components/TagsView/index.vue'
import ResizeMixin from './mixin/ResizeHandler'
import {getConfigInfo} from "@/api/system/config";

export default {
  name: 'Layout',
  components: {
    Navbar,
    Sidebar,
    AppMain,
    TagsView
  },
  mixins: [ResizeMixin],
  mounted() {
    this.getConfig('WebSocketServer')
    // this.$websocket.dispatch('WEBSOCKET_INIT', 'ws://192.168.1.20:10991/ws/ews')
  },
  computed: {
    sidebar() {
      return this.$store.state.app.sidebar
    },
    device() {
      return this.$store.state.app.device
    },
    fixedHeader() {
      return this.$store.state.settings.fixedHeader
    },
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === 'mobile'
      }
    },
    getMessage() {
      return this.$websocket.state.eventlist
    }
  },
  watch: {
    // getMessage() {
    //   this.$notify({
    //     title: '提示',
    //     message: '收到一个pong',
    //     position: 'bottom-right'
    //   })
    // }
  },
  methods: {
    // 获取配置信息
    getConfig(key) {
      const _that = this
      const data = {
        configKey: key
      }
      // console.log(data);
      getConfigInfo(data).then(res => {
        // console.log(res)
        if (res.data.configValue1) {
          _that.$websocket.dispatch('WEBSOCKET_INIT', res.data.configValue1)
        }
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    handleClickOutside() {
      this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
    },
    onClickJumpButton() {
      this.$router.push(document.getElementById('sys_favoritesInput').value)
    },
    alertMssage(value) {
      // console.log(value)
      // if (this.getMessage) {
        this.$notify({
          title: '提示',
          message: '收到一个pong',
          position: 'bottom-right'
        })
      // }
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/styles/mixin.scss";
@import "~@/styles/variables.scss";

.app-wrapper {
  @include clearfix;
  position: relative;
  height: 100%;
  width: 100%;

  &.mobile.openSidebar {
    position: fixed;
    top: 0;
  }
}

.drawer-bg {
  background: #000;
  opacity: 0.3;
  width: 100%;
  top: 0;
  height: 100%;
  position: absolute;
  z-index: 999;
}

.fixed-header {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 9;
  width: calc(100% - #{$sideBarWidth});
  transition: width 0.28s;
}

.hideSidebar .fixed-header {
  width: calc(100% - 54px)
}

.mobile .fixed-header {
  width: 100%;
}
</style>
