menuInfo.vue 3.0 KB

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