<template>
  <div class="basic-layout" :style="basicStyle">
    <div class="titleBar">
      <div class="title">
        <div class="logo">
          <img src="@/assets/logo.png">
        </div>
        <div class="txt">{{ systemTitle }}</div>
      </div>
      <div class="windowTool">
        <div @click="miniSize">
          <el-tag
            color="#a20d13"
            effect="dark">
            <i class="el-icon-minus"/>
          </el-tag>
        </div>
        <!--<div>
          <el-mqtt
            v-if="isMaxSize"
            @click="restore"
            color="#a20d13"
            effect="dark">
            <i class="el-icon-copy-document"/>
          </el-mqtt>

          <el-mqtt
            v-else
            @click="maxsize"
            color="#a20d13"
            effect="dark">
            <i class="el-icon-full-screen"/>
          </el-mqtt>
        </div>-->
        <div>
          <el-tag
            color="#a20d13"
            effect="dark"
            class="close-tag"
            @click="close">
            <i class="el-icon-close"/>
          </el-tag>
        </div>
      </div>
    </div>
    <el-container>
      <el-aside width="auto">
        <div style="height: 40px;border-right: solid 1px #dbd8d2"/>
        <el-menu
          :router="true"
          :default-active="$route.path === '/home' ? '/' : $route.path"
          :unique-opened="true"
          :collapse-transition="false"
        >
          <jg-menu :menu-list="routes"/>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main class="page-content">
          <router-view/>
        </el-main>
        <!--<el-footer height="28px">Copyright © 2022 辽宁津港科技技术部</el-footer>-->
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { asyncRouterMap } from '@/config/router.config'
import JgMenu from '@/components/JgMenu'
import { mapState } from 'vuex'

const { ipcRenderer } = require('electron')

export default {
  name: 'BasicLayout',
  components: { JgMenu },
  data () {
    return {
      isAlive: true,
      isMaxSize: false,
      basicStyle: {},
      routes: asyncRouterMap[0].children,
    }
  },
  computed: {
    ...mapState({
      systemTitle: (state, getter) => state.company.systemTitle,
    }),
  },
  created () {
    ipcRenderer.removeAllListeners('mainWin-max')
    ipcRenderer.on('mainWin-max', (event, data) => {
      this.isMaxSize = data
    })
  },
  mounted () {
    const _this = this
    _this.basicStyle = {
      // width: window.screenWidth + 'px',
      height: window.innerHeight + 'px',
      overflow: 'hidden',
    }
    window.onresize = () => (() => {
      window.screenWidth = document.body.clientWidth
      _this.basicStyle = {
        width: window.screenWidth + 'px',
        height: window.innerHeight + 'px',
        overflow: 'auto',
      }
    })()
  },
  methods: {
    miniSize () {
      const win = window.remote.getCurrentWindow()
      win.minimize()
    },
    //恢复
    restore () {
      window.remote.getCurrentWindow().restore()
    },
    //最大化
    maxsize () {
      const win = window.remote.getCurrentWindow()
      win.maximize()
    },
    //关闭
    close () {
      const win = window.remote.getCurrentWindow()
      win.destroy()
    },
  },
  beforeDestroy () {
    window.onresize = null
    ipcRenderer.removeAllListeners('mainWin-max')
  }
}
</script>

<style lang="less" scoped>

  .basic-layout {
    display: flex;
    flex-direction: column;
    background-color: #ebebeb;
    user-select: none;

    .titleBar {
      height: 38px;
      line-height: 36px;
      background: linear-gradient(#d52730, #a20d13);
      display: flex;
      justify-content: space-between;
      color: white;
      user-select: none;

      .title {
        flex: 1;
        display: flex;
        -webkit-app-region: drag;

        .logo {
          padding-left: 8px;
          padding-right: 6px;
        }

        .logo img {
          width: 20px;
          height: 20px;
          margin-top: 7px;
        }

        .txt {
          text-align: left;
          flex: 1;
          font-size: 14px;
        }
      }

      .windowTool {
        margin-right: 5px;

        div {
          height: 100%;
          width: 38px;
          display: inline-block;
          cursor: pointer;
        }

        .el-tag {
          .el-icon-close {
            border-radius: 50%;
            text-align: center;
            position: relative;
            cursor: pointer;
            font-size: 12px;
            height: 16px;
            width: 16px;
            line-height: 16px;
            vertical-align: middle;
            top: -1px;
            right: 0;
          }
        }

        .el-tag--dark {
          border-color: #a20d13;
          color: #fff;
        }

        .el-tag:hover {
          color: #fff;
          background-color: #409eff
        }

        .el-tag:active {
          opacity: .5;
        }
      }
    }

    .el-header {
      padding: 0;
      /*color: #ffffff;*/
      display: flex;
      align-items: center;
      border-bottom: 1px solid #e6e6e6;
    }

    .el-aside {
      height: 100%;
      width: 314px;

      /deep/ .el-menu {
        height: calc(100% - 40px);
        background-color: #ebebeb;
        border-right: solid 1px #dbd8d2;
      }

      .el-menu--horizontal .el-menu-item:not(.is-disabled):focus, .el-menu--horizontal .el-menu-item:not(.is-disabled):hover {
        color: inherit !important;
      }

      /deep/ .el-submenu__title i {
        color: inherit;
      }
    }

    .el-tag:active {
      opacity: .5;
    }

    .page-content {
      padding: 0;
      position: relative;
    }
  }
</style>
