<template>
  <div class="home">
    <el-container>
      <el-header>
        <el-row :gutter="20">
          <el-col :span="4"
            ><img class="logo" src="../assets/logo.png"
          /></el-col>
          <el-col :span="16"><h2>算法集后台管理系统</h2></el-col>
          <el-col :span="4"
            ><span class="quit" @click="logout_function">退出登录</span></el-col
          >
        </el-row>
      </el-header>
      <el-container>
        <el-aside width="200px"
          ><el-menu
            active-text-color="#ffd04b"
            background-color="#545c64"
            class="el-menu-vertical-demo"
            default-active="2"
            text-color="#fff"
            router
          >
            <el-menu-item
              :index="item.path"
              v-for="item in list"
              :key="item.path"
            >
              <el-icon><icon-menu /></el-icon>
              <span>{{ item.meta.title }}</span>
            </el-menu-item>
          </el-menu></el-aside
        >
        <el-main>
          <RouterView></RouterView>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
import { logout } from "../request/api";
import { ElMessage } from "element-plus";
import { useStore } from "@/stores/counter";

const router = useRouter();
// console.log(router.getRoutes());
const list = router.getRoutes().filter((v) => v.meta.isShow);
function logout_function() {
  const store = useStore();
  logout().then((res) => {
    console.log(res);

    if (res == null) {
      return;
    }
    store.auth.user = null;
    // window.localStorage.clear();
    ElMessage.success("退出成功");
    router.push("/login");
  });
}
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0px;
  left: 0px;
}
.el-header {
  height: 80px;
  background-color: #666;
  .logo {
    height: 80px;
  }
  h2,
  .quit {
    text-align: center;
    height: 80px;
    line-height: 80px;
    color: #fff;
  }
}
.el-aside {
  .el-menu {
    height: calc(100vh - 80px);
  }
}
</style>
