<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
  import menu from './util/menuList'
export default {
  name: 'App',
  data(){
    return {

    }
  },
  mounted(){
    // 权限验证 动态路由
    if(window.location.href.indexOf('login') < 0){
      let permission = this.$store.state.progressList;
      let menuList = [];
      this.$router.options.routes[0].children = [];
      let routerUserDetail = {
          path: '/userDetail/:id',
          name:'userDetail',
          component: e=>require(['@/components/userDetail'],e),
        };
        let routerTeacherDetail ={
          path: '/teacher/:id',
          name:'teacherDetail',
          component: e=>require(['@/components/teacherDetail'],e),
    };
      menu.forEach(i=>{
        let p = false;
        let t = [];
        i.list.forEach(j=>{
          let find = permission.find(x=>{return x.cover === j.cover});
          if(find){
            j.router.meta = {};
            j.router.meta.readonly = find.readonly;
            j.router.meta.delete = !!find.delete;
            j.router.meta.refund = find.refund;
            t.push(j);
            if(find.cover === '3-1'){
              routerTeacherDetail.meta = {};
              routerTeacherDetail.meta.readonly = find.readonly;
              routerTeacherDetail.meta.delete = !!find.delete;
              this.$router.options.routes[0].children.push(routerTeacherDetail);
            }

            if(find.cover === '3-2'){
              routerUserDetail.meta = {};
              routerUserDetail.meta.readonly = find.readonly;
              routerUserDetail.meta.delete = !!find.delete;
              this.$router.options.routes[0].children.push(routerUserDetail);
            }
            this.$router.options.routes[0].children.push(j.router);
            p = true;
          }
        });
        if(p){
          i.list = t;
          menuList.push(i)
        }
      });
      this.$router.addRoutes([this.$router.options.routes[0]]);//调用add;
      this.$store.dispatch('setMenu',menuList)
    }

  }
}
</script>

<style>
#app {
  height: 100%;
}
  html,body{
    height: 100%;
    margin: 0;
    padding: 0;
  }
</style>
