menuInfo.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div id="menuInfo">
  3. <el-row>
  4. <el-col :span="24">
  5. <el-col :span="24" class="top">
  6. <el-image :src="topUrl"></el-image>
  7. <span>个人中心</span>
  8. </el-col>
  9. <el-col :span="24">
  10. <el-menu :default-active="active" @select="setRight" text-color="#999" active-text-color="#044b79">
  11. <template v-for="(i, index) in menuList">
  12. <el-menu-item :key="index" :index="`${index}`" v-if="i.cpt">
  13. <template slot="title">
  14. <!-- <i class="el-icon-pie-chart"></i> -->
  15. <span>{{ i.name }}</span>
  16. </template>
  17. </el-menu-item>
  18. </template>
  19. </el-menu>
  20. </el-col>
  21. </el-col>
  22. </el-row>
  23. </div>
  24. </template>
  25. <script>
  26. import _ from 'lodash';
  27. import { mapState, createNamespacedHelpers } from 'vuex';
  28. const { mapActions } = createNamespacedHelpers('role');
  29. export default {
  30. name: 'menuInfo',
  31. props: {},
  32. components: {},
  33. data: function() {
  34. return {
  35. topUrl: require('@/assets/live/square_big.png'),
  36. active: '0',
  37. haveMsg: false,
  38. menuList: [],
  39. };
  40. },
  41. created() {
  42. //TODO 子管理员需要查询对应的权限表
  43. this.search();
  44. },
  45. methods: {
  46. ...mapActions(['query', 'create', 'update', 'delete']),
  47. async search() {
  48. let data;
  49. if (this.user.role == '0' && !_.get(this.user, 'pid')) {
  50. const res = await this.query();
  51. if (this.$checkRes(res)) {
  52. data = res.data.reverse();
  53. data = this.dataChange(data);
  54. }
  55. } else {
  56. let menus = _.get(this.user, 'menus');
  57. data = this.dataChange(JSON.parse(menus));
  58. }
  59. this.$set(this, `menuList`, data);
  60. this.setRight(this.active);
  61. },
  62. dataChange(data) {
  63. data = data.map(i => {
  64. let { role_name: name, url: cpt } = i;
  65. return { name, cpt };
  66. });
  67. return data;
  68. },
  69. // 菜单跳转
  70. setRight(index) {
  71. let r = this.menuList[index];
  72. if (r) this.$emit('setRight', r);
  73. },
  74. },
  75. watch: {
  76. active: {
  77. handler(val) {
  78. this.setRight(val);
  79. },
  80. },
  81. },
  82. computed: {
  83. ...mapState(['user']),
  84. pageTitle() {
  85. return `${this.$route.meta.title}`;
  86. },
  87. },
  88. metaInfo() {
  89. return { title: this.$route.meta.title };
  90. },
  91. };
  92. </script>
  93. <style lang="less" scoped>
  94. .top {
  95. height: 50px;
  96. line-height: 50px;
  97. text-align: center;
  98. border-bottom: 1px solid #2d64b3;
  99. .el-image {
  100. float: left;
  101. padding: 10px 40px;
  102. width: 30px;
  103. height: 30px;
  104. }
  105. span {
  106. font-size: 24px;
  107. color: #92959a;
  108. font-weight: 600;
  109. float: left;
  110. text-align: left;
  111. }
  112. }
  113. /deep/.el-menu-item {
  114. font-weight: bold;
  115. font-size: 20px;
  116. text-align: center;
  117. border-bottom: 1px solid #2d64b3;
  118. margin: 0 20px;
  119. }
  120. </style>