<template>
  <div class="common-layout">
    <el-container style="height: 100vh">
      <el-header>
        <el-menu :default-active="activeIndex" class="el-menu-demo pl-20 bg-blueGray-2 custom-menu" mode="horizontal">
          <el-menu-item index="index">
            <router-link to="/"> 首页 </router-link>
          </el-menu-item>
          <el-menu-item index="protocol">
            <router-link to="/protocol"> 协议 </router-link>
          </el-menu-item>
          <el-menu-item index="communication">
            <router-link to="/communication"> 通信参数 </router-link>
          </el-menu-item>
        </el-menu>
      </el-header>
      <el-main>
        <router-view />
        <!-- <router-view v-slot="{ Component }">
          <keep-alive>
            <component :is="Component" />
          </keep-alive>
        </router-view> -->
      </el-main>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
const activeIndex = ref('1')
import { DeviceProtocol, ProtocolCmd } from "@/dao/device";
import { GetProtocolVersion, GetCurrentVersion } from '@/dao/protocol';
import { useProtocolInfoStore } from './stores/protocolInfo';
import { useProtocolVersionStore } from '@/stores/allProtocolVersion';

const store = useProtocolVersionStore()
const protocolStore = useProtocolInfoStore()

onMounted(async () => {
  await GetProtocolVersion()
  .then(res => {
    store.protocolVersions.push(...res)
  })
  await GetCurrentVersion()
  .then(res => {
    store.currentVersions = res    
  })
  await DeviceProtocol()
  .then((res) => {
    protocolStore.deviceProtocol = res.data
  })
  await ProtocolCmd()
  .then((res) => {
    protocolStore.protocolCmd = res.data
  })
})
</script>

<style>
.el-header {
  --el-header-padding: 0 !important;
}
.el-main{
  align-items: stretch;
  background-color: #f4f4f4;
}
.custom-menu {
  display: flex;
  justify-content: center;
  
}
.custom-menu .el-menu-item{
  font-size: 18px;
}

</style>
