<script>


import AdminLayout from "~/components/layout/adminLayout.vue";
import {adminMenus} from "~/map/adminSideBar";
import Vue from 'vue'
import antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
import {login_types} from "../../store/login";
import handle from "../../until/handle";
Vue.use(antd);

export default {
  name: "mangerIndex",
  components: {AdminLayout},
  async asyncData(ctx) {
    // 判断 store 中的 isLogin 是否为 true $store.state.login.captcha
    console.log(ctx?.store?.state?.login)
    if (!ctx?.store?.state?.login?.isLogin) {
      // 如果未登录，重定向到登录页
      // ctx.redirect('/manger/login')
      ctx.redirect('/manger/login')
    }
    return {}
  },
  data(){
    return {
      headerMenus:[
        {
          text: '前往首页',
          href: '/',
          key: 'toIndex'
        }
      ],
      sidebarMenus: adminMenus

    }
  },
  computed: {
    userInfo(){
      return this.$store.state.login.userInfo
    }
  },
  methods: {
    dataLogOut(){
      this.$store.commit('login/'+login_types.mutations.userLogout);
    },
    async logout(){
      let [err,res] = await handle(this.$axios.get('/api/user/logout'));
      this.dataLogOut();
      if(err){
        return {};
      }
      this.$message.success('退出成功');
      // 切换url至 /login
      this.$router.push('/manger/login');
    }
  }
}
</script>

<template>
<div class="w-full">
<admin-layout
  :logoTitle="'深圳合方圆站点管理'"
  :header-menus="headerMenus"
  :sidebar-menus="sidebarMenus"
  index-path="/manger"
>
<!--  下拉菜单,对应slot user-->
  <a-dropdown slot="user">
    <a class="ant-dropdown-link" href="#">
      {{ userInfo.name }} <a-icon type="down" />
    </a>
    <a-menu slot="overlay">
<!--      <a-menu-info key="1">-->
<!--        <a href="#">1st menu info</a>-->
<!--      </a-menu-info>-->
      <a-menu-item key="3">
        <span @click="logout">退出登录</span>
      </a-menu-item>
    </a-menu>
  </a-dropdown>
  <nuxt-child>

  </nuxt-child>
</admin-layout>
</div>
</template>

<style scoped>

</style>
