田源
2025-01-15 78fa1f005a9ec2581611e53d7eba8efeacb4df6e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
  <div class="top-menu">
    <el-menu :default-active="activeIndex"
             mode="horizontal"
             text-color="#333">
      <el-menu-item key="0" index="0" @click.native="openHome(itemHome)">
        <template slot="title">
          <i :class="itemHome.source"></i>
          <span>{{ generateTitle(itemHome) }}</span>
        </template>
      </el-menu-item>
      <template v-for="(item,index) in items">
        <el-menu-item :key="index" :index="item.id+''" @click.native="openMenu(item)">
          <template slot="title">
            <i :class="item.source" style="padding-right: 5px;"></i>
            <span>{{ generateTitle(item) }}</span>
          </template>
        </el-menu-item>
      </template>
    </el-menu>
  </div>
</template>
 
<script>
import {mapGetters} from "vuex";
 
export default {
  name: "top-menu",
  data() {
    return {
      itemHome: {
        name: '首页',
        source: 'el-icon-menu',
      },
      activeIndex: "0",
      items: [],
    };
  },
  inject: ["index"],
  created() {
    this.getMenu();
  },
  computed: {
    ...mapGetters(["tagCurrent", "menu"])
  },
  methods: {
    openHome(itemHome) {
      this.index.openMenu(itemHome);
      this.$router.push({
        path: this.$router.$avueRouter.getPath({name: itemHome.name, src: ''}, {})
      });
    },
    openMenu(item) {
      this.index.openMenu(item)
    },
    getMenu() {
      /*this.$store.dispatch("GetTopMenu").then(res => {
        this.items = res;
      });*/
    },
    generateTitle(item) {
      return this.$router.$avueRouter.generateTitle(
        item.name,
        (item.meta || {}).i18n
      );
    },
  }
};
</script>