Sidebar.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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">
  19. <span>{{ item.title }}</span>
  20. <span class="num" v-bind:style="{ color: getColor(item.num) }" v-if="item.num"
  21. >[<span>{{ getNum(item.num) }}</span
  22. >]</span
  23. >
  24. </span>
  25. </template>
  26. <template v-for="subItem in item.subs">
  27. <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
  28. <template slot="title">{{ subItem.title }}</template>
  29. <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">{{ threeItem.title }}</el-menu-item>
  30. </el-submenu>
  31. <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}</el-menu-item>
  32. </template>
  33. </el-submenu>
  34. </template>
  35. <template v-else>
  36. <el-menu-item class="first" :index="item.index" :key="item.index">
  37. <i :class="item.icon"></i>
  38. <span slot="title">
  39. <span>{{ item.title }}</span>
  40. <span class="num" v-bind:style="{ color: getColor(item.num) }" v-if="item.num"
  41. >[<span>{{ getNum(item.num) }}</span
  42. >]</span
  43. >
  44. </span>
  45. </el-menu-item>
  46. </template>
  47. </template>
  48. </el-menu>
  49. </div>
  50. </template>
  51. <script>
  52. import _ from 'lodash';
  53. import { mapState, createNamespacedHelpers } from 'vuex';
  54. const { mapActions: menu } = createNamespacedHelpers('menu');
  55. const { mapActions: achieveApply } = createNamespacedHelpers('achieveApply');
  56. import bus from '../common/bus';
  57. export default {
  58. data() {
  59. return {
  60. collapse: false,
  61. items: [
  62. {
  63. icon: 'el-icon-s-home',
  64. index: 'homeIndex',
  65. title: '系统首页',
  66. },
  67. ],
  68. num: {},
  69. };
  70. },
  71. computed: {
  72. ...mapState(['user']),
  73. onRoutes() {
  74. return this.$route.path;
  75. },
  76. },
  77. created() {
  78. // 通过 Event Bus 进行组件间通信,来折叠侧边栏
  79. bus.$on('collapse', msg => {
  80. this.collapse = msg;
  81. bus.$emit('collapse-content', msg);
  82. });
  83. },
  84. methods: {
  85. ...menu(['query']),
  86. ...achieveApply(['queryNum']),
  87. // 分配用户彩带权限
  88. async getMenu() {
  89. // 客户信息
  90. let user = this.user;
  91. let list = _.cloneDeep(this.items);
  92. if (user.role == '1') {
  93. let data = [
  94. { icon: 'el-icon-eleme', index: '/adminApplyExpert', title: '专家管理' },
  95. { icon: 'el-icon-eleme', index: '/adminExamine', title: '形式审查' },
  96. { icon: 'el-icon-thumb', index: '/adminScore', title: '专家初评' },
  97. { icon: 'el-icon-orange', index: '/adminMeet', title: '专家会审' },
  98. { icon: 'el-icon-edit-outline', index: '/adminPerfect', title: '资料完善' },
  99. { icon: 'el-icon-postcard', index: '/adminCate', title: '证书发放' },
  100. { icon: 'el-icon-postcard', index: '/adminHaveCert', title: '已证书发放' },
  101. ];
  102. list.push(...data);
  103. this.$set(this, `items`, _.uniqBy(list, 'index'));
  104. } else if (user.role == '2') {
  105. let data = [
  106. { icon: 'el-icon-eleme', index: '/adminApplyExpert', title: '专家管理' },
  107. { icon: 'el-icon-eleme', index: '/adminExamine', title: '形式审查' },
  108. { icon: 'el-icon-thumb', index: '/adminScore', title: '专家初评' },
  109. { icon: 'el-icon-orange', index: '/adminMeet', title: '专家会审' },
  110. { icon: 'el-icon-edit-outline', index: '/adminPerfect', title: '资料完善' },
  111. { icon: 'el-icon-postcard', index: '/adminCate', title: '证书发放' },
  112. { icon: 'el-icon-postcard', index: '/adminHaveCert', title: '已证书发放' },
  113. ];
  114. list.push(...data);
  115. this.$set(this, `items`, _.uniqBy(list, 'index'));
  116. } else if (user.role === '3') {
  117. let data = [{ icon: 'el-icon-thumb', index: '/expertCenter', title: '专家审核' }];
  118. list.push(...data);
  119. this.$set(this, `items`, _.uniqBy(list, 'index'));
  120. } else {
  121. let data = [
  122. {
  123. num: 'cs',
  124. icon: 'el-icon-eleme',
  125. index: '2',
  126. title: '我的申报',
  127. subs: [
  128. {
  129. icon: 'el-icon-eleme',
  130. index: '/nowDeclare',
  131. title: '申报中',
  132. },
  133. {
  134. icon: 'el-icon-eleme',
  135. index: '/pastDeclare',
  136. title: '已往申报',
  137. },
  138. ],
  139. },
  140. { num: 'pf', icon: 'el-icon-postcard', index: '/userExpertScore', title: '专家评分' },
  141. { num: 'hs', icon: 'el-icon-postcard', index: '/userExpertMeet', title: '专家会审' },
  142. { num: 'zs', icon: 'el-icon-medal', index: '/userCert', title: '证书管理' },
  143. ];
  144. list.push(...data);
  145. this.$set(this, `items`, _.uniqBy(list, 'index'));
  146. }
  147. },
  148. // 查询成果数
  149. async searchNum() {
  150. let role = this.user.role;
  151. if (role == undefined) {
  152. let res = await this.queryNum(this.user.id);
  153. if (this.$checkRes(res)) {
  154. this.$set(this, `num`, res.data);
  155. }
  156. }
  157. },
  158. // 分菜单成果数
  159. getNum(data) {
  160. if (data == 'cs') return this.num.cs;
  161. else if (data == 'pf') return this.num.pf;
  162. else if (data == 'hs') return this.num.hs;
  163. else if (data == 'zs') return this.num.zs;
  164. },
  165. // 显示颜色
  166. getColor(data) {
  167. if (data == 'cs' && this.num.cs > 0) return '#ff0000';
  168. else if (data == 'pf' && this.num.pf > 0) return '#ff0000';
  169. else if (data == 'hs' && this.num.hs > 0) return '#ff0000';
  170. else if (data == 'zs' && this.num.zs > 0) return '#ff0000';
  171. },
  172. },
  173. watch: {
  174. user: {
  175. deep: true,
  176. immediate: true,
  177. handler(val) {
  178. this.getMenu();
  179. this.searchNum();
  180. },
  181. },
  182. },
  183. };
  184. </script>
  185. <style lang="less" scoped>
  186. .sidebar {
  187. display: block;
  188. position: absolute;
  189. left: 0;
  190. top: 60px;
  191. bottom: 0;
  192. overflow-y: scroll;
  193. }
  194. .sidebar::-webkit-scrollbar {
  195. width: 0;
  196. }
  197. .sidebar-el-menu:not(.el-menu--collapse) {
  198. width: 200px;
  199. }
  200. .sidebar > ul {
  201. height: 100%;
  202. }
  203. .num {
  204. font-size: 16px;
  205. padding: 0 10px;
  206. span {
  207. padding: 0 5px;
  208. }
  209. }
  210. </style>