top-left.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div class="main-framework--top-left">
  3. <aside class="main-framework--top-left__aside main-framework__aside" :class="{'is-collapse':collapse}">
  4. <div class="main-framework--top-left__name main-framework__name" :class="{'is-collapse':collapse}">
  5. <slot name="name" :is-collapse="collapse"></slot>
  6. </div>
  7. <div class="main-framework--top-left__aside__nav">
  8. <el-scrollbar>
  9. <slot name="nav" :is-collapse="collapse"></slot>
  10. </el-scrollbar>
  11. </div>
  12. <div class="main-framework--top-left__aside__switch main-framework__aside__switch">
  13. <i @click="toggleCollapse" :class="collapse ? 'el-icon-s-unfold': 'el-icon-s-fold'" class="fold-icon"/>
  14. </div>
  15. </aside>
  16. <div class="main-framework--top-left__content">
  17. <header class="main-framework--top-left__header main-framework__header">
  18. <div> <slot name="headerNav"></slot></div>
  19. <slot name="header"></slot>
  20. </header>
  21. <div style="display: flex; flex-direction: column;flex-grow:2;height:0;">
  22. <div class="main-framework--top-left__tabs" v-show="withTabs === true">
  23. <slot name="tabs"></slot>
  24. </div>
  25. <main class="main-framework--top-left__main main-framework__main">
  26. <slot></slot>
  27. </main>
  28. </div>
  29. <footer class="main-framework--top-left__footer main-framework__footer" v-if="!hideFooter">
  30. <slot name="footer"></slot>
  31. </footer>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import { ref, defineComponent, onMounted, onBeforeUnmount, computed } from 'vue'
  37. import { ElScrollbar } from 'element-plus'
  38. import { isEmpty } from '@cip/utils/util'
  39. export default defineComponent({
  40. name: 'MainFrameworkLeft',
  41. components: { ElScrollbar },
  42. props: {
  43. hideFooter: Boolean,
  44. layout: String,
  45. withTabs: Boolean
  46. },
  47. setup () {
  48. const localCollapse = localStorage.getItem('isCollapse')
  49. const isCollapse = ref(localCollapse ? JSON.parse(localCollapse) : undefined)
  50. const toggleCollapse = () => {
  51. isCollapse.value = !collapse.value
  52. localStorage.setItem('isCollapse', isCollapse.value)
  53. window.removeEventListener('resize', autoAdaptation)
  54. }
  55. const autoCollapse = ref(false)
  56. const collapse = computed(() => {
  57. return isCollapse.value ?? autoCollapse.value
  58. })
  59. const autoAdaptation = () => {
  60. if (window.innerWidth <= 1400) {
  61. autoCollapse.value = true
  62. } else {
  63. autoCollapse.value = false
  64. }
  65. }
  66. onMounted(() => {
  67. if (isEmpty(isCollapse.value)) {
  68. autoAdaptation()
  69. window.addEventListener('resize', autoAdaptation)
  70. }
  71. })
  72. onBeforeUnmount(() => {
  73. window.removeEventListener('resize', autoAdaptation)
  74. })
  75. return {
  76. collapse,
  77. toggleCollapse
  78. }
  79. }
  80. })
  81. </script>
  82. <style lang="less">
  83. @headerHeight: 60px;
  84. @footerHeight: 52px;
  85. @sideWidth: 240px;
  86. .main-framework--top-left{
  87. width: 100%;
  88. height: 100%;
  89. display: flex;
  90. &__aside{
  91. width: @sideWidth;
  92. flex-shrink: 0;
  93. height: 100%;
  94. transition: width 0.2s;
  95. &.is-collapse{
  96. width: 64px; // el-menu collapse的宽度
  97. }
  98. &__nav{
  99. height: calc(100% - @headerHeight - @footerHeight);
  100. }
  101. &__switch{
  102. height: @footerHeight;
  103. display: flex;
  104. align-items: center;
  105. justify-content: center;
  106. }
  107. .fold-icon{
  108. //color: #fff;
  109. font-size: 24px;
  110. cursor: pointer;
  111. }
  112. }
  113. &__name{
  114. width: 100%;
  115. height: @headerHeight;
  116. display: flex;
  117. align-items: center;
  118. justify-content: flex-start;
  119. padding: 0 20px;
  120. box-sizing: border-box;
  121. flex-wrap: nowrap;
  122. white-space: nowrap;
  123. position: relative;
  124. z-index:1;
  125. &.is-collapse{
  126. padding: 0 8px;
  127. justify-content: center;
  128. overflow: hidden;
  129. width: 64px; // el-menu collapse的宽度
  130. }
  131. }
  132. &__header{
  133. height: @headerHeight;
  134. display: flex;
  135. align-items: center;
  136. justify-content: space-between;
  137. flex-shrink: 0;
  138. position: relative;
  139. z-index: 200;
  140. }
  141. &__main{
  142. width: 100%;
  143. height: 0;
  144. flex-grow: 2;
  145. box-sizing: border-box;
  146. //padding-top: 22px;
  147. overflow: auto;
  148. }
  149. &__tabs{
  150. flex-shrink: 0;
  151. padding: 0 20px;
  152. //height: 52px;
  153. box-sizing: border-box;
  154. }
  155. //&__breadcrumb{
  156. // position: absolute;
  157. // top: @headerHeight;
  158. // left: 0;
  159. // right:0;
  160. // background: #fff;
  161. // z-index: 9;
  162. //}
  163. &__footer{
  164. height: @footerHeight;
  165. }
  166. &__content{
  167. position: relative;
  168. flex-grow: 2;
  169. width: 0;
  170. height: 100%;
  171. display: flex;
  172. flex-direction: column;
  173. }
  174. }
  175. </style>