<!-- vue 页面模板 -->
<template>
  <div class="layout">
    <Layout>
      <PageHeader title=" ">
        <template #action>
          <div class="login_out" @click="login_out">退出</div>
        </template>
        <template #content> </template>
      </PageHeader>
      <Layout>
        <Sider hide-trigger :style="{ background: '#fff' }">
          <Menu
            :active-name="active_name"
            theme="primary"
            width="auto"
            :open-names="['home']"
            @on-select="changePage"
            accordion
          >
            <div v-for="(item, i) in menu_list" :key="i">
              <Submenu v-if="item.children" :name="item.name">
                <template #title>
                  <Icon :type="item.icon" />
                  {{ item.title }}
                </template>
                <MenuItem
                  v-for="v in item.children"
                  :key="v.name"
                  :name="v.name"
                >
                  {{ v.title }}
                </MenuItem>
              </Submenu>
              <MenuItem v-else :name="item.name">
                <Icon v-if="item.icon" :type="item.icon" />
                {{ item.title }}
              </MenuItem>
            </div>
          </Menu>
        </Sider>
        <Layout :style="{ padding: '24px' }">
          <Content
            :style="{
              padding: '24px',
              height: content_height + 'px',
              background: '#fff',
            }"
          >
            <router-view></router-view>
          </Content>
        </Layout>
      </Layout>
    </Layout>
  </div>
</template>

<script>
import api from '../../api/index.js';
import { default_menu } from '../../config/index';

export default {
  data() {
    return {
      content_height: 0,
      active_name: '',
      menu_list: default_menu,
    };
  },
  mounted() {
    // 计算内容区域高度
    this.content_height = document.documentElement.clientHeight - 120;
    this.active_name = this.$route.path;
    api.menu_api().then(r => {
      console.log(r);
      //   this.menu_list = (r || []);
    });
  },
  methods: {
    changePage(p) {
      this.$router.replace(p);
    },
    login_out() {
      api.login_out_api().then(r => {
        console.log(r);
        localStorage.setItem('neican_token', '');
        this.$router.replace('/');
      });
    },
  },
};
</script>

<style lang="scss">
.layout {
  border: 1px solid #d7dde4;
  background: #f5f7f9;
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  width: 100%;
  height: 100%;
  .login_out {
    cursor: pointer;
  }
}
</style>
