left.vue 5.1 KB

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