Sidebar.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. {
  95. icon: 'el-icon-s-home',
  96. index: '',
  97. title: '管理员测试菜单',
  98. },
  99. ];
  100. list.push(...data);
  101. this.$set(this, `items`, _.uniqBy(list, 'index'));
  102. } else if (user.role == '2') {
  103. let data = [
  104. { icon: 'el-icon-eleme', index: '/adminApplyExpert', title: '专家管理' },
  105. { icon: 'el-icon-eleme', index: '/adminExamine', title: '初审申请书' },
  106. { icon: 'el-icon-thumb', index: '/adminScore', title: '专家评分' },
  107. { icon: 'el-icon-orange', index: '/adminMeet', title: '专家会审' },
  108. { icon: 'el-icon-edit-outline', index: '/adminPerfect', title: '资料完善' },
  109. { icon: 'el-icon-postcard', index: '/adminCate', title: '证书发放' },
  110. { icon: 'el-icon-postcard', index: '/adminHaveCert', title: '已证书发放' },
  111. ];
  112. list.push(...data);
  113. this.$set(this, `items`, _.uniqBy(list, 'index'));
  114. } else if (user.role === '3') {
  115. let data = [
  116. // { icon: 'el-icon-thumb', index: '/expertScore', title: '专家评分' },
  117. // { icon: 'el-icon-thumb', index: '/expertMeet', title: '专家会审' },
  118. { icon: 'el-icon-thumb', index: '/expertCenter', title: '专家审核' },
  119. ];
  120. list.push(...data);
  121. this.$set(this, `items`, _.uniqBy(list, 'index'));
  122. } else {
  123. // let data = [
  124. // {
  125. // icon: 'el-icon-eleme',
  126. // index: '2',
  127. // title: '申请书管理',
  128. // subs: [
  129. // {
  130. // icon: 'el-icon-eleme',
  131. // index: '/firstApply',
  132. // title: '待审中',
  133. // },
  134. // {
  135. // icon: 'el-icon-eleme',
  136. // index: '/updateApply',
  137. // title: '审核未通过',
  138. // },
  139. // ],
  140. // },
  141. // {
  142. // icon: 'el-icon-eleme',
  143. // index: '3',
  144. // title: '专家评分',
  145. // subs: [
  146. // {
  147. // icon: 'el-icon-eleme',
  148. // index: '/expertExam',
  149. // title: '待评分',
  150. // },
  151. // {
  152. // icon: 'el-icon-eleme',
  153. // index: '/noExpertScore',
  154. // title: '评分审核未通过',
  155. // },
  156. // ],
  157. // },
  158. // {
  159. // icon: 'el-icon-eleme',
  160. // index: '4',
  161. // title: '专家会审管理',
  162. // subs: [
  163. // {
  164. // icon: 'el-icon-eleme',
  165. // index: '/expertPay',
  166. // title: '待缴费',
  167. // },
  168. // {
  169. // icon: 'el-icon-eleme',
  170. // index: '/expertMeet',
  171. // title: '待会审',
  172. // },
  173. // {
  174. // icon: 'el-icon-eleme',
  175. // index: '/noExpertMeet',
  176. // title: '会审未通过',
  177. // },
  178. // ],
  179. // },
  180. // { icon: 'el-icon-eleme', index: '/perfectData', title: '完善资料' },
  181. // {
  182. // icon: 'el-icon-eleme',
  183. // index: '6',
  184. // title: '证书管理',
  185. // subs: [
  186. // {
  187. // icon: 'el-icon-eleme',
  188. // index: '/readyCert',
  189. // title: '待发证书',
  190. // },
  191. // {
  192. // icon: 'el-icon-eleme',
  193. // index: '/alreadyCert',
  194. // title: '已发证书',
  195. // },
  196. // ],
  197. // },
  198. // ];
  199. let data = [
  200. {
  201. num: 'cs',
  202. icon: 'el-icon-eleme',
  203. index: '2',
  204. title: '我的申报',
  205. subs: [
  206. {
  207. icon: 'el-icon-eleme',
  208. index: '/nowDeclare',
  209. title: '申报中',
  210. },
  211. {
  212. icon: 'el-icon-eleme',
  213. index: '/pastDeclare',
  214. title: '已往申报',
  215. },
  216. ],
  217. },
  218. { num: 'pf', icon: 'el-icon-postcard', index: '/userExpertScore', title: '专家评分' },
  219. { num: 'hs', icon: 'el-icon-postcard', index: '/userExpertMeet', title: '专家会审' },
  220. { num: 'zs', icon: 'el-icon-medal', index: '/userCert', title: '证书管理' },
  221. ];
  222. list.push(...data);
  223. this.$set(this, `items`, _.uniqBy(list, 'index'));
  224. }
  225. },
  226. // 查询成果数
  227. async searchNum() {
  228. let role = this.user.role;
  229. if (role == undefined) {
  230. let res = await this.queryNum(this.user.id);
  231. if (this.$checkRes(res)) {
  232. this.$set(this, `num`, res.data);
  233. }
  234. }
  235. },
  236. // 分菜单成果数
  237. getNum(data) {
  238. if (data == 'cs') return this.num.cs;
  239. else if (data == 'pf') return this.num.pf;
  240. else if (data == 'hs') return this.num.hs;
  241. else if (data == 'zs') return this.num.zs;
  242. },
  243. // 显示颜色
  244. getColor(data) {
  245. if (data == 'cs' && this.num.cs > 0) return '#ff0000';
  246. else if (data == 'pf' && this.num.pf > 0) return '#ff0000';
  247. else if (data == 'hs' && this.num.hs > 0) return '#ff0000';
  248. else if (data == 'zs' && this.num.zs > 0) return '#ff0000';
  249. },
  250. },
  251. watch: {
  252. user: {
  253. deep: true,
  254. immediate: true,
  255. handler(val) {
  256. this.getMenu();
  257. this.searchNum();
  258. },
  259. },
  260. },
  261. };
  262. </script>
  263. <style lang="less" scoped>
  264. .sidebar {
  265. display: block;
  266. position: absolute;
  267. left: 0;
  268. top: 60px;
  269. bottom: 0;
  270. overflow-y: scroll;
  271. }
  272. .sidebar::-webkit-scrollbar {
  273. width: 0;
  274. }
  275. .sidebar-el-menu:not(.el-menu--collapse) {
  276. width: 200px;
  277. }
  278. .sidebar > ul {
  279. height: 100%;
  280. }
  281. .num {
  282. font-size: 16px;
  283. padding: 0 10px;
  284. span {
  285. padding: 0 5px;
  286. }
  287. }
  288. </style>