AdminHeader.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <a-layout-header :class="[headerTheme, 'admin-header']">
  3. <div :class="['admin-header-wide', layout, pageWidth]">
  4. <router-link
  5. v-if="isMobile || layout === 'head'"
  6. to="/"
  7. :class="['logo', isMobile ? null : 'pc', headerTheme]"
  8. >
  9. <img width="32" src="@/assets/img/title.png" />
  10. <h1 v-if="!isMobile">{{ systemName }}</h1>
  11. </router-link>
  12. <a-divider v-if="isMobile" type="vertical" />
  13. <div class="breadcrumb">
  14. <a-breadcrumb>
  15. <a-breadcrumb-item :key="index" v-for="(item, index) in breadcrumb">
  16. <!-- {{ item.path }} -->
  17. <router-link
  18. v-if="item.path == '/channel'"
  19. :to="'/personnelManage' + item.path"
  20. >{{ item.name }}</router-link
  21. >
  22. <router-link v-else :to="item.path">{{ item.name }}</router-link>
  23. </a-breadcrumb-item>
  24. </a-breadcrumb>
  25. </div>
  26. <!-- <a-icon v-if="layout !== 'head'" class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="toggleCollapse"/> -->
  27. <!-- <div v-if="layout !== 'side' && !isMobile" class="admin-header-menu" :style="`width: ${menuWidth};`">
  28. <i-menu class="head-menu" :theme="headerTheme" mode="horizontal" :options="menuData" @select="onSelect"/>
  29. </div> -->
  30. <div :class="['admin-header-right', headerTheme]">
  31. <!-- <header-search class="header-item" @active="val => searchActive = val" /> -->
  32. <!-- <a-tooltip class="header-item" title="帮助文档" placement="bottom" >
  33. <a href="https://iczer.gitee.io/vue-antd-admin-docs/" target="_blank">
  34. <a-icon type="question-circle-o" />
  35. </a>
  36. </a-tooltip> -->
  37. <!-- <ExpandOutlined /> -->
  38. <!-- <a-icon :class="['header-notice-icon']" type="scan" /> -->
  39. <HeaderExpand class="header-item"></HeaderExpand>
  40. <!-- <header-notice class="header-item" /> -->
  41. <header-avatar class="header-item" />
  42. <!-- <a-dropdown class="lang header-item">
  43. <div><a-icon type="global" /> {{ langAlias }}</div>
  44. <a-menu
  45. @click="(val) => setLang(val.key)"
  46. :selected-keys="[lang]"
  47. slot="overlay"
  48. >
  49. <a-menu-item v-for="lang in langList" :key="lang.key">{{
  50. lang.key.toLowerCase() + " " + lang.name
  51. }}</a-menu-item>
  52. </a-menu>
  53. </a-dropdown> -->
  54. </div>
  55. </div>
  56. </a-layout-header>
  57. </template>
  58. <script>
  59. // import HeaderSearch from './HeaderSearch'
  60. // import HeaderNotice from "./HeaderNotice";
  61. import HeaderAvatar from "./HeaderAvatar";
  62. import HeaderExpand from "./HeaderExpand";
  63. // import IMenu from '@/components/menu/menu'
  64. import { mapState, mapMutations } from "vuex";
  65. // import { getI18nKey } from "@/utils/routerUtil";
  66. export default {
  67. name: "AdminHeader",
  68. components: { HeaderAvatar, HeaderExpand },
  69. props: ["collapsed", "menuData"],
  70. data() {
  71. return {
  72. langList: [
  73. { key: "CN", name: "简体中文", alias: "简体" },
  74. { key: "HK", name: "繁體中文", alias: "繁體" },
  75. { key: "US", name: "English", alias: "English" },
  76. ],
  77. searchActive: false,
  78. page: {},
  79. };
  80. },
  81. created() {
  82. this.page = this.$route.meta.page;
  83. },
  84. computed: {
  85. ...mapState("setting", [
  86. "theme",
  87. "isMobile",
  88. "layout",
  89. "systemName",
  90. "lang",
  91. "pageWidth",
  92. ]),
  93. headerTheme() {
  94. if (
  95. this.layout == "side" &&
  96. this.theme.mode == "dark" &&
  97. !this.isMobile
  98. ) {
  99. return "light";
  100. }
  101. return this.theme.mode;
  102. },
  103. langAlias() {
  104. let lang = this.langList.find((item) => item.key == this.lang);
  105. return lang.alias;
  106. },
  107. menuWidth() {
  108. const { layout, searchActive } = this;
  109. const headWidth = layout === "head" ? "100% - 188px" : "100%";
  110. const extraWidth = searchActive ? "600px" : "400px";
  111. return `calc(${headWidth} - ${extraWidth})`;
  112. },
  113. breadcrumb() {
  114. let page = this.page;
  115. let breadcrumb = page && page.matched;
  116. if (breadcrumb) {
  117. let i18nBreadcrumb = [];
  118. breadcrumb.forEach((item) => {
  119. i18nBreadcrumb.push(item.name);
  120. });
  121. return i18nBreadcrumb;
  122. } else {
  123. return this.getRouteBreadcrumb();
  124. }
  125. },
  126. },
  127. methods: {
  128. toggleCollapse() {
  129. this.$emit("toggleCollapse");
  130. },
  131. onSelect(obj) {
  132. this.$emit("menuSelect", obj);
  133. },
  134. ...mapMutations("setting", ["setLang", "correctPageMinHeight"]),
  135. // ...mapMutations('setting', ['correctPageMinHeight']),
  136. getRouteBreadcrumb() {
  137. let routes = this.$route.matched;
  138. const path = this.$route.path;
  139. let breadcrumb = [];
  140. routes
  141. .filter((item) => path.includes(item.path))
  142. .forEach((route) => {
  143. const path = route.path;
  144. breadcrumb.push({ path: path, name: route.name });
  145. });
  146. let pageTitle = this.page && this.page.title;
  147. if (this.customTitle || pageTitle) {
  148. breadcrumb[breadcrumb.length - 1] = this.customTitle || pageTitle;
  149. }
  150. // console.log(breadcrumb)
  151. return breadcrumb;
  152. },
  153. },
  154. };
  155. </script>
  156. <style lang="less" scoped>
  157. @import "index";
  158. </style>