index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="app-container" :style="appContainerStyle">
  3. <template v-if="$store.state.auth.canRenderDefaultLayout">
  4. <navbar />
  5. <div class="app-content position-relative h-100">
  6. <sidebar-drawer v-if="isShowMenu" :active-menu="l2Menu" />
  7. <l2-menu :l2-menu="l2Menu" v-if="l2MenuVisible && isShowMenu" />
  8. <div
  9. id="app-page"
  10. class="app-page"
  11. :class="{ 'l2-menu-show': l2MenuVisible && l2MenuVisibleForStore }">
  12. <div :style="appPageWrapperStyle">
  13. <top-alert />
  14. <div class="app-page-content">
  15. <slot />
  16. </div>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <template v-else>
  22. <div class="h-100 d-flex align-items-center justify-content-center">
  23. <a-spin />
  24. </div>
  25. </template>
  26. </div>
  27. </template>
  28. <script>
  29. import { mapGetters, mapState } from 'vuex'
  30. import Navbar from '@scope/layouts/Navbar'
  31. import TopAlert from '@/sections/TopAlert'
  32. import { menusConfig } from '@/router/routes'
  33. import L2Menu from '../Sidebar/Menu'
  34. import SidebarDrawer from '../Sidebar/Drawer'
  35. export default {
  36. name: 'DefaultLayout',
  37. components: {
  38. SidebarDrawer,
  39. Navbar,
  40. TopAlert,
  41. 'l2-menu': L2Menu,
  42. },
  43. data () {
  44. return {
  45. l2MenuVisible: false,
  46. l2Menu: {},
  47. menuitems: menusConfig,
  48. }
  49. },
  50. computed: {
  51. ...mapGetters(['userInfo']),
  52. ...mapState('common', {
  53. openCloudShell: state => state.openCloudShell,
  54. cloudShellHeight: state => state.cloudShellHeight,
  55. }),
  56. isShowMenu () {
  57. const { globalSetting } = this.$store.state
  58. if (!globalSetting || (globalSetting && !globalSetting.value) || (globalSetting.value && !globalSetting.value.key)) {
  59. return true
  60. }
  61. return globalSetting.value.key.length > 0
  62. },
  63. l2MenuVisibleForStore () {
  64. return this.$store.state.setting.l2MenuVisible
  65. },
  66. appPageWrapperStyle () {
  67. const style = {
  68. flex: '1 1 100%',
  69. height: '100%',
  70. display: 'flex',
  71. flexDirection: 'column',
  72. }
  73. return style
  74. },
  75. appContainerStyle () {
  76. if (this.openCloudShell) {
  77. return {
  78. maxHeight: `calc(100% - ${this.cloudShellHeight}px)`,
  79. flex: '1 1 auto',
  80. }
  81. }
  82. return {}
  83. },
  84. },
  85. watch: {
  86. $route: {
  87. handler (val, oldVal) {
  88. const newParentPath = val.matched[0] && val.matched[0].path
  89. const oldParentPath = oldVal && oldVal.matched && oldVal.matched[0] && oldVal.matched[0].path
  90. if (newParentPath !== oldParentPath) {
  91. const firstMatched = val.matched[0]
  92. for (let i = 0, len = this.menuitems.length; i < len; i++) {
  93. const item = this.menuitems[i]
  94. if (item.meta.group === firstMatched.meta.group) {
  95. this.l2Menu = item
  96. let l2MenuVisible = false
  97. if (item.menus) {
  98. l2MenuVisible = true
  99. }
  100. this.l2MenuVisible = l2MenuVisible
  101. break
  102. } else {
  103. this.l2Menu = {}
  104. this.l2MenuVisible = false
  105. }
  106. }
  107. }
  108. },
  109. immediate: true,
  110. },
  111. },
  112. }
  113. </script>
  114. <style lang="less" scoped>
  115. .app-content {
  116. padding-top: 60px;
  117. display: flex;
  118. flex-direction: column;
  119. }
  120. .app-page {
  121. // margin-bottom: 74px;
  122. padding: 15px 15px 0 15px;
  123. &.l2-menu-show {
  124. margin-left: 160px !important;
  125. }
  126. overflow: auto;
  127. }
  128. .app-page-content {
  129. flex: 1;
  130. overflow-y: auto;
  131. min-height: 0;
  132. // height: 100%;
  133. }
  134. </style>