left.vue 4.7 KB

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