top-left.vue 5.4 KB

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