top-left.vue 5.6 KB

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