top-left.bak.vue 4.8 KB

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