Sidebar.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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;
  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 if (user.role === '3') {
  99. let data = [{ icon: 'el-icon-thumb', index: '/expertScore', title: '专家评分' }];
  100. list.push(...data);
  101. this.$set(this, `items`, _.uniqBy(list, 'index'));
  102. } else {
  103. let data = [
  104. {
  105. icon: 'el-icon-eleme',
  106. index: '2',
  107. title: '申请书管理',
  108. subs: [
  109. {
  110. icon: 'el-icon-eleme',
  111. index: '/firstApply',
  112. title: '待审中',
  113. },
  114. {
  115. icon: 'el-icon-eleme',
  116. index: '/updateApply',
  117. title: '审核未通过',
  118. },
  119. ],
  120. },
  121. {
  122. icon: 'el-icon-eleme',
  123. index: '3',
  124. title: '专家评分',
  125. subs: [
  126. {
  127. icon: 'el-icon-eleme',
  128. index: '/expertExam',
  129. title: '待评分',
  130. },
  131. {
  132. icon: 'el-icon-eleme',
  133. index: '/noExpertScore',
  134. title: '评分审核未通过',
  135. },
  136. ],
  137. },
  138. {
  139. icon: 'el-icon-eleme',
  140. index: '4',
  141. title: '专家会审管理',
  142. subs: [
  143. {
  144. icon: 'el-icon-eleme',
  145. index: '/expertPay',
  146. title: '待缴费',
  147. },
  148. {
  149. icon: 'el-icon-eleme',
  150. index: '/expertMeet',
  151. title: '待会审',
  152. },
  153. {
  154. icon: 'el-icon-eleme',
  155. index: '/noExpertMeet',
  156. title: '会审未通过',
  157. },
  158. ],
  159. },
  160. { icon: 'el-icon-eleme', index: '/perfectData', title: '完善资料' },
  161. {
  162. icon: 'el-icon-eleme',
  163. index: '6',
  164. title: '证书管理',
  165. subs: [
  166. {
  167. icon: 'el-icon-eleme',
  168. index: '/readyCert',
  169. title: '待发证书',
  170. },
  171. {
  172. icon: 'el-icon-eleme',
  173. index: '/alreadyCert',
  174. title: '已发证书',
  175. },
  176. ],
  177. },
  178. ];
  179. list.push(...data);
  180. this.$set(this, `items`, _.uniqBy(list, 'index'));
  181. }
  182. },
  183. },
  184. watch: {
  185. user: {
  186. deep: true,
  187. immediate: true,
  188. handler(val) {
  189. this.getMenu();
  190. },
  191. },
  192. },
  193. };
  194. </script>
  195. <style lang="less" scoped>
  196. .sidebar {
  197. display: block;
  198. position: absolute;
  199. left: 0;
  200. top: 60px;
  201. bottom: 0;
  202. overflow-y: scroll;
  203. }
  204. .sidebar::-webkit-scrollbar {
  205. width: 0;
  206. }
  207. .sidebar-el-menu:not(.el-menu--collapse) {
  208. width: 200px;
  209. }
  210. .sidebar > ul {
  211. height: 100%;
  212. }
  213. // /deep/.first {
  214. // padding-left: 0 !important;
  215. // }
  216. // /deep/.second .el-submenu__title {
  217. // padding-left: 0 !important;
  218. // }
  219. </style>