<template>
  <a-breadcrumb :routes="routes">
    <template slot="itemRender" slot-scope="{route}">
      <template v-if="$route.path.startsWith(route.path) || route.path == '/portal-home'">
        <!-- <span v-if="routes.indexOf(route) === routes.length - 1">
          {{route.meta.title}}
        </span> -->
        <span v-if="route.path != '/portal-home'">
          {{route.meta.title}}
        </span>
        <router-link v-else :to="route.path">
          {{route.meta.title}}
        </router-link>
      </template>
    </template>
  </a-breadcrumb>
</template>
<script>
import {routes} from '@/router/routes.js'
export default {
  name: 'NavBar',
  computed: {
    routes() {
      const result = []
      const routeList = routes[0].children.slice(1)
      if (routeList && routeList.length > 0) {
        routeList.forEach(route => {
          result.push(route)
          if (route.children && route.children.length > 0) {
            result.push(...route.children)
          }
        })
      }

      // const result = []
      // const routeList = routes[0].children.slice(1)
      // let isLoadExtendMenu = this.$cookie.get('customKeyEnable')
      // if (routeList && routeList.length > 0) {
      //   for(let i = 0; i < routeList.length; i++) {
      //     result.push(routeList[i])
      //     if (routeList[i].children && routeList[i].children.length > 0 && routeList[i].children.name == 'tbls') {
      //       // result.push(...route.children)
      //       console.log(JSON.stringify(routeList[i].children))
      //     } else {
      //       console.log(JSON.stringify(routeList[i].children))
      //     }
      //   }
      // }
      return [{path: '/portal-home', name: 'Home', meta: {title: '首页'}}, ...result]
    }
  },
}
</script>
