<!--
 * @Descripttion:
 * @Version: 1.0
 * @Author: +C
 * @Date: 2022-02-24 15:16:27
 * @LastEditors: wufz
 * @LastEditTime: 2023-01-12 11:56:33
-->
<template>
  <a-layout id="components-layout-demo-custom-trigger" style="height:100%">
    <a-layout-sider v-model="collapsed" :trigger="null" collapsible style="overflow:auto">
      <div class="logo">
        {{ collapsed?version:'dxx-ui@'+version }}
      </div>
      <menu-model></menu-model>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0">
        <a-icon class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="() => (collapsed = !collapsed)" />
        <div style="float: right;padding-right: 20px">
          <a-auto-complete v-model="value" style="width: 200px" placeholder="搜索文档" @select="onSelect" @search="onSearch">
            <template slot="dataSource">
              <a-select-option v-for="item in dataSource" :key="'/'+item.fold+'/'+item.comName">
                {{ item.comName+' '+item.name }}
              </a-select-option>
            </template>
          </a-auto-complete>
        </div>
      </a-layout-header>
      <a-layout-content :style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: 'unset' }">
        <router-view></router-view>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>

<script>
import { navList } from "./navList.json"
import config from "../package.json";
import MenuModel from './components/menu'
export default {
  components: {

    MenuModel
  },
  data() {
    return {
      version: config.version,
      collapsed: false,
      value: '',
      navList: JSON.parse(JSON.stringify(navList)),
      dataSource: []
    };
  },
  methods: {
    onSearch(searchText) {
      if (!searchText) {
        this.dataSource = []
      } else {
        let allList = []
        this.navList.forEach((item) => {
          item.list.forEach((listItem) => {
            listItem.fold = item.fold
          })
          let list = item.list.filter((listItem) => {
            return listItem.name.indexOf(searchText) > -1 || listItem.comName.indexOf(searchText) > -1
          })
          allList = [...allList, ...list]
        })
        this.dataSource = allList
      }
    },
    onSelect(value) {
      this.$router.push({
        path: value
      })
      this.dataSource = []
      this.value = ''
    }
  }
};
</script>

<style>
#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px;
  color: #fff;
  text-align: center;
  line-height: 32px;
}
</style>