<!--
 * @Author: 曹捷
 * @Date: 2020-04-22 14:28:38
 * @LastEditors: 曹捷
 * @LastEditTime: 2022-02-11 13:04:52
 * @Description: 主应用  面包屑
  1放在header里面
  2放在body里面 breadcrumb-content

  面包屑规则修改详情界面规范 
  详情界面路径必须在父路径之后增加路径
 -->
<template>
  <a-breadcrumb class="app-breadcrumb" separator="/">
    <a-breadcrumb-item class="bread-item" :key="'bread' + index" v-for="(item, index) in levelList">
      <span class="no-redirect" v-if="item.path === 'noRedirect' || index == levelList.length - 1">{{ item[sysConfig.menu.name] }}</span>
      <a @click.prevent="handleLink(item)" v-else>{{ item[sysConfig.menu.name] }}</a>
    </a-breadcrumb-item>
  </a-breadcrumb>
</template>

<script>
import crumbMix from './crumb'
export default {
  mixins: [crumbMix],
  data () {
    return {
      appRouter: {}
    }
  },
  watch: {
    appRouter: {
      handler (list) {
        let appInfo = this.getMainAppRoute()
        if (appInfo.lastRoute) {
          this.getBreadcrumb()
        }
      },
      deep: true
    },
  },
  created () {
    //      子应用没有引入乾坤  webpack会报错  不能import 改为require
    // 思路  子应用 webpack  忽略qiankun的引入
    // 已解决  字因为webpack externals qiankun
    let qkStore = require('./../../qiankun/qkStore').default
    this.appRouter = qkStore.getGlobalState('appRouter')
  },
  methods: {
    // 主框架
    getMainAppRoute () {
      let path = this.$route.path
      path = path.substring(1, path.length)
      let appCode = path.substring(0, path.indexOf('/'))
      let configPath = this.sysConfig.menu.url
      let lastRoute, routeInfo
      if (this.appRouter[appCode]) {
        let list = this.appRouter[appCode]
        routeInfo = list.find(el => path.indexOf(el.path) !== -1)
        if (routeInfo) {
          lastRoute = this.sysMenuList.find((item) => {
            return item[configPath].indexOf(routeInfo.meta.parentPath) !== -1
          })
        }
      }
      return { lastRoute, routeInfo }
      // let appCode = 
    },
    findLastRoute (arr) {
      // 主框架 通过子框架获取
      let appInfo = this.getMainAppRoute()
      let lastRoute = appInfo.lastRoute
      if (lastRoute) {
        let detailsInfo = {}
        detailsInfo[this.sysConfig.menu.name] = appInfo.routeInfo.meta.name
        arr.push(detailsInfo)
      }
      return lastRoute
    },
  },
}
</script>

<style lang="less" scoped>
.app-breadcrumb {
  display: inline-block;
  font-size: 14px;
  line-height: 50px;
  margin-left: 8px;
  .no-redirect {
    cursor: text;
  }
}
// 面包屑在主体里面
.app-breadcrumb.breadcrumb-content {
  line-height: normal !important;
  .breadcrumb {
    float: right;
    padding-right: 20px;
  }
}
</style>
