menu.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div class="menu_panel" >
  3. <div v-if="show">
  4. <el-menu v-if="show" :default-active="activeIndex" active-text-color="#3874f6" text-color="#333" class="el-menu-demo shadow" mode="horizontal" @select="handleSelect" ref="menuList" >
  5. <el-submenu v-for="(mod,index) in sys_modules" :key="index" :index="String(index)" >
  6. <template slot="title"><b>{{mod.systemmodulename}}</b></template>
  7. <el-menu-item :index="app.path" v-for="(app) in mod.apps" :key="app.index" @click="setActiveModules(mod,app)">{{app.meta.title}}</el-menu-item>
  8. </el-submenu>
  9. <!-- <el-menu-item v-show="!hasMoreApp(mod)" :index="mod.path" v-for="(mod) in sys_modules" :key="mod.index" @click="setActiveModules(mod,mod.apps[0])"><b>{{mod.systemmodulename}}</b></el-menu-item> -->
  10. </el-menu>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. import {mapGetters} from 'vuex'
  16. export default {
  17. data () {
  18. return {
  19. activeIndex:'2',
  20. modules:[],
  21. show:true
  22. }
  23. },
  24. computed:{
  25. ...mapGetters({
  26. activeApp:'activeApp',
  27. sys_modules:'sys_modules'
  28. })
  29. },
  30. methods:{
  31. hasMoreApp (mod) {
  32. if (mod.apps.length > 1) {
  33. return true
  34. } else {
  35. mod.path = mod.apps[0].path
  36. return false
  37. }
  38. },
  39. setActiveModules (mod,app) {
  40. const link = ()=>{
  41. this.$router.push({path:app.path})
  42. }
  43. this.$store.dispatch('setActiveApp',{name:app.systemappname,app:app,val:'',link})
  44. sessionStorage.setItem('active_modules',JSON.stringify(mod))
  45. },
  46. setDefaultData (mod) {
  47. let active_modules = JSON.parse(sessionStorage.getItem('active_modules'))
  48. let sys_modules = JSON.parse(sessionStorage.getItem('module_info'))
  49. let arr = sys_modules.filter(e=>{
  50. if (e.systemid === active_modules.systemid) {
  51. return e
  52. }
  53. })
  54. this.$store.dispatch('getModules',{mod:arr[0].modules})
  55. },
  56. handleSelect(key, keyPath) {
  57. this.activeIndex = key
  58. }
  59. },
  60. mounted () {
  61. this.setDefaultData()
  62. },
  63. watch:{
  64. activeApp (val) {
  65. this.show = false
  66. setTimeout(() => {
  67. this.show = true
  68. this.activeIndex = val.path
  69. }, 0);
  70. }
  71. }
  72. }
  73. </script>
  74. <style>
  75. .el-menu--popup{
  76. padding: 0 10px;
  77. min-width: 50px;
  78. }
  79. </style>
  80. <style scoped>
  81. .shadow{
  82. box-shadow: 0 2px 5px rgb(0 0 0 / 10%);
  83. transform: translate3d(0,-2px,0);
  84. border-radius: 10px;
  85. border:none;
  86. overflow: hidden;
  87. }
  88. .menu_panel{
  89. padding: 0;
  90. height:58px;
  91. width: 100%;
  92. background: #fff;
  93. border-radius: 10px;
  94. }
  95. </style>