header.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <nav class="client-head">
  3. <div class="client-container head-layout">
  4. <div class="head-left">
  5. <a></a>
  6. <el-menu
  7. :default-active="activeIndex"
  8. class="el-menu-demo"
  9. mode="horizontal"
  10. :router="true"
  11. >
  12. <template v-for="(item,index) in headerArr">
  13. <el-submenu :index="`${item.keyPath}`" v-if="item.children && item.children.length > 0"
  14. popper-class="mta-menu-two">
  15. <template slot="title">{{item.content}}</template>
  16. <el-menu-item :index="`${child.keyPath}`" v-for="child of item.children"
  17. :key="child.keyPath">{{child.content}}
  18. </el-menu-item>
  19. </el-submenu>
  20. <el-menu-item :index="`${item.keyPath}`" v-else>
  21. {{item.content}}
  22. </el-menu-item>
  23. </template>
  24. </el-menu>
  25. </div>
  26. <div class="head-right">
  27. <i></i><span>4000-522-130</span>
  28. </div>
  29. </div>
  30. </nav>
  31. </template>
  32. <script>
  33. import MtaUploadAlCloud
  34. from '@/components/management/Layout/UploadAlCloud/UploadAlCloud';
  35. import axios from 'axios';
  36. import { mapGetters } from 'vuex';
  37. import { setAuth, removeAuth } from '@/utils/auth';
  38. import { setUserIcon, checkUrlIsNotHttpUrl, getTrimData } from '@/utils/common';
  39. export default {
  40. name: 'mtaHeader',
  41. props: {
  42. activeNav: { // 默认选中的 路径 与组件中的index相互对应
  43. type: String,
  44. require: true,
  45. default: '0',
  46. },
  47. },
  48. components: {},
  49. data() {
  50. return {
  51. activeIndex: this.activeNav,
  52. headerArr: [
  53. {
  54. content: '首页',
  55. keyPath: '/c/index',
  56. },
  57. {
  58. content: '考试平台',
  59. keyPath: '/c/examPlatform',
  60. children: [],
  61. },
  62. {
  63. content: '培训平台',
  64. keyPath: '/c/peixunPlatform',
  65. children: [],
  66. },
  67. {
  68. content: '课程开发',
  69. keyPath: '/c/courseDev',
  70. children: [],
  71. },
  72. {
  73. content: '新闻资讯',
  74. keyPath: '/c/newsInfor',
  75. children: [],
  76. },
  77. {
  78. content: '帮助中心',
  79. keyPath: '/c/helpCenter',
  80. children: [],
  81. }, {
  82. content: '关于我们',
  83. keyPath: '/c/aboutUs',
  84. children: [],
  85. },
  86. ],
  87. };
  88. },
  89. watch: {
  90. // 监听
  91. '$route.path': {
  92. handler(newVal, oldVal) {
  93. this.activeIndexSync();
  94. },
  95. immediate: true,
  96. },
  97. },
  98. computed: {
  99. ...mapGetters([
  100. 'getThemeColor',
  101. ]),
  102. },
  103. methods: {
  104. activeIndexSync() {
  105. const path = this.$route.path;
  106. const idx = _.findIndex(this.headerArr, function (o) {
  107. return o.keyPath === path;
  108. });
  109. if (idx > -1) {
  110. this.activeIndex = this.headerArr[idx].keyPath;
  111. } else {
  112. for (const header of this.headerArr) {
  113. if (header.children) {
  114. const idx2 = _.findIndex(header.children, function (o) {
  115. return o.keyPath === path;
  116. });
  117. if (idx2 > -1) {
  118. this.activeIndex = header.keyPath;
  119. return;
  120. }
  121. }
  122. }
  123. }
  124. },
  125. }
  126. ,
  127. created() {
  128. },
  129. };
  130. </script>