newmenu.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template lang="html">
  2. <div id="sideMenu">
  3. <div id="menuBox">
  4. <el-col :span="24">
  5. <el-menu :unique-opened="true">
  6. <template v-for="item in menu">
  7. <template v-if="!item.children">
  8. <el-menu-item :index="item.path" @click="selectMenu(item.path)" :key="item.name">
  9. <i v-if="item.icon" :class="item.icon"></i>
  10. <span v-if="item.name" slot="title">{{ item.name }}</span>
  11. </el-menu-item>
  12. </template>
  13. <el-submenu v-else :index="item.name || item.path" :key="item.name">
  14. <template slot="title">
  15. <i v-if="item && item.icon" :class="item.icon"></i>
  16. <span v-if="item && item.name" slot="title">{{ item.name }}</span>
  17. </template>
  18. <template v-for="(child, childIndex) in item.children">
  19. <div :key="childIndex" v-if="!child.hidden">
  20. <el-menu-item :index="item.path || '' + child.path" @click="selectMenu(item.path || '' + child.path)">
  21. <span v-if="child && child.name" slot="title">{{ child.name }}</span>
  22. </el-menu-item>
  23. </div>
  24. </template>
  25. </el-submenu>
  26. </template>
  27. </el-menu>
  28. </el-col>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. import {
  34. index,
  35. menu,
  36. // department,
  37. permission,
  38. adminUser,
  39. business,
  40. vip,
  41. user,
  42. duijiehui,
  43. enterpriseProduct,
  44. enterpriseTrans,
  45. technical,
  46. defaultMenu,
  47. } from '@/util/role_menu.js';
  48. import * as menus from '@/util/role_menu.js';
  49. import { mapState, createNamespacedHelpers } from 'vuex';
  50. const { mapActions } = createNamespacedHelpers('login');
  51. import _ from 'lodash';
  52. export default {
  53. name: 'sideMenu',
  54. components: {},
  55. data() {
  56. return {
  57. menu: [],
  58. };
  59. },
  60. computed: {
  61. ...mapState(['user']),
  62. },
  63. created() {},
  64. methods: {
  65. ...mapActions(['toGetMenu', 'logout']),
  66. async search() {
  67. if (!this.user.uid) return;
  68. if (this.user.role == '0') {
  69. this.menu.push(
  70. index,
  71. menu,
  72. // department,
  73. permission,
  74. adminUser,
  75. business,
  76. vip,
  77. user,
  78. duijiehui,
  79. enterpriseProduct,
  80. enterpriseTrans,
  81. technical,
  82. defaultMenu
  83. );
  84. return;
  85. }
  86. const res = await this.toGetMenu({ id: this.user.uid });
  87. if (this.$checkRes(res)) {
  88. let menu = res.data.menus;
  89. menu = menu.map(i => {
  90. return { name: i.role_name, path: i.url };
  91. });
  92. let duplicate = JSON.parse(JSON.stringify(this.menu));
  93. duplicate.push(...menu);
  94. let nm = _.uniqBy(duplicate, 'path');
  95. this.$set(this, `menu`, nm);
  96. }
  97. },
  98. selectMenu(path) {
  99. this.$router.push({ path: path });
  100. },
  101. },
  102. watch: {
  103. user: {
  104. handler(val, oval) {
  105. if (val && !_.isEqual(val, oval)) this.search();
  106. },
  107. immediate: true,
  108. },
  109. },
  110. };
  111. </script>
  112. <style lang="less" scoped></style>