<script setup>
import myHeader from "./myHeader.vue";
import myAside from "./myAside.vue";
import { ref, nextTick, onMounted, onUnmounted } from "vue";
import mitt from "@/utils/mitt.js";




const KeyboardEvent = (e)=>{
  console.log('按下', e.keyCode);
  if(e.keyCode == 16) mitt.emit('shift');
  if(e.keyCode == 120) mitt.emit('F9');
  if(e.keyCode == 13) mitt.emit('enter');
  if(e.keyCode == 37) mitt.emit('left');
  if(e.keyCode == 39) mitt.emit('right');
  if(e.keyCode == 38) mitt.emit('up');
  if(e.keyCode == 40) mitt.emit('down');
  if(e.keyCode == 46) mitt.emit('delete');
  if(e.keyCode == 45) mitt.emit('insert');
}

onMounted(()=>{
  window.addEventListener('keydown', KeyboardEvent);
  console.log('开启键盘监听');
})

onUnmounted(()=>{
  window.removeEventListener('keydown', KeyboardEvent);
  console.log('关闭键盘监听');
})
</script>

<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <myHeader></myHeader>
      </el-header>
      <el-container>
        <el-aside width="6.25rem">
          <myAside></myAside>
        </el-aside>
        <el-main style="color: #333;">
          <router-view v-slot="{ Component }" class="my-main">
            <transition name="el-zoom-in-top">
              <component :is="Component"></component>
            </transition>
          </router-view>
          <!-- <transition name="el-zoom-in-top">
            <router-view class="my-main"></router-view>
          </transition> -->
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style scoped lang="scss">
.common-layout {
  width: 100vw;
  height: 100vh;
  background-color: #001529;
  .el-header {
    color: #fff;
    height: 4rem;
  }
  .el-aside {
    color: #fff;
  }
  .el-main {
    background-color: #f5f5f5;
    width: calc(100vw - 6.25rem);
    height: calc(100vh - 4rem);
    border-radius: 2rem 0 0 0;
    overflow-y: scroll;
    padding: 1rem;
    
    .my-main {
      height: 100%;
      width: 100%;
    }
  }
}
</style>
