SidebarItem.vue 5.02 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1 2
<template>
  <div v-if="!item.hidden">
3 4 5 6 7 8 9
    <template
      v-if="
        hasOneShowingChild(item.children, item) &&
        (!onlyOneChild.children || onlyOneChild.noShowingChildren) &&
        !item.alwaysShow
      "
    >
耿迪迪's avatar
耿迪迪 committed
10
      <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)">
11 12 13 14 15 16 17
        <el-menu-item
          :index="resolvePath(onlyOneChild.path)"
          :class="{ 'submenu-title-noDropdown': !isNest }"
        >
          <item
            :icon="onlyOneChild.meta.icon || (item.meta && item.meta.icon)"
          /><br />
18
          <!-- <item :title="onlyOneChild.meta.title" /> -->
19
          {{ onlyOneChild.meta.title }}
耿迪迪's avatar
耿迪迪 committed
20 21 22 23
        </el-menu-item>
      </app-link>
    </template>

24 25 26 27 28 29
    <el-submenu
      v-else
      ref="subMenu"
      :index="resolvePath(item.path)"
      popper-append-to-body
    >
耿迪迪's avatar
耿迪迪 committed
30
      <template slot="title">
31 32 33 34 35
        <item
          v-if="item.meta"
          :icon="item.meta && item.meta.icon"
          :title="item.meta.title"
        />
耿迪迪's avatar
耿迪迪 committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49
      </template>
      <sidebar-item
        v-for="child in item.children"
        :key="child.path"
        :is-nest="true"
        :item="child"
        :base-path="resolvePath(child.path)"
        class="nest-menu"
      />
    </el-submenu>
  </div>
</template>

<script>
50 51 52 53 54
import path from "path";
import { isExternal } from "@/utils/validate";
import Item from "./Item";
import AppLink from "./Link";
import FixiOSBug from "./FixiOSBug";
耿迪迪's avatar
耿迪迪 committed
55 56

export default {
57
  name: "SidebarItem",
耿迪迪's avatar
耿迪迪 committed
58 59 60 61 62 63
  components: { Item, AppLink },
  mixins: [FixiOSBug],
  props: {
    // route object
    item: {
      type: Object,
64
      required: true,
耿迪迪's avatar
耿迪迪 committed
65 66 67
    },
    isNest: {
      type: Boolean,
68
      default: false,
耿迪迪's avatar
耿迪迪 committed
69 70 71
    },
    basePath: {
      type: String,
72 73
      default: "",
    },
耿迪迪's avatar
耿迪迪 committed
74 75
  },
  data() {
76 77
    this.onlyOneChild = null;
    return {};
耿迪迪's avatar
耿迪迪 committed
78 79 80 81 82 83
  },
  methods: {
    hasOneShowingChild(children = [], parent) {
      if (!children) {
        children = [];
      }
84
      const showingChildren = children.filter((item) => {
耿迪迪's avatar
耿迪迪 committed
85
        if (item.hidden) {
86
          return false;
耿迪迪's avatar
耿迪迪 committed
87 88
        } else {
          // Temp set(will be used if only has one showing child)
89 90
          this.onlyOneChild = item;
          return true;
耿迪迪's avatar
耿迪迪 committed
91
        }
92
      });
耿迪迪's avatar
耿迪迪 committed
93 94 95

      // When there is only one child router, the child router is displayed by default
      if (showingChildren.length === 1) {
96
        return true;
耿迪迪's avatar
耿迪迪 committed
97 98 99 100
      }

      // Show parent if there are no child router to display
      if (showingChildren.length === 0) {
101 102
        this.onlyOneChild = { ...parent, path: "", noShowingChildren: true };
        return true;
耿迪迪's avatar
耿迪迪 committed
103 104
      }

105
      return false;
耿迪迪's avatar
耿迪迪 committed
106 107 108
    },
    resolvePath(routePath) {
      if (isExternal(routePath)) {
109
        return routePath;
耿迪迪's avatar
耿迪迪 committed
110 111
      }
      if (isExternal(this.basePath)) {
112
        return this.basePath;
耿迪迪's avatar
耿迪迪 committed
113
      }
114 115 116 117
      return path.resolve(this.basePath, routePath);
    },
  },
};
耿迪迪's avatar
耿迪迪 committed
118
</script>
yaqizhang's avatar
yaqizhang committed
119
<style lang="scss">
120 121 122 123
#app .sidebar-container .submenu-title-noDropdown:hover,
#app .sidebar-container .el-submenu__title:hover {
  /* box-shadow: inset 2px 2px 20px #5CD9D4; */
  background: rgba(0, 0, 0, 0);
yaqizhang's avatar
yaqizhang committed
124
}
125 126 127 128 129
#app .sidebar-container .el-menu-item,
#app .sidebar-container .el-submenu__title {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  background: rgba(0, 0, 0, 0);
yaqizhang's avatar
yaqizhang committed
130
}
131 132 133
// 顶部导航的样式
.navbar {
  .el-menu-item:hover {
yaqizhang's avatar
yaqizhang committed
134
    outline: none;
yaqizhang's avatar
yaqizhang committed
135 136 137 138
    background-image: url("../../../assets/logo/item-background.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    /* background: rgba(0, 0, 0, 0); */
139 140 141 142
    color: #31eaea !important;
  }
  .el-menu-item:focus,
  .is-active {
yaqizhang's avatar
yaqizhang committed
143 144 145 146 147
    outline: none;
    background-image: url("../../../assets/logo/item-background.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    /* background: rgba(0, 0, 0, 0); */
148 149 150
    color: #31eaea !important;
  }
  .el-menu--horizontal > .el-submenu .el-submenu__title:hover {
yaqizhang's avatar
yaqizhang committed
151 152 153 154 155
    background-color: rgba(0, 0, 0, 0);
    color: #fff;
    background-image: url("../../../assets/logo/item-background.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
156 157
  }
  .el-menu--horizontal > .el-submenu .el-submenu__title {
yaqizhang's avatar
yaqizhang committed
158 159 160 161 162 163
    height: 50px !important;
    line-height: 50px !important;
    margin-top: 15px;
    font-size: 22px;
    font-weight: 600;
    color: #fff;
164 165 166
  }
  .el-menu--horizontal > .el-submenu:focus .el-submenu__title,
  .el-menu--horizontal > .el-submenu:hover .el-submenu__title {
yaqizhang's avatar
yaqizhang committed
167
    color: #fff;
168 169
  }
  .el-menu--horizontal > .el-submenu.is-active .el-submenu__title {
yaqizhang's avatar
yaqizhang committed
170 171
    border-bottom: 0px solid;
    color: #fff;
172 173
  }
  .el-submenu__title i {
yaqizhang's avatar
yaqizhang committed
174
    color: #fff;
175 176 177 178
  }
  .el-menu--horizontal .el-menu .el-menu-item,
  .el-menu--horizontal .el-menu .el-submenu__title {
    background-color: #053b6a;
yaqizhang's avatar
yaqizhang committed
179 180 181 182 183
    float: none;
    height: 36px;
    line-height: 36px;
    padding: 0;
    color: #fff;
184 185
  }
  .el-menu--popup {
yaqizhang's avatar
yaqizhang committed
186 187 188 189 190 191 192
    z-index: 100;
    min-width: 120px;
    border: none;
    padding: 5px;
    border-radius: 2px;
    -webkit-box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
    box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
193 194
    background-color: #053b6a;
  }
yaqizhang's avatar
yaqizhang committed
195
}
196 197
// 》〉》〉》〉顶部导航的样式

yaqizhang's avatar
yaqizhang committed
198
</style>