menus.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div id="menus">
  3. <el-menu :default-active="activeMenu" active-text-color="#850000" :router="true" v-if="!is_router">
  4. <template v-for="(item, index) in list">
  5. <el-menu-item
  6. v-if="item.type === 'column'"
  7. :key="index"
  8. :index="item.path"
  9. :style="`${activeMenu === item.path ? 'border-left:2px solid #850000;color:#850000' : ''}`"
  10. >
  11. <span slot="title">{{ item.title }} </span>
  12. </el-menu-item>
  13. <el-menu-item v-else-if="item.type === 'content'" :index="item.path" :key="index">{{ item.title }}</el-menu-item>
  14. <el-menu-item v-else index="" :key="index" @click="turnTo(item.url)">{{ item.title }}</el-menu-item>
  15. </template>
  16. </el-menu>
  17. <el-menu :default-active="activeMenu" active-text-color="#850000" :router="true" v-else>
  18. <template v-for="(item, index) in list">
  19. <el-menu-item :key="index" :index="item.path" :style="`${activeMenu === item.path ? 'border-left:2px solid #850000;color:#850000' : ''}`">
  20. <span slot="title">{{ item.title }} </span>
  21. </el-menu-item>
  22. </template>
  23. </el-menu>
  24. </div>
  25. </template>
  26. <script>
  27. import { jobMenu, masterMenu } from '@/config/jobs-menu';
  28. import _ from 'lodash';
  29. export default {
  30. name: 'menus',
  31. props: {
  32. menuList: { type: Array, default: () => [] },
  33. },
  34. data: () => ({
  35. activeMenu: '',
  36. jobs: [],
  37. list: [],
  38. title: '',
  39. is_router: false,
  40. }),
  41. created() {
  42. this.initJobs();
  43. this.getMenu();
  44. },
  45. mounted() {
  46. this.getPage();
  47. },
  48. computed: {
  49. parent_id() {
  50. return this.$route.params.parent_id;
  51. },
  52. },
  53. watch: {
  54. $route: {
  55. handler(val) {
  56. this.$set(this, `activeMenu`, val.path);
  57. },
  58. deep: true,
  59. },
  60. parent_id: 'getMenu',
  61. },
  62. methods: {
  63. getMenu() {
  64. let route = this.$route.path;
  65. if (!route.includes('/info/list')) {
  66. //显示固定的招聘菜单
  67. this.$set(this, `list`, this.jobs.children);
  68. this.$set(this, `is_router`, true);
  69. return;
  70. }
  71. //过滤自定义的栏目出来
  72. let menu = sessionStorage.getItem('menu');
  73. if (menu) {
  74. menu = JSON.parse(menu);
  75. let res = menu.filter(fil => {
  76. let is_this = false;
  77. if (fil.children) {
  78. for (const item of fil.children) {
  79. if (item.path === route) {
  80. is_this = true;
  81. break;
  82. }
  83. }
  84. }
  85. return is_this;
  86. });
  87. if (res.length > 0) {
  88. let this_menu = res[0];
  89. if (this_menu.children.length > 0) {
  90. this_menu = this_menu.children;
  91. }
  92. console.log(this_menu);
  93. this.$set(this, `list`, this_menu);
  94. }
  95. }
  96. },
  97. getPage() {
  98. let path = this.$route.path;
  99. this.$set(this, `activeMenu`, path);
  100. return path;
  101. },
  102. turnTo(url) {
  103. window.open(url);
  104. },
  105. initJobs() {
  106. if (this.$site === 'master') this.$set(this, `jobs`, masterMenu);
  107. else this.$set(this, `jobs`, jobMenu);
  108. },
  109. },
  110. metaInfo() {
  111. let path = this.$route.path;
  112. let obj = this.list.find(f => f.path == path);
  113. return { title: obj.title || '就业指导' };
  114. },
  115. };
  116. </script>
  117. <style lang="less" scoped>
  118. .el-menu-item {
  119. line-height: 32px;
  120. height: 32px;
  121. }
  122. </style>