Sidebar.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="sidebar">
  3. <el-menu
  4. class="sidebar-el-menu"
  5. :default-active="onRoutes"
  6. :collapse="collapse"
  7. background-color="#324157"
  8. text-color="#bfcbd9"
  9. active-text-color="#20a0ff"
  10. unique-opened
  11. router
  12. >
  13. <template v-for="item in items">
  14. <template v-if="item.subs">
  15. <el-submenu class="second" :index="item.index" :key="item.index">
  16. <template slot="title">
  17. <i :class="item.icon"></i>
  18. <span slot="title">{{ item.title }}</span>
  19. </template>
  20. <template v-for="subItem in item.subs">
  21. <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
  22. <template slot="title">{{ subItem.title }}</template>
  23. <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">{{ threeItem.title }}</el-menu-item>
  24. </el-submenu>
  25. <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}</el-menu-item>
  26. </template>
  27. </el-submenu>
  28. </template>
  29. <template v-else>
  30. <el-menu-item class="first" :index="item.index" :key="item.index">
  31. <i :class="item.icon"></i>
  32. <span slot="title">{{ item.title }}</span>
  33. </el-menu-item>
  34. </template>
  35. </template>
  36. </el-menu>
  37. </div>
  38. </template>
  39. <script>
  40. import _ from 'lodash';
  41. import { mapState, createNamespacedHelpers } from 'vuex';
  42. const { mapActions: menu } = createNamespacedHelpers('menu');
  43. import bus from '../common/bus';
  44. export default {
  45. data() {
  46. return {
  47. collapse: false,
  48. items: [
  49. {
  50. icon: 'el-icon-s-home',
  51. index: 'homeIndex',
  52. title: '系统首页',
  53. },
  54. ],
  55. };
  56. },
  57. computed: {
  58. ...mapState(['user']),
  59. onRoutes() {
  60. return this.$route.path.replace('/', '');
  61. },
  62. },
  63. created() {
  64. // 通过 Event Bus 进行组件间通信,来折叠侧边栏
  65. bus.$on('collapse', msg => {
  66. this.collapse = msg;
  67. bus.$emit('collapse-content', msg);
  68. });
  69. },
  70. methods: {
  71. ...menu(['query']),
  72. // 分配用户彩带权限
  73. async getMenu() {
  74. // 客户信息
  75. let user = this.user;
  76. let list = _.cloneDeep(this.items);
  77. if (user.role == '1') {
  78. let data = [
  79. {
  80. icon: 'el-icon-s-home',
  81. index: '',
  82. title: '管理员测试菜单',
  83. },
  84. ];
  85. list.push(...data);
  86. this.$set(this, `items`, _.uniqBy(list, 'index'));
  87. } else if (user.role == '2') {
  88. let data = [
  89. { icon: 'el-icon-eleme', index: 'adminExamine', title: '初审申请书' },
  90. { icon: 'el-icon-thumb', index: 'adminScore', title: '专家评分' },
  91. { icon: 'el-icon-orange', index: 'adminMeet', title: '专家会审' },
  92. { icon: 'el-icon-edit-outline', index: 'adminPerfect', title: '资料完善' },
  93. { icon: 'el-icon-postcard', index: 'adminCate', title: '证书发放' },
  94. { icon: 'el-icon-postcard', index: 'adminHaveCert', title: '已证书发放' },
  95. ];
  96. list.push(...data);
  97. this.$set(this, `items`, _.uniqBy(list, 'index'));
  98. } else {
  99. let data = [
  100. {
  101. icon: 'el-icon-eleme',
  102. index: '2',
  103. title: '申请书管理',
  104. subs: [
  105. {
  106. icon: 'el-icon-eleme',
  107. index: 'firstApply',
  108. title: '待审中',
  109. },
  110. {
  111. icon: 'el-icon-eleme',
  112. index: 'updateApply',
  113. title: '审核未通过',
  114. },
  115. ],
  116. },
  117. {
  118. icon: 'el-icon-eleme',
  119. index: '3',
  120. title: '专家评分',
  121. subs: [
  122. {
  123. icon: 'el-icon-eleme',
  124. index: 'expertExam',
  125. title: '待评分',
  126. },
  127. {
  128. icon: 'el-icon-eleme',
  129. index: 'expetScoreUpdate',
  130. title: '审核未通过',
  131. },
  132. ],
  133. },
  134. // { icon: 'el-icon-eleme', index: 'userScore', title: '申请书' },
  135. // { icon: 'el-icon-eleme', index: 'userExamine', title: '申请书' },
  136. // { icon: 'el-icon-eleme', index: 'userExamine', title: '申请书' },
  137. ];
  138. list.push(...data);
  139. this.$set(this, `items`, _.uniqBy(list, 'index'));
  140. }
  141. },
  142. },
  143. watch: {
  144. user: {
  145. deep: true,
  146. immediate: true,
  147. handler(val) {
  148. this.getMenu();
  149. },
  150. },
  151. },
  152. };
  153. </script>
  154. <style lang="less" scoped>
  155. .sidebar {
  156. display: block;
  157. position: absolute;
  158. left: 0;
  159. top: 60px;
  160. bottom: 0;
  161. overflow-y: scroll;
  162. }
  163. .sidebar::-webkit-scrollbar {
  164. width: 0;
  165. }
  166. .sidebar-el-menu:not(.el-menu--collapse) {
  167. width: 200px;
  168. }
  169. .sidebar > ul {
  170. height: 100%;
  171. }
  172. // /deep/.first {
  173. // padding-left: 0 !important;
  174. // }
  175. // /deep/.second .el-submenu__title {
  176. // padding-left: 0 !important;
  177. // }
  178. </style>