left-2.vue 5.8 KB

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