BasicLayout.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <a-layout :class="['layout', device]">
  3. <!-- layout header -->
  4. <global-header
  5. :mode="layoutMode"
  6. :menus="menus"
  7. :theme="navTheme"
  8. :collapsed="collapsed"
  9. :device="device"
  10. @toggle="toggle"
  11. />
  12. <!-- layout axis -->
  13. <a-layout :class="[layoutMode, `content-width-${contentWidth}`]">
  14. <div class="container" :style="{ paddingLeft: contentPaddingLeft}">
  15. <!-- layout sidemenu -->
  16. <side-menu
  17. v-if="isSideMenu()"
  18. mode="inline"
  19. :menus="menus"
  20. :theme="navTheme"
  21. :collapsed="collapsed"
  22. :collapsible="true"
  23. ></side-menu>
  24. <!-- layout content -->
  25. <a-layout-content :style="{ height: '100%' }">
  26. <transition name="page-transition">
  27. <route-view />
  28. </transition>
  29. </a-layout-content>
  30. <!-- 主题修改器 -->
  31. <!-- Setting Drawer (show in development mode) -->
  32. <!-- <setting-drawer v-if="!production && false"></setting-drawer> -->
  33. </div>
  34. </a-layout>
  35. <!-- layout footer -->
  36. <a-layout-footer>
  37. <global-footer />
  38. </a-layout-footer>
  39. </a-layout>
  40. </template>
  41. <script>
  42. import { triggerWindowResizeEvent } from '@/utils/util'
  43. import { mapState, mapActions } from 'vuex'
  44. import { mixin, mixinDevice } from '@/utils/mixin'
  45. import config from '@/config/defaultSettings'
  46. import RouteView from './RouteView'
  47. import SideMenu from '@/components/Menu/SideMenu'
  48. import GlobalHeader from '@/components/GlobalHeader'
  49. import GlobalFooter from '@/components/GlobalFooter'
  50. // import SettingDrawer from '@/components/SettingDrawer'
  51. import { convertRoutes } from '@/utils/routeConvert'
  52. export default {
  53. name: 'BasicLayout',
  54. mixins: [mixin, mixinDevice],
  55. components: {
  56. RouteView,
  57. SideMenu,
  58. GlobalHeader,
  59. GlobalFooter
  60. // SettingDrawer
  61. },
  62. data () {
  63. return {
  64. production: config.production,
  65. collapsed: false,
  66. menus: []
  67. }
  68. },
  69. computed: {
  70. ...mapState({
  71. // 动态主路由
  72. mainMenu: state => state.permission.addRouters
  73. }),
  74. contentPaddingLeft () {
  75. if (!this.fixSidebar || this.isMobile()) {
  76. return '0'
  77. }
  78. if (this.sidebarOpened) {
  79. return '256px'
  80. }
  81. return '80px'
  82. }
  83. },
  84. watch: {
  85. sidebarOpened (val) {
  86. this.collapsed = !val
  87. }
  88. },
  89. created () {
  90. const routes = convertRoutes(this.mainMenu.find(item => item.path === '/'))
  91. this.menus = (routes && routes.children) || []
  92. this.collapsed = !this.sidebarOpened
  93. },
  94. mounted () {
  95. const userAgent = navigator.userAgent
  96. if (userAgent.indexOf('Edge') > -1) {
  97. this.$nextTick(() => {
  98. this.collapsed = !this.collapsed
  99. setTimeout(() => {
  100. this.collapsed = !this.collapsed
  101. }, 16)
  102. })
  103. }
  104. },
  105. methods: {
  106. ...mapActions(['setSidebar']),
  107. toggle () {
  108. this.collapsed = !this.collapsed
  109. this.setSidebar(!this.collapsed)
  110. triggerWindowResizeEvent()
  111. },
  112. paddingCalc () {
  113. let left = ''
  114. if (this.sidebarOpened) {
  115. left = this.isDesktop() ? '256px' : '80px'
  116. } else {
  117. left = (this.isMobile() && '0') || ((this.fixSidebar && '80px') || '0')
  118. }
  119. return left
  120. },
  121. menuSelect () {
  122. },
  123. drawerClose () {
  124. this.collapsed = false
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="less" scoped>
  130. /*
  131. * The following styles are auto-applied to elements with
  132. * transition="page-transition" when their visibility is toggled
  133. * by Vue.js.
  134. *
  135. * You can easily play with the page transition by editing
  136. * these styles.
  137. */
  138. .page-transition-enter {
  139. opacity: 0;
  140. }
  141. .page-transition-leave-active {
  142. opacity: 0;
  143. }
  144. .page-transition-enter .page-transition-container,
  145. .page-transition-leave-active .page-transition-container {
  146. -webkit-transform: scale(1.1);
  147. transform: scale(1.1);
  148. }
  149. .container {
  150. flex: 1;
  151. display: flex;
  152. flex-direction: row;
  153. min-height: 87vh;
  154. max-width: 1500px;
  155. min-width: 1000px;
  156. margin: 0px auto;
  157. }
  158. @media only screen and (max-width: 1500px) {
  159. .container {
  160. max-width: 1350px;
  161. }
  162. }
  163. @media only screen and (max-width: 1400px) {
  164. .container {
  165. max-width: 1250px;
  166. }
  167. }
  168. @media only screen and (max-width: 1300px) {
  169. .container {
  170. max-width: 1150px;
  171. }
  172. }
  173. </style>